当前位置: 首页>>代码示例>>PHP>>正文


PHP Dispatcher::setEventsManager方法代码示例

本文整理汇总了PHP中Phalcon\Mvc\Dispatcher::setEventsManager方法的典型用法代码示例。如果您正苦于以下问题:PHP Dispatcher::setEventsManager方法的具体用法?PHP Dispatcher::setEventsManager怎么用?PHP Dispatcher::setEventsManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phalcon\Mvc\Dispatcher的用法示例。


在下文中一共展示了Dispatcher::setEventsManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUpDispatcher

 private function setUpDispatcher()
 {
     $this->dispatcher->setControllerName($this->router->getControllerName());
     $this->dispatcher->setActionName($this->router->getActionName());
     $this->dispatcher->setParams($this->router->getParams());
     $oDispatcherEventManager = new Manager();
     $oDispatcherEventManager->attach('dispatch:beforeDispatch', function (Event $oEvent, Dispatcher $oDispatcher, $data) {
         return false;
     });
     $this->dispatcher->setEventsManager($oDispatcherEventManager);
 }
开发者ID:rcmonitor,项目名称:abboom_phalcon_code_example,代码行数:11,代码来源:DefaultDispatcherTest.php

示例2: registerServices

 /**
  * Registration services for specific module
  * @param \Phalcon\DI $di
  * @access public
  * @return mixed
  */
 public function registerServices($di)
 {
     // Dispatch register
     $di->set('dispatcher', function () use($di) {
         $eventsManager = $di->getShared('eventsManager');
         $eventsManager->attach('dispatch:beforeException', function ($event, $dispatcher, $exception) {
             switch ($exception->getCode()) {
                 case \Phalcon\Mvc\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                 case \Phalcon\Mvc\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                     $dispatcher->forward(['module' => self::MODULE, 'namespace' => 'Modules\\' . self::MODULE . '\\Controllers\\', 'controller' => 'error', 'action' => 'notFound']);
                     return false;
                     break;
                 default:
                     $dispatcher->forward(['module' => self::MODULE, 'namespace' => 'Modules\\' . self::MODULE . '\\Controllers\\', 'controller' => 'error', 'action' => 'uncaughtException']);
                     return false;
                     break;
             }
         });
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setEventsManager($eventsManager);
         $dispatcher->setDefaultNamespace('Modules\\' . self::MODULE . '\\Controllers');
         return $dispatcher;
     }, true);
     // Registration of component representations (Views)
     $di->set('view', function () {
         $view = new View();
         $view->setViewsDir($this->_config['application']['viewsFront'])->setMainView('layout');
         return $view;
     });
     return require_once APP_PATH . '/Modules/' . self::MODULE . '/config/services.php';
 }
开发者ID:stanislav-web,项目名称:phalcon-development,代码行数:37,代码来源:Module.php

示例3: registerServices

 /**
  * Registers the module-only services
  *
  * @param \Phalcon\DiInterface $di
  */
 public function registerServices($di)
 {
     /**
      * Read application wide and module only configurations
      */
     $appConfig = $di->get('config');
     $moduleConfig = (include __DIR__ . '/config/config.php');
     $di->set('moduleConfig', $moduleConfig);
     /**
      * The URL component is used to generate all kind of urls in the application
      */
     $di->set('url', function () use($appConfig) {
         $url = new UrlResolver();
         $url->setBaseUri($appConfig->application->baseUri);
         return $url;
     });
     /**
      * Module specific dispatcher
      */
     $di->set('dispatcher', function () use($di) {
         $dispatcher = new Dispatcher();
         $dispatcher->setEventsManager($di->getShared('eventsManager'));
         $dispatcher->setDefaultNamespace('App\\Modules\\Oauth\\');
         return $dispatcher;
     });
     /**
      * Module specific database connection
      */
     $di->set('db', function () use($appConfig) {
         return new DbAdapter(['host' => $moduleConfig->database->host, 'username' => $moduleConfig->database->username, 'password' => $moduleConfig->database->password, 'dbname' => $moduleConfig->database->name]);
     });
 }
开发者ID:sarahsampan,项目名称:compare-api,代码行数:37,代码来源:Module.php

示例4: registerServices

 public function registerServices(DiInterface $di)
 {
     $di['dispatcher'] = function () {
         $eventsManager = new \Phalcon\Events\Manager();
         //Attach a listener
         $eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
             //controller or action doesn't exist
             if ($exception instanceof \Phalcon\Mvc\Dispatcher\Exception) {
                 $dispatcher->forward(array('controller' => 'error', 'action' => 'error404'));
                 return false;
             }
             switch ($exception->getCode()) {
                 case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                 case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                     $dispatcher->forward(array('controller' => 'error', 'action' => 'error404'));
                     return false;
             }
         });
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace("Modules\\Frontend\\Controllers");
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     };
     $di['view'] = function () {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->setLayoutsDir('../../common/layout_frontend/');
         return $view;
     };
 }
开发者ID:OwLoop,项目名称:Fresh,代码行数:30,代码来源:Module.php

示例5: registerServices

 public function registerServices($di)
 {
     $config = $di->get('config');
     /**
      * Set multiple cache
      */
     $di->set('cache', function () use($config) {
         if (false === is_dir(ROOT . DS . 'cache' . DS . 'data_cache' . DS . date('Ym'))) {
             mkdir(ROOT . DS . 'cache' . DS . 'data_cache' . DS . date('Ym'), 0755, true);
         }
         return new FileCache(new DataFrontend(array('lifetime' => 3600)), array('prefix' => 'bountyHunterCache.', 'cacheDir' => ROOT . DS . 'cache' . DS . 'data_cache' . DS . date('Ym') . DS));
     });
     $di->set('memcache', function () use($config) {
         return new MemCached(new DataFrontend(array('lifetime' => 3600)), array('servers' => array(array('host' => $config->memcached[ENVIRONMENT]->host, 'port' => (int) $config->memcached->port, 'weight' => 1)), 'client' => array(\Memcached::OPT_HASH => \Memcached::HASH_MD5, \Memcached::OPT_PREFIX_KEY => $config->memcached->prefix, \Memcached::OPT_RECV_TIMEOUT => 1000, \Memcached::OPT_SEND_TIMEOUT => 1000, \Memcached::OPT_TCP_NODELAY => true, \Memcached::OPT_SERVER_FAILURE_LIMIT => 50, \Memcached::OPT_CONNECT_TIMEOUT => 500, \Memcached::OPT_RETRY_TIMEOUT => 300, \Memcached::OPT_DISTRIBUTION => \Memcached::DISTRIBUTION_CONSISTENT, \Memcached::OPT_REMOVE_FAILED_SERVERS => true, \Memcached::OPT_LIBKETAMA_COMPATIBLE => true), 'lifetime' => (int) $config->memcached->lifetime, 'prefix' => $config->memcached->prefix));
     });
     $di->set('dispatcher', function () use($di, $config) {
         $eventsManager = new Manager();
         $eventsManager = $di->getShared('eventsManager');
         /**
          * Middleware
          * @var Middleware
          */
         // $eventsManager->attach('dispatch', new Middleware());
         $dispatcher = new MvcDispatcher();
         $dispatcher->setEventsManager($eventsManager);
         $dispatcher->setDefaultNamespace('Lininliao\\Frontend\\Controllers\\');
         return $dispatcher;
     });
 }
开发者ID:inno-v,项目名称:LinInLiao,代码行数:29,代码来源:Module.php

示例6: registerServices

 /**
  * @param DI $di
  */
 public function registerServices($di)
 {
     //Registering a dispatcher
     $di->setShared('dispatcher', function () use($di) {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace("Admin");
         $eventsManager = $di->getShared('eventsManager');
         $eventsManager->attach('dispatch', new AdminSecurity($di));
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     $auto_admin = new \AutoAdmin\Module();
     $auto_admin->registerServices($di);
     $di->setShared('admin_views_dir', function () {
         return ADMINROOT . '/views/';
     });
     $di->setShared('session', function () {
         $session = new Session();
         $session->start();
         return $session;
     });
     $di->setShared('config', function () use($di) {
         $configFront = (require COREROOT . '/app/config/config.php');
         $configBack = (require ADMINROOT . '/config/config.php');
         $configFront->merge($configBack);
         return $configFront;
     });
 }
开发者ID:moaljazaery,项目名称:phalcon-module-admin,代码行数:31,代码来源:module.php

示例7: __construct

 /**
  * Initialize Phalcon .
  */
 public function __construct()
 {
     $executionTime = -microtime(true);
     define('APP_PATH', realpath('..') . '/');
     $this->config = $config = new ConfigIni(APP_PATH . 'app/config/config.ini');
     $this->di = new FactoryDefault();
     $this->di->set('config', $config);
     $this->di->set('dispatcher', function () {
         $eventsManager = new EventsManager();
         $eventsManager->attach('dispatch:beforeExecuteRoute', new SecurityPlugin());
         $dispatcher = new Dispatcher();
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     $this->di->set('crypt', function () use($config) {
         $crypt = new Crypt();
         $crypt->setKey($config->application->phalconCryptKey);
         return $crypt;
     });
     $this->setDisplayErrors();
     $this->title = $config->application->title;
     $this->registerDirs();
     $this->setDB($config);
     $this->setViewProvider($config);
     $this->setURLProvider($config);
     $this->setSession();
     $this->application = new Application($this->di);
     $this->application->view->executionTime = $executionTime;
     $this->setCSSCollection();
     $this->setJSCollection();
     $this->setTitle();
 }
开发者ID:joszz,项目名称:Chell-PHP-Portal,代码行数:35,代码来源:FrontController.php

示例8: registerServices

 /**
  * Register the services here to make them general or register in the
  * ModuleDefinition to make them module-specific
  */
 public function registerServices($di)
 {
     //Registering a dispatcher
     $di['dispatcher'] = function () {
         $dispatcher = new PhDispatcher();
         //Attach a event listener to the dispatcher
         $eventManager = new PhManager();
         //Notfound redirect
         // $eventManager->attach('dispatch:beforeException', function($event, $dispatcher, $exception) {
         //     //Alternative way, controller or action doesn't exist
         //     if ($event->getType() == 'beforeException') {
         //         switch ($exception->getCode()) {
         //             case PhDispatcher::EXCEPTION_HANDLER_NOT_FOUND:
         //             case PhDispatcher::EXCEPTION_ACTION_NOT_FOUND:
         //                 $dispatcher->forward([
         //                     'module' => 'common',
         //                     'controller' => 'notfound'
         //                 ]);
         //                 return false;
         //         }
         //     }
         // });
         // $eventManager->attach('dispatch', new \Fly\Authorization('mobile'));
         $dispatcher->setEventsManager($eventManager);
         $dispatcher->setDefaultNamespace('Controller\\Mobile');
         return $dispatcher;
     };
     // Load template directory
     $defaultTemplate = $di['config']->defaultTemplate;
     $di['view']->setViewsDir(ROOT_PATH . '/modules/mobile/views/' . $defaultTemplate . '/');
 }
开发者ID:aisuhua,项目名称:phalcon-jumpstart,代码行数:35,代码来源:Module.php

示例9: registerServices

 /**
  * Register the services here to make them general
  * or register in the ModuleDefinition to make them module-specific
  */
 public function registerServices(DiInterface $di)
 {
     //Read configuration
     $config = (include __DIR__ . "/config/config.php");
     // The URL component is used to generate all kind of urls in the application
     $di->set('url', function () use($config) {
         $url = new Url();
         $url->setBaseUri($config->application->baseUri);
         return $url;
     });
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         //Create/Get an EventManager
         $eventsManager = new EventsManager();
         //Attach a listener
         $eventsManager->attach('dispatch', function ($event, $dispatcher, $exception) {
             //controller or action doesn't exist
             if ($event->getType() == 'beforeException') {
                 switch ($exception->getCode()) {
                     case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                     case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                         $dispatcher->forward(['module' => 'backend', 'controller' => 'errors', 'action' => 'notFound']);
                         return false;
                 }
             }
         });
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace("Phanbook\\Backend\\Controllers");
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     /**
      * Setting up the view component
      */
     $di->set('view', function () use($config) {
         $view = new View();
         $view->setViewsDir($config->application->viewsDir);
         $view->disableLevel([View::LEVEL_MAIN_LAYOUT => true, View::LEVEL_LAYOUT => true]);
         $view->registerEngines(['.volt' => 'volt']);
         // Create an event manager
         $eventsManager = new EventsManager();
         // Attach a listener for type 'view'
         $eventsManager->attach('view', function ($event, $view) {
             if ($event->getType() == 'notFoundView') {
                 throw new \Exception('View not found!!! (' . $view->getActiveRenderPath() . ')');
             }
         });
         // Bind the eventsManager to the view component
         $view->setEventsManager($eventsManager);
         return $view;
     });
     $configMenu = (include __DIR__ . "/config/config.menu.php");
     $di->setShared('menuStruct', function () use($configMenu) {
         // if structure received from db table instead getting from $config
         // we need to store it to cache for reducing db connections
         $struct = $configMenu->get('menuStruct')->toArray();
         return $struct;
     });
 }
开发者ID:kjmtrue,项目名称:phanbook,代码行数:63,代码来源:Module.php

示例10: registerServices

 /**
  * Registers the module-only services
  *
  * @param Phalcon\DI $di
  */
 public function registerServices(\Phalcon\DiInterface $di = NULL)
 {
     /**
      * Read configuration
      */
     $config = (include __DIR__ . "/config/config.php");
     $authConfig = (include __DIR__ . "/config/authConfig.php");
     /**
      * Setting up the view component
      */
     $di->set('dispatcher', function () {
         $eventsManager = new EventsManager();
         $eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
             //Handle 404 exceptions
             if ($exception instanceof DispatchException) {
                 $dispatcher->forward(array('controller' => 'public', 'action' => 'error404'));
                 return false;
             }
             //Alternative way, controller or action doesn't exist
             if ($event->getType() == 'beforeException') {
                 switch ($exception->getCode()) {
                     case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                     case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                         $dispatcher->forward(array('controller' => 'public', 'action' => 'error404'));
                         return false;
                 }
             }
         });
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setEventsManager($eventsManager);
         $dispatcher->setDefaultNamespace("Mall\\Mall\\Controllers");
         return $dispatcher;
     });
     $di['view'] = function () {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         return $view;
     };
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di['db'] = function () use($config) {
         return new Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, "options" => array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'", \PDO::ATTR_CASE => \PDO::CASE_LOWER, \PDO::ATTR_EMULATE_PREPARES => false)));
     };
     $di->set('cookies', function () {
         $cookies = new \Phalcon\Http\Response\Cookies();
         $cookies->useEncryption(false);
         return $cookies;
     });
     $di->set('authConfig', function () use($authConfig) {
         return $authConfig;
     });
     $di->set('casLoginUrl', function () {
         $config = (include __DIR__ . "/../utils/cas/config/webpcConfig.php");
         $backurl = $config['domain'] . '/index/vali?forward=' . $config['domain'] . $_SERVER['REQUEST_URI'];
         return $config['loginUrl'] . '?siteid=' . $config['siteid'] . '&backurl=' . urlencode($backurl);
     });
 }
开发者ID:nicklos17,项目名称:littlemall,代码行数:63,代码来源:Module.php

示例11: registerServices

 /**
  * Registers services related to the module
  *
  * @param DiInterface $dependencyInjector
  */
 public function registerServices(DiInterface $dependencyInjector)
 {
     /**
      * Read configuration
      */
     $config = (include __DIR__ . "/config/config.php");
     /**
      * Registering a dispatcher
      */
     $dependencyInjector->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('Frontend\\Controllers');
         /**
          * Not-found action or handler
          */
         $eventsManager = new EventsManager();
         $eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
             switch ($exception->getCode()) {
                 case Dispatcher::EXCEPTION_CYCLIC_ROUTING:
                 case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                 case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                     $dispatcher->forward(['controller' => 'about', 'action' => 'error']);
                     return false;
             }
         });
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     /**
      * Setting up the view component
      */
     $dependencyInjector->set('view', function () {
         $view = new View();
         $view->registerEngines(array('.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         $view->setViewsDir(__DIR__ . '/views/');
         return $view;
     });
     $dependencyInjector->set('viewCache', function () use($config) {
         //Cache data for one day by default
         $frontCache = new OutputFrontend(array("lifetime" => 86400));
         //File connection settings
         $cache = new FileBackend($frontCache, array('cacheDir' => STATIC_PATH . '/'));
         return $cache;
     });
     $dependencyInjector->set('cookies', function () {
         $cookies = new Cookies();
         $cookies->useEncryption(false);
         return $cookies;
     });
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $dependencyInjector->set('db', function () use($config) {
         return new DbAdapter($config->database->toArray());
     });
 }
开发者ID:xw716825,项目名称:work,代码行数:61,代码来源:Module.php

示例12: registerServices

 /**
  * Registers the module-only services
  *
  * @param Phalcon\DI $di
  */
 public function registerServices(\Phalcon\DiInterface $di = NULL)
 {
     /**
      * Read configuration
      */
     $config = (include __DIR__ . "/config/config.php");
     $sdkconfig = (include __DIR__ . "/config/sdkConfig.php");
     /**
      * Setting up the view component
      */
     $di['view'] = function () {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         return $view;
     };
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di['db'] = function () use($config) {
         return new Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, "options" => array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'", \PDO::ATTR_CASE => \PDO::CASE_LOWER)));
     };
     /**
      * Setting up the view component
      */
     $di->set('dispatcher', function () {
         $eventsManager = new EventsManager();
         $eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
             //Handle 404 exceptions
             if ($exception instanceof DispatchException) {
                 $dispatcher->forward(array('controller' => 'public', 'action' => 'error404'));
                 return false;
             }
             //Alternative way, controller or action doesn't exist
             if ($event->getType() == 'beforeException') {
                 switch ($exception->getCode()) {
                     case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                     case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                         $dispatcher->forward(array('controller' => 'public', 'action' => 'error404'));
                         return false;
                 }
             }
         });
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setEventsManager($eventsManager);
         $dispatcher->setDefaultNamespace("Ucenter\\Webpc\\Controllers");
         return $dispatcher;
     });
     $di['sdkconfig'] = function () use($sdkconfig) {
         return $sdkconfig;
     };
     $di->set('cookies', function () {
         $cookies = new \Phalcon\Http\Response\Cookies();
         $cookies->useEncryption(false);
         return $cookies;
     });
 }
开发者ID:nicklos17,项目名称:ucenter,代码行数:61,代码来源:Module.php

示例13: registerDispatcher

 protected function registerDispatcher()
 {
     $this->di->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('Cronmonitor\\Controllers');
         $eventsManager = new \Phalcon\Events\Manager();
         $eventsManager->attach('dispatch:beforeExecuteRoute', new Security());
         $eventsManager->attach('dispatch:beforeException', new NotFound());
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
 }
开发者ID:bilna-dev,项目名称:monitoring-tools,代码行数:12,代码来源:AppServiceProvider.php

示例14: onBoot

 public function onBoot()
 {
     // TODO: Implement onBoot() method.
     $this->getDI()->setShared('dispatcher', function () {
         $di = $this->getDI();
         $em = $di->getEventsManager();
         $em->attach('dispatch', new DispatchListener());
         $dispatcher = new Dispatcher();
         $dispatcher->setDI($di);
         $dispatcher->setEventsManager($em);
         return $dispatcher;
     });
 }
开发者ID:dotronglong,项目名称:phalcon-engine,代码行数:13,代码来源:ServiceRegister.php

示例15: boot

 public function boot(Container $container)
 {
     // As of phalcon 3, definition will bind to di by default
     $container->setShared('dispatcher', function () {
         $eventsManager = $this->getShared('eventsManager');
         $eventsManager->attach('dispatch', new \Pails\Plugins\CustomRender());
         $dispatcher = new PhalconDispatcher();
         $dispatcher->setEventsManager($eventsManager);
         $dispatcher->setDefaultNamespace('App\\Controllers');
         $dispatcher->setModelBinding(true);
         return $dispatcher;
     });
 }
开发者ID:xueron,项目名称:pails,代码行数:13,代码来源:Dispatcher.php


注:本文中的Phalcon\Mvc\Dispatcher::setEventsManager方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。