Example #1
1
 /**
  * @param Event $event
  * @param Application $application
  * @return mixed
  */
 public function boot(Event $event, Application $application)
 {
     $config = $application->getConfig()->application;
     if (isset($config->view) && $config->view !== false) {
         $view = new View();
         $view->setViewsDir($config->view->viewsDir);
         $view->setLayoutsDir($config->view->layoutsDir);
         $view->setLayout($config->view->layout);
         $application->getDI()->setShared('view', $view);
     }
 }
Example #2
1
 private function resourceNotFound($resourceKey, View $view)
 {
     $view->setViewsDir(__DIR__ . '/../modules/Index/views/');
     $view->setPartialsDir('');
     $view->message = "Acl resource <b>{$resourceKey}</b> in <b>/app/config/acl.php</b> not exists";
     $view->partial('error/error404');
     $response = new \Phalcon\Http\Response();
     $response->setHeader(404, 'Not Found');
     $response->sendHeaders();
     echo $response->getContent();
     exit;
 }
 /**
  * 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;
 }
Example #4
0
 /**
  * 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;
 }
Example #5
0
 /**
  * Registers services related to the module
  *
  * @param DiInterface $di Dependency Injection Container
  */
 public function registerServices(DiInterface $di)
 {
     /**
      * Read configuration
      */
     $config = (require __DIR__ . "/config/config.php");
     /**
      * Setting up the view component
      */
     $di->setShared('view', function () {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->setTemplateBefore('main');
         $view->registerEngines([".volt" => function ($view, $di) {
             $volt = new Volt($view, $di);
             $volt->setOptions(['compiledPath' => function ($templatePath) {
                 return realpath(__DIR__ . "/../../var/volt") . '/' . md5($templatePath) . '.php';
             }, 'compiledExtension' => '.php', 'compiledSeparator' => '%']);
             return $volt;
         }]);
         return $view;
     });
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di->setShared('db', function () use($config) {
         return new Connection(['host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname]);
     });
 }
Example #6
0
 /**
  * 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;
     });
 }
Example #7
0
 /**
  * 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);
 }
Example #8
0
 public function modulesClosure(IntegrationTester $I)
 {
     $I->wantTo('handle request and get content by using single modules strategy (closure)');
     Di::reset();
     $_GET['_url'] = '/login';
     $di = new FactoryDefault();
     $di->set('router', function () {
         $router = new Router(false);
         $router->add('/index', ['controller' => 'index', 'module' => 'frontend', 'namespace' => 'Phalcon\\Test\\Modules\\Frontend\\Controllers']);
         $router->add('/login', ['controller' => 'login', 'module' => 'backend', 'namespace' => 'Phalcon\\Test\\Modules\\Backend\\Controllers']);
         return $router;
     });
     $application = new Application();
     $view = new View();
     $application->registerModules(['frontend' => function ($di) use($view) {
         /** @var \Phalcon\DiInterface $di */
         $di->set('view', function () use($view) {
             $view->setViewsDir(PATH_DATA . 'modules/frontend/views/');
             return $view;
         });
     }, 'backend' => function ($di) use($view) {
         /** @var \Phalcon\DiInterface $di */
         $di->set('view', function () use($view) {
             $view->setViewsDir(PATH_DATA . 'modules/backend/views/');
             return $view;
         });
     }]);
     $application->setDI($di);
     $I->assertEquals('<html>here</html>' . PHP_EOL, $application->handle()->getContent());
 }
Example #9
0
 /**
  * Registers services related to the module
  *
  * @param DiInterface $di
  */
 public function registerServices(DiInterface $di)
 {
     /**
      * Read configuration
      */
     $config = (include APP_PATH . "/apps/frontend/config/config.php");
     /**
      * Setting up the view component
      */
     $di['view'] = function () use($config) {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->registerEngines(array('.html' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
             return $volt;
         }));
         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);
     };
     $di['wechat'] = 'App\\Libs\\Wechat';
     $di['config'] = $config;
 }
Example #10
0
 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'));
     };
 }
Example #11
0
 /**
  * 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";
 }
Example #12
0
 /**
  * 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;
     });
 }
Example #13
0
 public function afterRenderView(Event $event, View $view)
 {
     if ('afterRenderView' == $event->getType()) {
         $this->levels[] = $view->getCurrentRenderLevel();
     }
     return true;
 }
 /**
  * Setup Breadcrumbs views dir
  * @param string $value
  * @access public
  * @return this
  */
 public function setBreadrumbsView(View $view, $value)
 {
     $this->_viewDir = (string) $value;
     $view->setPartialsDir($this->_viewDir);
     $view->partial($this->_partialName, ['elements' => $this->_elements, 'separator' => $this->_separator]);
     return;
 }
Example #15
0
 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;
     };
 }
Example #16
0
 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));
     };
 }
 private function setView($manager, $theme)
 {
     /* ==================================================
      * ตั้งค่าเรียกใช้งานไฟล์ View ทั้งหมด
      * Setting up the view component
      * ================================================== */
     $manager->set('view', function () use($theme) {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         /* ตำแหน่งเก็บไฟล์ views ทั้งหมด */
         $view->setLayoutsDir(sprintf('%s/%s/', $this->config->theme->themesDir, $theme));
         /* ตำแหน่งเก็บไฟล์ layouts ทั้งหมด */
         $view->setTemplateAfter('layouts/' . $this->layoutName);
         /* เลือกไฟล์ layout เริ่มต้น*/
         /* สร้างโฟล์เดอร์เก็บไฟล์ cache */
         $cacheDir = sprintf('%s/%s/%s/', APPLICATION_PATH, $this->config->application->cacheDir, $this->moduleName);
         if (!is_dir($cacheDir)) {
             mkdir($cacheDir);
         }
         $view->registerEngines(array('.phtml' => function ($view, $di) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => sprintf('%s/%s/%s/', APPLICATION_PATH, $this->config->application->cacheDir, $this->moduleName), 'compiledSeparator' => '_'));
             return $volt;
         }));
         return $view;
     });
 }
Example #18
0
 /**
  * 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));
     };
 }
Example #19
0
 /**
  * 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);
 }
Example #20
0
 public function registerServices(DiInterface $di)
 {
     $di->set('view', function () {
         $view = new View();
         $view->setViewsDir(PATH_DATA . 'modules/backend/views/');
         return $view;
     });
 }
Example #21
0
 /**
  * @return View
  */
 public function getView()
 {
     if ($this->view === null) {
         $this->view = $this->di->get('widgetView');
         $this->view->setDi($this->di);
     }
     return $this->view;
 }
Example #22
0
 /**
  * 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);
     });
 }
Example #23
0
 /**
  * Register services
  */
 public function register()
 {
     $this->container->set('view', function () {
         $view = new PhalconView();
         $view->setViewsDir($this->getViewsDir());
         $view->registerEngines($this->getEnginesList());
         return $view;
     });
 }
Example #24
0
 /**
  * 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;
     });
 }
Example #25
0
 /**
  * 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());
     });
 }
Example #26
0
 public function __construct(Dispatcher $dispatcher, Request $request, Router $router, View $view)
 {
     if ($view->getLayout() == 'admin') {
         return;
     }
     $match_url_entry = $this->matchingUrl($request->getURI());
     if ($match_url_entry) {
         $this->pick($match_url_entry);
     }
 }
Example #27
0
 /**
  * Register specific services for the module
  */
 public function registerServices($di)
 {
     $dispatcher = $di->getDispatcher();
     $dispatcher->setDefaultNamespace('Eva\\CounterRank\\Controllers');
     //Registering the view component
     $di->set('view', function () {
         $view = new View();
         $view->setViewsDir('/src/views/');
         return $view;
     });
 }
 public function attachViewService($voltCacheDir, $viewPath)
 {
     $this->attachVoltService($voltCacheDir);
     $this->_di->setShared('view', function () use($viewPath) {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir($viewPath);
         $view->registerEngines(['.volt' => 'voltService', '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php']);
         return $view;
     });
     return $this;
 }
 private function setView($manager)
 {
     /* ==================================================
      * ตั้งค่าเรียกใช้งานไฟล์ View ทั้งหมด
      * ================================================== */
     $manager->set('view', function () {
         $view = new View();
         $view->disable();
         return $view;
     });
 }
Example #30
0
 /**
  * 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;
     });
 }