mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-05 14:53:12 +08:00
47 lines
1.7 KiB
PHP
47 lines
1.7 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Shlinkio\Shlink\Common\Factory;
|
|
|
|
use Doctrine\Common\Cache\ArrayCache;
|
|
use Doctrine\Common\Cache\Cache;
|
|
use Doctrine\ORM\EntityManager;
|
|
use Doctrine\ORM\Tools\Setup;
|
|
use Interop\Container\ContainerInterface;
|
|
use Interop\Container\Exception\ContainerException;
|
|
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
|
|
use Zend\ServiceManager\Exception\ServiceNotFoundException;
|
|
use Zend\ServiceManager\Factory\FactoryInterface;
|
|
|
|
class EntityManagerFactory implements FactoryInterface
|
|
{
|
|
/**
|
|
* Create an object
|
|
*
|
|
* @param ContainerInterface $container
|
|
* @param string $requestedName
|
|
* @param null|array $options
|
|
* @return object
|
|
* @throws ServiceNotFoundException if unable to resolve the service.
|
|
* @throws ServiceNotCreatedException if an exception is raised when creating a service.
|
|
* @throws ContainerException if any other error occurs
|
|
*/
|
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
|
|
{
|
|
$globalConfig = $container->get('config');
|
|
$isDevMode = isset($globalConfig['debug']) ? ((bool) $globalConfig['debug']) : false;
|
|
$cache = $container->has(Cache::class) ? $container->get(Cache::class) : new ArrayCache();
|
|
$emConfig = $globalConfig['entity_manager'] ?? [];
|
|
$connectionConfig = $emConfig['connection'] ?? [];
|
|
$ormConfig = $emConfig['orm'] ?? [];
|
|
|
|
return EntityManager::create($connectionConfig, Setup::createAnnotationMetadataConfiguration(
|
|
$ormConfig['entities_paths'] ?? [],
|
|
$isDevMode,
|
|
$ormConfig['proxies_dir'] ?? null,
|
|
$cache,
|
|
false
|
|
));
|
|
}
|
|
}
|