-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
226 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
/** | ||
* | ||
* PHP.Gt (http://php.gt) | ||
* @copyright Copyright Ⓒ 2014 Bright Flair Ltd. (http://brightflair.com) | ||
* @license Apache Version 2.0, January 2004. http://www.apache.org/licenses | ||
*/ | ||
namespace Gt\Session; | ||
|
||
class Session { | ||
|
||
private $config; | ||
private $store; | ||
|
||
public function __construct($config) { | ||
$this->config = $config; | ||
session_start(); | ||
if(!isset($_SESSION[$this->config->base_namespace])) { | ||
$_SESSION[$this->config->base_namespace] = new Store($this->config); | ||
} | ||
|
||
$this->store = $_SESSION[$this->config->base_namespace]; | ||
} | ||
|
||
|
||
/** | ||
* | ||
*/ | ||
public function get($key) { | ||
return $this->store[$key]; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function exists($key) { | ||
return isset($this->store[$key]); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function set($key, $value) { | ||
$this->store[$key] = $value; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function delete($key) { | ||
unset($this->store[$key]); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
private function fixCase($key) { | ||
if(!$config->case_sensitive) { | ||
return strtoupper($key); | ||
} | ||
|
||
return $key; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
private function getNamespaceArray($string) { | ||
$nsArray = array(); | ||
|
||
if(is_string($ns)) { | ||
$nsArray = explode(".", $ns); | ||
} | ||
else if(is_array($ns)) { | ||
$nsArray = $ns; | ||
} | ||
else { | ||
// TODO: throw exception | ||
die("getNsArray error!!!"); | ||
} | ||
|
||
return $nsArray; | ||
} | ||
|
||
/** | ||
* Initialises a nested array and returns reference to the deepest (the leaf). | ||
* | ||
* @param array $arrayContainer description | ||
*/ | ||
private function initLeaf(&$arrayContainer, $nsToInit, &$leaf = null) { | ||
if(empty($nsToInit)) { | ||
return $leaf; | ||
} | ||
|
||
$initKey = array_shift($nsToInit); | ||
|
||
if(!isset($arrayContainer[$initKey])) { | ||
$arrayContainer[$initKey] = array(); | ||
} | ||
|
||
return self::initLeaf( | ||
$arrayContainer[$initKey], | ||
$nsToInit, | ||
$arrayContainer[$initKey] | ||
); | ||
} | ||
|
||
}# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
/** | ||
* Represents a branch of a session namespace. | ||
* Session storage Shop.Basket.Intl.value has three stores (Shop that contains | ||
* Basket, that in turn contains Intl, that in turn contains the StoreValue | ||
* represented by value). | ||
* | ||
* PHP.Gt (http://php.gt) | ||
* @copyright Copyright Ⓒ 2014 Bright Flair Ltd. (http://brightflair.com) | ||
* @license Apache Version 2.0, January 2004. http://www.apache.org/licenses | ||
*/ | ||
namespace Gt\Session; | ||
|
||
class Store implements \ArrayAccess { | ||
|
||
private $tempStorage = []; | ||
|
||
public function __construct($config) { | ||
$this->caseSensitive = $config->case_sensitive; | ||
} | ||
|
||
public function offsetExists($key) { | ||
return isset($this->tempStorage[$key]); | ||
} | ||
public function offsetGet($key) { | ||
return $this->tempStorage[$key]; | ||
} | ||
public function offsetSet($key, $value) { | ||
$this->tempStorage[$key] = $value; | ||
} | ||
public function offsetUnset($key) { | ||
unset($this->tempStorage[$key]); | ||
} | ||
|
||
}# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
/** | ||
* | ||
* PHP.Gt (http://php.gt) | ||
* @copyright Copyright Ⓒ 2014 Bright Flair Ltd. (http://brightflair.com) | ||
* @license Apache Version 2.0, January 2004. http://www.apache.org/licenses | ||
*/ | ||
namespace Gt\Session; | ||
|
||
class StoreValue { | ||
|
||
public function __construct() { | ||
} | ||
|
||
}# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
/** | ||
* PHP.Gt (http://php.gt) | ||
* @copyright Copyright Ⓒ 2014 Bright Flair Ltd. (http://brightflair.com) | ||
* @license Apache Version 2.0, January 2004. http://www.apache.org/licenses | ||
*/ | ||
namespace Gt\Api; | ||
|
||
class Api_Test extends \PHPUnit_Framework_TestCase { | ||
|
||
public function testTest() { | ||
$this->assertFalse(false); | ||
} | ||
|
||
}# |