Esempio n. 1
0
 /**
  * Save messages to cookie.
  *
  * @return $this
  */
 protected function save()
 {
     $messages = [];
     foreach ([self::DURABLE, self::NEXT] as $when) {
         if (!empty($this->messages[$when])) {
             $messages[$when] = $this->messages[$when];
         }
     }
     if ($messages) {
         $messages = json_encode($messages);
         $this->cookie->set($this->cookieKey, $messages);
     } else {
         $this->cookie->remove($this->cookieKey);
     }
     return $this;
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  */
 public function register(Container $container)
 {
     // Append custom settings with missing params from default settings
     $container['settings']['cookie'] = self::mergeWithDefaultSettings($container['settings']['cookie']);
     /**
      * Add dependency (DI).
      *
      * @param Container $c
      *
      * @return CookieHandler
      */
     $container['cookie'] = function (Container $c) {
         $settings = $c['settings']['cookie'];
         $cookie = CookieHandler::create($c['request']->getCookieParams())->setDefaults($settings['default'])->setPrefix($settings['prefix']);
         return $cookie;
     };
 }