2020-04-22 22:48:56 +03:00
|
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
2018-01-15 10:57:17 +03:00
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2024-01-01 01:14:38 +03:00
|
|
|
|
* MaketRandevu - MAKET Randevu Portalı
|
2018-01-15 10:57:17 +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
|
2018-01-15 10:57:17 +03:00
|
|
|
|
* @since v1.3.0
|
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
/**
|
2021-10-23 14:04:15 +03:00
|
|
|
|
* Get / set the specified config value.
|
2021-12-14 09:47:35 +03:00
|
|
|
|
*
|
2021-10-23 14:13:43 +03:00
|
|
|
|
* If an array is passed as the key, we will assume you want to set an array of values.
|
2018-01-15 10:57:17 +03:00
|
|
|
|
*
|
2021-10-23 14:04:15 +03:00
|
|
|
|
* Example "Get":
|
|
|
|
|
*
|
2021-10-23 14:17:38 +03:00
|
|
|
|
* $version = config('version', '1.0.0');
|
2021-10-23 14:04:15 +03:00
|
|
|
|
*
|
|
|
|
|
* Example "Set":
|
|
|
|
|
*
|
2021-10-23 14:06:41 +03:00
|
|
|
|
* config(['version' => '1.0.0']);
|
2021-10-23 14:04:15 +03:00
|
|
|
|
*
|
|
|
|
|
* @param array|string $key Configuration key.
|
2023-03-13 11:06:18 +03:00
|
|
|
|
* @param mixed|null $default Default value in case the requested config has no value.
|
2018-01-15 10:57:17 +03:00
|
|
|
|
*
|
2021-10-23 14:20:39 +03:00
|
|
|
|
* @return mixed|NULL Returns the requested value or NULL if you assign a new configuration value.
|
2021-10-23 14:06:41 +03:00
|
|
|
|
*
|
|
|
|
|
* @throws InvalidArgumentException
|
2018-01-15 10:57:17 +03:00
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
|
function config(array|string $key, mixed $default = null): mixed
|
2018-01-23 12:08:37 +03:00
|
|
|
|
{
|
2021-10-23 14:04:15 +03:00
|
|
|
|
/** @var EA_Controller $CI */
|
2020-12-02 23:10:11 +03:00
|
|
|
|
$CI = &get_instance();
|
2018-01-15 10:57:17 +03:00
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (empty($key)) {
|
2021-10-23 14:08:24 +03:00
|
|
|
|
throw new InvalidArgumentException('The $key argument cannot be empty.');
|
2021-10-23 14:04:15 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (is_array($key)) {
|
|
|
|
|
foreach ($key as $item => $value) {
|
2021-10-23 14:04:15 +03:00
|
|
|
|
$CI->config->set_item($item, $value);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
return null;
|
2021-10-23 14:04:15 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-23 13:59:39 +03:00
|
|
|
|
$value = $CI->config->item($key);
|
|
|
|
|
|
|
|
|
|
return $value ?? $default;
|
2018-01-15 10:57:17 +03:00
|
|
|
|
}
|
2021-12-14 09:47:35 +03:00
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (!function_exists('script_vars')) {
|
2021-12-14 09:47:35 +03:00
|
|
|
|
/**
|
|
|
|
|
* Get / set the specified JS config value.
|
|
|
|
|
*
|
|
|
|
|
* If an array is passed as the key, we will assume you want to set an array of values.
|
|
|
|
|
*
|
|
|
|
|
* Example "Get":
|
|
|
|
|
*
|
2021-12-17 12:52:46 +03:00
|
|
|
|
* $version = script_vars('version', '1.0.0');
|
2021-12-14 09:47:35 +03:00
|
|
|
|
*
|
|
|
|
|
* Example "Set":
|
|
|
|
|
*
|
2021-12-17 12:52:46 +03:00
|
|
|
|
* script_vars(['version' => '1.0.0']);
|
2021-12-14 09:47:35 +03:00
|
|
|
|
*
|
2023-03-13 11:06:18 +03:00
|
|
|
|
* @param array|string|null $key Configuration key.
|
|
|
|
|
* @param mixed|null $default Default value in case the requested config has no value.
|
2021-12-14 09:47:35 +03:00
|
|
|
|
*
|
|
|
|
|
* @return mixed|NULL Returns the requested value or NULL if you assign a new configuration value.
|
|
|
|
|
*
|
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
|
function script_vars(array|string $key = null, mixed $default = null): mixed
|
2021-12-14 09:47:35 +03:00
|
|
|
|
{
|
2021-12-17 12:52:46 +03:00
|
|
|
|
$script_vars = config('script_vars', []);
|
2021-12-14 09:47:35 +03:00
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (empty($key)) {
|
2021-12-17 12:52:46 +03:00
|
|
|
|
return $script_vars;
|
2021-12-14 09:47:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (is_array($key)) {
|
|
|
|
|
foreach ($key as $item => $value) {
|
2021-12-17 12:52:46 +03:00
|
|
|
|
$script_vars[$item] = $value;
|
2021-12-14 09:47:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-17 12:52:46 +03:00
|
|
|
|
config(['script_vars' => $script_vars]);
|
2021-12-14 09:51:26 +03:00
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
return null;
|
2021-12-14 09:47:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
$value = $script_vars[$key] ?? null;
|
2021-12-14 09:47:35 +03:00
|
|
|
|
|
|
|
|
|
return $value ?? $default;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-17 10:46:47 +03:00
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (!function_exists('html_vars')) {
|
2021-12-17 10:46:47 +03:00
|
|
|
|
/**
|
2021-12-17 12:52:46 +03:00
|
|
|
|
* Get / set the specified HTML variable.
|
2021-12-17 10:46:47 +03:00
|
|
|
|
*
|
|
|
|
|
* If an array is passed as the key, we will assume you want to set an array of values.
|
|
|
|
|
*
|
|
|
|
|
* Example "Get":
|
|
|
|
|
*
|
2021-12-17 12:52:46 +03:00
|
|
|
|
* $version = html_vars('title', 'Default Title');
|
2021-12-17 10:46:47 +03:00
|
|
|
|
*
|
|
|
|
|
* Example "Set":
|
|
|
|
|
*
|
2021-12-17 12:52:46 +03:00
|
|
|
|
* html_vars(['title' => 'Test Title']);
|
2021-12-17 10:46:47 +03:00
|
|
|
|
*
|
2023-03-13 11:06:18 +03:00
|
|
|
|
* @param array|string|null $key Variable key.
|
|
|
|
|
* @param mixed|null $default Default value in case the requested variable has no value.
|
2021-12-17 10:46:47 +03:00
|
|
|
|
*
|
|
|
|
|
* @return mixed|NULL Returns the requested value or NULL if you assign a new configuration value.
|
|
|
|
|
*
|
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
|
function html_vars(array|string $key = null, mixed $default = null): mixed
|
2021-12-17 10:46:47 +03:00
|
|
|
|
{
|
2021-12-17 12:52:46 +03:00
|
|
|
|
$html_vars = config('html_vars', []);
|
2021-12-17 10:46:47 +03:00
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (empty($key)) {
|
2021-12-17 12:52:46 +03:00
|
|
|
|
return $html_vars;
|
2021-12-17 10:46:47 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (is_array($key)) {
|
|
|
|
|
foreach ($key as $item => $value) {
|
2021-12-17 12:52:46 +03:00
|
|
|
|
$html_vars[$item] = $value;
|
2021-12-17 10:46:47 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-17 12:52:46 +03:00
|
|
|
|
config(['html_vars' => $html_vars]);
|
2021-12-17 10:46:47 +03:00
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
return null;
|
2021-12-17 10:46:47 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
$value = $html_vars[$key] ?? null;
|
2021-12-17 10:46:47 +03:00
|
|
|
|
|
|
|
|
|
return $value ?? $default;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-18 10:45:02 +03:00
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (!function_exists('vars')) {
|
2022-01-18 10:45:02 +03:00
|
|
|
|
/**
|
|
|
|
|
* Get / set the specified HTML & JS config value.
|
|
|
|
|
*
|
|
|
|
|
* If an array is passed as the key, we will assume you want to set an array of values.
|
|
|
|
|
*
|
|
|
|
|
* Example "Get":
|
|
|
|
|
*
|
|
|
|
|
* $version = vars('version', '1.0.0');
|
|
|
|
|
*
|
|
|
|
|
* Example "Set":
|
|
|
|
|
*
|
|
|
|
|
* vars(['version' => '1.0.0']);
|
|
|
|
|
*
|
2023-03-13 11:06:18 +03:00
|
|
|
|
* @param array|string|null $key Configuration key.
|
|
|
|
|
* @param mixed|null $default Default value in case the requested config has no value.
|
2022-01-18 10:45:02 +03:00
|
|
|
|
*
|
|
|
|
|
* @return mixed|NULL Returns the requested value or NULL if you assign a new configuration value.
|
|
|
|
|
*
|
|
|
|
|
* @throws InvalidArgumentException
|
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
|
function vars(array|string $key = null, mixed $default = null): mixed
|
2022-01-18 10:45:02 +03:00
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
return html_vars($key) ?? (script_vars($key) ?? $default);
|
2022-01-18 10:45:02 +03:00
|
|
|
|
}
|
|
|
|
|
}
|