Example #1
0
 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();
 }
 /**
  * Get a reference to the DBAL connection with the given name.
  * If the connection name is not provided, this method will try to use the
  * default connection as mentionned in the config file.
  *
  * @param string $connectionName
  * @return \Doctrine\DBAL\Connection
  */
 public function getConnection($connectionName = null)
 {
     if ($connectionName === null) {
         $connectionName = ConfigManager::get('datasources.default');
     }
     if (!array_key_exists($connectionName, self::$connections)) {
         $config = new Configuration();
         $connectionParams = ConfigManager::get('datasources.list.' . $connectionName);
         self::$connections[$connectionName] = DriverManager::getConnection($connectionParams, $config);
     }
     return self::$connections[$connectionName];
 }
Example #3
0
 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];
 }
 public function getEntityManager($datasourceName = null)
 {
     if ($datasourceName === null) {
         $datasourceName = ConfigManager::get('database.default');
     }
     try {
         if (self::$locator === null || self::$locator->config()->connection() === false) {
             $connectionParams = ConfigManager::get('database.list.' . $datasourceName);
             self::$config->addConnection($datasourceName, $connectionParams);
             if (self::$locator === null) {
                 self::$locator = new Locator(self::$config);
             } else {
                 self::$locator->config(self::$config);
             }
         }
     } catch (Exception $e) {
         throw new \RuntimeException('Unknown "' . $datasourceName . '" entity manager.');
     }
     return self::$locator;
 }
 /**
  * Load app interceptors
  */
 private function loadInterceptors()
 {
     $this->logger->debug('Loading interceptors.');
     $interceptors = ConfigManager::get('interceptors');
     if (!empty($interceptors)) {
         foreach ($interceptors as $interceptorName => $config) {
             if (array_key_exists('className', $config) && !class_exists($config['className'])) {
                 throw new \RuntimeException('Unable to load "' . $interceptorName . '" service: class not found.');
             }
             $reflectionClass = new \ReflectionClass($config['className']);
             if (!$reflectionClass->implementsInterface('Panda\\Core\\Interceptor\\HandlerInterceptor')) {
                 throw new \RuntimeException('Unable to load "' . $interceptorName . '" interceptor: class doesn\'t
                 implement HandlerInterceptor interface.');
             }
             unset($config['className']);
             $this->services[$interceptorName] = $reflectionClass->newInstanceArgs($config);
         }
     }
 }