PHP Класс Habari\Session

Manages sessions for the PHP session routines
Наследование: extends Singleton
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$session_changed
$session_id
$stored_session_hash
$write_queue * The initial data. Used to determine whether we should write anything.

Открытые методы

Метод Описание
add_to_set ( string $set, mixed $value, string $key = null ) Adds a value to a session set
cache_limiter ( string $type = 'nocache' ) : void Sends HTTP headers that limit the cacheability of the page.
changed ( ) : boolean Determine if the session data has changed
clear_userid ( integer $user_id ) Clear the user_id attached to sessions, delete other sessions that are associated to the user_id
cookie ( string $data, null | integer $expiration = null ) Sends the Habari session cookie to the browser with the given payload and expiration.
create ( ) Create a new session - that is, generate an ID and set the session cookie
destroy ( ) Destroy stored session data by session id
error ( string $error, string $key = null ) Store an error message in the user's session
gc ( ) Session garbage collection deletes expired sessions
get_error ( string $key, boolean $clear = true ) : string Retrieve a specific error from stored errors.
get_errors ( boolean $clear = true ) : array Get all error messages from the user session
get_notice ( string $key, boolean $clear = true ) : string Retrieve a specific notice from stored errors.
get_notices ( boolean $clear = true ) : array Get all notice messages from the user session
get_set ( string $set, boolean $clear = true ) : array Return a set of messages
has_errors ( string $key = null ) : boolean Determine if there are error messages to display
has_messages ( ) : boolean Determine if there are messages that should be displayed Messages are not cleared when calling this function.
init ( ) Initialize the session handlers
messages_get ( boolean $clear = true, array $callback = null ) : mixed Return output of notice and error messages
messages_out ( boolean $clear = true, null | callable $callback = null ) Output notice and error messages
notice ( string $notice, string $key = null ) Store a notice message in the user's session
process_queue ( ) Call update() on QueryRecords or execute the function queued with self::queue()
queue ( QueryRecord | Callable $fn, null | string $name = null ) Add objects or functions to the post-processing queue, executed via self::process_queue()
read ( ) : boolean Read session data from the database and load it into the $_SESSION global.
remove_error ( string $key ) : boolean Removes a specific error from the stored errors.
remove_notice ( string $key ) : boolean Removes a specific notice from the stored notices.
session_data_hash ( ) : string Get a hash of the contents of the session data for change comparison
set_userid ( integer $user_id ) Sets the user_id attached to the current session
shutdown ( )
write ( ) Commit $_SESSION data to the database for this user.

Защищенные методы

Метод Описание
get_subnet ( string $remote_address = '' ) : integer | string Helper function to find the Class A, B, or C subnet of the given IP address.

Описание методов

add_to_set() публичный статический Метод

Adds a value to a session set
public static add_to_set ( string $set, mixed $value, string $key = null )
$set string Name of the set
$value mixed value to store
$key string Optional unique key for the set under which to store the value

cache_limiter() публичный статический Метод

Sends HTTP headers that limit the cacheability of the page.
public static cache_limiter ( string $type = 'nocache' ) : void
$type string The type of caching headers to send. One of: 'public', 'private_no_expire', 'private', 'nocache', or ''.
Результат void

changed() публичный статический Метод

Determine if the session data has changed
public static changed ( ) : boolean
Результат boolean True if the session data has changed

clear_userid() публичный статический Метод

Clear the user_id attached to sessions, delete other sessions that are associated to the user_id
public static clear_userid ( integer $user_id )
$user_id integer The user_id to clear.

create() публичный статический Метод

Create a new session - that is, generate an ID and set the session cookie
public static create ( )

destroy() публичный статический Метод

Destroy stored session data by session id
public static destroy ( )

error() публичный статический Метод

Store an error message in the user's session
public static error ( string $error, string $key = null )
$error string The error message
$key string An optional id that would guarantee a single unique message for this key

gc() публичный статический Метод

Session garbage collection deletes expired sessions
public static gc ( )

get_error() публичный статический Метод

Retrieve a specific error from stored errors.
public static get_error ( string $key, boolean $clear = true ) : string
$key string ID of the error to retrieve
$clear boolean true to clear the error from the session upon receipt
Результат string Return the error message

get_errors() публичный статический Метод

Get all error messages from the user session
public static get_errors ( boolean $clear = true ) : array
$clear boolean true to clear the messages from the session upon receipt
Результат array And array of error messages

get_notice() публичный статический Метод

Retrieve a specific notice from stored errors.
public static get_notice ( string $key, boolean $clear = true ) : string
$key string ID of the notice to retrieve
$clear boolean true to clear the notice from the session upon receipt
Результат string Return the notice message

get_notices() публичный статический Метод

Get all notice messages from the user session
public static get_notices ( boolean $clear = true ) : array
$clear boolean true to clear the messages from the session upon receipt
Результат array And array of notice messages

get_set() публичный статический Метод

Return a set of messages
public static get_set ( string $set, boolean $clear = true ) : array
$set string The name of the message set
$clear boolean true to clear the messages from the session upon receipt
Результат array An array of message strings

get_subnet() защищенный статический Метод

We use this to store subnets for each IPv4 session, rather than distinct IPs, which could be pooled or rotated on large networks.
protected static get_subnet ( string $remote_address = '' ) : integer | string
$remote_address string The remote host's IP address.
Результат integer | string The numeric subnet, if IPv4. The complete address, as passed, if a valid IPv6.

has_errors() публичный статический Метод

Determine if there are error messages to display
public static has_errors ( string $key = null ) : boolean
$key string Optional key of the unique error message
Результат boolean true if there are errors, false if not

has_messages() публичный статический Метод

Determine if there are messages that should be displayed Messages are not cleared when calling this function.
public static has_messages ( ) : boolean
Результат boolean true if there are messages to display.

init() публичный статический Метод

Initialize the session handlers
public static init ( )

messages_get() публичный статический Метод

Return output of notice and error messages
public static messages_get ( boolean $clear = true, array $callback = null ) : mixed
$clear boolean true to clear the messages from the session upon receipt
$callback array a reference to a callback function for formatting the the messages or the string 'array' to get a raw array
Результат mixed output of messages

messages_out() публичный статический Метод

Output notice and error messages
public static messages_out ( boolean $clear = true, null | callable $callback = null )
$clear boolean true to clear the messages from the session upon receipt
$callback null | callable A reference to a callback function for formatting the messages

notice() публичный статический Метод

Store a notice message in the user's session
public static notice ( string $notice, string $key = null )
$notice string The notice message
$key string An optional id that would guarantee a single unique message for this key

process_queue() публичный статический Метод

Call update() on QueryRecords or execute the function queued with self::queue()
public static process_queue ( )

queue() публичный статический Метод

Add objects or functions to the post-processing queue, executed via self::process_queue()
public static queue ( QueryRecord | Callable $fn, null | string $name = null )
$fn QueryRecord | Callable A QueryRecord to call ->update() on, or a function to execute
$name null | string An index to save the queue under, defaults to the SPL object hash for objects

read() публичный статический Метод

Verifies against a number of parameters for security purposes.
public static read ( ) : boolean
Результат boolean Whether a session was loaded or not

remove_error() публичный статический Метод

Removes a specific error from the stored errors.
public static remove_error ( string $key ) : boolean
$key string ID of the error to remove
Результат boolean True or false depending if the error was removed successfully.

remove_notice() публичный статический Метод

Removes a specific notice from the stored notices.
public static remove_notice ( string $key ) : boolean
$key string ID of the notice to remove
Результат boolean True or false depending if the notice was removed successfully.

session_data_hash() публичный статический Метод

Get a hash of the contents of the session data for change comparison
public static session_data_hash ( ) : string
Результат string a hash of the session data

set_userid() публичный статический Метод

Sets the user_id attached to the current session
public static set_userid ( integer $user_id )
$user_id integer The user id of the current user

shutdown() публичный статический Метод

public static shutdown ( )

write() публичный статический Метод

Commit $_SESSION data to the database for this user.
public static write ( )

Описание свойств

$session_changed статическое публичное свойство

static public $session_changed

$session_id статическое публичное свойство

static public $session_id

$stored_session_hash статическое публичное свойство

static public $stored_session_hash

$write_queue статическое публичное свойство

* The initial data. Used to determine whether we should write anything.
static public $write_queue