Commit faf59f6a authored by Avris's avatar Avris

v4.0

parent d4624b66
Avris\Micrus\Doctrine\:
dir: '%MODULE_DIR%/src/'
exclude:
- '#^DoctrineUserProvider$#'
Avris\Micrus\Doctrine\Doctrine:
params:
- '@config.database'
- '%APP_DEBUG%'
- '%PROJECT_DIR%/var/cache/{@env}/doctrine'
- '#module'
- '@Psr\Log\LoggerInterface'
- '@?doctrineCache'
arguments:
$connection: '@config.database'
$proxyDir: '%PROJECT_DIR%/var/cache/{@env}/doctrine'
$cache: '@?doctrineCache'
# TODO userProvider: Avris\Micrus\Doctrine\DoctrineUserProvider
userProvider:
class: Avris\Micrus\Doctrine\DoctrineUserProvider
params: ['@Avris\Micrus\Doctrine\Doctrine']
Doctrine\ORM\EntityManagerInterface:
resolve: '@Avris\Micrus\Doctrine\Doctrine.entityManager'
......@@ -22,7 +22,7 @@ class Doctrine implements ParametersProvider, EventSubscriberInterface
public function __construct(
Bag $connection,
bool $debug,
bool $envAppDebug,
string $proxyDir,
array $modules,
LoggerInterface $logger,
......@@ -36,7 +36,7 @@ class Doctrine implements ParametersProvider, EventSubscriberInterface
}
}
$config = Setup::createAnnotationMetadataConfiguration($dirs, $debug, $proxyDir, $cache, false);
$config = Setup::createAnnotationMetadataConfiguration($dirs, $envAppDebug, $proxyDir, $cache, false);
$config->setSQLLogger(new DoctrineLogger($logger));
$this->entityManager = EntityManager::create($connection->all(), $config);
......
<?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;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\MappingException;
class DoctrineAutomatcher // implements Something
class DoctrineMatchProvider implements MatchProvider
{
/** @var EntityManager */
private $em;
// TODO remove somehow
private $i = 0;
public function __construct(EntityManagerInterface $entityManager)
{
$this->em = $entityManager;
}
public function supports(string $className)
public function supports(\ReflectionParameter $parameter): bool
{
if (!$parameter->getClass()) {
return false;
}
try {
$this->em->getClassMetadata($className);
$this->em->getClassMetadata($parameter->getClass()->getName());
return true;
} catch (MappingException $e) {
......@@ -27,21 +36,25 @@ class DoctrineAutomatcher // implements Something
}
}
public function fetch(string $className, string $key, $value)
public function fetch(\ReflectionParameter $parameter, RouteMatch $routeMatch)
{
$repo = $this->em->getRepository($className);
$repo = $this->em->getRepository($parameter->getClass()->getName());
$object = $repo->findOneBy([$key => $value]);
$key = array_keys($routeMatch->getTags())[$this->i]; // TODO waaay nicer
$value = $routeMatch->getTags()[$key];
$entity = $repo->findOneBy([$key => $value]);
if (!$object) {
if (!$entity) {
throw new NotFoundException(sprintf(
'Cannot find an object of type "%s" with %s=%s',
$className,
'Cannot find an entity of type "%s" with %s=%s',
$parameter->getClass()->getName(),
$key,
$value
));
}
return $object;
$this->i++;
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