1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This software package is licensed under AGPL, Commercial license. |
5
|
|
|
* |
6
|
|
|
* @package maslosoft/addendum |
7
|
|
|
* @licence AGPL, Commercial |
8
|
|
|
* @copyright Copyright (c) Piotr Masełkowski <[email protected]> (Meta container, further improvements, bugfixes) |
9
|
|
|
* @copyright Copyright (c) Maslosoft (Meta container, further improvements, bugfixes) |
10
|
|
|
* @copyright Copyright (c) Jan Suchal (Original version, builder, parser) |
11
|
|
|
* @link https://maslosoft.com/addendum/ - maslosoft addendum |
12
|
|
|
* @link https://code.google.com/p/addendum/ - original addendum project |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Maslosoft\Addendum\Cache; |
16
|
|
|
|
17
|
|
|
use Maslosoft\Addendum\Addendum; |
18
|
|
|
use Maslosoft\Addendum\Interfaces\AnnotatedInterface; |
19
|
|
|
use Maslosoft\Addendum\Options\MetaOptions; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Flyweight accessor for meta cache |
23
|
|
|
* |
24
|
|
|
* @author Piotr Maselkowski <pmaselkowski at gmail.com> |
25
|
|
|
*/ |
26
|
|
|
class FlyCache |
27
|
|
|
{ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Instances of meta cache |
31
|
|
|
* @var ClassCache[] |
32
|
|
|
*/ |
33
|
|
|
private static $_instances = []; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get flyweight instance of meta cache. |
37
|
|
|
* This is based on meta class and addendum instance id. |
38
|
|
|
* @param string $metaClass |
39
|
|
|
* @param string|object|AnnotatedInterface $component |
40
|
|
|
* @param MetaOptions $options |
41
|
|
|
* @return ClassCache |
42
|
|
|
*/ |
43
|
37 |
|
public static function instance($metaClass = null, $component = null, MetaOptions $options = null) |
44
|
|
|
{ |
45
|
37 |
|
if (empty($options)) |
46
|
|
|
{ |
47
|
33 |
|
$instanceId = Addendum::DefaultInstanceId; |
48
|
|
|
} |
49
|
|
|
else |
50
|
|
|
{ |
51
|
4 |
|
$instanceId = $options->instanceId; |
52
|
|
|
} |
53
|
37 |
|
$key = sprintf('%s@%s', $metaClass, $instanceId); |
54
|
|
|
|
55
|
37 |
|
if (empty(self::$_instances[$key])) |
56
|
|
|
{ |
57
|
1 |
|
self::$_instances[$key] = new ClassCache($metaClass, $component, $options); |
|
|
|
|
58
|
|
|
} |
59
|
37 |
|
self::$_instances[$key]->setOptions($options); |
60
|
37 |
|
return self::$_instances[$key]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.