mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-12-26 08:33:21 +03:00
60 lines
1.7 KiB
PHP
60 lines
1.7 KiB
PHP
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
*
|
|
* @package EasyAppointments
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
|
* @copyright Copyright (c) Alex Tselegidis
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
* @link https://easyappointments.org
|
|
* @since v1.5.0
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
if ( ! function_exists('session'))
|
|
{
|
|
/**
|
|
* Get / set the specified session value.
|
|
*
|
|
* If an array is passed as the key, we will assume you want to set an array of values.
|
|
*
|
|
* Example "Get":
|
|
*
|
|
* $logged_in = session('logged_in', FALSE);
|
|
*
|
|
* Example "Set":
|
|
*
|
|
* session(['logged_in' => FALSE]);
|
|
*
|
|
* @param array|string $key Session item key.
|
|
* @param mixed $default Default value in case the requested session item has no value.
|
|
*
|
|
* @return mixed|NULL Returns the requested value or NULL if you assign a new session value.
|
|
*
|
|
* @throws InvalidArgumentException
|
|
*/
|
|
function session($key = NULL, $default = NULL)
|
|
{
|
|
/** @var EA_Controller $CI */
|
|
$CI = &get_instance();
|
|
|
|
if (empty($key))
|
|
{
|
|
throw new InvalidArgumentException('The $key argument cannot be empty.');
|
|
}
|
|
|
|
if (is_array($key))
|
|
{
|
|
foreach ($key as $item => $value)
|
|
{
|
|
$CI->session->set_userdata($item, $value);
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
$value = $CI->session->userdata($key);
|
|
|
|
return $value ?? $default;
|
|
}
|
|
}
|