Skip to content

Commit

Permalink
Tidied up the Session Adapters.
Browse files Browse the repository at this point in the history
  • Loading branch information
SidRoberts committed May 30, 2015
1 parent 7813230 commit 3a2f3f1
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 111 deletions.
14 changes: 1 addition & 13 deletions phalcon/session/adapter.zep
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ abstract class Adapter

/**
* Starts the session (if headers are already sent the session will not be started)
*
* @return boolean
*/
public function start() -> boolean
{
Expand All @@ -76,8 +74,6 @@ abstract class Adapter
* 'uniqueId' => 'my-private-app'
* ));
*</code>
*
* @param array options
*/
public function setOptions(array! options)
{
Expand All @@ -92,10 +88,8 @@ abstract class Adapter

/**
* Get internal options
*
* @return array
*/
public function getOptions()
public function getOptions() -> array
{
return this->_options;
}
Expand Down Expand Up @@ -143,8 +137,6 @@ abstract class Adapter
*<code>
* var_dump($session->has('auth'));
*</code>
*
* @param string index
*/
public function has(string index) -> boolean
{
Expand Down Expand Up @@ -181,8 +173,6 @@ abstract class Adapter
*<code>
* $session->setId($id);
*</code>
*
* @param string id
*/
public function setId(string id)
{
Expand Down Expand Up @@ -269,8 +259,6 @@ abstract class Adapter

/**
* Alias: Check whether a session variable is set in an application context
*
* @param string index
*/
public function __isset(string index) -> boolean
{
Expand Down
49 changes: 20 additions & 29 deletions phalcon/session/adapter/libmemcached.zep
Original file line number Diff line number Diff line change
Expand Up @@ -59,50 +59,41 @@ class Libmemcached extends Adapter implements AdapterInterface

/**
* Phalcon\Session\Adapter\Libmemcached constructor
*
* @param array options
*/
public function __construct(options = null)
public function __construct(array options)
{
var servers, client, lifetime, prefix, statsKey;

if typeof options != "array" {
throw new Exception("The options must be an array");
}

if !isset options["servers"] {
if !fetch servers, options["servers"] {
throw new Exception("No servers given in options");
}

let servers = options["servers"];

if !isset options["client"] {
let client = NULL;
} else {
let client = options["client"];
if !fetch client, options["client"] {
let client = null;
}

if fetch lifetime, options["lifetime"] {
let this->_lifetime = lifetime;
} else {
let this->_lifetime = 8600;
if !fetch lifetime, options["lifetime"] {
let lifetime = 8600;
}

let this->_lifetime = lifetime;

if !fetch prefix, options["prefix"] {
let prefix = NULL;
} else {
let prefix = options["prefix"];
let prefix = null;
}

if !fetch statsKey, options["statsKey"] {
let statsKey = NULL;
} else {
let statsKey = options["statsKey"];
let statsKey = null;
}

let this->_libmemcached = new Libmemcached(
new FrontendData(["lifetime": this->_lifetime]),
["servers": servers, "client": client, "prefix": prefix, "statsKey": statsKey]
[
"servers": servers,
"client": client,
"prefix": prefix,
"statsKey": statsKey
]
);

session_set_save_handler(
Expand Down Expand Up @@ -155,12 +146,12 @@ class Libmemcached extends Adapter implements AdapterInterface
* @param string sessionId
* @return boolean
*/
public function destroy(session_id = null)
public function destroy(sessionId = null)
{
if session_id === null {
let session_id = this->getId();
if sessionId === null {
let sessionId = this->getId();
}
return this->_libmemcached->delete(session_id);
return this->_libmemcached->delete(sessionId);
}

/**
Expand Down
18 changes: 6 additions & 12 deletions phalcon/session/adapter/memcache.zep
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,17 @@ use Phalcon\Cache\Frontend\Data as FrontendData;
class Memcache extends Adapter implements AdapterInterface
{

protected _memcache = NULL { get };
protected _memcache = null { get };

protected _lifetime = 8600 { get };

/**
* Phalcon\Session\Adapter\Memcache constructor
*
* @param array options
*/
public function __construct(options = null)
public function __construct(array options = [])
{
var lifetime;

if typeof options != "array" {
let options = [];
}

if !isset options["host"] {
let options["host"] = "127.0.0.1";
}
Expand Down Expand Up @@ -137,12 +131,12 @@ class Memcache extends Adapter implements AdapterInterface
* @param string sessionId
* @return boolean
*/
public function destroy(session_id = null)
public function destroy(sessionId = null) -> boolean
{
if session_id === null {
let session_id = this->getId();
if sessionId === null {
let sessionId = this->getId();
}
return this->_memcache->delete(session_id);
return this->_memcache->delete(sessionId);
}

/**
Expand Down
33 changes: 8 additions & 25 deletions phalcon/session/adapterinterface.zep
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,18 @@ interface AdapterInterface

/**
* Starts session, optionally using an adapter
*
* @param array options
*/
public function start();

/**
* Sets session options
*
* @param array options
*/
public function setOptions(array! options);

/**
* Get internal options
*
* @return array
*/
public function getOptions();
public function getOptions() -> array;

/**
* Gets a session variable from an application context
Expand All @@ -55,50 +49,39 @@ interface AdapterInterface
* @param mixed defaultValue
* @return mixed
*/
public function get(index, defaultValue = null);
public function get(string index, defaultValue = null);

/**
* Sets a session variable in an application context
*
* @param string index
* @param string value
*/
public function set(index, value);
public function set(string index, value);

/**
* Check whether a session variable is set in an application context
*
* @param string index
* @return boolean
*/
public function has(index);
public function has(string index) -> boolean;

/**
* Removes a session variable from an application context
*
* @param string index
*/
public function remove(index);
public function remove(string index);

/**
* Returns active session id
*
* @return string
*/
public function getId();
public function getId() -> string;

/**
* Check whether the session has been started
*
* @return boolean
*/
public function isStarted();
public function isStarted() -> boolean;

/**
* Destroys the active session
*
* @return boolean
*/
public function destroy();
public function destroy() -> boolean;

}
20 changes: 0 additions & 20 deletions phalcon/session/bag.zep
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class Bag implements InjectionAwareInterface, BagInterface, \IteratorAggregate,

/**
* Phalcon\Session\Bag constructor
*
* @param string name
*/
public function __construct(string! name)
{
Expand All @@ -60,8 +58,6 @@ class Bag implements InjectionAwareInterface, BagInterface, \IteratorAggregate,

/**
* Sets the DependencyInjector container
*
* @param Phalcon\DiInterface dependencyInjector
*/
public function setDI(<DiInterface> dependencyInjector)
{
Expand All @@ -70,8 +66,6 @@ class Bag implements InjectionAwareInterface, BagInterface, \IteratorAggregate,

/**
* Returns the DependencyInjector container
*
* @return Phalcon\DiInterface
*/
public function getDI() -> <DiInterface>
{
Expand Down Expand Up @@ -210,9 +204,6 @@ class Bag implements InjectionAwareInterface, BagInterface, \IteratorAggregate,
*<code>
* var_dump($user->has('name'));
*</code>
*
* @param string property
* @return boolean
*/
public function has(string! property) -> boolean
{
Expand All @@ -229,9 +220,6 @@ class Bag implements InjectionAwareInterface, BagInterface, \IteratorAggregate,
*<code>
* var_dump(isset($user['name']));
*</code>
*
* @param string property
* @return boolean
*/
public function __isset(string! property) -> boolean
{
Expand All @@ -244,9 +232,6 @@ class Bag implements InjectionAwareInterface, BagInterface, \IteratorAggregate,
*<code>
* $user->remove('name');
*</code>
*
* @param string property
* @return boolean
*/
public function remove(string! property) -> boolean
{
Expand All @@ -264,9 +249,6 @@ class Bag implements InjectionAwareInterface, BagInterface, \IteratorAggregate,
*<code>
* unset($user['name']);
*</code>
*
* @param string property
* @return boolean
*/
public function __unset(string! property) -> boolean
{
Expand All @@ -279,8 +261,6 @@ class Bag implements InjectionAwareInterface, BagInterface, \IteratorAggregate,
*<code>
* echo $user->count();
*</code>
*
* @return int
*/
public final function count() -> int
{
Expand Down
18 changes: 6 additions & 12 deletions phalcon/session/baginterface.zep
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ interface BagInterface
* @param string property
* @param string value
*/
public function set(property, value);
public function set(string! property, value);

/**
* Getter of values
Expand All @@ -52,38 +52,32 @@ interface BagInterface
* @param mixed defaultValue
* @return mixed
*/
public function get(property, defaultValue = null);
public function get(string! property, defaultValue = null);

/**
* Isset property
*
* @param string property
* @return boolean
*/
public function has(property);
public function has(string! property) -> boolean;

/**
* Setter of values
*
* @param string property
* @param string value
*/
public function __set(property, value);
public function __set(string! property, value);

/**
* Getter of values
*
* @param string property
* @return mixed
*/
public function __get(property);
public function __get(string! property);

/**
* Isset property
*
* @param string property
* @return boolean
*/
public function __isset(property);
public function __isset(string! property) -> boolean;

}

0 comments on commit 3a2f3f1

Please sign in to comment.