PHP 클래스 Cake\Network\Session

CakePHP abstracts the handling of sessions. There are several convenient methods to access session information. This class is the implementation of those methods. They are mostly used by the Session Component.
파일 보기 프로젝트 열기: cakephp/cakephp 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$_engine SessionHandlerInterface The Session handler instance used as an engine for persisting the session data.
$_isCLI boolean Whether this session is running under a CLI environment
$_lifetime integer The time in seconds the session will be valid for
$_started boolean Indicates whether the sessions has already started

공개 메소드들

메소드 설명
__construct ( array $config = [] ) Constructor.
check ( string | null $name = null ) : boolean Returns true if given variable name is set in session.
clear ( boolean $renew = false ) : void Clears the session.
consume ( string $name ) : mixed Reads and deletes a variable from session.
create ( array $sessionConfig = [] ) : Session Returns a new instance of a session after building a configuration bundle for it.
delete ( string $name ) : void Removes a variable from session.
destroy ( ) : void Helper method to destroy invalid sessions.
engine ( string | SessionHandlerInterface | null $class = null, array $options = [] ) : SessionHandlerInterface | null Sets the session handler instance to use for this session.
id ( string | null $id = null ) : string Returns the session id.
options ( array $options ) : void Calls ini_set for each of the keys in $options and set them to the respective value in the passed array.
read ( string | null $name = null ) : string | null Returns given session variable, or all of them, if no parameters given.
renew ( ) : void Restarts this session.
start ( ) : boolean Starts the Session.
started ( ) : boolean Determine if Session has already been started.
write ( string | array $name, mixed $value = null ) : void Writes value to given session variable name.

보호된 메소드들

메소드 설명
_defaultConfig ( string $name ) : boolean | array Get one of the prebaked default session configurations.
_hasSession ( ) : boolean Returns whether a session exists
_overwrite ( array &$old, array $new ) : void Used to write new data to _SESSION, since PHP doesn't like us setting the _SESSION var itself.
_timedOut ( ) : boolean Returns true if the session is no longer valid because the last time it was accessed was after the configured timeout.

메소드 상세

__construct() 공개 메소드

### Configuration: - timeout: The time in minutes the session should be valid for. - cookiePath: The url path for which session cookie is set. Maps to the session.cookie_path php.ini config. Defaults to base path of app. - ini: A list of php.ini directives to change before the session start. - handler: An array containing at least the class key. To be used as the session engine for persisting data. The rest of the keys in the array will be passed as the configuration array for the engine. You can set the class key to an already instantiated session handler object.
public __construct ( array $config = [] )
$config array The Configuration to apply to this session object

_defaultConfig() 보호된 정적인 메소드

Get one of the prebaked default session configurations.
protected static _defaultConfig ( string $name ) : boolean | array
$name string Config name.
리턴 boolean | array

_hasSession() 보호된 메소드

Returns whether a session exists
protected _hasSession ( ) : boolean
리턴 boolean

_overwrite() 보호된 메소드

Used to write new data to _SESSION, since PHP doesn't like us setting the _SESSION var itself.
protected _overwrite ( array &$old, array $new ) : void
$old array Set of old variables => values
$new array New set of variable => value
리턴 void

_timedOut() 보호된 메소드

Returns true if the session is no longer valid because the last time it was accessed was after the configured timeout.
protected _timedOut ( ) : boolean
리턴 boolean

check() 공개 메소드

Returns true if given variable name is set in session.
public check ( string | null $name = null ) : boolean
$name string | null Variable name to check for
리턴 boolean True if variable is there

clear() 공개 메소드

Optionally it also clears the session id and renews the session.
public clear ( boolean $renew = false ) : void
$renew boolean If session should be renewed, as well. Defaults to false.
리턴 void

consume() 공개 메소드

Reads and deletes a variable from session.
public consume ( string $name ) : mixed
$name string The key to read and remove (or a path as sent to Hash.extract).
리턴 mixed The value of the session variable, null if session not available, session not started, or provided name not found in the session.

create() 공개 정적인 메소드

This function allows an options array which will be used for configuring the session and the handler to be used. The most important key in the configuration array is defaults, which indicates the set of configurations to inherit from, the possible defaults are: - php: just use session as configured in php.ini - cache: Use the CakePHP caching system as an storage for the session, you will need to pass the config key with the name of an already configured Cache engine. - database: Use the CakePHP ORM to persist and manage sessions. By default this requires a table in your database named sessions or a model key in the configuration to indicate which Table object to use. - cake: Use files for storing the sessions, but let CakePHP manage them and decide where to store them. The full list of options follows: - defaults: either 'php', 'database', 'cache' or 'cake' as explained above. - handler: An array containing the handler configuration - ini: A list of php.ini directives to set before the session starts. - timeout: The time in minutes the session should stay active
또한 보기: Cake\Network\Session::__construct()
public static create ( array $sessionConfig = [] ) : Session
$sessionConfig array Session config.
리턴 Session

delete() 공개 메소드

Removes a variable from session.
public delete ( string $name ) : void
$name string Session variable to remove
리턴 void

destroy() 공개 메소드

Helper method to destroy invalid sessions.
public destroy ( ) : void
리턴 void

engine() 공개 메소드

If a string is passed for the first argument, it will be treated as the class name and the second argument will be passed as the first argument in the constructor. If an instance of a SessionHandlerInterface is provided as the first argument, the handler will be set to it. If no arguments are passed it will return the currently configured handler instance or null if none exists.
public engine ( string | SessionHandlerInterface | null $class = null, array $options = [] ) : SessionHandlerInterface | null
$class string | SessionHandlerInterface | null The session handler to use
$options array the options to pass to the SessionHandler constructor
리턴 SessionHandlerInterface | null

id() 공개 메소드

Calling this method will not auto start the session. You might have to manually assert a started session. Passing an id into it, you can also replace the session id if the session has not already been started. Note that depending on the session handler, not all characters are allowed within the session id. For example, the file session handler only allows characters in the range a-z A-Z 0-9 , (comma) and - (minus).
public id ( string | null $id = null ) : string
$id string | null Id to replace the current session id
리턴 string Session id

options() 공개 메소드

### Example: $session->options(['session.use_cookies' => 1]);
public options ( array $options ) : void
$options array Ini options to set.
리턴 void

read() 공개 메소드

Returns given session variable, or all of them, if no parameters given.
public read ( string | null $name = null ) : string | null
$name string | null The name of the session variable (or a path as sent to Hash.extract)
리턴 string | null The value of the session variable, null if session not available, session not started, or provided name not found in the session.

renew() 공개 메소드

Restarts this session.
public renew ( ) : void
리턴 void

start() 공개 메소드

Starts the Session.
public start ( ) : boolean
리턴 boolean True if session was started

started() 공개 메소드

Determine if Session has already been started.
public started ( ) : boolean
리턴 boolean True if session has been started.

write() 공개 메소드

Writes value to given session variable name.
public write ( string | array $name, mixed $value = null ) : void
$name string | array Name of variable
$value mixed Value to write
리턴 void

프로퍼티 상세

$_engine 보호되어 있는 프로퍼티

The Session handler instance used as an engine for persisting the session data.
protected SessionHandlerInterface $_engine
리턴 SessionHandlerInterface

$_isCLI 보호되어 있는 프로퍼티

Whether this session is running under a CLI environment
protected bool $_isCLI
리턴 boolean

$_lifetime 보호되어 있는 프로퍼티

The time in seconds the session will be valid for
protected int $_lifetime
리턴 integer

$_started 보호되어 있는 프로퍼티

Indicates whether the sessions has already started
protected bool $_started
리턴 boolean