Exemplo n.º 1
1
 /**
  * Registers the module-only services
  *
  * @param Phalcon\DI $di
  */
 public function registerServices($di)
 {
     $dispatcher = $di->getDispatcher();
     $dispatcher->setDefaultNamespace('Wscn\\Controllers');
     View::registerComponent('post', 'Eva\\EvaBlog\\Components\\Post');
     View::registerComponent('search', 'Eva\\EvaBlog\\Components\\Search');
     $di->set('widget', function () {
         return new Components\Widget();
     });
 }
Exemplo n.º 2
0
 /**
  * Configuration application default DI
  *
  * @return FactoryDefault| CLI
  */
 public function getDI()
 {
     if ($this->di) {
         return $this->di;
     }
     if ($this->appMode == 'cli') {
         $di = new FactoryDefault\CLI();
     } else {
         $di = new FactoryDefault();
     }
     //PHP5.3 not support $this in closure
     $self = $this;
     /**********************************
      * DI initialize for MVC core
      ***********************************/
     //$di->set('application', $this);
     //call loadmodules will overwrite this
     $di->set('moduleManager', function () use($di) {
         $moduleManager = new ModuleManager();
         $moduleManager->setEventsManager($di->getEventsManager());
         return $moduleManager;
     }, true);
     //System global events manager
     $di->set('eventsManager', function () use($di) {
         $eventsManager = new EventsManager();
         $eventsManager->enablePriorities(true);
         // dispatch caching event handler
         $eventsManager->attach("dispatch", new DispatchInterceptor(), -1);
         $eventsManager->enablePriorities(true);
         return $eventsManager;
     }, true);
     $di->set('config', function () use($self) {
         return $self->diConfig();
     }, true);
     $di->set('router', function () use($self) {
         return $self->diRouter();
     }, true);
     $di->set('dispatcher', function () use($di) {
         $dispatcher = new Dispatcher();
         $dispatcher->setEventsManager($di->getEventsManager());
         return $dispatcher;
     }, true);
     $di->set('modelsMetadata', function () use($self) {
         return $self->diModelsMetadata();
     }, true);
     $di->set('modelsManager', function () use($di) {
         $config = $di->getConfig();
         ModelManager::setDefaultPrefix($config->dbAdapter->prefix);
         //for solving db master/slave under static find method
         $modelsManager = new ModelManager();
         return $modelsManager;
     });
     $di->set('view', function () use($di) {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->setEventsManager($di->getEventsManager());
         return $view;
     });
     $di->set('session', function () use($self) {
         return $self->diSession();
     });
     $di->set('tokenStorage', function () use($self) {
         return $self->diTokenStorage();
     }, true);
     /**********************************
      * DI initialize for database
      ***********************************/
     $di->set('dbMaster', function () use($self) {
         return $self->diDbMaster();
     }, true);
     $di->set('dbSlave', function () use($self) {
         return $self->diDbSlave();
     }, true);
     $di->set('transactions', function () use($di) {
         $transactions = new \Phalcon\Mvc\Model\Transaction\Manager();
         $transactions->setDbService('dbMaster');
         return $transactions;
     }, true);
     /**********************************
      * DI initialize for cache
      ***********************************/
     $di->set('globalCache', function () use($self) {
         return $self->diGlobalCache();
     }, true);
     $di->set('viewCache', function () use($self) {
         return $self->diViewCache();
     }, true);
     $di->set('modelsCache', function () use($self) {
         return $self->diModelsCache();
     }, true);
     $di->set('apiCache', function () use($self) {
         return $self->diApiCache();
     }, true);
     $di->set('fastCache', function () use($self) {
         return $self->diFastCache();
     }, true);
     /**********************************
      * DI initialize for queue
      ***********************************/
     $di->set('queue', function () use($di) {
         $config = $di->getConfig();
         $client = new \GearmanClient();
         $client->setTimeout(1000);
         foreach ($config->queue->servers as $key => $server) {
             $client->addServer($server->host, $server->port);
         }
         return $client;
     }, true);
     $di->set('worker', function () use($di) {
         $config = $di->getConfig();
         $worker = new \GearmanWorker();
         foreach ($config->queue->servers as $key => $server) {
             $worker->addServer($server->host, $server->port);
         }
         return $worker;
     }, true);
     /**********************************
      * DI initialize for email
      ***********************************/
     $di->set('mailer', function () use($self) {
         return $self->diMailer();
     }, true);
     $di->set('mailMessage', 'Eva\\EvaEngine\\MailMessage');
     $di->set('smsSender', function () use($self) {
         return $self->diSmsSender();
     }, true);
     /**********************************
      * DI initialize for helpers
      ***********************************/
     $di->set('url', function () use($di) {
         $config = $di->getConfig();
         $url = new UrlResolver();
         $url->setVersionFile($config->staticBaseUriVersionFile);
         $url->setBaseUri($config->baseUri);
         $url->setStaticBaseUri($config->staticBaseUri);
         return $url;
     }, true);
     $di->set('escaper', 'Phalcon\\Escaper');
     $di->set('tag', function () use($di, $self) {
         Tag::setDi($di);
         $self->registerViewHelpers();
         return new Tag();
     });
     $di->set('flash', 'Phalcon\\Flash\\Session');
     $di->set('placeholder', 'Eva\\EvaEngine\\View\\Helper\\Placeholder');
     $di->set('cookies', function () {
         $cookies = new \Phalcon\Http\Response\Cookies();
         $cookies->useEncryption(false);
         return $cookies;
     });
     $di->set('translate', function () use($self) {
         return $self->diTranslate();
     });
     $di->set('fileSystem', function () use($self) {
         return $self->diFileSystem();
     });
     $di->set('logException', function () use($di) {
         $config = $di->getConfig();
         return new FileLogger($config->logger->path . 'error.log');
     });
     if ($this->appMode == 'cli') {
         $this->cliDI($di);
     }
     IoC::setDI($di);
     return $this->di = $di;
 }
Exemplo n.º 3
0
 /**
  * Registers the module-only services
  *
  * @param Phalcon\DI $di
  */
 public function registerServices($di)
 {
     $dispatcher = $di->getDispatcher();
     $dispatcher->setDefaultNamespace('WscnGold\\Controllers');
     View::registerComponent('post', 'Eva\\EvaBlog\\Components\\Post');
 }
Exemplo n.º 4
0
 public static function component($componentName, array $params = array())
 {
     return Mvc\View::getComponent($componentName, $params);
 }