Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250706) (a6b17d8f6bd)
core\tests\session\mock_handler Class Reference
Inheritance diagram for core\tests\session\mock_handler:
core\session\database core\session\handler

Public Member Functions

 abort ()
 Release lock on the session without writing it.
 
 add_session (int $userid)
 Insert new empty session record.
 
 add_test_session (\stdClass $record)
 Insert a new session record to be used in unit tests.
 
 close ()
 Close session handler.
 
 count_sessions ()
 Returns the number of all sessions stored.
 
 destroy (string $id)
 Destroy a specific session and delete this session record for this session id.
 
 destroy_all ()
 Destroy all sessions, and delete all the session data.
 
 destroy_by_auth_plugin (string $pluginname)
 Destroy all sessions for a given plugin.
 
 gc (int $max_lifetime=0)
 Periodic timed-out session cleanup.
 
 get_all_sessions ()
 Returns all session records.
 
 get_session_by_sid (string $sid)
 Returns a single session record for this session id.
 
 get_sessions_by_userid (int $userid)
 Returns all the session records for this user id.
 
 init ()
 Init session handler.
 
 open (string $path, string $name)
 Open session handler.
 
 read (string $sid)
 Read session handler.
 
 requires_write_lock ()
 Has this session been opened with a writelock?
 
 session_exists ($sid)
 Check the backend contains data for this session id.
 
 set_requires_write_lock ($requireswritelock)
 This is called after init() and before start() to indicate whether the session opened should be writable or not.
 
 start ()
 Start the session.
 
 update_session (stdClass $record)
 Update a session record.
 
 write (string $id, string $data)
 Write session handler.
 
 write_close ()
 Write the session and release lock.
 

Protected Member Functions

 destroy_all_expired_sessions (int $purgebefore)
 Clean up all expired sessions.
 
 destroy_expired_user_sessions (int $purgebefore, int $userid)
 Clean up expired sessions.
 

Protected Attributes

int $acquiretimeout = 120
 $acquiretimeout how long to wait for session lock
 
moodle_database $database = null
 $database session database
 
bool $failed = false
 $failed session read/init failed, do not write back to DB
 
string $lasthash = null
 $lasthash hash of the session data content
 
int $recordid = null
 $record session record
 
boolean $requireswritelock = false
 $requireswritelock does the session need and/or have a lock?
 

Member Function Documentation

◆ abort()

core\session\handler::abort ( )
inherited

Release lock on the session without writing it.

May not be possible in older versions of PHP. If so, session may be written anyway so that any locks are released.

◆ add_session()

core\session\handler::add_session ( int $userid)
inherited

Insert new empty session record.

Parameters
int$userid
Return values
stdClassthe new record

Reimplemented in core\session\redis.

◆ add_test_session()

core\tests\session\mock_handler::add_test_session ( \stdClass $record)

Insert a new session record to be used in unit tests.

Parameters
stdClass$record
Return values
intInserted record id.

◆ close()

core\session\database::close ( )
inherited

Close session handler.

{

See also
http://php.net/manual/en/function.session-set-save-handler.php}
Return values
boolsuccess

◆ count_sessions()

core\tests\session\mock_handler::count_sessions ( )

Returns the number of all sessions stored.

Return values
int

◆ destroy()

core\session\database::destroy ( string $id)
inherited

Destroy a specific session and delete this session record for this session id.

Parameters
string$idsession id
Return values
bool

Reimplemented from core\session\handler.

◆ destroy_all()

core\session\handler::destroy_all ( )
inherited

Destroy all sessions, and delete all the session data.

Return values
bool

Reimplemented in core\session\file, core\session\memcached, and core\session\redis.

◆ destroy_all_expired_sessions()

core\session\handler::destroy_all_expired_sessions ( int $purgebefore)
protectedinherited

Clean up all expired sessions.

Parameters
int$purgebefore

◆ destroy_by_auth_plugin()

core\session\handler::destroy_by_auth_plugin ( string $pluginname)
inherited

Destroy all sessions for a given plugin.

Typically used when a plugin is disabled or uninstalled, so all sessions (users) for that plugin are logged out.

Parameters
string$pluginnameAuth plugin name.

◆ destroy_expired_user_sessions()

core\session\handler::destroy_expired_user_sessions ( int $purgebefore,
int $userid )
protectedinherited

Clean up expired sessions.

Parameters
int$purgebeforeSessions that have not updated for the last purgebefore timestamp will be removed.
int$userid

◆ gc()

core\session\handler::gc ( int $max_lifetime = 0)
inherited

Periodic timed-out session cleanup.

Parameters
int$max_lifetimeSessions that have not updated for the last max_lifetime seconds will be removed.
Return values
int|falseNumber of deleted sessions or false if an error occurred.

Reimplemented in core\session\redis.

◆ get_all_sessions()

core\tests\session\mock_handler::get_all_sessions ( )

Returns all session records.

Return values
Iterator

Reimplemented from core\session\handler.

◆ get_session_by_sid()

core\session\handler::get_session_by_sid ( string $sid)
inherited

Returns a single session record for this session id.

Parameters
string$sid
Return values
stdClass

Reimplemented in core\session\redis.

◆ get_sessions_by_userid()

core\session\handler::get_sessions_by_userid ( int $userid)
inherited

Returns all the session records for this user id.

Parameters
int$userid
Return values
array

Reimplemented in core\session\redis.

◆ init()

core\tests\session\mock_handler::init ( )

Init session handler.

Reimplemented from core\session\database.

◆ open()

core\session\database::open ( string $path,
string $name )
inherited

Open session handler.

{

See also
http://php.net/manual/en/function.session-set-save-handler.php}
Parameters
string$path
string$name
Return values
boolsuccess

◆ read()

core\session\database::read ( string $sid)
inherited

Read session handler.

{

See also
http://php.net/manual/en/function.session-set-save-handler.php}
Parameters
string$sid
Return values
string|false

◆ requires_write_lock()

core\session\handler::requires_write_lock ( )
inherited

Has this session been opened with a writelock?

Your handler should call this during start() if you support read-only sessions.

Return values
booltrue if session is intended to have a write lock.

◆ session_exists()

core\tests\session\mock_handler::session_exists ( $sid)

Check the backend contains data for this session id.

Note: this is intended to be called from manager::session_exists() only.

Parameters
string$sid
Return values
booltrue if session found.

Reimplemented from core\session\database.

◆ set_requires_write_lock()

core\session\handler::set_requires_write_lock ( $requireswritelock)
inherited

This is called after init() and before start() to indicate whether the session opened should be writable or not.

This is intentionally captured even if your handler doesn't support non-locking sessions, so that behavior (upon session close) matches closely between handlers.

Parameters
bool$requireswritelocktrue if needs to be open for writing

◆ start()

core\session\handler::start ( )
inherited

Start the session.

Return values
boolsuccess

Reimplemented in core\session\memcached.

◆ update_session()

core\session\handler::update_session ( stdClass $record)
inherited

Update a session record.

Parameters
stdClass$record
Return values
bool

◆ write()

core\session\database::write ( string $id,
string $data )
inherited

Write session handler.

{

See also
http://php.net/manual/en/function.session-set-save-handler.php}

NOTE: Do not write to output or throw any exceptions! Hopefully the next page is going to display nice error or it recovers...

Parameters
string$id
string$data
Return values
boolsuccess

◆ write_close()

core\session\handler::write_close ( )
inherited

Write the session and release lock.

If the session was not intentionally opened with a write lock, then we will abort the session instead if able.


The documentation for this class was generated from the following file: