Пример #1
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;
     };
 }
Пример #2
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;
     });
 }
Пример #3
0
 /**
  * Register specific services for the module
  */
 function registerServices(\Phalcon\DiInterface $di)
 {
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('Modules\\Frontend\\Controllers');
         return $dispatcher;
     });
     $config = $di->getShared('config');
     $di->set('view', function () use($config, $di) {
         $view = new View();
         $router = $di->getShared('router');
         /*
          * @todo 给layouts等目录统一变量
          * */
         $view->setViewsDir(__DIR__ . '/views/');
         $view->setLayoutsDir('/../../../layouts/');
         // 多模块的话, 可能会有多个风格,所以需要切换layout,这里的Path是根据当前module的Path向上走的
         $view->setLayout('index');
         $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
             return $volt;
         }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         return $view;
     }, true);
 }
Пример #4
0
 /**
  * @param Dispatcher $dispatcher
  */
 public function beforeExecuteRoute(Dispatcher $dispatcher)
 {
     $controllerName = $dispatcher->getControllerName();
     $actionName = $dispatcher->getActionName();
     // This confirm a private zone
     //check for a closed controller and Action is exist a current session
     if ($this->acl->isClosed($controllerName, $actionName)) {
         if (!is_null($this->auth->getAccess())) {
             //This redirect to another Controller/Action
             $this->response->redirect('dashboard');
             // Disable the view to avoid rendering
             $this->view->disable();
         }
         return true;
     }
     if ($this->acl->isPrivate($controllerName)) {
         if (!is_null($this->auth->getAccess())) {
             //echo "Logeado";
         } else {
             //Display a error by a flash component
             $this->flash->notice('Upss! Access denied, Please Registry first or Login into Kangoo');
             //Execute the dispatcher to move above the user
             $dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
             return false;
         }
     }
 }
Пример #5
0
 /**
  * This action is executed before execute any action in the application.
  *
  * @param PhalconEvent $event      Event object.
  * @param Dispatcher   $dispatcher Dispatcher object.
  *
  * @return mixed
  */
 public function beforeDispatch(PhEvent $event, Dispatcher $dispatcher)
 {
     $di = $this->getDI();
     $cookie = $di->getCookie();
     $session = $di->getSession();
     $config = $di->getConfig();
     $languageCode = '';
     if ($di->get('app')->isConsole()) {
         return;
     }
     // Detect language from cookie
     if ($cookie->has('languageCode')) {
         $languageCode = $cookie->get('languageCode')->getValue();
     } else {
         // Get default language from language model
         $languageCode = LanguageModel::findFirst(['default = :isdefault: AND status = :enable:', 'bind' => ['isdefault' => LanguageModel::IS_DEFAULT, 'enable' => LanguageModel::STATUS_ENABLE]])->code;
     }
     // Set language code to session
     if ($session->has('languageCode') && $session->get('languageCode') != $languageCode || !$session->has('languageCode')) {
         $session->set('languageCode', $languageCode);
     }
     $messages = [];
     $directory = $di->get('registry')->directories->modules . ucfirst($dispatcher->getModuleName()) . '/Lang/' . $languageCode . '/' . strtolower($dispatcher->getControllerName());
     $extension = '.php';
     if (file_exists($directory . $extension)) {
         require $directory . $extension;
     }
     // add default core lang package
     require $di->get('registry')->directories->modules . self::DEFAULT_LANG_PACK . '/Lang/' . $languageCode . '/default.php';
     $translate = new PhTranslateArray(['content' => array_merge($messages, $default)]);
     $di->set('lang', $translate);
     return !$event->isStopped();
 }
Пример #6
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));
     };
 }
Пример #7
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'));
     };
 }
    public function beforeExecuteRoute(Event $event,Dispatcher $dispatcher){
        //return;
        //$this->session->destroy();

        $role=$this->session->get('role');
        if(!$role){
            $role=self::GUEST;
        }

        //Get the current Controller & Action from the dispatcher
        $controller=$dispatcher->getControllerName();
        $action=$dispatcher->getActionName();

        //Get the ACL rule list
        $acl=$this->_getAcl();

        //See if they have permission
        $allowed=$acl->isAllowed($role, $controller,$action);
        if($allowed!=Acl::ALLOW){
            $this->flash->error('You Don\'t Have Permission To Access This Area');
            $this->response->redirect('index');

            //Stops the dispatcher at current operation
            return false;
        }
    }
 public function afterDispatchLoop(Event $event, Dispatcher $dispatcher)
 {
     $di = $this->getDI();
     $response = $di->get('response');
     $content = $response->getContent();
     if ($content === '' && $dispatcher->getActiveController() instanceof RestControllerInterface) {
         $returnedResponse = $dispatcher->getReturnedValue() instanceof ResponseInterface;
         if ($returnedResponse === false) {
             /** @var \PhalconRest\Mvc\RestView $rest */
             $rest = $di->get('rest');
             /** @var Manager $eventsManager */
             $eventsManager = $this->_eventsManager;
             //$eventsManager = $dispatcher->getDI()->get('eventsManager');
             $renderStatus = true;
             if ($eventsManager instanceof ManagerInterface) {
                 $renderStatus = $eventsManager->fire('application:viewRender', $this, $rest);
             }
             if ($renderStatus) {
                 $rest->render($dispatcher->getControllerName(), $dispatcher->getActionName());
                 $content = $rest->getContent();
             }
             /** @var \Phalcon\Http\Response $response */
             $response = $di->get('response');
             $response->setContent($content)->send();
         }
     }
 }
Пример #10
0
 /**
  * This action is executed before execute any action in the application
  */
 public function beforeDispatch(Event $event, Dispatcher $dispatcher)
 {
     if ($this->config->application->user_login_form_cookies) {
         //use cookies
         $auth = $this->_getCookie('auth');
         if (!$auth) {
             $role = 'Guests';
         } else {
             $role = $this->_getCookie('role');
             $role = 'Person';
         }
     } else {
         $auth = $this->session->get('auth');
         $auth = $this->_getCookie('auth');
         if (!$auth) {
             $role = 'Guests';
         } else {
             $role = $auth['role'];
             // $role='Common';
         }
     }
     $controller = $dispatcher->getControllerName();
     $action = $dispatcher->getActionName();
     $acl = $this->getAcl();
     $allowed = $acl->isAllowed($role, $controller, $action);
     if ($allowed != Acl::ALLOW) {
         $this->flash->error("You don't have access to this module");
         $dispatcher->forward(array('controller' => 'user', 'action' => 'login'));
         return false;
     }
 }
Пример #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";
 }
Пример #12
0
 /**
  * This action is executed after execute any action in the application.
  *
  * @param PhalconEvent $event      Event object.
  * @param Dispatcher   $dispatcher Dispatcher object.
  *
  * @return mixed
  */
 public function afterExecuteRoute(PhEvent $event, Dispatcher $dispatcher)
 {
     $config = $this->getDI()->get('config')->toArray();
     $controllerName = $dispatcher->getControllerName();
     $actionName = $dispatcher->getActionName();
     $this->getDI()->get('view')->pick($controllerName . '/' . $config['global']['template'][$controllerName] . '/' . $actionName);
 }
Пример #13
0
 /**
  * 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';
 }
Пример #14
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]);
     });
 }
Пример #15
0
 public function beforeException(Event $event, Dispatcher $dispatcher, \Exception $e)
 {
     $this->getLogger()->exception($e);
     $this->response->setStatusCode($e->getCode() ?: 500, $e->getMessage() ?: 'Application error');
     $dispatcher->forward(['namespace' => 'Controller', 'controller' => 'error', 'action' => 'index', 'params' => [0 => $e->getMessage()]]);
     return false;
 }
Пример #16
0
 public function __construct(Dispatcher $dispatcher)
 {
     $cmsCache = new CmsCache();
     $languages = $cmsCache->get('languages');
     $defaultLangArray = array_values(array_slice($languages, 0, 1));
     $defaultLang = $defaultLangArray[0];
     $request = $this->getDI()->get('request');
     $queryLang = $request->getQuery('lang');
     if (!$queryLang) {
         $langParam = $dispatcher->getParam('lang');
     } else {
         $langParam = $queryLang;
     }
     if (!$langParam) {
         $langParam = $defaultLang['iso'];
     }
     foreach ($languages as $language) {
         if ($langParam == $language['iso']) {
             define('LANG', $language['iso']);
             define('LANG_URL', '/' . $language['url']);
         }
     }
     if (!defined('LANG')) {
         define('LANG', $defaultLang['iso']);
         \Application\Mvc\Model\Model::$lang = $defaultLang['iso'];
     }
     if (!defined('LANG_URL')) {
         define('LANG_URL', $defaultLang['url']);
     }
     $translations = \Cms\Model\Translate::findCachedByLangInArray(LANG);
     $this->getDI()->set('translate', new \Phalcon\Translate\Adapter\NativeArray(['content' => $translations]));
 }
Пример #17
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));
     };
 }
Пример #18
0
 public function beforeExecuteRoute(Dispatcher $dispatcher)
 {
     $actionName = $dispatcher->getActionName();
     $controllerName = $dispatcher->getControllerName() . 'Controller';
     $nameSpaceName = $dispatcher->getNamespaceName();
     $className = $nameSpaceName . '\\' . ucwords($controllerName);
     $no_auth_array = [];
     if (class_exists($className)) {
         $no_auth_array = array_merge($className::$no_auth_array, self::$no_auth_array);
     }
     if (in_array($actionName, $no_auth_array)) {
         return true;
     }
     if ($this->isLogin()) {
         //判断是否有权限操作此资源
         if (!$this->isAllowed($actionName)) {
             //echo '没有权限';
             $dispatcher->forward(array('controller' => 'index', 'action' => 'noauth'));
             //die();
             return false;
         }
         return true;
     } else {
         if (!($host = $this->request->getServerName())) {
             $host = $this->request->getHttpHost();
         }
         $sourceUrl = $this->request->getScheme() . '://' . $host . $this->request->getURI();
         $url = $this->request->getScheme() . '://' . $host . self::USER_LOGIN_URL . '?ref=' . $sourceUrl;
         $this->redirect($url);
     }
 }
Пример #19
0
 public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
 {
     echo $resource = $this->_module . '-' . $dispatcher->getControllerName(), PHP_EOL;
     // frontend-dashboard
     echo $access = $dispatcher->getActionName();
     // null
 }
Пример #20
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 . '/');
 }
Пример #21
0
 /**
  * This action is executed before execute any action in the application
  */
 public function beforeDispatch(Event $event, Dispatcher $dispatcher)
 {
     $controller = \strtolower($dispatcher->getControllerName());
     $action = \strtolower($dispatcher->getActionName());
     $resource = "{$controller}::{$action}";
     $role = 'GUEST';
     if ($this->session->get('authenticated')) {
         $user = User::findFirstByIdUser($this->session->get('idUser'));
         if ($user) {
             $role = $user->role->name;
             $userEfective = new stdClass();
             $userEfective->enable = false;
             $efective = $this->session->get('userEfective');
             if (isset($efective)) {
                 $userEfective->enable = true;
                 $role = $efective->role->name;
                 $user->role = $efective->role;
             }
             // Inyectar el usuario
             $this->_dependencyInjector->set('userData', $user);
             $this->_dependencyInjector->set('userEfective', $userEfective);
         }
     }
     $map = $this->getControllerMap();
     $this->publicurls = array('error::index', 'error::notavailable', 'error::unauthorized', 'error::forbidden', 'session::login', 'session::logout', 'session::recoverpass', 'session::resetpassword', 'session::setnewpass', 'session::questionpass', 'session::changepass');
     if ($role == 'GUEST') {
         if (!in_array($resource, $this->publicurls)) {
             $this->response->redirect("session/login");
             return false;
         }
     } else {
         if ($resource == 'session::login') {
             $this->response->redirect("index");
             return false;
         } else {
             $acl = $this->getAcl();
             $this->logger->log("Validando el usuario con rol [{$role}] en [{$resource}]");
             if (!isset($map[$resource])) {
                 $this->logger->log("El recurso no se encuentra registrado");
                 $dispatcher->forward(array('controller' => 'error', 'action' => 'index'));
                 return false;
             }
             $reg = $map[$resource];
             foreach ($reg as $resources => $actions) {
                 foreach ($actions as $act) {
                     if (!$acl->isAllowed($role, $resources, $act)) {
                         $this->logger->log('Acceso denegado');
                         $dispatcher->forward(array('controller' => 'error', 'action' => 'forbidden'));
                         return false;
                     }
                 }
             }
             $mapForLoginLikeAnyUser = array('session::superuser');
             if (in_array($resource, $mapForLoginLikeAnyUser)) {
                 $this->session->set('userEfective', $user);
             }
             return true;
         }
     }
 }
Пример #22
0
 /**
  * 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();
 }
Пример #23
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;
     });
 }
Пример #24
0
 /**
  * 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;
 }
 public function __construct(Dispatcher $dispatcher)
 {
     $request = $this->getDI()->get('request');
     $queryLang = $request->getQuery('lang');
     if (!$queryLang) {
         $lang = $dispatcher->getParam('lang');
     } else {
         $lang = $queryLang;
     }
     switch ($lang) {
         case 'uk':
             define('LANG', 'uk');
             define('LANG_SUFFIX', '_uk');
             define('LANG_URL', '/uk');
             define('LOCALE', 'uk_UA');
             break;
         case 'en':
             define('LANG', 'en');
             define('LANG_SUFFIX', '_en');
             define('LANG_URL', '/en');
             define('LOCALE', 'en_EN');
             break;
         default:
             define('LANG', 'ru');
             define('LANG_SUFFIX', '');
             define('LANG_URL', '/');
             define('LOCALE', 'ru_RU');
     }
     Locale::setDefault(LOCALE);
     $this->getDI()->set('translate', new \Application\Localization\GettextAdapter(array('locale' => LOCALE, 'lang' => LANG, 'file' => 'messages', 'directory' => APPLICATION_PATH . '/lang')));
 }
Пример #26
0
 public function registerServices(DiInterface $di)
 {
     global $config;
     $di->setShared('url', function () use($config) {
         $url = new UrlResolver();
         $url->setBaseUri($config->backend->baseUri);
         return $url;
     });
     $di->setShared('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace("Multiple\\Backend\\Controllers");
         return $dispatcher;
     });
     $di->setShared('view', function () use($config) {
         $view = new View();
         $view->setViewsDir($config->backend->viewsDir);
         $view->setLayoutsDir('layouts/');
         $view->setPartialsDir('partials/');
         $view->registerEngines(array('.phtml' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => $config->backend->cacheDir, 'compiledSeparator' => '_'));
             return $volt;
         }, '.volt' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         return $view;
     });
 }
Пример #27
0
 /**
  * @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;
     });
 }
Пример #28
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;
 }
Пример #29
0
 public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
 {
     // Check whether the "auth" variable exists in session to define the active role
     $auth = $this->session->get('auth');
     if (!$auth) {
         $role = 'Guests';
     } else {
         $role = 'Users';
     }
     // Take the active controller/action from the dispatcher
     $controller = $dispatcher->getControllerName();
     $action = $dispatcher->getActionName();
     // Obtain the ACL list
     $acl = $this->getAcl();
     // Check if the Role have access to the controller (resource)
     $allowed = $acl->isAllowed($role, $controller, $action);
     if ($allowed != Acl::ALLOW) {
         // If he doesn't have access forward him to the index controller
         $this->flash->error("You don't have access to this module");
         $dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
         // Returning "false" we tell to the dispatcher to stop the current operation
         return false;
     }
     //return true;
 }
Пример #30
0
 /**
  * {@inheridoc}.
  */
 public function register()
 {
     $dispatcher = new MvcDispatcher();
     $dispatcher->setDefaultNamespace('App\\Controllers');
     $dispatcher->setActionSuffix($this->getActionSuffix());
     return $dispatcher;
 }