An open API service indexing awesome lists of open source software.

https://github.com/tomkyle/session

PHP Session helper, extracted from my melting codebase monolith.
https://github.com/tomkyle/session

Last synced: 12 months ago
JSON representation

PHP Session helper, extracted from my melting codebase monolith.

Awesome Lists containing this project

README

          

#tomkyle/session

[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/tomkyle/Session/badges/quality-score.png?s=a80068f1af1333ff735c22e65e949c173b7872a0)](https://scrutinizer-ci.com/g/tomkyle/Session/)

A PHP Session helper that stores session data in sub-namespaces.

$_SESSION (PHP superglobal)
|
+-- SessionStorage (or derived class name)
|
+-- keyword (passed in instantiation)
|
+-- foo => bar
+-- key => value

##Example

```php
foo = "bar";
$namespace1->key = "value";

$namespace2 = new MySessionData( "user" );
$namespace2->foo = "baz";
$namespace2->key = 2000;

$namespace3 = new SessionStorage( "keyword" );
$namespace3->foo = "anything";
$namespace3->key = "something";

// will both print "bar":
echo $namespace1->foo;
// compare old-school:
echo $_SESSION['MySessionData']['keyword']['foo'];

// will both print "baz":
echo $namespace2->foo;
// compare old-school:
echo $_SESSION['MySessionData']['user']['foo'];

// will both print "not the same"
echo ($namespace1->foo == $namespace2->foo)
? "samesame" : "not the same";

echo ($namespace2->foo == $namespace3->foo)
? "samesame" : "not the same";
```