@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * THE SOFTWARE. |
| 24 | 24 | */ |
| 25 | 25 | |
| 26 | -class EncryptedCookie extends CookieBase implements CookieInterface { |
|
| 26 | +class EncryptedCookie extends CookieBase implements CookieInterface {
|
|
| 27 | 27 | |
| 28 | 28 | /* |
| 29 | 29 | * AES key |
@@ -43,23 +43,23 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @throws \Comodojo\Exception\CookieException |
| 45 | 45 | */ |
| 46 | - public function __construct($name, $key) { |
|
| 46 | + public function __construct($name, $key) {
|
|
| 47 | 47 | |
| 48 | 48 | if ( empty($key) OR !is_scalar($key) ) throw new CookieException("Invalid secret key"); |
| 49 | 49 | |
| 50 | 50 | $this->key = $key; |
| 51 | 51 | |
| 52 | - try { |
|
| 52 | + try {
|
|
| 53 | 53 | |
| 54 | 54 | $this->setName($name); |
| 55 | 55 | |
| 56 | - } catch (CookieException $ce) { |
|
| 56 | + } catch (CookieException $ce) {
|
|
| 57 | 57 | |
| 58 | 58 | throw $ce; |
| 59 | 59 | |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - if ( defined("COMODOJO_COOKIE_MAX_SIZE") ) { |
|
| 62 | + if ( defined("COMODOJO_COOKIE_MAX_SIZE") ) {
|
|
| 63 | 63 | |
| 64 | 64 | $this->max_cookie_size = filter_var(COMODOJO_COOKIE_MAX_SIZE, FILTER_VALIDATE_INT, array( |
| 65 | 65 | 'options' => array( |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * |
| 82 | 82 | * @throws \Comodojo\Exception\CookieException |
| 83 | 83 | */ |
| 84 | - public function setValue($value, $serialize = true) { |
|
| 84 | + public function setValue($value, $serialize = true) {
|
|
| 85 | 85 | |
| 86 | 86 | if ( !is_scalar($value) AND $serialize === false ) throw new CookieException("Cannot set non-scalar value without serialization"); |
| 87 | 87 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * |
| 115 | 115 | * @return mixed |
| 116 | 116 | */ |
| 117 | - public function getValue($unserialize = true) { |
|
| 117 | + public function getValue($unserialize = true) {
|
|
| 118 | 118 | |
| 119 | 119 | $cipher = new Crypt_AES(CRYPT_AES_MODE_ECB); |
| 120 | 120 | |
@@ -149,15 +149,15 @@ discard block |
||
| 149 | 149 | * |
| 150 | 150 | * @throws \Comodojo\Exception\CookieException |
| 151 | 151 | */ |
| 152 | - public static function create($name, $key, $properties = array(), $serialize = true) { |
|
| 152 | + public static function create($name, $key, $properties = array(), $serialize = true) {
|
|
| 153 | 153 | |
| 154 | - try { |
|
| 154 | + try {
|
|
| 155 | 155 | |
| 156 | 156 | $cookie = new EncryptedCookie($name, $key); |
| 157 | 157 | |
| 158 | 158 | self::cookieProperties($cookie, $properties, $serialize); |
| 159 | 159 | |
| 160 | - } catch (CookieException $ce) { |
|
| 160 | + } catch (CookieException $ce) {
|
|
| 161 | 161 | |
| 162 | 162 | throw $ce; |
| 163 | 163 | |
@@ -178,15 +178,15 @@ discard block |
||
| 178 | 178 | * |
| 179 | 179 | * @throws \Comodojo\Exception\CookieException |
| 180 | 180 | */ |
| 181 | - public static function retrieve($name, $key) { |
|
| 181 | + public static function retrieve($name, $key) {
|
|
| 182 | 182 | |
| 183 | - try { |
|
| 183 | + try {
|
|
| 184 | 184 | |
| 185 | 185 | $cookie = new EncryptedCookie($name, $key); |
| 186 | 186 | |
| 187 | 187 | $return = $cookie->load(); |
| 188 | 188 | |
| 189 | - } catch (CookieException $ce) { |
|
| 189 | + } catch (CookieException $ce) {
|
|
| 190 | 190 | |
| 191 | 191 | throw $ce; |
| 192 | 192 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * |
| 206 | 206 | * @return string |
| 207 | 207 | */ |
| 208 | - private static function EncryptedKey($key) { |
|
| 208 | + private static function EncryptedKey($key) {
|
|
| 209 | 209 | |
| 210 | 210 | return hash('sha256', $key); |
| 211 | 211 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * THE SOFTWARE. |
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | -class CookieBase { |
|
| 23 | +class CookieBase {
|
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * The cookie name |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @throws \Comodojo\Exception\CookieException |
| 91 | 91 | */ |
| 92 | - public function setName($name) { |
|
| 92 | + public function setName($name) {
|
|
| 93 | 93 | |
| 94 | 94 | if ( empty($name) OR !is_scalar($name) ) throw new CookieException("Invalid cookie name"); |
| 95 | 95 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @return string |
| 106 | 106 | */ |
| 107 | - public function getName() { |
|
| 107 | + public function getName() {
|
|
| 108 | 108 | |
| 109 | 109 | return $this->name; |
| 110 | 110 | |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * |
| 120 | 120 | * @throws \Comodojo\Exception\CookieException |
| 121 | 121 | */ |
| 122 | - public function setExpire($timestamp) { |
|
| 122 | + public function setExpire($timestamp) {
|
|
| 123 | 123 | |
| 124 | 124 | if ( !is_int($timestamp) ) throw new CookieException("Invalud cookie's expiration time"); |
| 125 | 125 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * |
| 139 | 139 | * @throws \Comodojo\Exception\CookieException |
| 140 | 140 | */ |
| 141 | - public function setPath($location) { |
|
| 141 | + public function setPath($location) {
|
|
| 142 | 142 | |
| 143 | 143 | if ( !is_string($location) ) throw new CookieException("Invalid path attribute"); |
| 144 | 144 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * |
| 158 | 158 | * @throws \Comodojo\Exception\CookieException |
| 159 | 159 | */ |
| 160 | - public function setDomain($domain) { |
|
| 160 | + public function setDomain($domain) {
|
|
| 161 | 161 | |
| 162 | 162 | if ( !is_scalar($domain) OR !self::checkDomain($domain) ) throw new CookieException("Invalid domain attribute"); |
| 163 | 163 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @return \Comodojo\Cookies\CookieBase |
| 176 | 176 | */ |
| 177 | - public function setSecure($mode = true) { |
|
| 177 | + public function setSecure($mode = true) {
|
|
| 178 | 178 | |
| 179 | 179 | $this->secure = filter_var($mode, FILTER_VALIDATE_BOOLEAN); |
| 180 | 180 | |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | * |
| 190 | 190 | * @return \Comodojo\Cookies\CookieBase |
| 191 | 191 | */ |
| 192 | - public function setHttponly($mode = true) { |
|
| 192 | + public function setHttponly($mode = true) {
|
|
| 193 | 193 | |
| 194 | 194 | $this->httponly = filter_var($mode, FILTER_VALIDATE_BOOLEAN); |
| 195 | 195 | |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * |
| 205 | 205 | * @throws \Comodojo\Exception\CookieException |
| 206 | 206 | */ |
| 207 | - public function save() { |
|
| 207 | + public function save() {
|
|
| 208 | 208 | |
| 209 | 209 | if ( setcookie( |
| 210 | 210 | $this->name, |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | * |
| 228 | 228 | * @throws \Comodojo\Exception\CookieException |
| 229 | 229 | */ |
| 230 | - public function load() { |
|
| 230 | + public function load() {
|
|
| 231 | 231 | |
| 232 | 232 | if ( !$this->exists() ) throw new CookieException("Cookie does not exists"); |
| 233 | 233 | |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | * |
| 245 | 245 | * @throws \Comodojo\Exception\CookieException |
| 246 | 246 | */ |
| 247 | - public function delete() { |
|
| 247 | + public function delete() {
|
|
| 248 | 248 | |
| 249 | 249 | if ( !$this->exists() ) return true; |
| 250 | 250 | |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | * |
| 268 | 268 | * @return bool |
| 269 | 269 | */ |
| 270 | - public function exists() { |
|
| 270 | + public function exists() {
|
|
| 271 | 271 | |
| 272 | 272 | return isset($_COOKIE[$this->name]); |
| 273 | 273 | |
@@ -282,15 +282,15 @@ discard block |
||
| 282 | 282 | * |
| 283 | 283 | * @throws \Comodojo\Exception\CookieException |
| 284 | 284 | */ |
| 285 | - public static function erase($name) { |
|
| 285 | + public static function erase($name) {
|
|
| 286 | 286 | |
| 287 | - try { |
|
| 287 | + try {
|
|
| 288 | 288 | |
| 289 | 289 | $cookie = new Cookie($name); |
| 290 | 290 | |
| 291 | 291 | $return = $cookie->delete(); |
| 292 | 292 | |
| 293 | - } catch (CookieException $ce) { |
|
| 293 | + } catch (CookieException $ce) {
|
|
| 294 | 294 | |
| 295 | 295 | throw $ce; |
| 296 | 296 | |
@@ -311,11 +311,11 @@ discard block |
||
| 311 | 311 | * |
| 312 | 312 | * @return \Comodojo\Cookies\CookieBase |
| 313 | 313 | */ |
| 314 | - protected static function cookieProperties(\Comodojo\Cookies\CookieInterface\CookieInterface $cookie, $properties, $serialize) { |
|
| 314 | + protected static function cookieProperties(\Comodojo\Cookies\CookieInterface\CookieInterface $cookie, $properties, $serialize) {
|
|
| 315 | 315 | |
| 316 | - foreach ( $properties as $property => $value ) { |
|
| 316 | + foreach ( $properties as $property => $value ) {
|
|
| 317 | 317 | |
| 318 | - switch ( $property ) { |
|
| 318 | + switch ( $property ) {
|
|
| 319 | 319 | |
| 320 | 320 | case 'value': |
| 321 | 321 | |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | * |
| 371 | 371 | * @return bool |
| 372 | 372 | */ |
| 373 | - protected static function checkDomain($domain_name) { |
|
| 373 | + protected static function checkDomain($domain_name) {
|
|
| 374 | 374 | |
| 375 | 375 | if ( $domain_name[0] == '.' ) $domain_name = substr($domain_name, 1); |
| 376 | 376 | |