Overview

Namespaces

  • Deimos
    • Cookie
      • Extensions
  • PHP

Classes

  • Deimos\Cookie\Cookie
  • Deimos\Cookie\Extension
  • Deimos\Cookie\SecureDefault

Interfaces

  • Throwable

Traits

  • Deimos\Cookie\Extensions\Flash
  • Deimos\Cookie\Extensions\Option
  • Deimos\Cookie\Extensions\Variable

Exceptions

  • Exception
  • InvalidArgumentException
  • LogicException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: namespace Deimos\Cookie;
  4: 
  5: use Deimos\Cookie\Extensions\Flash;
  6: 
  7: class Cookie extends Extension
  8: {
  9: 
 10:     use Flash;
 11: 
 12:     /**
 13:      * @param $value
 14:      * @param $options
 15:      *
 16:      * @return string
 17:      */
 18:     protected function decrypt($value, $options)
 19:     {
 20:         $secure = $this->secure($options);
 21: 
 22:         return $secure->decrypt($value);
 23:     }
 24: 
 25:     /**
 26:      * @param string $name
 27:      * @param null   $default
 28:      * @param array  $options
 29:      *
 30:      * @return mixed
 31:      *
 32:      * @throws \InvalidArgumentException
 33:      */
 34:     public function get($name, $default = null, array $options = [])
 35:     {
 36:         $options = $this->options($options);
 37:         $value   = $this->helper()->arr()->get($this->storage(), $name, $default);
 38: 
 39:         return $value === null || $value === $default ? $default : $this->decrypt($value, $options);
 40:     }
 41: 
 42:     /**
 43:      * @param string $name
 44:      * @param array  $options
 45:      *
 46:      * @return string
 47:      *
 48:      * @throws \Deimos\Helper\Exceptions\ExceptionEmpty
 49:      * @throws \InvalidArgumentException
 50:      */
 51:     public function getRequired($name, array $options = [])
 52:     {
 53:         $options = $this->options($options);
 54:         $value   = $this->helper()->arr()->getRequired($this->storage(), $name);
 55: 
 56:         return $this->decrypt($value, $options);
 57:     }
 58: 
 59:     /**
 60:      * Alias getRequired($name)
 61:      *
 62:      * @param string $name
 63:      *
 64:      * @return mixed
 65:      *
 66:      * @throws \InvalidArgumentException
 67:      */
 68:     public function __get($name)
 69:     {
 70:         return $this->get($name);
 71:     }
 72: 
 73:     /**
 74:      * @inheritdoc
 75:      *
 76:      * @return bool
 77:      *
 78:      * @throws \InvalidArgumentException
 79:      */
 80:     public function set($name, $value, array $options = [])
 81:     {
 82:         $options = $this->options($options);
 83:         $value   = parent::set($name, $value, $options);
 84: 
 85:         return setcookie(
 86:             $this->normalize($name),
 87:             $value,
 88:             $options[self::OPTION_EXPIRE],
 89:             $options[self::OPTION_PATH],
 90:             $options[self::OPTION_DOMAIN],
 91:             false,
 92:             $options[self::OPTION_HTTP_ONLY]
 93:         );
 94:     }
 95: 
 96:     /**
 97:      * @param string $name
 98:      *
 99:      * @return bool
100:      *
101:      * @throws \InvalidArgumentException
102:      */
103:     public function remove($name)
104:     {
105:         parent::remove($name);
106: 
107:         return $this->set($name, null, [
108:             self::OPTION_EXPIRE => 0
109:         ]);
110:     }
111: 
112:     /**
113:      * @param string $name
114:      * @param mixed  $value
115:      *
116:      * @throws \InvalidArgumentException
117:      */
118:     public function __set($name, $value)
119:     {
120:         $this->set($name, $value);
121:     }
122: 
123:     /**
124:      * @param string $name
125:      *
126:      * @return bool
127:      *
128:      * @throws \InvalidArgumentException
129:      */
130:     public function __isset($name)
131:     {
132:         return $this->helper()->arr()->keyExists($this->storage(), $name);
133:     }
134: 
135:     /**
136:      * @return array
137:      */
138:     protected function storage()
139:     {
140:         return $this->object() ?: [];
141:     }
142: 
143: }
API documentation generated by ApiGen