コード例 #1
0
ファイル: Module.php プロジェクト: nicklos17/littlemall
 /**
  * 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;
     });
 }
コード例 #2
0
ファイル: Module.php プロジェクト: cengizcoskun/phonebook
 /**
  * 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;
     });
 }
コード例 #3
0
ファイル: SecurityPlugin.php プロジェクト: nbtetreault/igo
 public function beforeExecuteRoute(Phalcon\Events\Event $event, Phalcon\Mvc\Dispatcher $dispatcher)
 {
     $authentificationModule = $this->getDI()->get("authentificationModule");
     if ($authentificationModule == null) {
         return;
     }
     $controller = $dispatcher->getControllerName();
     $action = $dispatcher->getActionName();
     error_log("Controleur: {$controller}, Action: {$action}");
     if ($controller === "connexion" || $controller === "error") {
         $config = $this->getDI()->get("config");
         $this->getDI()->get("view")->setViewsDir($config->application->services->viewsDir);
         //        }else if($this->estAnonyme()){
         //            error_log("2");
         //            return $this->forwardToUnauthorizedPage();
     } else {
         if (!$this->estAuthentifie()) {
             return $this->forwardToLoginPage();
         } else {
             if (!$this->session->get("info_utilisateur")->estAdmin && !$this->session->get("info_utilisateur")->estPilote) {
                 $this->session->set("erreur", "Droits insuffisants");
                 return $this->forwardToLoginPage();
             } else {
                 // Contrôle d'accès.
                 return $this->filtrerRoutes($controller, $action);
             }
         }
     }
 }
コード例 #4
0
ファイル: Module.php プロジェクト: noikiy/public
 /**
  * 注册服务
  * @param type $di
  */
 public function registerServices(\Phalcon\DiInterface $di = NULL)
 {
     $config = \TConfig::instance()->getModule($this->moduleId);
     if (php_sapi_name() == 'cli') {
         //处理CLI模式
         $di['dispatcher'] = function () use($config) {
             $dispatcher = new \Phalcon\Cli\Dispatcher();
             if (isset($config['defaultNamespace']) && isset($config['defaultNamespace']['task'])) {
                 $dispatcher->setDefaultNamespace($config['defaultNamespace']);
             }
             return $dispatcher;
         };
     } else {
         //处理WEB模式
         $di['dispatcher'] = function () use($config) {
             $dispatcher = new \Phalcon\Mvc\Dispatcher();
             if (isset($config['defaultNamespace']) && isset($config['defaultNamespace']['controller'])) {
                 $dispatcher->setDefaultNamespace($config['defaultNamespace']['controller']);
             }
             return $dispatcher;
         };
         //添加视图
         $di->set('view', function () use($config) {
             $view = new \Phalcon\Mvc\View();
             $view->setViewsDir($config['autoloadDir']['view']);
             $view->registerEngines(array('.html' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
             return $view;
         });
     }
 }
コード例 #5
0
ファイル: Module.php プロジェクト: abuelezz/mvc
 public function registerServices($di)
 {
     /**
      * Read configuration
      */
     $config = (include __DIR__ . "/config/config.php");
     $di['dispatcher'] = function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace("Modules\\Frontend\\Controllers");
         return $dispatcher;
     };
     /**
      * Setting up the view component
      */
     $di['view'] = function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->setLayoutsDir('../../common/layouts/');
         $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 \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name));
     };
 }
コード例 #6
0
 public function registerServices($di)
 {
     /** Read configuration */
     $config = (include __DIR__ . "/../configs/config.php");
     $di['dispatcher'] = function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace("Modules\\Admin\\Controllers");
         return $dispatcher;
     };
     /** Setting up the view component */
     $di['view'] = function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->setLayoutsDir('../../common/layouts/');
         $view->setPartialsDir('../../common/partials/');
         return $view;
     };
     /** set config */
     $di->set('config', function () use($config) {
         return $config;
     }, true);
     /** Database connection is created based in the parameters defined in the configuration file */
     $di['db'] = function () use($config) {
         return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name, "charset" => "utf8", "options" => array(\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")));
     };
 }
コード例 #7
0
ファイル: Module.php プロジェクト: quyquoc/rmt-studio.com
 public function registerServices($di)
 {
     $di['dispatcher'] = function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace("Modules\\Frontend\\Controllers");
         return $dispatcher;
     };
     /**
      * Setting up the view component
      */
     $di['view'] = function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(__DIR__ . '/views/');
         return $view;
     };
     /**
      * Register a component
      */
     $di->set('menu', function () {
         return new \Modules\Frontend\Elements\Menu();
     });
     $di->set('element', function () {
         return new \Modules\Frontend\Elements\Element();
     });
 }
コード例 #8
0
ファイル: Security.php プロジェクト: iJonKofee/server-API
 public function beforeExecuteRoute(Phalcon\Events\Event $event, Phalcon\Mvc\Dispatcher $dispatcher)
 {
     $userEnum = Core_UserCenter_Enum::getInstance();
     // Получаем активные контроллер и действие от диспетчера
     $controller = $dispatcher->getControllerName();
     $action = $dispatcher->getActionName();
     // Получаем список ACL
     $acl = $this->_getAcl();
     if ($acl->isAllowed($userEnum->getName($userEnum::GUEST), $controller, $action)) {
         return TRUE;
     }
     // Проверяем, установлен ли в сессии user
     $isAuth = $this->session->has('user');
     //Если не авторизован, но перенаправляем на страницу авторизации
     if (!$isAuth) {
         return $this->_forwardToLogin();
     }
     $user = $this->session->get('user');
     $role = $user->type;
     // Проверяем, имеет ли данная роль доступ к контроллеру (ресурсу)
     $allowed = $acl->isAllowed($userEnum->getName($role), $controller, $action);
     if ($allowed != Phalcon\Acl::ALLOW) {
         throw new Core_UserCenter_Exception_AccessDenied($controller, $action, $role);
     }
 }
コード例 #9
0
ファイル: Module.php プロジェクト: einstein95/FAOpen
 /**
  * @param \Phalcon\DiInterface $di
  */
 public function registerServices(\Phalcon\DiInterface $di = null)
 {
     // Set up MVC dispatcher.
     $controller_class = 'Modules\\' . $this->_module_class_name . '\\Controllers';
     $di['dispatcher'] = function () use($controller_class) {
         $eventsManager = new \Phalcon\Events\Manager();
         $eventsManager->attach("dispatch:beforeDispatchLoop", function ($event, $dispatcher) {
             // Set odd/even pairs as the key and value of parameters, respectively.
             $keyParams = array();
             $params = $dispatcher->getParams();
             foreach ($params as $position => $value) {
                 if (is_int($position)) {
                     if ($position & 1) {
                         $keyParams[$params[$position - 1]] = urldecode($value);
                     }
                 } else {
                     // The "name" parameter is internal to routes.
                     if ($position != 'name') {
                         $keyParams[$position] = urldecode($value);
                     }
                 }
             }
             $dispatcher->setParams($keyParams);
             // Detect filename in controller and convert to "format" parameter.
             $controller_name = $dispatcher->getControllerName();
             if (strstr($controller_name, '.') !== false) {
                 list($controller_clean, $format) = explode('.', $controller_name, 2);
                 $dispatcher->setControllerName($controller_clean);
                 $dispatcher->setParam('format', $format);
             }
             // Detect filename in action and convert to "format" parameter.
             $action_name = $dispatcher->getActionName();
             if (strstr($action_name, '.') !== false) {
                 list($action_clean, $format) = explode('.', $action_name, 2);
                 $dispatcher->setActionName($action_clean);
                 $dispatcher->setParam('format', $format);
             }
         });
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setEventsManager($eventsManager);
         $dispatcher->setDefaultNamespace($controller_class);
         return $dispatcher;
     };
     // Set up module-specific configuration.
     $module_base_name = strtolower($this->_module_class_name);
     $module_config = $di->get('module_config');
     $di->setShared('current_module_config', function () use($module_base_name, $module_config) {
         if (isset($module_config[$module_base_name])) {
             return $module_config[$module_base_name];
         } else {
             return null;
         }
     });
     // Set up the view component and shared templates.
     $views_dir = 'modules/' . $module_base_name . '/views/scripts/';
     $di['view'] = function () use($views_dir) {
         return \FA\Phalcon\View::getView(array('views_dir' => $views_dir));
     };
 }
コード例 #10
0
ファイル: Module.php プロジェクト: NAMEs/phyar-framework
 /**
  * Register specific services for the module
  */
 public function registerServices($di)
 {
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace("App\\Modules\\User\\Controllers");
         return $dispatcher;
     });
 }
コード例 #11
0
ファイル: InitApp.php プロジェクト: threestarsgenius/homework
 public static function initDispatcher()
 {
     //Create an EventsManager
     $eventsManager = new \Phalcon\Events\Manager();
     $dispatcher = new \Phalcon\Mvc\Dispatcher();
     //Bind the EventsManager to the dispatcher
     $dispatcher->setEventsManager($eventsManager);
     return $dispatcher;
 }
コード例 #12
0
 public function attachDispatcher()
 {
     $this->_di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace('PhalconCart\\Controllers\\Frontend');
         return $dispatcher;
     });
     return $this;
 }
コード例 #13
0
ファイル: Module.php プロジェクト: luoshulin/falcon
 /**
  *
  * Register the services here to make them module-specific
  *
  */
 public function registerServices($di)
 {
     // get bootstrap obj
     $bootstrap = $di->get('bootstrap');
     // get config class name
     $confClass = $bootstrap->getConfClass();
     // module config
     $mConfPath = __DIR__ . '/confs/' . PHALCON_ENV . '.' . PHALCON_CONF_TYPE;
     if (!is_file($mConfPath)) {
         throw new \Phalcon\Config\Exception("Module config file not exist, file position: {$mConfPath}");
     }
     if (PHALCON_CONF_TYPE == 'ini') {
         $mConfig = new $confClass($mConfPath);
     } else {
         if (PHALCON_CONF_TYPE == 'php') {
             $mConfig = new $confClass(require_once $mConfPath);
         }
     }
     // global config
     $gConfig = $di->get('config');
     // merge module config and global config, module's will override global's
     $gConfig->merge($mConfig);
     // set config back
     $di->set('config', $gConfig);
     // registering a dispatcher
     $di->set('dispatcher', function () use($di) {
         $evtManager = $di->getShared('eventsManager');
         $evtManager->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(array('module' => 'sample', 'controller' => 'error', 'action' => 'show404'));
                     return false;
             }
         });
         $acl = new \BullSoft\Sample\Plugins\Acl($di, $evtManager);
         $evtManager->attach('dispatch', $acl);
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setEventsManager($evtManager);
         $dispatcher->setDefaultNamespace("BullSoft\\Sample\\Controllers\\");
         return $dispatcher;
     });
     // set view with volt
     $di->set('view', function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->registerEngines(array(".volt" => function ($view, $di) {
             $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
             $volt->setOptions(array("compiledPath" => $di->get('config')->view->compiledPath, "compiledExtension" => $di->get('config')->view->compiledExtension, "compileAlways" => (bool) $di->get('config')->application->debug));
             $compiler = $volt->getCompiler();
             $compiler->addExtension(new \BullSoft\Volt\Extension\PhpFunction());
             return $volt;
         }));
         return $view;
     });
 }
コード例 #14
0
ファイル: Module.php プロジェクト: xsat/www.mail.com
 public function registerServices(\Phalcon\DiInterface $di)
 {
     $this->di = $di;
     $this->di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace($this->prefix . '\\Controllers');
         return $dispatcher;
     });
     $this->di->set('view', $this->setView(), true);
     $this->di->set('modelsMetadata', $this->setModelsMetadata());
 }
コード例 #15
0
ファイル: Module.php プロジェクト: boiler256/mvc
 /**
  * Register the services here to make them module-specific
  */
 public function registerServices($di)
 {
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace("Multiple\\Frontend\\Controllers\\");
         return $dispatcher;
     });
     $di->set('db', function () {
         return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => "localhost", "username" => "root", "password" => "secret", "dbname" => "invo"));
     });
 }
コード例 #16
0
ファイル: Module.php プロジェクト: sharkodlak/pinek
 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;
     });
 }
コード例 #17
0
ファイル: Module.php プロジェクト: quyquoc/rmt-studio.com
 public function registerServices($di)
 {
     $di['dispatcher'] = function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace("Modules\\Backend\\Controllers");
         return $dispatcher;
     };
     /**
      * Setting up the view component
      */
     $di['view'] = function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(__DIR__ . '/views/');
         return $view;
     };
 }
コード例 #18
0
ファイル: UnitTestCase.php プロジェクト: nicklos17/appserver
 public function setUp(Phalcon\DiInterface $di = NULL, Phalcon\Config $config = NULL)
 {
     // Load any additional services that might be required during testing
     include __DIR__ . '/../config/services.php';
     include __DIR__ . '/../config/loader.php';
     // $di = DI::getDefault();
     // get any DI components here. If you have a config, be sure to pass it to the parent
     $di->set('dispatcher', function () {
         $dispatcher = new Phalcon\Mvc\Dispatcher();
         $dispatcher->setControllerName($this->_ctrl);
         $dispatcher->setActionName($this->_act);
         return $dispatcher;
     }, true);
     $this->di = $di;
     parent::setUp($di);
     $this->_loaded = true;
 }
コード例 #19
0
ファイル: Module.php プロジェクト: viniciusilveira/pluton
 /**
  * Registra os serviços específicos para este módulo
  */
 public function registerServices($di)
 {
     //Registra o dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $eventManager = new \Phalcon\Events\Manager();
         $eventManager->attach('dispatch', new \Acl('backend'));
         $dispatcher->setEventsManager($eventManager);
         $dispatcher->setDefaultNamespace("Multiple\\Backend\\Controllers\\");
         return $dispatcher;
     });
     //Registra os diretórios das views
     $di->set('view', function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir('../apps/backend/views/');
         return $view;
     });
 }
コード例 #20
0
ファイル: Security.php プロジェクト: netstu/invo
 /**
  * This action is executed before execute any action in the application
  */
 public function beforeDispatch(Phalcon\Events\Event $event, Phalcon\Mvc\Dispatcher $dispatcher)
 {
     $auth = $this->session->get('auth');
     if (!$auth) {
         $role = 'Guests';
     } else {
         $role = 'Users';
     }
     $controller = $dispatcher->getControllerName();
     $action = $dispatcher->getActionName();
     $acl = $this->getAcl();
     $allowed = $acl->isAllowed($role, $controller, $action);
     if ($allowed != Phalcon\Acl::ALLOW) {
         $this->flash->error("You don't have access to this module");
         $dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
         return false;
     }
 }
コード例 #21
0
ファイル: Module.php プロジェクト: nicklos17/appserver
 /**
  * Registers the module-only services
  *
  * @param Phalcon\DI $di
  */
 public function registerServices(\Phalcon\DiInterface $di = NULL)
 {
     /**
      * Read configuration
      */
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace("Appserver\\v2\\Controllers");
         return $dispatcher;
     });
     $di->set('cookies', function () {
         $cookies = new \Phalcon\Http\Response\Cookies();
         $cookies->useEncryption(false);
         return $cookies;
     });
 }
コード例 #22
0
ファイル: Module.php プロジェクト: viniciusilveira/pluton
 /**
  * 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 \Phalcon\Mvc\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;
     });
 }
コード例 #23
0
 private static function cgiRegister()
 {
     $di = get_app_di();
     $config = self::getConfig();
     self::registCommonService($di, $config);
     $di->setShared('router', function () {
         $router = new \Phalcon\Mvc\Router();
         $router->removeExtraSlashes(true);
         $router->add('/:controller/:action/:params', array('controller' => 1, 'action' => 2, 'params' => 3));
         return $router;
     });
     $di->setShared('dispatcher', function () {
         $eventsManager = new \Phalcon\Events\Manager();
         $eventsManager->attach('dispatch:beforeException', new NotFoundPlugin());
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setEventsManager($eventsManager);
         $dispatcher->setDefaultNamespace("App\\Controllers\\");
         return $dispatcher;
     });
     $di->setShared('view', function () use($config) {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir($config->view->templatePath);
         $view->registerEngines(array('.html' => function ($view, $di) {
             $config = $di->get('config');
             $compiledPath = $config->view->compiledPath;
             if (!file_exists($compiledPath)) {
                 mkdir($compiledPath, 0744, true);
             }
             $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
             $volt->setOptions(array('compiledPath' => $compiledPath, 'compiledExtension' => $config->view->compiledExtension, 'compileAlways' => isset($config->view->compileAlways) ?: false));
             $compiler = $volt->getCompiler();
             $compiler->addExtension(new VoltExtension());
             $autoEscape = isset($config->view->autoEscape) ?: true;
             ClassUtil::modifyPrivateProperties($compiler, array('_autoescape' => $autoEscape));
             return $volt;
         }));
         return $view;
     });
     $di->setShared('elements', function () {
         return new ElementsPlugin();
     });
 }
コード例 #24
0
ファイル: Module.php プロジェクト: ariborneo/phalcon-restful
 /**
  * Registers the module-only services
  *
  * @param Phalcon\DI $di
  */
 public function registerServices($di)
 {
     $config = (include __DIR__ . "/../../config/constants.php");
     //Redefining Dispatcher
     $di['dispatcher'] = function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace("App\\Modules\\Frontend\\Controllers");
         return $dispatcher;
     };
     //Setting UP View component
     $di['view'] = function () {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         return $view;
     };
     //Databse Connection
     $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, "options" => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')));
     };
 }
コード例 #25
0
ファイル: index.php プロジェクト: abuelezz/mvc
 /**
  * This methods registers the services to be used by the application
  */
 protected function _registerServices()
 {
     $di = new \Phalcon\DI();
     //Registering a router
     $di->set('router', function () {
         return new \Phalcon\Mvc\Router();
     });
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setDefaultNamespace('Single\\Controllers\\');
         return $dispatcher;
     });
     //Registering a Http\Response
     $di->set('response', function () {
         return new \Phalcon\Http\Response();
     });
     //Registering a Http\Request
     $di->set('request', function () {
         return new \Phalcon\Http\Request();
     });
     //Registering the view component
     $di->set('view', function () {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir('../apps/views/');
         return $view;
     });
     $di->set('db', function () {
         return new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => "localhost", "username" => "root", "password" => "", "dbname" => "invo"));
     });
     //Registering the Models-Metadata
     $di->set('modelsMetadata', function () {
         return new \Phalcon\Mvc\Model\Metadata\Memory();
     });
     //Registering the Models Manager
     $di->set('modelsManager', function () {
         return new \Phalcon\Mvc\Model\Manager();
     });
     $this->setDI($di);
 }
コード例 #26
0
 /**
  * Register specific services for the module
  */
 public function registerServices(\Phalcon\DiInterface $dependencyInjector)
 {
     /**
      * Read configuration
      */
     $config = (require_once MODULES_DIR . $this->module_name . DS . "config" . DS . "config.php");
     //Registering a dispatcher
     $dependencyInjector->set('dispatcher', function () {
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         //Attach a event listener to the dispatcher
         $eventManager = new \Phalcon\Events\Manager();
         //$eventManager->attach('dispatch', new \Acl($this->module_name));
         $dispatcher->setEventsManager($eventManager);
         $dispatcher->setDefaultNamespace("Mod\\ModMan\\Controllers\\");
         return $dispatcher;
     });
     /**
      * Setting up the view component
      */
     $dependencyInjector->set('view', function () use($config) {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir($config->module->viewsDir);
         $view->setViewsDir(MODULES_DIR . $this->module_name . DS . 'views' . DS);
         $view->setLayoutsDir(MODULES_DIR . $this->module_name . DS . 'layouts' . DS);
         //$view->setTemplateAfter('index');
         $view->registerEngines(array('.volt' => function ($view, $di) {
             $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
             $volt->setOptions(array('compiledPath' => MODULES_DIR . $this->module_name . DS . 'views' . DS . '_compiled' . DS, 'stat' => true, 'compileAlways' => true));
             return $volt;
         }));
         return $view;
     });
     /**
      * Database connection is created based in the parameters defined in the configuration file
      * http://stackoverflow.com/questions/22197678/how-to-connect-multiple-database-in-phalcon-framework
      */
     $dependencyInjector->set('db', function () use($config) {
         return new DbAdapter(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name));
     });
 }
コード例 #27
0
ファイル: BaseModule.php プロジェクト: Riu/kirocms
 public function registerServices(\Phalcon\DiInterface $di = NULL)
 {
     $config = $di->get('config');
     $di->set('dispatcher', function () use($di) {
         $eventsManager = $di->getShared('eventsManager');
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setEventsManager($eventsManager);
         $dispatcher->setDefaultNamespace($this->namespace . '\\Controllers\\');
         return $dispatcher;
     });
     if (file_exists('../' . $config->app->apps . $this->moduleName . '/config/routers.ini')) {
         $router = $di->get('router');
         $routers = new \Phalcon\Config\Adapter\Ini('../' . $config->app->apps . $this->moduleName . '/config/routers.ini');
         if (!empty($routers)) {
             foreach ($routers as $name => $rule) {
                 $rule->module = $this->moduleName;
                 $pattern = $rule->pattern;
                 unset($rule->pattern);
                 $router->add($pattern, $rule->toArray())->setName($name);
             }
         }
         $router->handle();
     }
     $di->set('view', function () use($config) {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir('../' . $config->app->apps . $this->moduleName . '/' . $config->app->views);
         $view->registerEngines(array('.html' => function ($view, $di) use($config) {
             $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
             $volt->setOptions(array('compiledPath' => '../' . $config->app->apps . $this->moduleName . '/cache/volt/', 'compiledExtension' => '.php', 'compileAlways' => true, 'compiledSeparator' => '_'));
             return $volt;
         }));
         return $view;
     });
     $di->set('flashSession', function () {
         return new \Phalcon\Flash\Session(array('error' => 'alert alert-warning alert-small', 'success' => 'alert alert-success', 'notice' => 'alert alert-info'));
     });
     $di->set('flash', function () {
         return new \Phalcon\Flash\Direct(array('error' => 'alert alert-error', 'success' => 'alert alert-success', 'notice' => 'alert alert-info'));
     });
 }
コード例 #28
0
ファイル: Module.php プロジェクト: abuelezz/mvc
 /**
  * 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 \Phalcon\Mvc\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 \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => "localhost", "username" => "root", "password" => "secret", "dbname" => "invo"));
     });
 }
コード例 #29
0
ファイル: Security.php プロジェクト: pavlitskiyegor/vk-parser
 public function beforeExecuteRoute(Phalcon\Events\Event $event, Phalcon\Mvc\Dispatcher $dispatcher)
 {
     // Получаем активные контроллер и действие от диспетчера
     $controller = $dispatcher->getControllerName();
     $action = $dispatcher->getActionName();
     // Получаем список ACL
     $acl = $this->_getAcl();
     if ($acl->isAllowed(Core_UserCenter_Enum::GUESTS, $controller, $action)) {
         return TRUE;
     }
     // Проверяем, установлена ли в сессии переменная "auth" для определения активной роли.
     $auth = $this->session->has('auth_type');
     if (!$auth) {
         return $this->_forwardToLogin();
     }
     $role = $this->session->get('auth_type')['type'];
     // Проверяем, имеет ли данная роль доступ к контроллеру (ресурсу)
     $allowed = $acl->isAllowed($role, $controller, $action);
     if ($allowed != Phalcon\Acl::ALLOW) {
         throw new Core_UserCenter_Exception_AccessDenied($controller, $action, $role);
     }
 }
コード例 #30
0
 /**
  * This action is executed before execute any action in the application
  */
 public function beforeDispatch(Phalcon\Events\Event $event, Phalcon\Mvc\Dispatcher $dispatcher)
 {
     $auth = $this->session->get('auth');
     if (!$auth) {
         $auth['role'] = 'Guest';
         $role = 'Guest';
     } else {
         $role = $auth['role'];
     }
     $controller = $dispatcher->getControllerName();
     $action = $dispatcher->getActionName();
     $acl = $this->getAcl();
     $allowed = $acl->isAllowed($role, $controller, $action);
     if ($role == 'Admin' || $role == 'User' || $role == 'Guest') {
         return true;
     } elseif ($allowed != Phalcon\Acl::ALLOW) {
         if ($role != 'Guest') {
             $this->flash->error("You don't have access to {$controller}/{$action}) please login to get access");
         }
         $dispatcher->forward(array('namespace' => 'PRIME\\Controllers', 'controller' => 'session', 'action' => 'index'));
         return false;
     }
 }