コード例 #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
ファイル: Config.php プロジェクト: aciden/generator
 public function setCoockie()
 {
     $this->set('cookies', function () {
         $cookies = new \Phalcon\Http\Response\Cookies();
         $cookies->useEncryption(true);
         return $cookies;
     });
 }
コード例 #3
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");
     $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);
     });
 }
コード例 #4
0
ファイル: Module.php プロジェクト: nicklos17/ucenter
 /**
  * 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;
     });
 }
コード例 #5
0
 public static function getStringLang($name)
 {
     $di = Phalcon\DI::getDefault();
     $cookies = new Phalcon\Http\Response\Cookies();
     if (!$cookies->has('lang')) {
         $lang = Users::getLang($di->get('session')->get('auth')['id']);
     } else {
         $lang = $cookies->get('lang');
     }
     return ResourceStrings::getString($name, $lang);
 }
コード例 #6
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;
     });
 }
コード例 #7
0
ファイル: index.php プロジェクト: sunxfancy/Questionnaire
 if ($config->security->protectBackend) {
     $di->set("dispatcher", function () use($di) {
         $dispatcher = new Phalcon\Mvc\Dispatcher();
         $eventsManager = $di->getShared("eventsManager");
         $security = new Security($di);
         $eventsManager->attach('dispatch', $security);
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
 }
 $di->set('flash', function () {
     return new Phalcon\Flash\Session(array('error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info'));
 });
 //cookie
 $di->set("cookies", function () {
     $cookies = new Phalcon\Http\Response\Cookies();
     $cookies->useEncryption(false);
     return $cookies;
 });
 /**
  * If the configuration specify the use of metadata adapter use it or use memory otherwise
  */
 $di->set('modelsMetadata', function () use($config) {
     if (isset($config->models->metadata)) {
         $metadataAdapter = 'Phalcon\\Mvc\\Model\\Metadata\\' . $config->models->metadata->adapter;
         return new $metadataAdapter();
     } else {
         return new \Phalcon\Mvc\Model\Metadata\Memory();
     }
 });
 /**
コード例 #8
0
ファイル: Engine.php プロジェクト: hushibing/EvaEngine
 /**
  * Configuration application default DI
  *
  * @return FactoryDefault| CLI
  */
 public function getDI()
 {
     if ($this->di) {
         return $this->di;
     }
     if ($this->appMode == 'cli') {
         $di = new FactoryDefault\CLI();
     } else {
         $di = new FactoryDefault();
     }
     //PHP5.3 not support $this in closure
     $self = $this;
     /**********************************
      * DI initialize for MVC core
      ***********************************/
     //$di->set('application', $this);
     //call loadmodules will overwrite this
     $di->set('moduleManager', function () use($di) {
         $moduleManager = new ModuleManager();
         $moduleManager->setEventsManager($di->getEventsManager());
         return $moduleManager;
     }, true);
     //System global events manager
     $di->set('eventsManager', function () use($di) {
         $eventsManager = new EventsManager();
         $eventsManager->enablePriorities(true);
         // dispatch caching event handler
         $eventsManager->attach("dispatch", new DispatchInterceptor(), -1);
         $eventsManager->enablePriorities(true);
         return $eventsManager;
     }, true);
     $di->set('config', function () use($self) {
         return $self->diConfig();
     }, true);
     $di->set('router', function () use($self) {
         return $self->diRouter();
     }, true);
     $di->set('dispatcher', function () use($di) {
         $dispatcher = new Dispatcher();
         $dispatcher->setEventsManager($di->getEventsManager());
         return $dispatcher;
     }, true);
     $di->set('modelsMetadata', function () use($self) {
         return $self->diModelsMetadata();
     }, true);
     $di->set('modelsManager', function () use($di) {
         $config = $di->getConfig();
         ModelManager::setDefaultPrefix($config->dbAdapter->prefix);
         //for solving db master/slave under static find method
         $modelsManager = new ModelManager();
         return $modelsManager;
     });
     $di->set('view', function () use($di) {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->setEventsManager($di->getEventsManager());
         return $view;
     });
     $di->set('session', function () use($self) {
         return $self->diSession();
     });
     $di->set('tokenStorage', function () use($self) {
         return $self->diTokenStorage();
     }, true);
     /**********************************
      * DI initialize for database
      ***********************************/
     $di->set('dbMaster', function () use($self) {
         return $self->diDbMaster();
     }, true);
     $di->set('dbSlave', function () use($self) {
         return $self->diDbSlave();
     }, true);
     $di->set('transactions', function () use($di) {
         $transactions = new \Phalcon\Mvc\Model\Transaction\Manager();
         $transactions->setDbService('dbMaster');
         return $transactions;
     }, true);
     /**********************************
      * DI initialize for cache
      ***********************************/
     $di->set('globalCache', function () use($self) {
         return $self->diGlobalCache();
     }, true);
     $di->set('viewCache', function () use($self) {
         return $self->diViewCache();
     }, true);
     $di->set('modelsCache', function () use($self) {
         return $self->diModelsCache();
     }, true);
     $di->set('apiCache', function () use($self) {
         return $self->diApiCache();
     }, true);
     $di->set('fastCache', function () use($self) {
         return $self->diFastCache();
     }, true);
     /**********************************
      * DI initialize for queue
      ***********************************/
     $di->set('queue', function () use($di) {
         $config = $di->getConfig();
         $client = new \GearmanClient();
         $client->setTimeout(1000);
         foreach ($config->queue->servers as $key => $server) {
             $client->addServer($server->host, $server->port);
         }
         return $client;
     }, true);
     $di->set('worker', function () use($di) {
         $config = $di->getConfig();
         $worker = new \GearmanWorker();
         foreach ($config->queue->servers as $key => $server) {
             $worker->addServer($server->host, $server->port);
         }
         return $worker;
     }, true);
     /**********************************
      * DI initialize for email
      ***********************************/
     $di->set('mailer', function () use($self) {
         return $self->diMailer();
     }, true);
     $di->set('mailMessage', 'Eva\\EvaEngine\\MailMessage');
     $di->set('smsSender', function () use($self) {
         return $self->diSmsSender();
     }, true);
     /**********************************
      * DI initialize for helpers
      ***********************************/
     $di->set('url', function () use($di) {
         $config = $di->getConfig();
         $url = new UrlResolver();
         $url->setVersionFile($config->staticBaseUriVersionFile);
         $url->setBaseUri($config->baseUri);
         $url->setStaticBaseUri($config->staticBaseUri);
         return $url;
     }, true);
     $di->set('escaper', 'Phalcon\\Escaper');
     $di->set('tag', function () use($di, $self) {
         Tag::setDi($di);
         $self->registerViewHelpers();
         return new Tag();
     });
     $di->set('flash', 'Phalcon\\Flash\\Session');
     $di->set('placeholder', 'Eva\\EvaEngine\\View\\Helper\\Placeholder');
     $di->set('cookies', function () {
         $cookies = new \Phalcon\Http\Response\Cookies();
         $cookies->useEncryption(false);
         return $cookies;
     });
     $di->set('translate', function () use($self) {
         return $self->diTranslate();
     });
     $di->set('fileSystem', function () use($self) {
         return $self->diFileSystem();
     });
     $di->set('logException', function () use($di) {
         $config = $di->getConfig();
         return new FileLogger($config->logger->path . 'error.log');
     });
     if ($this->appMode == 'cli') {
         $this->cliDI($di);
     }
     IoC::setDI($di);
     return $this->di = $di;
 }
コード例 #9
0
        $formatter = new \Phalcon\Logger\Formatter\Line($this->_config->logger->format);
        $logger = new \Phalcon\Logger\Adapter\File($this->_config->logger->file);
        $logger->setFormatter($formatter);
        return $logger;
    }
    return false;
});
/**
 * Component flashSession (Session keep flash messages).
 */
$di->setShared('flash', function () {
    $flash = new Phalcon\Flash\Session(['error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info']);
    return $flash;
});
$di->setShared('cookies', function () {
    $cookies = new \Phalcon\Http\Response\Cookies();
    $cookies->useEncryption(true);
    return $cookies;
});
// Default component to crypt cookies values
$di->set('crypt', function () {
    $crypt = new \Phalcon\Crypt();
    $crypt->setKey($this->_config->cookieCryptKey);
    return $crypt;
});
// Setup Hansel & Gretel breadcrumbs ))
$di->set('breadcrumbs', function () {
    return new \Plugins\Breadcrumbs\Breadcrumbs();
});
// Component Navigation. Manage site navigation
$di->setShared('navigation', function () {
コード例 #10
0
 protected function initCookies()
 {
     $this->di->set('cookies', function () {
         $cookies = new \Phalcon\Http\Response\Cookies();
         $cookies->useEncryption(FALSE);
         return $cookies;
     }, TRUE);
 }
コード例 #11
0
ファイル: cookies-47.php プロジェクト: aodkrisda/phalcon-code
<?php

$di->set('cookies', function () {
    $cookies = new Phalcon\Http\Response\Cookies();
    $cookies->setEncryption(false);
    return $cookies;
});
コード例 #12
0
ファイル: Bootstrap.php プロジェクト: abc2001x/phalcon_mode
 private function initCookie()
 {
     $di = $this->getDI();
     $di->set('cookies', function () {
         $cookies = new \Phalcon\Http\Response\Cookies();
         $cookies->useEncryption(false);
         return $cookies;
     });
 }
コード例 #13
0
 /**
  * cookie 设置
  */
 protected function initCookie()
 {
     $config = $this->config;
     if ($config->offsetExists('cookie') && $config->cookie->offsetExists('encry') && $config->cookie->encry) {
         $this->di['cookies'] = function () {
             $cookies = new \Phalcon\Http\Response\Cookies();
             $cookies->useEncryption(true);
             // 是否加密
             return $cookies;
         };
     }
 }