Example #1
0
 /**
  * @param ServiceManager $service
  * @throws \Exception | \PDOException
  */
 public function __construct(ServiceManager $service)
 {
     $config = $service->get('Application')->getConfig();
     if (empty($config['entity_manager'])) {
         throw new \Exception('Нет настройки \'entity_manager\' для ' . __CLASS__ . ': \'dsn\', \'username\', \'password\', \'options\'');
     }
     $config = $config['entity_manager'];
     parent::__construct(isset($config['dsn']) ? $config['dsn'] : '', isset($config['username']) ? $config['username'] : '', isset($config['username']) ? $config['password'] : '', isset($config['options']) ? $config['options'] : []);
     $this->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     $driverName = ucfirst($this->getAttribute(\PDO::ATTR_DRIVER_NAME));
     try {
         $adapterName = 'Eva\\EntityManager\\Adapter\\' . $driverName;
         $this->adapter = new $adapterName($this);
     } catch (\Exception $e) {
         throw new \Exception('Адаптер для драйвера "' . $driverName . '" не поддерживается');
     }
 }
Example #2
0
 static function configure(array $config)
 {
     $coreConfig = ['modules' => [], 'services' => ['Application' => 'Eva\\Application\\Application', 'ModuleManager' => 'Eva\\Application\\ModuleManager', 'AssetManager' => 'Eva\\Application\\AssetManager', 'EntityManager' => 'Eva\\EntityManager\\EntityManager', 'View' => 'Eva\\View\\View', 'Authentication' => 'Eva\\Authentication\\Authentication', 'Geo' => 'Eva\\Geo\\Geo', 'Sender' => 'Eva\\Sender\\Sender', 'Filter' => 'Eva\\Filter\\Filter', 'Validator' => 'Eva\\Validator\\Validator', 'FlashMessenger' => 'Eva\\FlashMessenger\\FlashMessenger', 'Router' => 'Eva\\Application\\Router', 'Request' => function ($serviceManager) {
         if (PHP_SAPI === 'cli') {
             return new Console\Request($serviceManager);
         } else {
             return new Http\Request($serviceManager);
         }
     }], 'router' => ['http' => []], 'view' => ['helper' => ['breadcrumbs' => 'Eva\\View\\Helper\\Breadcrumbs', 'identity' => 'Eva\\View\\Helper\\Identity', 'config' => 'Eva\\View\\Helper\\Config', 'form' => 'Eva\\Form\\View\\Helper\\Form', 'url' => 'Eva\\View\\Helper\\Url', 'grid' => 'Eva\\Grid\\View\\Helper\\Grid', 'nav' => 'Eva\\View\\Helper\\Nav', 'navigation' => 'Eva\\View\\Helper\\Navigation', 'listGroup' => 'Eva\\View\\Helper\\ListGroup', 'flashMessages' => 'Eva\\FlashMessenger\\View\\Helper\\FlashMessages']], 'sender' => ['from_email' => null, 'from_email_name' => null]];
     $config = array_replace_recursive($coreConfig, $config);
     $serviceManager = new ServiceManager($config['services']);
     /** @var Application $application */
     $application = $serviceManager->get('Application');
     $application->setConfig($config);
     $serviceManager->get('ModuleManager');
     $serviceManager->get('AssetManager');
     return $application;
 }