Commit 7169ca59 authored by Avris's avatar Avris

v4.0

parent f9473033
<?php
namespace Avris\Micrus\Doctrine;
use Avris\Micrus\Controller\Routing\Model\RouteMatch;
use Avris\Micrus\Exception\NotFoundException;
use Avris\Micrus\Model\MatchProvider;
use Doctrine\ORM\EntityManager;
......@@ -13,9 +12,6 @@ class DoctrineMatchProvider implements MatchProvider
/** @var EntityManager */
private $em;
// TODO remove somehow
private $i = 1; // TODO 0 normally
public function __construct(EntityManagerInterface $entityManager)
{
$this->em = $entityManager;
......@@ -36,12 +32,17 @@ class DoctrineMatchProvider implements MatchProvider
}
}
public function fetch(\ReflectionParameter $parameter, RouteMatch $routeMatch)
public function fetch(\ReflectionParameter $parameter, array &$tags)
{
if (!count($tags)) {
return null;
}
$repo = $this->em->getRepository($parameter->getClass()->getName());
$key = array_keys($routeMatch->getTags())[$this->i]; // TODO waaay nicer
$value = $routeMatch->getTags()[$key];
$value = reset($tags);
$key = key($tags);
$entity = $repo->findOneBy([$key => $value]);
if (!$entity) {
......@@ -53,7 +54,7 @@ class DoctrineMatchProvider implements MatchProvider
));
}
$this->i++;
unset($tags[$key]);
return $entity;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment