private function setCookie()
 {
     $config = $this->getConfig('session');
     $this->getDI()->setShared('cookies', function () use($config) {
         $cookies = new Cookies();
         $cookies->useEncryption($config->encrypt);
         return $cookies;
     });
 }
예제 #2
0
파일: Module.php 프로젝트: xw716825/work
 /**
  * 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());
     });
 }
예제 #3
0
 public static function register(Di $di)
 {
     static::$di = $di;
     $di->set('Phalcon\\Http\\Cookie', 'Phwoolcon\\Http\\Cookie');
     static::$cookies = static::$di->getShared('cookies');
     static::$cookies->reset();
     static::$options = $options = Config::get('cookies');
     static::$cookies->useEncryption($encrypt = $options['encrypt']);
     $encrypt and static::$di->getShared('crypt')->setKey($options['encrypt_key'])->setPadding(Crypt::PADDING_ZERO);
     /* @var \Phalcon\Http\Response $response */
     if ($response = $di->getShared('response')) {
         $response->setCookies(static::$cookies);
     }
     Events::attach('view:generatePhwoolconJsOptions', function (Event $event) {
         $options = $event->getData() ?: [];
         $options['cookies'] = ['domain' => static::$options['domain'], 'path' => static::$options['path']];
         $event->setData($options);
         return $options;
     });
 }
예제 #4
0
    // Bind the eventsManager to the view component
    $view->setEventsManager($eventsManager);
    return $view;
});
// Register the flash service with custom CSS classes
$di->set('flashSession', function () {
    $flash = new Session(['error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning']);
    return $flash;
});
// Database connection is created based in the parameters defined in the configuration file
$di->set('db', function () use($di) {
    return new Mysql(['host' => $di->get('config')->database->mysql->host, 'username' => $di->get('config')->database->mysql->username, 'password' => $di->get('config')->database->mysql->password, 'dbname' => $di->get('config')->database->mysql->dbname, 'options' => [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $di->get('config')->database->mysql->charset]]);
}, true);
$di->set('cookies', function () {
    $cookies = new Cookies();
    $cookies->useEncryption(false);
    return $cookies;
}, true);
$di->set('crypt', function () use($di) {
    $crypt = new Crypt();
    $crypt->setKey($di->get('config')->application->cryptSalt);
    //Use your own key!
    return $crypt;
});
$di->set('security', function () {
    $security = new Security();
    //Set the password hashing factor to 12 rounds
    $security->setWorkFactor(12);
    return $security;
}, true);
//Set the models cache service
예제 #5
0
 public function register()
 {
     $cookie = new Cookies();
     $cookie->useEncryption(true);
     return $cookie;
 }
예제 #6
0
$di->setShared('dispatcher', function () use($di) {
    $security = new DispatcherSecurity();
    $security->setDI($di);
    //Listen for events produced in the dispatcher using the Security plugin
    $evManager = $di->getShared('eventsManager');
    $evManager->attach('dispatch', $security);
    $dispatcher = new Dispatcher();
    $dispatcher->setEventsManager($evManager);
    return $dispatcher;
});
$di->setShared('router', function () use($di) {
    $config = $di->get('config');
    $router = new Router();
    //Remove trailing slashes automatically
    $router->removeExtraSlashes(true);
    if (!isset($_GET['_url'])) {
        $router->setUriSource(Router::URI_SOURCE_SERVER_REQUEST_URI);
    }
    // Fetch routes from user
    require $config->path->configDir . '/routes.php';
    return $router;
});
$di->setShared('cookies', function () use($di) {
    $config = $di->get('config');
    $cookies = new Cookies();
    $cookies->useEncryption($config->server->https);
    return $cookies;
});
$di->set('flash', function () {
    return new Flash(['error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info']);
});
예제 #7
0
 /**
  *
  * @param type $options
  */
 protected function initCookies($options = [])
 {
     $this->_di->setShared('cookies', function () {
         $cookies = new Cookies();
         $cookies->useEncryption(false);
         return $cookies;
     });
 }
예제 #8
0
            $cache = new Phalcon\Cache\Backend\File($frontCache, ['cacheDir' => APP_URL . 'cache/model/']);
            break;
        case 'memcache':
            $cache = new Phalcon\Cache\Backend\Memcache($frontCache, ['host' => $config->memcache->host, 'port' => $config->memcache->port]);
            break;
    }
    return $cache;
};
$di['cache'] = function () use($di) {
    return $di->get('modelsCache');
};
/**
 * Access Control List
 */
$di['auth'] = function () {
    return new Auth();
};
/**
 * Init cookie
 */
$di->set('cookies', function () {
    $cookies = new Cookies();
    $cookies->useEncryption(true);
    return $cookies;
});
$di->set('crypt', function () {
    $crypt = new Crypt();
    $crypt->setMode(MCRYPT_MODE_CFB);
    $crypt->setKey('#1Pdj8$=dp?.ak#$');
    return $crypt;
});
예제 #9
0
 /**
  * Initializes the cookie
  */
 public function initCookie($options = [])
 {
     $this->di->setShared('cookie', function () {
         $cookie = new PhCookies();
         $cookie->useEncryption(true);
         return $cookie;
     });
 }
예제 #10
0
 /**
  * Init cookie.
  *
  * @param DI     $di     Dependency Injection.
  *
  * @return void
  */
 protected function _initCookie($di)
 {
     $di->set('cookie', function () {
         $cookie = new PhCookies();
         $cookie->useEncryption(true);
         return $cookie;
     });
 }
예제 #11
0
 public function useEncryption($useEncryption)
 {
     return parent::useEncryption($useEncryption);
 }
예제 #12
0
 /**
  * cookie 设置
  */
 protected function initCookie()
 {
     $config = $this->config;
     if ($config->offsetExists('cookie') && $config->cookie->offsetExists('encry')) {
         $this->di['cookies'] = function () {
             $cookies = new Cookies();
             $cookies->useEncryption(true);
             // 是否加密
             return $cookies;
         };
         $this->di['crypt'] = function () use($config) {
             $crypt = new Crypt();
             $cryptKey = $config->cookie->offsetExists('cryptKey') ? $config->cookie->cryptKey : 'ice.deng@2015';
             $crypt->setKey($cryptKey);
             return $crypt;
         };
     }
 }