private function setUpDispatcher()
 {
     $this->dispatcher->setControllerName($this->router->getControllerName());
     $this->dispatcher->setActionName($this->router->getActionName());
     $this->dispatcher->setParams($this->router->getParams());
     $oDispatcherEventManager = new Manager();
     $oDispatcherEventManager->attach('dispatch:beforeDispatch', function (Event $oEvent, Dispatcher $oDispatcher, $data) {
         return false;
     });
     $this->dispatcher->setEventsManager($oDispatcherEventManager);
 }
 /**
  * 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';
 }
Beispiel #3
0
 /**
  * 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]);
     });
 }
Beispiel #4
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;
     };
 }
Beispiel #5
0
 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;
     });
 }
 /**
  * @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;
     });
 }
 /**
  * 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;
 }
 /**
  * Initialize Phalcon .
  */
 public function __construct()
 {
     $executionTime = -microtime(true);
     define('APP_PATH', realpath('..') . '/');
     $this->config = $config = new ConfigIni(APP_PATH . 'app/config/config.ini');
     $this->di = new FactoryDefault();
     $this->di->set('config', $config);
     $this->di->set('dispatcher', function () {
         $eventsManager = new EventsManager();
         $eventsManager->attach('dispatch:beforeExecuteRoute', new SecurityPlugin());
         $dispatcher = new Dispatcher();
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     $this->di->set('crypt', function () use($config) {
         $crypt = new Crypt();
         $crypt->setKey($config->application->phalconCryptKey);
         return $crypt;
     });
     $this->setDisplayErrors();
     $this->title = $config->application->title;
     $this->registerDirs();
     $this->setDB($config);
     $this->setViewProvider($config);
     $this->setURLProvider($config);
     $this->setSession();
     $this->application = new Application($this->di);
     $this->application->view->executionTime = $executionTime;
     $this->setCSSCollection();
     $this->setJSCollection();
     $this->setTitle();
 }
Beispiel #9
0
 /**
  * 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 . '/');
 }
Beispiel #10
0
 /**
  * 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;
     });
 }
Beispiel #11
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);
     });
 }
Beispiel #12
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());
     });
 }
Beispiel #13
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;
     });
 }
 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 onBoot()
 {
     // TODO: Implement onBoot() method.
     $this->getDI()->setShared('dispatcher', function () {
         $di = $this->getDI();
         $em = $di->getEventsManager();
         $em->attach('dispatch', new DispatchListener());
         $dispatcher = new Dispatcher();
         $dispatcher->setDI($di);
         $dispatcher->setEventsManager($em);
         return $dispatcher;
     });
 }
Beispiel #16
0
 public function boot(Container $container)
 {
     // As of phalcon 3, definition will bind to di by default
     $container->setShared('dispatcher', function () {
         $eventsManager = $this->getShared('eventsManager');
         $eventsManager->attach('dispatch', new \Pails\Plugins\CustomRender());
         $dispatcher = new PhalconDispatcher();
         $dispatcher->setEventsManager($eventsManager);
         $dispatcher->setDefaultNamespace('App\\Controllers');
         $dispatcher->setModelBinding(true);
         return $dispatcher;
     });
 }
 /**
  * @param array $config
  * @return MvcDispatcher
  */
 public static function createMvcFrom(array $config) : MvcDispatcher
 {
     $dispatcher = new MvcDispatcher();
     $dispatcher->setEventsManager(new EventManager());
     $dispatcher->setControllerSuffix(null);
     $dispatcher->setDefaultNamespace($config['controllerDefaultNamespace']);
     $dispatcher->getEventsManager()->attach('dispatch:afterDispatchLoop', function (Event $event, MvcDispatcher $dispatcher) {
         if ($dispatcher->getReturnedValue() instanceof \Phalcon\Http\Response) {
             $dispatcher->getDI()->setShared('response', $dispatcher->getReturnedValue());
         }
     });
     return $dispatcher;
 }
Beispiel #18
0
 public function register()
 {
     $event_manager = new EventsManager();
     $event_manager->attach('dispatch:beforeException', function ($event, $dispatcher, $exception) {
         if ($exception instanceof DispatchException) {
             throw new ControllerNotFoundException($exception->getMessage());
             return false;
         }
     });
     $dispatcher = new MvcDispatcher();
     $dispatcher->setEventsManager($event_manager);
     $dispatcher->setDefaultNamespace('App\\Controllers');
     return $dispatcher;
 }
Beispiel #19
0
 /**
  * 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;
     });
 }
Beispiel #20
0
 private function setSecurity($manager)
 {
     /* ==================================================
      * ตั้งค่าความปลอดภัย 
      * ================================================== */
     $manager->set('dispatcher', function () use($manager) {
         $eventsManager = $manager->getShared('eventsManager');
         $security = new SecurityPlugin($manager);
         $security->setModule($this->moduleName);
         $eventsManager->attach('dispatch', $security);
         $dispatcher = new Dispatcher();
         $dispatcher->setEventsManager($eventsManager);
         $dispatcher->setDefaultNamespace(ucfirst($this->moduleName) . '\\Controllers');
         return $dispatcher;
     });
 }
Beispiel #21
0
 /**
  * Runs the application performing all initializations
  *
  * @param $options
  *
  * @return mixed
  */
 public function run($options)
 {
     $loaders = array('config', 'session', 'loader', 'url', 'router', 'database', 'view', 'cache', 'log', 'utils', 'debug');
     try {
         // Handing missing controller errors
         $this->di->set('dispatcher', function () {
             //Create an EventsManager
             $eventsManager = new EventsManager();
             // Attach a listener
             $eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
                 // Handle 404 exceptions
                 if ($exception instanceof DispatchException) {
                     $dispatcher->forward(array('controller' => 'index', 'action' => 'internalServerError'));
                     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' => 'index', 'action' => 'internalServerError'));
                             return false;
                     }
                 }
             });
             // Instantiate the Security plugin
             $security = new Security($di);
             // Listen for events produced in the dispatcher using the Security plugin
             $eventsManager->attach('dispatch', $security);
             $dispatcher = new \Phalcon\Mvc\Dispatcher();
             // Bind the EventsManager to the dispatcher
             $dispatcher->setEventsManager($eventsManager);
             return $dispatcher;
         }, true);
         foreach ($loaders as $service) {
             $function = 'init' . ucfirst($service);
             $this->{$function}();
         }
         $application = new PhApplication();
         $application->setDI($this->di);
         return $application->handle()->getContent();
     } catch (PhException $e) {
         echo $e->getMessage();
     } catch (\PDOException $e) {
         echo $e->getMessage();
     }
 }
Beispiel #22
0
 /**
  * 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\\Frontend\\');
         return $dispatcher;
     });
     $di->setShared('request', function () use($appConfig) {
         return new \Phalcon\Http\Request();
     });
     /**
      * Include config per environment
      */
     include __DIR__ . '/config/config_' . $appConfig->application->environment . '.php';
     $database = $di->getConfig()->application->site . $di->get('request')->getQuery("country_code");
     /**
      * Simple database connection to localhost
      */
     $di->setShared('mongo', function ($config, $database) {
         $mongo = new \Mongo();
         return $mongo->selectDb($config->{$database}->dbname);
     }, true);
     $di->setShared('collectionManager', function () {
         return new \Phalcon\Mvc\Collection\Manager();
     }, true);
 }
Beispiel #23
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('Api\\Controllers');
         /**
          * Not-found action or handler
          */
         $eventsManager = new EventsManager();
         $eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
             switch ($exception->getCode()) {
                 case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                 case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                     $dispatcher->forward(['controller' => 'error', 'action' => 'error404']);
                     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;
     });
     /**
      * 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());
     });
 }
Beispiel #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");
     $authConfig = (include __DIR__ . "/config/authConfig.php");
     /**
      * Setting up the view component
      */
     $di->set('dispatcher', function () {
         $eventsManager = new EventsManager();
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     /**
      * Setting up the view component
      */
     $di['view'] = function () {
         $view = new View();
         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\\MobiMall\\Controllers");
         return $dispatcher;
     });
     $di->set('cookies', function () {
         $cookies = new \Phalcon\Http\Response\Cookies();
         $cookies->useEncryption(false);
         return $cookies;
     });
     $di->set('authConfig', function () use($authConfig) {
         return $authConfig;
     });
 }
Beispiel #25
0
 /**
  * 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 PhEveManager();
         //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' => 'admin',
         //                     'controller' => 'notfound'
         //                 ]);
         //                 return false;
         //         }
         //     }
         // });
         //attach get param after controller as key/value
         $eventManager->attach("dispatch:beforeDispatchLoop", function ($event, $dispatcher) {
             $keyParams = [];
             $params = $dispatcher->getParams();
             //Use odd parameters as keys and even as values
             foreach ($params as $number => $value) {
                 if ($number & 1) {
                     $keyParams[$params[$number - 1]] = $value;
                 }
             }
             //Override parameters
             $dispatcher->setParams($keyParams);
         });
         // Authorization
         $eventManager->attach('dispatch', new \Fly\Authorization('admin'));
         $dispatcher->setEventsManager($eventManager);
         $dispatcher->setDefaultNamespace('Controller\\Admin');
         return $dispatcher;
     };
     $di['view']->setViewsDir(ROOT_PATH . '/modules/admin/views/');
 }
Beispiel #26
0
 /**
  * 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->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         //Attach a event listener to the dispatcher
         $eventManager = new \Phalcon\Events\Manager();
         //			$eventManager->attach('dispatch', new \Acl('frontend'));
         $dispatcher->setEventsManager($eventManager);
         $dispatcher->setDefaultNamespace("Multiple\\Frontend\\Controllers\\");
         return $dispatcher;
     });
     //Registering the view component
     $di->set('view', function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(__DIR__ . '/views/');
         return $view;
     });
 }
Beispiel #27
0
 /**
  * Initializes dispatcher
  */
 public function register()
 {
     $di = $this->getDi();
     $eventsManager = $this->getEventsManager();
     $config = $this->_config;
     $defaultModuleDir = $this->_module->getDefaultModuleDirectory();
     $di->set('defualtModuleDir', function () use($defaultModuleDir) {
         return $defaultModuleDir;
     });
     $moduleDirectory = $this->_module->getModuleDirectory();
     $di->set('moduleDirectory', function () use($moduleDirectory) {
         return $moduleDirectory;
     });
     $di->set('dispatcher', function () use($di, $eventsManager, $config) {
         // Create dispatcher
         $dispatcher = new MvcDispatcher();
         //Attach a listener
         $eventsManager->attach("dispatch:beforeException", function ($event, \Phalcon\Mvc\Dispatcher $dispatcher, $exception) use($di, $config) {
             if ($config->application->debug && $di->has('logger')) {
                 $logger = $di->get('logger');
                 $logger->error($exception->getMessage());
             }
             //Handle 404 exceptions
             if ($exception instanceof DispatchException) {
                 $dispatcher->forward(['controller' => 'error', 'action' => 'show404']);
                 return false;
             }
             if ($di->get('request')->isAjax() == true) {
             }
             //Handle other exceptions
             $dispatcher->forward(['controller' => 'error', 'action' => 'show503']);
             return false;
         });
         $eventsManager->attach("dispatch:beforeDispatchLoop", function ($event, \Phalcon\Mvc\Dispatcher $dispatcher) {
             $dispatcher->setControllerName(\Phalcon\Text::lower($dispatcher->getControllerName()));
         });
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
 }
Beispiel #28
0
 /**
  * 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);
     /**
      * Setting up the view component
      */
     $di->set('view', function () {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/../../../public/src/app/modules/leads/views/')->setLayoutsDir('../../../layouts/')->setPartialsDir('../../../partials/')->setTemplateAfter('main')->registerEngines(['.html' => 'Phalcon\\Mvc\\View\\Engine\\Php']);
         return $view;
     });
     /**
      * 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\\Leads\\');
         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]);
     });
 }
Beispiel #29
0
 /**
  * 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->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         //Attach a event listener to the dispatcher
         $eventManager = new \Phalcon\Events\Manager();
         $eventManager->attach('dispatch', new \Acl('frontend'));
         $dispatcher->setEventsManager($eventManager);
         $dispatcher->setDefaultNamespace("Multiple\\Frontend\\Controllers\\");
         return $dispatcher;
     });
     //Registering the view component
     $di->set('view', function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir('../apps/frontend/views/');
         return $view;
     });
     $di->set('db', function () {
         return new Database(array("host" => "localhost", "username" => "root", "password" => "secret", "dbname" => "invo"));
     });
 }
Beispiel #30
0
use Phalcon\Mvc\Url as UrlProvider;
use Phalcon\Session\Adapter\Files as SessionAdapter;
use Phalcon\Events\Manager as EventsManager;
/**
 * Framework
 */
$di = new FactoryDefault();
/**
 * Events manager
 */
$di->set('dispatcher', function () use($di) {
    $eventsManager = new EventsManager();
    //NotFound
    $eventsManager->attach('dispatch:beforeException', new NotFoundPlugin());
    $dispatcher = new Dispatcher();
    $dispatcher->setEventsManager($eventsManager);
    return $dispatcher;
});
/**
 * URL
 */
$di->set('url', function () use($config) {
    $url = new UrlProvider();
    $url->setBaseUri($config->application->baseUri);
    return $url;
});
/**
 * View
 */
$di->set('view', function () use($config) {
    $view = new View();