class-thelib-array.php
5 years ago
class-thelib-core.php
5 years ago
class-thelib-debug.php
5 years ago
class-thelib-html.php
5 years ago
class-thelib-net.php
5 years ago
class-thelib-session.php
5 years ago
class-thelib-ui.php
5 years ago
class-thelib-updates.php
5 years ago
class-thelib.php
5 years ago
class-thelib-session.php
57 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The Session storage component. |
| 4 | * Access via function `lib3()->session`. |
| 5 | * |
| 6 | * @since 1.1.4 |
| 7 | */ |
| 8 | class TheLib_Session extends TheLib { |
| 9 | |
| 10 | /** |
| 11 | * Adds a value to the data collection in the user session. |
| 12 | * |
| 13 | * @since 1.0.15 |
| 14 | * @api |
| 15 | * |
| 16 | * @param string $key The key of the value. |
| 17 | * @param mixed $value Value to store. |
| 18 | */ |
| 19 | public function add( $key, $value ) { |
| 20 | self::_sess_add( 'store:' . $key, $value ); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Returns the current data array of the specified value from user session. |
| 25 | * |
| 26 | * @since 1.0.15 |
| 27 | * @api |
| 28 | * |
| 29 | * @param string $key The key of the value. |
| 30 | * @return array The value, or an empty array if no value was assigned yet. |
| 31 | */ |
| 32 | public function get( $key ) { |
| 33 | $vals = self::_sess_get( 'store:' . $key ); |
| 34 | foreach ( $vals as $key => $val ) { |
| 35 | if ( null === $val ) { unset( $vals[ $key ] ); } |
| 36 | } |
| 37 | $vals = array_values( $vals ); |
| 38 | return $vals; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Returns the current data array of the specified value from user session |
| 43 | * and then clears the values from the session. |
| 44 | * |
| 45 | * @since 1.0.15 |
| 46 | * @api |
| 47 | * |
| 48 | * @param string $key The key of the value. |
| 49 | * @return array The value, or an empty array if no value was assigned yet. |
| 50 | */ |
| 51 | public function get_clear( $key ) { |
| 52 | $val = $this->get( $key ); |
| 53 | self::_sess_clear( 'store:' . $key ); |
| 54 | return $val; |
| 55 | } |
| 56 | |
| 57 | } |