本文整理汇总了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);
}
示例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';
}
示例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]);
});
}
示例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;
};
}
示例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;
});
}
示例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;
});
}
示例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();
}
示例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 . '/');
}
示例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;
});
}
示例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);
});
}
示例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());
});
}
示例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;
});
}
示例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;
});
}
示例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;
});
}
示例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;
});
}