/** * Sets the default namespace for the dispatcher * to locate controllers in. * * @param PhalconDispatcher $dispatcher * @return void */ protected function setDefaultNamespace(MVCDispatcher $dispatcher) { if ($this->di->has('module')) { if ($this->di->getService('module')->isResolved()) { return $dispatcher->setDefaultNamespace($this->di->get('module')->getControllerNamespace()); } } $config = $this->di->get('config'); if (isset($config['namespaces']['controllers'])) { return $dispatcher->setDefaultNamespace($config['namespaces']['controllers']); } throw new Exception('Controller namespace not specified.'); }
public function beforeDispatchLoop(Event $event, Dispatcher $dispatcher) { if (!$this->auth->logged_in() && $this->router->getActionName() != 'login' && $this->router->getControllerName() != 'rotator') { $dispatcher->setReturnedValue($this->response->redirect('login')); return false; } if ($this->router->getControllerName() != 'rotator') { if ($this->auth->logged_in('admin')) { $dispatcher->setDefaultNamespace('App\\Controllers\\Admin'); } elseif ($this->auth->logged_in('advertiser')) { $dispatcher->setDefaultNamespace('App\\Controllers\\Advertiser'); } } return true; }
/** * 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]); }); }
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; }; }
/** * {@inheridoc}. */ public function register() { $dispatcher = new MvcDispatcher(); $dispatcher->setDefaultNamespace('App\\Controllers'); $dispatcher->setActionSuffix($this->getActionSuffix()); return $dispatcher; }
/** * 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'; }
/** * 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', new \Plugins\Dispatcher\NotFoundPlugin()); $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']['viewsBack'])->setMainView('auth-layout')->setPartialsDir('partials'); return $view; }); require_once APP_PATH . '/Modules/' . self::MODULE . '/config/services.php'; // call profiler if ($this->_config->database->profiler === true) { new \Plugins\Debugger\Develop($di); } if (APPLICATION_ENV == 'development') { // share Fabfuel topbar $profiler = new \Fabfuel\Prophiler\Profiler(); $di->setShared('profiler', $profiler); $pluginManager = new \Fabfuel\Prophiler\Plugin\Manager\Phalcon($profiler); $pluginManager->register(); // add toolbar in your basic BaseController } return; }
/** * Register specific services for the module */ function registerServices(\Phalcon\DiInterface $di) { //Registering a dispatcher $di->set('dispatcher', function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace('Modules\\Frontend\\Controllers'); return $dispatcher; }); $config = $di->getShared('config'); $di->set('view', function () use($config, $di) { $view = new View(); $router = $di->getShared('router'); /* * @todo 给layouts等目录统一变量 * */ $view->setViewsDir(__DIR__ . '/views/'); $view->setLayoutsDir('/../../../layouts/'); // 多模块的话, 可能会有多个风格,所以需要切换layout,这里的Path是根据当前module的Path向上走的 $view->setLayout('index'); $view->registerEngines(array('.volt' => function ($view, $di) use($config) { $volt = new VoltEngine($view, $di); $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_')); return $volt; }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php')); return $view; }, true); }
public function registerServices(\Phalcon\DiInterface $di = null) { /** * Read configuration */ $config = (include dirname(dirname(dirname(__DIR__))) . "/apps/config/config.php"); $di->set('dispatcher', function () use($di) { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace('Modules\\Frontend\\Controllers'); return $dispatcher; }, true); $di->set('view', function () use($config) { $view = new View(); $view->setViewsDir(__DIR__ . '/views/'); $view->registerEngines(array('.volt' => function ($view, $di) use($config) { $volt = new VoltEngine($view, $di); $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_')); return $volt; }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php')); return $view; }); /** * Database connection is created based in the parameters defined in the configuration file */ $di['db'] = function () use($config) { return new DbAdapter(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, 'charset' => 'utf8')); }; }
/** * Registers the module-only services * * @param Phalcon\DI $di */ public function registerServices($di) { /** * Read configuration */ $config = (include __DIR__ . "/config/config.php"); $di['dispatcher'] = function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace("Test\\Backend\\Controllers"); return $dispatcher; }; //Register Volt as a service $di['voltService'] = function ($view, $di) { $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di); $volt->setOptions(array("compiledPath" => "../cache/compiled-templates/", "compiledExtension" => ".compiled", "compileAlways" => true)); return $volt; }; /** * Setting up the view component */ $di['view'] = function () { $view = new View(); $view->setViewsDir(__DIR__ . '/views/default/'); $view->registerEngines(array(".volt" => 'voltService')); return $view; }; /** * Database connection is created based in the parameters defined in the configuration file */ $di['db'] = function () use($config) { return new DbAdapter(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname)); }; }
public function registerServices(DiInterface $di) { global $config; $di->setShared('url', function () use($config) { $url = new UrlResolver(); $url->setBaseUri($config->backend->baseUri); return $url; }); $di->setShared('dispatcher', function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace("Multiple\\Backend\\Controllers"); return $dispatcher; }); $di->setShared('view', function () use($config) { $view = new View(); $view->setViewsDir($config->backend->viewsDir); $view->setLayoutsDir('layouts/'); $view->setPartialsDir('partials/'); $view->registerEngines(array('.phtml' => function ($view, $di) use($config) { $volt = new VoltEngine($view, $di); $volt->setOptions(array('compiledPath' => $config->backend->cacheDir, 'compiledSeparator' => '_')); return $volt; }, '.volt' => 'Phalcon\\Mvc\\View\\Engine\\Php')); return $view; }); }
/** * Register specific services for the module * @param \Phalcon\DiInterface $di */ public function registerServices(DiInterface $di) { $config = $this->_config; $configShared = $di->get('config'); $vDI = $di; //Registering a dispatcher $di->set('dispatcher', function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace('Cnab'); return $dispatcher; }); //Registering the view component $di->set('volt', function ($view, $vDI) use($config, $configShared) { $volt = new Volt($view, $vDI); $volt->setOptions(array('compiledPath' => $configShared->volt->path, 'compiledExtension' => $configShared->volt->extension, 'compiledSeparator' => $configShared->volt->separator, 'stat' => (bool) $configShared->volt->stat)); $compiler = $volt->getCompiler(); //Add funcao $compiler->addFunction('is_a', 'is_a'); return $volt; }); /** * Configura o serviço de view */ $di->set('view', function () use($config, $vDI) { $view = new View(); $view->setViewsDir($config->application->viewsDir); $view->registerEngines(array('.volt' => 'volt')); return $view; }); return $di; }
/** * Register specific services for the module */ public function registerServices(DiInterface $di) { $config = $di->get('config'); //Registering a dispatcher $di->set('dispatcher', function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace("Promoziti\\Modules\\Business\\Controllers"); return $dispatcher; }); $di->set('view', function () { $view = new View(); $view->setViewsDir(__DIR__ . '/views/'); $view->registerEngines(array('.volt' => function ($view, $di) { $volt = new VoltEngine($view, $di); $config = $di->get('config'); $volt->setOptions(array('compileAlways' => true, 'compiledPath' => $config->application->cache_dir . "volt/", 'compiledSeparator' => '_')); return $volt; })); return $view; }); $di->set('aws_s3', function () use($config) { //version 2.7 style $s3 = \Aws\S3\S3Client::factory(array('key' => $config->application->security->aws->key, 'secret' => $config->application->security->aws->secret, 'region' => 'us-west-2', 'version' => '2006-03-01')); return $s3; }); }
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; }); }
/** * Register specific services for the module */ public function registerServices(DiInterface $di) { // Assign our new tag a definition so we can call it $di->set('Utilitarios', function () { return new \Ecommerce\Admin\Helpers\UtilitariosHelper(); }); $di->set('dispatcher', function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace('Ecommerce\\Admin\\Controllers'); return $dispatcher; }); // Registering the view component $di->set('view', function () { $config = (include __DIR__ . "/config/config.php"); $view = new View(); $view->registerEngines(array('.volt' => function ($view, $di) use($config) { $volt = new VoltEngine($view, $di); $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_')); return $volt; }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php')); $view->setViewsDir('../apps/admin/views/'); return $view; }); include "../apps/admin/vendor/autoload.php"; }
/** * 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 . '/'); }
/** * @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; }); }
public function registerServices(DiInterface $di) { /** * Read configuration */ $config = (include __DIR__ . "/config/config.php"); $di['dispatcher'] = function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace("Modules\\Backend\\Controllers"); return $dispatcher; }; /** * Setting up the view component */ $di['view'] = function () { $view = new View(); $view->setViewsDir(__DIR__ . '/views/'); $view->setLayoutsDir('../../common/layouts/backend/'); $view->setTemplateAfter('main'); return $view; }; /** * Database connection is created based in the parameters defined in the configuration file */ $di['db'] = function () use($config) { return new MySQLAdapter(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name)); }; }
/** * 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; }); }
public function registerServices(DiInterface $di) { $di['dispatcher'] = function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace(self::$ctrlnamespace); return $dispatcher; }; }
public function register() { $app = $this->getConfig('loader.default_namespace'); $namespace = sprintf("%s\\%s", $app, self::CONTROLLER_NS); $dispatcher = new MvcDispatcher(); $dispatcher->setDefaultNamespace($namespace); return $dispatcher; }
/** * 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); }); }
public function registerServices(DiInterface $di) { //Registering a dispatcher $di->set('dispatcher', function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace($this->modulename() . '\\Controllers\\'); return $dispatcher; }); }
/** * 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()); }); }
/** * 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; }); }
/** * set the default dispatcher for the hrm module * * @return PhDispatcher */ protected function getDispatcher() { $dispatcher = new PhDispatcher(); /*$eventManager = new Manager(); $eventManager->attach('dispatch', new \Acl('frontend')); $dispatcher->setEventsManager($eventManager);*/ $dispatcher->setDefaultNamespace('app\\hrm\\controllers'); return $dispatcher; }
/** * Регистрация специфичных сервисов для модуля * @param DiInterface $di */ public function registerServices(DiInterface $di) { // Регистрация диспетчера $di->set('dispatcher', function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace("Multiple\\Inspector\\Controllers"); return $dispatcher; }); $view = $di->get("view"); $view->setViewsDir(__DIR__ . "/views/"); }
/** * Register services used by the backend application * * @param $di */ public function registerServices($di) { $config = $this->config(); /** * register the dispatcher */ $di->set('dispatcher', function () { $dispatcher = new Dispatcher(); /*$eventManager = new Manager(); $eventManager->attach('dispatch', new \Acl('backend')); $dispatcher->setEventsManager($eventManager);*/ $dispatcher->setDefaultNamespace('app\\backend\\controllers'); return $dispatcher; }); /** * The URL component is used to generate all kind of urls in the application */ $di->set('url', function () use($config) { $url = new UrlResolver(); $url->setBaseUri($config->application->baseUri); return $url; }, true); $di->setShared('view', function () use($config) { $view = new View(); $view->setViewsDir($config->application->viewsDir); $view->registerEngines(['.volt' => function ($view, $di) use($config) { $volt = new VoltEngine($view, $di); $volt->setOptions(['compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_']); return $volt; }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php']); return $view; }); /** * Database connection is created based in the parameters defined in the configuration file */ $di->set('db', function () use($config) { return new MysqlAdapter($config->database->toArray()); }); /** * If the configuration specify the use of metadata adapter use it or use memory otherwise */ $di->set('modelsMetadata', function () { return new MetaDataAdapter(); }); /** * Start the session the first time some component request the session service */ $di->setShared('session', function () { $session = new SessionAdapter(); $session->start(); return $session; }); }
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; }); }
public function registerServices(DiInterface $di) { // $di->setShared('view', function(){ // $view = new View; // //$view->disable(); // return $view; // }); $di['dispatcher'] = function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace("Lt\\Backend\\Controllers"); return $dispatcher; }; }