Exemplo n.º 1
0
 /**
  * @param string $name
  * @param mixed  $value
  * @param int    $expire
  * @param string $path
  * @param bool   $secure
  * @param string $domain
  * @param bool   $httpOnly
  * @return PhalconCookies
  */
 public static function set($name, $value = null, $expire = 0, $path = null, $secure = null, $domain = null, $httpOnly = null)
 {
     $options = static::$options;
     $path === null and $path = $options['path'];
     $domain === null and $domain = $options['domain'];
     return static::$cookies->set($name, $value, $expire, $path, $secure, $domain, $httpOnly);
 }
 private function setCookie()
 {
     $config = $this->getConfig('session');
     $this->getDI()->setShared('cookies', function () use($config) {
         $cookies = new Cookies();
         $cookies->useEncryption($config->encrypt);
         return $cookies;
     });
 }
Exemplo n.º 3
0
 /**
  * Registers services related to the module
  *
  * @param DiInterface $dependencyInjector
  */
 public function registerServices(DiInterface $dependencyInjector)
 {
     /**
      * Read configuration
      */
     $config = (include __DIR__ . "/config/config.php");
     /**
      * Registering a dispatcher
      */
     $dependencyInjector->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('Frontend\\Controllers');
         /**
          * Not-found action or handler
          */
         $eventsManager = new EventsManager();
         $eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
             switch ($exception->getCode()) {
                 case Dispatcher::EXCEPTION_CYCLIC_ROUTING:
                 case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                 case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                     $dispatcher->forward(['controller' => 'about', 'action' => 'error']);
                     return false;
             }
         });
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     /**
      * Setting up the view component
      */
     $dependencyInjector->set('view', function () {
         $view = new View();
         $view->registerEngines(array('.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         $view->setViewsDir(__DIR__ . '/views/');
         return $view;
     });
     $dependencyInjector->set('viewCache', function () use($config) {
         //Cache data for one day by default
         $frontCache = new OutputFrontend(array("lifetime" => 86400));
         //File connection settings
         $cache = new FileBackend($frontCache, array('cacheDir' => STATIC_PATH . '/'));
         return $cache;
     });
     $dependencyInjector->set('cookies', function () {
         $cookies = new Cookies();
         $cookies->useEncryption(false);
         return $cookies;
     });
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $dependencyInjector->set('db', function () use($config) {
         return new DbAdapter($config->database->toArray());
     });
 }
Exemplo n.º 4
0
 public function reset()
 {
     static::$disableSession = false;
     static::$disableCsrfCheck = false;
     $this->cookies->reset();
     $this->response->setContent('')->resetHeaders()->setStatusCode(200);
 }
Exemplo n.º 5
0
 public function get($name)
 {
     $cookie = parent::get($name);
     if ($this->isUsingEncryption()) {
         $cookie->setValue(base64_decode($cookie->getValue()));
     }
     return $cookie;
 }
Exemplo n.º 6
0
 public function register()
 {
     $cookie = new Cookies();
     $cookie->useEncryption(true);
     return $cookie;
 }
Exemplo n.º 7
0
 public function delete($name)
 {
     $name = isset($this->options['prefix']) ? $this->options['prefix'] . $name : $name;
     return parent::delete($name);
 }
Exemplo n.º 8
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']);
});
Exemplo n.º 9
0
 /**
  *
  * @param type $options
  */
 protected function initCookies($options = [])
 {
     $this->_di->setShared('cookies', function () {
         $cookies = new Cookies();
         $cookies->useEncryption(false);
         return $cookies;
     });
 }
Exemplo n.º 10
0
 public function cookie($index = NULL)
 {
     $cook = new Cookies();
     return $cook->get($index);
 }
Exemplo n.º 11
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;
         };
     }
 }
Exemplo n.º 12
0
 /**
  * Initializes the cookie
  */
 public function initCookie($options = [])
 {
     $this->di->setShared('cookie', function () {
         $cookie = new PhCookies();
         $cookie->useEncryption(true);
         return $cookie;
     });
 }
Exemplo n.º 13
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;
     });
 }
Exemplo n.º 14
0
 public function reset()
 {
     return parent::reset();
 }
Exemplo n.º 15
0
 public static function deleteCookies(Cookies $cookies)
 {
     $cookies->set(RememberTokens::USER_COOKIE_KEY, null, 0);
     $cookies->set(RememberTokens::TOKEN_COOKIE_KEY, null, 0);
     $cookies->send();
 }
Exemplo n.º 16
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);
Exemplo n.º 17
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;
});