|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Factory; |
|
6
|
|
|
|
|
7
|
|
|
use Psr\Container\ContainerInterface; |
|
8
|
|
|
use RuntimeException; |
|
9
|
|
|
use Yiisoft\Db\Cache\QueryCache; |
|
10
|
|
|
use Yiisoft\Factory\Definitions\DefinitionInterface; |
|
11
|
|
|
use Yiisoft\Factory\Definitions\Normalizer; |
|
12
|
|
|
use Yiisoft\Factory\Factory; |
|
13
|
|
|
|
|
14
|
|
|
final class QueryCacheFactory extends Factory |
|
15
|
|
|
{ |
|
16
|
|
|
private static ?ContainerInterface $container = null; |
|
17
|
|
|
private static ?DefinitionInterface $definition = null; |
|
18
|
|
|
private static Factory $queryCacheFactory; |
|
19
|
|
|
|
|
20
|
|
|
private function __construct(ContainerInterface $container = null) |
|
21
|
|
|
{ |
|
22
|
|
|
self::$container = $container; |
|
23
|
|
|
self::$definition = Normalizer::normalize(QueryCache::class); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public static function initialize(ContainerInterface $container = null): void |
|
27
|
|
|
{ |
|
28
|
|
|
self::$queryCacheFactory = new self($container); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Creates a `QueryCache` instance. |
|
33
|
|
|
* |
|
34
|
|
|
* @throws RuntimeException If the created object is not an instance of the `QueryCache`. |
|
35
|
|
|
* |
|
36
|
|
|
* @return QueryCache The `QueryCache` instance. |
|
37
|
|
|
* |
|
38
|
|
|
* @psalm-suppress RedundantConditionGivenDocblockType |
|
39
|
|
|
* @psalm-suppress DocblockTypeContradiction |
|
40
|
|
|
*/ |
|
41
|
|
|
public static function run(): QueryCache |
|
42
|
|
|
{ |
|
43
|
|
|
$queryCache = self::$definition->resolve(self::$container); |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
if (!($queryCache instanceof QueryCache)) { |
|
46
|
|
|
throw new RuntimeException(sprintf( |
|
47
|
|
|
'The "%s" is not an instance of the "Psr\Log\LoggerInterface".', |
|
48
|
|
|
(is_object($queryCache) ? get_class($queryCache) : gettype($queryCache)) |
|
49
|
|
|
)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return $queryCache; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.