/** * Registers the module-only services * * @param Phalcon\DI $di */ public function registerServices(\Phalcon\DiInterface $di) { /** * Read configuration */ /** * Setting up the view component */ $config = $this->config; $di->set('view', function () use($config) { $view = new View(); $view->setViewsDir($config->application->backendViewsDir); $view->registerEngines(array(".volt" => 'volt')); return $view; }, true); /** * Setting up volt */ $di->set('volt', function ($view, $di) use($config) { $volt = new Volt($view, $di); $volt->setOptions(array("compiledPath" => APP_PATH . "/app/cache/volt/", "compiledSeparator" => "_", "compileAlways" => $config->application->debug)); $volt->getCompiler()->addFunction('tr', function ($key) { return "messetool\\Modules\\Modules\\Backend\\Controllers\\ControllerBase::translate({$key})"; }); $volt->getCompiler()->addFunction('number_format', function ($resolvedArgs) { return 'number_format(' . $resolvedArgs . ')'; }); $volt->getCompiler()->addFunction('linkAllowed', function ($args) { return "messetool\\Acl\\Acl::linkAllowed({$args})"; }); return $volt; }, true); }
/** * 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); }
/** * 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]); }); }
/** * 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; }
/** * Registers the module-only services * * @param Phalcon\DI $di */ public function registerServices(\Phalcon\DiInterface $di = NULL) { /** * Read configuration */ $config = (include __DIR__ . "/config/config.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, \PDO::ATTR_EMULATE_PREPARES => false))); }; $di->set('dispatcher', function () { $dispatcher = new \Phalcon\Mvc\Dispatcher(); $dispatcher->setDefaultNamespace("Mall\\Admin\\Controllers"); return $dispatcher; }); $di->set('cookies', function () { $cookies = new \Phalcon\Http\Response\Cookies(); $cookies->useEncryption(false); return $cookies; }); }
/** * Registers services related to the module * * @param DiInterface $di */ public function registerServices(DiInterface $di) { /** * Read common configuration */ $config = $di->has('config') ? $di->getShared('config') : null; /** * Try to load local configuration */ if (file_exists(__DIR__ . '/config/config.php')) { $override = new Config(include __DIR__ . '/config/config.php'); if ($config instanceof Config) { $config->merge($override); } else { $config = $override; } } /** * Setting up the view component */ $view = $di->get('view'); $view->setViewsDir($config->get('application')->viewsDir); $di->set('view', $view); // add default namespace $dispatcher = $di->get('dispatcher'); $dispatcher->setDefaultNamespace("Application\\Frontend\\Controllers"); $di->set('dispatcher', $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"; }
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')); }; }
/** * 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; }); }
/** * Register specific services for the module * * @package base-app * @version 2.0 * * @param object $di dependency Injector * * @return void */ public function registerServices(\Phalcon\DiInterface $di) { //Registering a dispatcher $di->set('dispatcher', function () { //Create/Get an EventManager $eventsManager = new \Phalcon\Events\Manager(); //Attach a listener $eventsManager->attach("dispatch", function ($event, $dispatcher, $exception) { //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' => 'index', 'action' => 'notFound')); return false; } } }); $dispatcher = new \Phalcon\Mvc\Dispatcher(); //Set default namespace to documentation module $dispatcher->setDefaultNamespace("Baseapp\\Documentation\\Controllers"); //Bind the EventsManager to the dispatcher $dispatcher->setEventsManager($eventsManager); return $dispatcher; }); //Registering the view component $di->set('view', function () use($di) { $view = new \Phalcon\Mvc\View(); $view->setViewsDir(__DIR__ . '/views/'); $view->registerEngines(\Baseapp\Library\Tool::registerEngines($view, $di)); return $view; }); }
/** * 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; }); }
/** * Returns an associative array with the data about the user. * Fields array described in the method Init::setFields * * @example <code> * $this->getUser(); * </code> * * @return boolean|array data provided by the ISP authentication */ public function getUser() { if ($this->user === false) { $this->session->remove(self::KEY); $this->session->set(self::KEY, parent::getUser()); } return $this->user; }
/** * 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); }); }
/** * 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; }); }
/** * Registers services related to the module * * @param DiInterface $di */ public function registerServices(DiInterface $di) { /** * Read configuration */ $config = (include APP_PATH . "/apps/backend/config/config.php"); /** * Setting up the view component */ $di['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' => __DIR__ . '/cache/', 'compiledSeparator' => '_')); $compiler = $volt->getCompiler(); // format number $compiler->addFilter('number', function ($resolvedArgs) { return 'Helpers::number(' . $resolvedArgs . ');'; }); 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) { $config = $config->database->toArray(); $dbAdapter = '\\Phalcon\\Db\\Adapter\\Pdo\\' . $config['adapter']; unset($config['adapter']); return new $dbAdapter($config); }; /** * Logger service */ $di->set('logger', function ($filename = null, $format = null) use($config) { $format = $format ?: $config->get('logger')->format; $filename = trim($filename ?: $config->get('logger')->filename, '\\/'); $path = rtrim($config->get('logger')->path, '\\/') . DIRECTORY_SEPARATOR; $formatter = new FormatterLine($format, $config->get('logger')->date); $logger = new FileLogger($path . $filename); $logger->setFormatter($formatter); $logger->setLogLevel($config->get('logger')->logLevel); return $logger; }); $di->set('url', function () use($config) { $url = new UrlResolver(); $url->setBaseUri("/backend/"); return $url; }); }
/** * @param DiInterface $di */ public function registerServices(DiInterface $di) { // Регистрация диспетчера $di->set('dispatcher', function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace("Multiple\\Rest\\Controllers"); return $dispatcher; }); // Регистрация компонента представлений $view = $di->get("view"); $view->setViewsDir('../app/rest/views/'); $di->set('view', $view); }
/** * 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"; //Registering a dispatcher $di->set('dispatcher', function () { $eventsManager = new EventsManager(); $eventsManager->attach("dispatch", function ($event, $dispatcher, $exception) { //controller or action doesn't exist $object = $event->getData(); if ($event->getType() == 'beforeException') { switch ($exception->getCode()) { case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND: case Dispatcher::EXCEPTION_ACTION_NOT_FOUND: $dispatcher->forward(['controller' => 'errors', 'action' => 'index']); return false; case Dispatcher::EXCEPTION_CYCLIC_ROUTING: $dispatcher->forward(['controller' => 'errors', 'action' => 'show404']); return false; } } }); $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace("Phanbook\\Frontend\\Controllers"); $dispatcher->setEventsManager($eventsManager); return $dispatcher; }); /** * Setting up the view component */ $di->set('view', function () use($di) { $config = $di->get('config'); $view = new View(); $view->setViewsDir(ROOT_DIR . 'content/themes/' . $config->theme); $view->disableLevel([View::LEVEL_MAIN_LAYOUT => true, View::LEVEL_LAYOUT => true]); $view->registerEngines(['.volt' => 'volt']); // Create an event manager $eventsManager = new EventsManager(); $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; }); }
public function registerServices(DiInterface $di = null) { $di->set('dispatcher', function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace("Pohome\\Frontend\\Controllers"); return $dispatcher; }); $di->set('view', function () { $view = new View(); $view->setViewsDir('../apps/frontend/views/'); $view->registerEngines(array('.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Volt')); return $view; }); }
public function registerServices(\Phalcon\DiInterface $di) { // Registering a dispatcher $di->set('dispatcher', function () { $dispatcher = new \Phalcon\Mvc\Dispatcher(); $dispatcher->setDefaultNamespace('Bishop\\Shop\\Controllers'); return $dispatcher; }); // Registering the view component $di->set('view', function () { $view = new \Phalcon\Mvc\View(); $view->setViewsDir(ROOT_DIR . '/app/shop/views/'); return $view; }); }
/** * 注册自定义服务 */ public function registerServices(\Phalcon\DiInterface $di) { //Registering a dispatcher $di->set('dispatcher', function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace("Blog\\Backend\\Controllers"); return $dispatcher; }); //Registering the view component $di->set('view', function () { $view = new View(); $view->setViewsDir('../apps/backend/views/'); return $view; }); }
/** * Регистрация специфичных сервисов для модуля */ public function registerServices(DiInterface $di) { // Регистрация диспетчера $di->set('dispatcher', function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace("Pigeon\\Frontend\\Controllers"); return $dispatcher; }); // Регистрация компонента представлений $di->set('view', function () { $view = new View(); $view->setViewsDir('../apps/frontend/views/'); return $view; }); }
/** * Register the services here to make them general or register in the ModuleDefinition to make them module-specific */ public function registerServices(DiInterface $di) { // Registering a dispatcher $di->set('dispatcher', function () { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace("App\\Frontend\\Controllers\\"); return $dispatcher; }); //Registering a dispatcher /*$di->set('dispatcher', function(){ //Create an EventsManager $eventsManager = new EventsManager(); //Attach a listener $eventsManager->attach("dispatch", function($event, $dispatcher, $exception) { //Handle 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([ 'controller' => 'error', 'action' => 'index', 'params' => ['message' => $exception->getMessage()], ]); return false; } } }); $dispatcher = new MvcDispatcher(); //$dispatcher->setDefaultNamespace('App\Controllers\\'); $dispatcher->setEventsManager($eventsManager); return $dispatcher; });*/ // Registering a smarty component $di->set('smarty', function () { $smarty = new \Smarty(); $options = ['left_delimiter' => '<{', 'right_delimiter' => '}>', 'template_dir' => ROOT_DIR . '/app/Frontend/Views', 'compile_dir' => ROOT_DIR . '/runtime/Smarty/compile', 'cache_dir' => ROOT_DIR . '/runtime/Smarty/cache', 'error_reporting' => error_reporting() ^ E_NOTICE, 'escape_html' => true, 'force_compile' => false, 'compile_check' => true, 'caching' => false, 'debugging' => false]; foreach ($options as $k => $v) { $smarty->{$k} = $v; } $config = (include ROOT_DIR . "/config/main.php"); if (!empty($config['theme'])) { $smarty->addTemplateDir(ROOT_DIR . '/app/Frontend/Themes/' . $config['theme']); } return $smarty; }); }
/** * {@inheritdoc} */ public function register(DiInterface $di) { $config = $di->get('config'); $di->set(self::SERVICE_NAME, function () use($config) { return new \Vegas\Translate\Adapter\Gettext(['locale' => $config->application->language, 'file' => 'messages', 'directory' => APP_ROOT . '/lang']); }); }
/** * {@inheritdoc} */ public function register(DiInterface $di) { $di->set(self::SERVICE_NAME, function () use($di) { $mongo = new \MongoClient(); return $mongo->selectDb($di->get('config')->mongo->db); }, true); }
/** * {@inheritdoc} */ public function register(DiInterface $di) { $di->set(self::SERVICE_NAME, function () use($di) { $config = $di->get('config'); return new Phalcon\Db\Adapter\Pdo\Mysql(["host" => $config->database->host, "dbname" => $config->database->dbname, "port" => $config->database->port, "username" => $config->database->username, "password" => $config->database->password, "options" => [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']]); }, true); }
/** * Registers services related to the module * * @param DiInterface $di */ public function registerServices(DiInterface $di) { /** * 获取全局配置 */ $config = $di->has('config') ? $di->getShared('config') : null; /** * 各模块可自定义config文件并替换全局的config配置 */ if (file_exists($this->modulePath . '/config/config.php')) { $override = new Config(include $this->modulePath . '/config/config.php'); if ($config instanceof Config) { $config->merge($override); } else { $config = $override; } } //重置全局配置 $di->setShared('config', $config); /** * 设置各个模块的视图目录 */ $view = new View(); //$view->setViewsDir($this->modulePath . '/views/default/'); $view->setViewsDir(FRONTEND_PUBLIC_PATH . 'views/default/'); $view->registerEngines(['.volt' => 'volt', '.php' => 'volt', '.html' => 'volt']); $di->set('view', $view); }
/** * {@inheritdoc} */ public function register(DiInterface $di) { $di->set(self::SERVICE_NAME, function () use($di) { $arrayConfig = $di->get('config')->db->toArray(); return new \Phalcon\Db\Adapter\Pdo\Mysql($arrayConfig); }, true); }
/** * {@inheritdoc} * @see http://docs.phalconphp.com/pl/latest/reference/odm.html */ public function register(DiInterface $di) { $di->set(self::SERVICE_NAME, function () use($di) { $mongoConfig = $di->get('config')->mongo->toArray(); if (isset($mongoConfig['dsn'])) { $hostname = $mongoConfig['dsn']; unset($mongoConfig['dsn']); } else { //obtains hostname if (isset($mongoConfig['host'])) { $hostname = 'mongodb://' . $mongoConfig['host']; } else { $hostname = 'mongodb://localhost'; } if (isset($mongoConfig['port'])) { $hostname .= ':' . $mongoConfig['port']; } //removes options that are not allowed in MongoClient constructor unset($mongoConfig['host']); unset($mongoConfig['port']); } $dbName = $mongoConfig['dbname']; unset($mongoConfig['dbname']); $mongo = new \MongoClient($hostname, $mongoConfig); return $mongo->selectDb($dbName); }, true); }
/** * {@inheritdoc} */ public function register(DiInterface $di) { $di->set(self::SERVICE_NAME, function () use($di) { $session = new Vegas\Session($di->get('session')); return $session; }, true); }