meobda-website/app/helpers.php

39 lines
1.1 KiB
PHP

<?php
use App\Services\SiteDataService;
/**
* Get or set site data values.
*
* When called without arguments, returns the SiteDataService instance.
* When called with a key, retrieves the value for that key.
* When called with a key and value, sets the value and returns it.
*
* @param string|null $key The site data key to get or set
* @param mixed $value The value to set (optional)
* @return mixed The SiteDataService instance, retrieved value, or set value
*
* @throws \InvalidArgumentException If the key is not defined in configuration
*
* @example
* siteData() // Returns SiteDataService instance
* siteData('concertClinicDates') // Returns the value
* siteData('concertClinicDates', '2025-03-15') // Sets and returns the value
*/
function siteData(?string $key = null, mixed $value = null): mixed
{
$dataService = app(SiteDataService::class);
if (is_null($key)) {
return $dataService;
}
if (func_num_args() === 1) {
return $dataService->get($key);
}
$dataService->set($key, $value);
return $value;
}