public function initDoctrine()
{
$this->register(new \Silex\Provider\DoctrineServiceProvider(), array('dbs.options' => array('default' => $this['config']['database'])));
$this->register(new \Saxulum\DoctrineOrmManagerRegistry\Silex\Provider\DoctrineOrmManagerRegistryProvider());
// プラグインのmetadata定義を合わせて行う.
$pluginConfigs = $this->getPluginConfigAll();
$ormMappings = array();
$ormMappings[] = array('type' => 'yml', 'namespace' => 'Eccube\\Entity', 'path' => array(__DIR__ . '/Resource/doctrine', __DIR__ . '/Resource/doctrine/master'));
foreach ($pluginConfigs as $code) {
$config = $code['config'];
// Doctrine Extend
if (isset($config['orm.path']) && is_array($config['orm.path'])) {
$paths = array();
foreach ($config['orm.path'] as $path) {
$paths[] = $this['config']['plugin_realdir'] . '/' . $config['code'] . $path;
}
$ormMappings[] = array('type' => 'yml', 'namespace' => 'Plugin\\' . $config['code'] . '\\Entity', 'path' => $paths);
}
}
$options = array('mappings' => $ormMappings);
if (!$this['debug']) {
$cacheDrivers = array();
if (array_key_exists('doctrine_cache', $this['config'])) {
$cacheDrivers = $this['config']['doctrine_cache'];
}
if (array_key_exists('metadata_cache', $cacheDrivers)) {
$options['metadata_cache'] = $cacheDrivers['metadata_cache'];
}
if (array_key_exists('query_cache', $cacheDrivers)) {
$options['query_cache'] = $cacheDrivers['query_cache'];
}
if (array_key_exists('result_cache', $cacheDrivers)) {
$options['result_cache'] = $cacheDrivers['result_cache'];
}
if (array_key_exists('hydration_cache', $cacheDrivers)) {
$options['hydration_cache'] = $cacheDrivers['hydration_cache'];
}
}
$this->register(new \Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider(), array('orm.proxies_dir' => __DIR__ . '/../../app/cache/doctrine/proxies', 'orm.em.options' => $options, 'orm.custom.functions.numeric' => array('EXTRACT' => 'Eccube\\Doctrine\\ORM\\Query\\Extract')));
/**
* YamlDriverのPHP7対応. Doctrine2.4で修正されれば不要.
* @see https://github.com/EC-CUBE/ec-cube/issues/1338
*/
$config = $this['orm.em']->getConfiguration();
/** @var $driver \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain */
$chain = $config->getMetadataDriverImpl();
// $ormMappingsの1要素ごとにDriverが生成されている.
$drivers = $chain->getDrivers();
foreach ($drivers as $namespace => $oldDriver) {
/** @var $newDriver \Eccube\Doctrine\ORM\Mapping\Driver\YamlDriver */
$newDriver = new YamlDriver($oldDriver->getLocator());
// 修正したDriverに差し替える. メソッド名はaddだけど実際はsetしてる.
$chain->addDriver($newDriver, $namespace);
}
}