Skip to content

Commit

Permalink
phalcon#10789 - Add CookieInterface and use it
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Garbé committed Aug 13, 2015
1 parent 6d49131 commit f752d0d
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 14 deletions.
20 changes: 10 additions & 10 deletions phalcon/http/cookie.zep
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use Phalcon\Session\AdapterInterface as SessionInterface;
*
* Provide OO wrappers to manage a HTTP cookie
*/
class Cookie implements InjectionAwareInterface
class Cookie implements CookieInterface, InjectionAwareInterface
{

protected _readed = false;
Expand Down Expand Up @@ -117,7 +117,7 @@ class Cookie implements InjectionAwareInterface
* @param string value
* @return \Phalcon\Http\Cookie
*/
public function setValue(value) -> <Cookie>
public function setValue(value) -> <CookieInterface>
{
let this->_value = value,
this->_readed = true;
Expand Down Expand Up @@ -201,7 +201,7 @@ class Cookie implements InjectionAwareInterface
* Sends the cookie to the HTTP client
* Stores the cookie definition in session
*/
public function send() -> <Cookie>
public function send() -> <CookieInterface>
{
var name, value, expire, domain, path, secure, httpOnly,
dependencyInjector, definition, session, crypt, encryptValue;
Expand Down Expand Up @@ -287,7 +287,7 @@ class Cookie implements InjectionAwareInterface
* Reads the cookie-related info from the SESSION to restore the cookie as it was set
* This method is automatically called internally so normally you don't need to call it
*/
public function restore() -> <Cookie>
public function restore() -> <CookieInterface>
{
var dependencyInjector, expire, domain, path, secure,
httpOnly, session, definition;
Expand Down Expand Up @@ -360,7 +360,7 @@ class Cookie implements InjectionAwareInterface
/**
* Sets if the cookie must be encrypted/decrypted automatically
*/
public function useEncryption(boolean useEncryption) -> <Cookie>
public function useEncryption(boolean useEncryption) -> <CookieInterface>
{
let this->_useEncryption = useEncryption;
return this;
Expand All @@ -377,7 +377,7 @@ class Cookie implements InjectionAwareInterface
/**
* Sets the cookie's expiration time
*/
public function setExpiration(int expire) -> <Cookie>
public function setExpiration(int expire) -> <CookieInterface>
{
if !this->_restored {
this->restore();
Expand All @@ -400,7 +400,7 @@ class Cookie implements InjectionAwareInterface
/**
* Sets the cookie's expiration time
*/
public function setPath(string! path) -> <Cookie>
public function setPath(string! path) -> <CookieInterface>
{
if !this->_restored {
this->restore();
Expand Down Expand Up @@ -431,7 +431,7 @@ class Cookie implements InjectionAwareInterface
/**
* Sets the domain that the cookie is available to
*/
public function setDomain(string! domain) -> <Cookie>
public function setDomain(string! domain) -> <CookieInterface>
{
if !this->_restored {
this->restore();
Expand All @@ -454,7 +454,7 @@ class Cookie implements InjectionAwareInterface
/**
* Sets if the cookie must only be sent when the connection is secure (HTTPS)
*/
public function setSecure(boolean secure) -> <Cookie>
public function setSecure(boolean secure) -> <CookieInterface>
{
if !this->_restored {
this->restore();
Expand All @@ -477,7 +477,7 @@ class Cookie implements InjectionAwareInterface
/**
* Sets if the cookie is accessible only through the HTTP protocol
*/
public function setHttpOnly(boolean httpOnly) -> <Cookie>
public function setHttpOnly(boolean httpOnly) -> <CookieInterface>
{
if !this->_restored {
this->restore();
Expand Down
119 changes: 119 additions & 0 deletions phalcon/http/cookieinterface.zep
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@

/*
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to license@phalconphp.com so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Olivier Garbe <ogarbe@voyageprive.com |
+------------------------------------------------------------------------+
*/

namespace Phalcon\Http;

/**
* Phalcon\Http\CookieInterface
*
* Interface for Phalcon\Http\Cookie
*/
interface CookieInterface
{
/**
* Sets the cookie's value
*
* @param string value
* @return \Phalcon\Http\CookieInterface
*/
public function setValue(value) -> <CookieInterface>;

/**
* Returns the cookie's value
*
* @param string|array filters
* @param string defaultValue
* @return mixed
*/
public function getValue(filters = null, defaultValue = null);

/**
* Sends the cookie to the HTTP client
*/
public function send() -> <CookieInterface>;

/**
* Deletes the cookie
*/
public function delete();

/**
* Sets if the cookie must be encrypted/decrypted automatically
*/
public function useEncryption(boolean useEncryption) -> <CookieInterface>;

/**
* Check if the cookie is using implicit encryption
*/
public function isUsingEncryption() -> boolean;

/**
* Sets the cookie's expiration time
*/
public function setExpiration(int expire) -> <CookieInterface>;

/**
* Returns the current expiration time
*/
public function getExpiration() -> string;

/**
* Sets the cookie's expiration time
*/
public function setPath(string! path) -> <CookieInterface>;

/**
* Returns the current cookie's name
*/
public function getName() -> string;

/**
* Returns the current cookie's path
*/
public function getPath() -> string;

/**
* Sets the domain that the cookie is available to
*/
public function setDomain(string! domain) -> <CookieInterface>;

/**
* Returns the domain that the cookie is available to
*/
public function getDomain() -> string;

/**
* Sets if the cookie must only be sent when the connection is secure (HTTPS)
*/
public function setSecure(boolean secure) -> <CookieInterface>;

/**
* Returns whether the cookie must only be sent when the connection is secure (HTTPS)
*/
public function getSecure() -> boolean;

/**
* Sets if the cookie is accessible only through the HTTP protocol
*/
public function setHttpOnly(boolean httpOnly) -> <CookieInterface>;

/**
* Returns if the cookie is accessible only through the HTTP protocol
*/
public function getHttpOnly() -> boolean;
}
8 changes: 4 additions & 4 deletions phalcon/http/response/cookies.zep
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace Phalcon\Http\Response;

use Phalcon\DiInterface;
use Phalcon\Http\Cookie;
use Phalcon\Http\CookieInterface;
use Phalcon\Http\Response\CookiesInterface;
use Phalcon\Di\InjectionAwareInterface;
use Phalcon\Http\Cookie\Exception;
Expand Down Expand Up @@ -90,7 +90,7 @@ class Cookies implements CookiesInterface, InjectionAwareInterface
*/
if !fetch cookie, this->_cookies[name] {
let cookie =
<Cookie> this->_dependencyInjector->get("Phalcon\\Http\\Cookie",
<CookieInterface> this->_dependencyInjector->get("Phalcon\\Http\\Cookie",
[name, value, expire, path, secure, domain, httpOnly]);

/**
Expand Down Expand Up @@ -144,7 +144,7 @@ class Cookies implements CookiesInterface, InjectionAwareInterface
/**
* Gets a cookie from the bag
*/
public function get(string! name) -> <Cookie>
public function get(string! name) -> <CookieInterface>
{
var dependencyInjector, encryption, cookie;

Expand All @@ -155,7 +155,7 @@ class Cookies implements CookiesInterface, InjectionAwareInterface
/**
* Create the cookie if the it does not exist
*/
let cookie = <Cookie> this->_dependencyInjector->get("Phalcon\\Http\\Cookie", [name]),
let cookie = <CookieInterface> this->_dependencyInjector->get("Phalcon\\Http\\Cookie", [name]),
dependencyInjector = this->_dependencyInjector;

if typeof dependencyInjector == "object" {
Expand Down

0 comments on commit f752d0d

Please sign in to comment.