| 1 | <?php |
||
| 9 | class CSession |
||
| 10 | { |
||
| 11 | use \Anax\TConfigure; |
||
| 12 | |||
| 13 | |||
| 14 | |||
| 15 | /** |
||
| 16 | * Construct session. |
||
| 17 | * |
||
| 18 | * @param array $options to configure options. |
||
| 19 | */ |
||
| 20 | 4 | public function __construct($options = []) |
|
| 24 | |||
| 25 | |||
| 26 | |||
| 27 | /** |
||
| 28 | * Set a session name or use one from config. |
||
| 29 | * |
||
| 30 | * @param array $aName to set as session name, default is null and then use name from config. |
||
| 31 | */ |
||
| 32 | 2 | public function name($aName = null) |
|
| 33 | { |
||
| 34 | 2 | $name = isset($aName) |
|
| 35 | 2 | ? $aName |
|
| 36 | 2 | : (isset($this->config['name']) |
|
| 37 | 1 | ? $this->config['name'] |
|
| 38 | 2 | : "anax"); |
|
| 39 | |||
| 40 | 2 | session_name($name); |
|
| 41 | 2 | } |
|
| 42 | |||
| 43 | |||
| 44 | /** |
||
| 45 | * Start session. |
||
| 46 | * |
||
| 47 | * @param array $options to configure options. |
||
| 48 | */ |
||
| 49 | public function start($options = []) |
||
| 53 | |||
| 54 | |||
| 55 | |||
| 56 | /** |
||
| 57 | * Get values from session. |
||
| 58 | * |
||
| 59 | * @param string $key in session variable. |
||
| 60 | * @param mixed $default default value to return when key is not set in session. |
||
| 61 | * |
||
| 62 | * @return mixed |
||
| 63 | */ |
||
| 64 | 1 | public function get($key, $default = null) |
|
| 65 | { |
||
| 66 | 1 | return isset($_SESSION) && isset($_SESSION[$key]) |
|
| 67 | 1 | ? $_SESSION[$key] |
|
| 68 | 1 | : $default; |
|
| 69 | } |
||
| 70 | |||
| 71 | |||
| 72 | |||
| 73 | /** |
||
| 74 | * Set values in session. |
||
| 75 | * |
||
| 76 | * @param string $key in session variable. |
||
| 77 | * @param mixed $value to set in session. |
||
| 78 | * |
||
| 79 | * @return void |
||
| 80 | */ |
||
| 81 | 1 | public function set($key, $value) |
|
| 85 | |||
| 86 | |||
| 87 | |||
| 88 | /** |
||
| 89 | * Check if a value is set in the session. |
||
| 90 | * |
||
| 91 | * @param string $key in session variable. |
||
| 92 | * |
||
| 93 | * @return boolean true if $key is set, else false. |
||
| 94 | */ |
||
| 95 | 1 | public function has($key) |
|
| 99 | } |
||
| 100 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.