35 lines
772 B
PHP
35 lines
772 B
PHP
<?php
|
|
|
|
namespace KupShop\KupShopBundle\Util;
|
|
|
|
use KupShop\KupShopBundle\Context\ContextInterface;
|
|
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
|
|
|
class Contexts
|
|
{
|
|
private static $cache = [];
|
|
|
|
/**
|
|
* @template T of ContextInterface
|
|
*
|
|
* @param class-string<T> $context
|
|
*
|
|
* @return T
|
|
*
|
|
* @TODO(hauschwitz): Přidat return type ContextInterface, až bude jistota, že to nic nerozbije. :)
|
|
*/
|
|
public static function get(string $context)
|
|
{
|
|
if (!(static::$cache[$context] ?? false)) {
|
|
static::$cache[$context] = ServiceContainer::getService($context);
|
|
}
|
|
|
|
return static::$cache[$context];
|
|
}
|
|
|
|
public static function clear(): void
|
|
{
|
|
static::$cache = [];
|
|
}
|
|
}
|