1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-13 17:24:03 +00:00

phpstan, global_cache, resolver improvements, InitializationHelpers trait

This commit is contained in:
Samuel Štancl 2022-09-29 02:47:13 +02:00
parent fd65cf1754
commit 87212e5390
35 changed files with 170 additions and 231 deletions

View file

@ -2,6 +2,7 @@
declare(strict_types=1);
use Stancl\Tenancy\CacheManager;
use Stancl\Tenancy\Contracts\Tenant;
use Stancl\Tenancy\Tenancy;
@ -35,6 +36,7 @@ if (! function_exists('tenant')) {
if (! function_exists('tenant_asset')) {
// todo docblock
// todo add an option to generate paths respecting the ASSET_URL
function tenant_asset(string|null $asset): string
{
return route('stancl.tenancy.asset', ['path' => $asset]);
@ -42,16 +44,42 @@ if (! function_exists('tenant_asset')) {
}
if (! function_exists('global_asset')) {
function global_asset(string $asset) // todo types, also inside the globalUrl implementation
function global_asset(string $asset): string
{
return app('globalUrl')->asset($asset);
}
}
if (! function_exists('global_cache')) {
function global_cache()
/**
* Get / set the specified cache value in the global cache store.
*
* If an array is passed, we'll assume you want to put to the cache.
*
* @param dynamic key|key,default|data,expiration|null
* @return mixed|\Illuminate\Cache\CacheManager
*
* @throws \InvalidArgumentException
*/
function global_cache(): mixed
{
return app('globalCache');
$arguments = func_get_args();
if (empty($arguments)) {
return app('globalCache');
}
if (is_string($arguments[0])) {
return app('globalCache')->get(...$arguments);
}
if (!is_array($arguments[0])) {
throw new InvalidArgumentException(
'When setting a value in the cache, you must pass an array of key / value pairs.'
);
}
return app('globalCache')->put(key($arguments[0]), reset($arguments[0]), $arguments[1] ?? null);
}
}