2021-10-23 14:18:20 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2021-10-23 14:18:20 +03:00
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
2021-10-23 14:29:31 +03:00
|
|
|
* @since v1.5.0
|
2021-10-23 14:18:20 +03:00
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (!function_exists('session')) {
|
2021-10-23 14:18:20 +03:00
|
|
|
/**
|
|
|
|
* 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]);
|
|
|
|
*
|
2023-11-29 12:24:09 +03:00
|
|
|
* @param array|string|null $key Session item key.
|
2023-03-13 11:06:18 +03:00
|
|
|
* @param mixed|null $default Default value in case the requested session item has no value.
|
2021-10-23 14:18:20 +03:00
|
|
|
*
|
2021-10-23 14:20:33 +03:00
|
|
|
* @return mixed|NULL Returns the requested value or NULL if you assign a new session value.
|
2021-10-23 14:18:20 +03:00
|
|
|
*
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
function session(array|string $key = null, mixed $default = null): mixed
|
2021-10-23 14:18:20 +03:00
|
|
|
{
|
|
|
|
/** @var EA_Controller $CI */
|
|
|
|
$CI = &get_instance();
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (empty($key)) {
|
2021-10-23 14:18:20 +03:00
|
|
|
throw new InvalidArgumentException('The $key argument cannot be empty.');
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (is_array($key)) {
|
|
|
|
foreach ($key as $item => $value) {
|
2021-10-23 14:18:20 +03:00
|
|
|
$CI->session->set_userdata($item, $value);
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
return null;
|
2021-10-23 14:18:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$value = $CI->session->userdata($key);
|
|
|
|
|
|
|
|
return $value ?? $default;
|
|
|
|
}
|
|
|
|
}
|