public static function register(Application $app) { $whoops = new Run(); if (ConfigManager::exists('app.display_errors') && ConfigManager::get('app.display_errors')) { $whoops->pushHandler(new PrettyPageHandler()); } else { $whoops->pushHandler(new ProdHandler($app)); } $whoops->register(); }
public function __construct(array $bundles) { if (ConfigManager::exists('router.provider')) { $providerName = ConfigManager::get('router.provider'); if ($providerName === 'Annotation') { $this->setRoutesProvider(new AnnotationRoutesProvider($bundles)); } else { if ($providerName === 'File') { $this->setRoutesProvider(new FileRoutesProvider($bundles)); } else { throw new \InvalidArgumentException('Invalid routes provider "' . $providerName . '"'); } } } else { $this->setRoutesProvider(new FileRoutesProvider($bundles)); } }
/** * @param $datasourceName * @return mixed */ public function getEntityManager($datasourceName = null) { if ($datasourceName === null) { $datasourceName = ConfigManager::get('datasources.default'); } else { if (!is_string($datasourceName) || empty($datasourceName)) { throw new \InvalidArgumentException('Invalid datasource name "' . (string) $datasourceName . '"'); } } if (!array_key_exists($datasourceName, self::$connections)) { $isDebug = ConfigManager::exists('datasources.debug') ? ConfigManager::get('datasources.debug') : false; $cacheName = ConfigManager::get('datasources.list.' . $datasourceName . '.cache'); $cacheClass = '\\Doctrine\\Common\\Cache\\' . (!empty($cacheName) ? $cacheName : 'ArrayCache'); $entityManagerConfig = Setup::createConfiguration($isDebug); //Load annotations stuff AnnotationRegistry::registerFile(VENDORS_DIR . 'doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'); $cache = new $cacheClass(); $annotationReader = new AnnotationReader(); $cachedAnnotationReader = new CachedReader($annotationReader, $cache, $isDebug); //Load event manager $this->eventManager = new EventManager(); $listenersList = ConfigManager::get('datasources.listeners'); if (!empty($listenersList)) { foreach ($listenersList as $listener) { $l = new $listener(); $this->eventManager->addEventSubscriber($l); } } //Tables prefix if (ConfigManager::exists('datasources.list.' . $datasourceName . '.prefix')) { $tablePrefix = new DoctrineTablePrefixListener(ConfigManager::get('datasources.list.' . $datasourceName . '.prefix')); $this->eventManager->addEventListener(Events::loadClassMetadata, $tablePrefix); } //Load doctrine extensions listeners if any if (!empty($listenersList) && class_exists('\\Gedmo\\DoctrineExtensions')) { $driverChain = new MappingDriverChain(); DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $cachedAnnotationReader); } $driver = new AnnotationDriver($cachedAnnotationReader, glob(APP_DIR . '*/entity')); $entityManagerConfig->setMetadataDriverImpl($driver); self::$entityManagers[$datasourceName] = EntityManager::create(ConfigManager::get('datasources.list.' . $datasourceName), $entityManagerConfig, $this->eventManager); } return self::$entityManagers[$datasourceName]; }
/** * Load a list of bundles from the configuration file */ private function loadBundles() { $this->logger->debug('Loading bundles.'); if (!ConfigManager::exists('bundles')) { throw new \RuntimeException('No bundle to load.'); } $bundles = ConfigManager::get('bundles'); foreach ($bundles as $bundle) { $bundleName = substr($bundle, strrpos($bundle, '\\') + 1); if (!class_exists($bundle . '\\' . $bundleName . 'Controller')) { throw new \RuntimeException('Unable to find a controller in "' . $bundleName . '"'); } $this->loadedBundles[$bundle] = new \ReflectionClass($bundle . '\\' . $bundleName . 'Controller'); } }