@@ -14,50 +14,50 @@ |
||
14 | 14 | */ |
15 | 15 | class LegacyTextDomainOptions |
16 | 16 | { |
17 | - private LoadedTextDomains $loaded_text_domains; |
|
17 | + private LoadedTextDomains $loaded_text_domains; |
|
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * @param LoadedTextDomains|null $loaded_text_domains |
|
22 | - */ |
|
23 | - public function __construct(?LoadedTextDomains $loaded_text_domains = null) |
|
24 | - { |
|
25 | - $this->loaded_text_domains = $loaded_text_domains ?? new LoadedTextDomains(); |
|
26 | - } |
|
20 | + /** |
|
21 | + * @param LoadedTextDomains|null $loaded_text_domains |
|
22 | + */ |
|
23 | + public function __construct(?LoadedTextDomains $loaded_text_domains = null) |
|
24 | + { |
|
25 | + $this->loaded_text_domains = $loaded_text_domains ?? new LoadedTextDomains(); |
|
26 | + } |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * attempts to collect all the ee_lang_check_* options stored in the database |
|
31 | - * and add them to one single option handled by EventEspresso\core\services\i18n\LoadedTextDomains |
|
32 | - * |
|
33 | - * @since 5.0.0.p |
|
34 | - */ |
|
35 | - public function convertToConsolidatedFormat() |
|
36 | - { |
|
37 | - $options = wp_load_alloptions(); |
|
38 | - foreach ($options as $slug => $values) { |
|
39 | - if (strpos($slug, 'ee_lang_check_') === 0) { |
|
40 | - // convert something like "ee_lang_check_en_CA_4.10.39.rc.018" to 'en_CA_4.10.39.rc.018' |
|
41 | - $locale_version = str_replace('ee_lang_check_', '', $slug); |
|
42 | - // split 'en_CA_4.10.39.rc.018' into [ 'en', 'CA', '4.10.39.rc.018' ] |
|
43 | - $locale_version = explode('_', $locale_version); |
|
44 | - $locale = null; |
|
45 | - $version = null; |
|
46 | - switch (count($locale_version)) { |
|
47 | - case 3: |
|
48 | - $locale = "$locale_version[0]_$locale_version[1]"; |
|
49 | - $version = $locale_version[2]; |
|
50 | - break; |
|
51 | - case 2: |
|
52 | - $locale = $locale_version[0]; |
|
53 | - $version = $locale_version[1]; |
|
54 | - break; |
|
55 | - } |
|
56 | - if ($locale && $version) { |
|
57 | - $this->loaded_text_domains->versionLoaded($locale, $version); |
|
58 | - delete_option($slug); |
|
59 | - } |
|
60 | - } |
|
61 | - } |
|
62 | - } |
|
29 | + /** |
|
30 | + * attempts to collect all the ee_lang_check_* options stored in the database |
|
31 | + * and add them to one single option handled by EventEspresso\core\services\i18n\LoadedTextDomains |
|
32 | + * |
|
33 | + * @since 5.0.0.p |
|
34 | + */ |
|
35 | + public function convertToConsolidatedFormat() |
|
36 | + { |
|
37 | + $options = wp_load_alloptions(); |
|
38 | + foreach ($options as $slug => $values) { |
|
39 | + if (strpos($slug, 'ee_lang_check_') === 0) { |
|
40 | + // convert something like "ee_lang_check_en_CA_4.10.39.rc.018" to 'en_CA_4.10.39.rc.018' |
|
41 | + $locale_version = str_replace('ee_lang_check_', '', $slug); |
|
42 | + // split 'en_CA_4.10.39.rc.018' into [ 'en', 'CA', '4.10.39.rc.018' ] |
|
43 | + $locale_version = explode('_', $locale_version); |
|
44 | + $locale = null; |
|
45 | + $version = null; |
|
46 | + switch (count($locale_version)) { |
|
47 | + case 3: |
|
48 | + $locale = "$locale_version[0]_$locale_version[1]"; |
|
49 | + $version = $locale_version[2]; |
|
50 | + break; |
|
51 | + case 2: |
|
52 | + $locale = $locale_version[0]; |
|
53 | + $version = $locale_version[1]; |
|
54 | + break; |
|
55 | + } |
|
56 | + if ($locale && $version) { |
|
57 | + $this->loaded_text_domains->versionLoaded($locale, $version); |
|
58 | + delete_option($slug); |
|
59 | + } |
|
60 | + } |
|
61 | + } |
|
62 | + } |
|
63 | 63 | } |
@@ -13,131 +13,131 @@ |
||
13 | 13 | */ |
14 | 14 | class Loader implements LoaderInterface |
15 | 15 | { |
16 | - private LoaderDecoratorInterface $new_loader; |
|
17 | - |
|
18 | - private CachingLoaderDecoratorInterface $shared_loader; |
|
19 | - |
|
20 | - private ClassInterfaceCache $class_cache; |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * Loader constructor. |
|
25 | - * |
|
26 | - * @param LoaderDecoratorInterface $new_loader |
|
27 | - * @param CachingLoaderDecoratorInterface $shared_loader |
|
28 | - * @param ClassInterfaceCache $class_cache |
|
29 | - */ |
|
30 | - public function __construct( |
|
31 | - LoaderDecoratorInterface $new_loader, |
|
32 | - CachingLoaderDecoratorInterface $shared_loader, |
|
33 | - ClassInterfaceCache $class_cache |
|
34 | - ) { |
|
35 | - $this->new_loader = $new_loader; |
|
36 | - $this->shared_loader = $shared_loader; |
|
37 | - $this->class_cache = $class_cache; |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * @return LoaderDecoratorInterface |
|
43 | - */ |
|
44 | - public function getNewLoader(): LoaderDecoratorInterface |
|
45 | - { |
|
46 | - return $this->new_loader; |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * @return CachingLoaderDecoratorInterface |
|
52 | - */ |
|
53 | - public function getSharedLoader(): CachingLoaderDecoratorInterface |
|
54 | - { |
|
55 | - return $this->shared_loader; |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @param FullyQualifiedName|string $fqcn |
|
61 | - * @param array $arguments |
|
62 | - * @param bool $shared |
|
63 | - * @return mixed |
|
64 | - */ |
|
65 | - public function load($fqcn, array $arguments = [], bool $shared = true) |
|
66 | - { |
|
67 | - $fqcn = $this->class_cache->getFqn($fqcn); |
|
68 | - if ($this->class_cache->hasInterface($fqcn, 'EventEspresso\core\interfaces\ReservedInstanceInterface')) { |
|
69 | - $shared = true; |
|
70 | - } |
|
71 | - return $shared |
|
72 | - ? $this->getSharedLoader()->load($fqcn, $arguments, $shared) |
|
73 | - : $this->getNewLoader()->load($fqcn, $arguments, $shared); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * @param FullyQualifiedName|string $fqcn |
|
79 | - * @param array $arguments |
|
80 | - * @return mixed |
|
81 | - */ |
|
82 | - public function getNew($fqcn, array $arguments = []) |
|
83 | - { |
|
84 | - return $this->load($fqcn, $arguments, false); |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * @param FullyQualifiedName|string $fqcn |
|
90 | - * @param array $arguments |
|
91 | - * @return mixed |
|
92 | - */ |
|
93 | - public function getShared($fqcn, array $arguments = []) |
|
94 | - { |
|
95 | - return $this->load($fqcn, $arguments); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @param FullyQualifiedName|string $fqcn |
|
101 | - * @param array $arguments |
|
102 | - * @return bool |
|
103 | - */ |
|
104 | - public function isShared($fqcn, array $arguments = []): bool |
|
105 | - { |
|
106 | - $fqcn = $this->class_cache->getFqn($fqcn); |
|
107 | - return $this->getSharedLoader()->isShared($fqcn, $arguments); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @param FullyQualifiedName|string $fqcn |
|
113 | - * @param mixed $object |
|
114 | - * @param array $arguments |
|
115 | - * @return bool |
|
116 | - */ |
|
117 | - public function share($fqcn, $object, array $arguments = []): bool |
|
118 | - { |
|
119 | - $fqcn = $this->class_cache->getFqn($fqcn); |
|
120 | - return $this->getSharedLoader()->share($fqcn, $object, $arguments); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @param FullyQualifiedName|string $fqcn |
|
126 | - * @param array $arguments |
|
127 | - * @return bool |
|
128 | - */ |
|
129 | - public function remove($fqcn, array $arguments = []): bool |
|
130 | - { |
|
131 | - $fqcn = $this->class_cache->getFqn($fqcn); |
|
132 | - return $this->getSharedLoader()->remove($fqcn, $arguments); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * calls reset() on loaders if that method exists |
|
138 | - */ |
|
139 | - public function reset() |
|
140 | - { |
|
141 | - $this->shared_loader->reset(); |
|
142 | - } |
|
16 | + private LoaderDecoratorInterface $new_loader; |
|
17 | + |
|
18 | + private CachingLoaderDecoratorInterface $shared_loader; |
|
19 | + |
|
20 | + private ClassInterfaceCache $class_cache; |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * Loader constructor. |
|
25 | + * |
|
26 | + * @param LoaderDecoratorInterface $new_loader |
|
27 | + * @param CachingLoaderDecoratorInterface $shared_loader |
|
28 | + * @param ClassInterfaceCache $class_cache |
|
29 | + */ |
|
30 | + public function __construct( |
|
31 | + LoaderDecoratorInterface $new_loader, |
|
32 | + CachingLoaderDecoratorInterface $shared_loader, |
|
33 | + ClassInterfaceCache $class_cache |
|
34 | + ) { |
|
35 | + $this->new_loader = $new_loader; |
|
36 | + $this->shared_loader = $shared_loader; |
|
37 | + $this->class_cache = $class_cache; |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * @return LoaderDecoratorInterface |
|
43 | + */ |
|
44 | + public function getNewLoader(): LoaderDecoratorInterface |
|
45 | + { |
|
46 | + return $this->new_loader; |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * @return CachingLoaderDecoratorInterface |
|
52 | + */ |
|
53 | + public function getSharedLoader(): CachingLoaderDecoratorInterface |
|
54 | + { |
|
55 | + return $this->shared_loader; |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @param FullyQualifiedName|string $fqcn |
|
61 | + * @param array $arguments |
|
62 | + * @param bool $shared |
|
63 | + * @return mixed |
|
64 | + */ |
|
65 | + public function load($fqcn, array $arguments = [], bool $shared = true) |
|
66 | + { |
|
67 | + $fqcn = $this->class_cache->getFqn($fqcn); |
|
68 | + if ($this->class_cache->hasInterface($fqcn, 'EventEspresso\core\interfaces\ReservedInstanceInterface')) { |
|
69 | + $shared = true; |
|
70 | + } |
|
71 | + return $shared |
|
72 | + ? $this->getSharedLoader()->load($fqcn, $arguments, $shared) |
|
73 | + : $this->getNewLoader()->load($fqcn, $arguments, $shared); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * @param FullyQualifiedName|string $fqcn |
|
79 | + * @param array $arguments |
|
80 | + * @return mixed |
|
81 | + */ |
|
82 | + public function getNew($fqcn, array $arguments = []) |
|
83 | + { |
|
84 | + return $this->load($fqcn, $arguments, false); |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * @param FullyQualifiedName|string $fqcn |
|
90 | + * @param array $arguments |
|
91 | + * @return mixed |
|
92 | + */ |
|
93 | + public function getShared($fqcn, array $arguments = []) |
|
94 | + { |
|
95 | + return $this->load($fqcn, $arguments); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @param FullyQualifiedName|string $fqcn |
|
101 | + * @param array $arguments |
|
102 | + * @return bool |
|
103 | + */ |
|
104 | + public function isShared($fqcn, array $arguments = []): bool |
|
105 | + { |
|
106 | + $fqcn = $this->class_cache->getFqn($fqcn); |
|
107 | + return $this->getSharedLoader()->isShared($fqcn, $arguments); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @param FullyQualifiedName|string $fqcn |
|
113 | + * @param mixed $object |
|
114 | + * @param array $arguments |
|
115 | + * @return bool |
|
116 | + */ |
|
117 | + public function share($fqcn, $object, array $arguments = []): bool |
|
118 | + { |
|
119 | + $fqcn = $this->class_cache->getFqn($fqcn); |
|
120 | + return $this->getSharedLoader()->share($fqcn, $object, $arguments); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @param FullyQualifiedName|string $fqcn |
|
126 | + * @param array $arguments |
|
127 | + * @return bool |
|
128 | + */ |
|
129 | + public function remove($fqcn, array $arguments = []): bool |
|
130 | + { |
|
131 | + $fqcn = $this->class_cache->getFqn($fqcn); |
|
132 | + return $this->getSharedLoader()->remove($fqcn, $arguments); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * calls reset() on loaders if that method exists |
|
138 | + */ |
|
139 | + public function reset() |
|
140 | + { |
|
141 | + $this->shared_loader->reset(); |
|
142 | + } |
|
143 | 143 | } |
@@ -70,68 +70,68 @@ |
||
70 | 70 | */ |
71 | 71 | class LoaderFactory |
72 | 72 | { |
73 | - private static ?LoaderInterface $loader = null; |
|
73 | + private static ?LoaderInterface $loader = null; |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * @param EE_Registry|CoffeeShop $generator provided during very first instantiation in |
|
78 | - * BootstrapDependencyInjectionContainer::buildLoader() |
|
79 | - * otherwise can be left null |
|
80 | - * @param ClassInterfaceCache|null $class_cache also provided during first instantiation |
|
81 | - * @param ObjectIdentifier|null $object_identifier |
|
82 | - * @return LoaderInterface |
|
83 | - * @throws InvalidArgumentException |
|
84 | - * @throws InvalidDataTypeException |
|
85 | - * @throws InvalidInterfaceException |
|
86 | - */ |
|
87 | - public static function getLoader( |
|
88 | - $generator = null, |
|
89 | - ClassInterfaceCache $class_cache = null, |
|
90 | - ObjectIdentifier $object_identifier = null |
|
91 | - ): LoaderInterface { |
|
92 | - if ( |
|
93 | - ! LoaderFactory::$loader instanceof LoaderInterface |
|
94 | - && ($generator instanceof EE_Registry || $generator instanceof CoffeeShop) |
|
95 | - && $class_cache instanceof ClassInterfaceCache |
|
96 | - && $object_identifier instanceof ObjectIdentifier |
|
97 | - ) { |
|
98 | - $core_loader = new CoreLoader($generator); |
|
99 | - LoaderFactory::$loader = new Loader( |
|
100 | - $core_loader, |
|
101 | - new CachingLoader( |
|
102 | - $core_loader, |
|
103 | - new LooseCollection(''), |
|
104 | - $object_identifier |
|
105 | - ), |
|
106 | - $class_cache |
|
107 | - ); |
|
108 | - } |
|
109 | - return LoaderFactory::$loader; |
|
110 | - } |
|
76 | + /** |
|
77 | + * @param EE_Registry|CoffeeShop $generator provided during very first instantiation in |
|
78 | + * BootstrapDependencyInjectionContainer::buildLoader() |
|
79 | + * otherwise can be left null |
|
80 | + * @param ClassInterfaceCache|null $class_cache also provided during first instantiation |
|
81 | + * @param ObjectIdentifier|null $object_identifier |
|
82 | + * @return LoaderInterface |
|
83 | + * @throws InvalidArgumentException |
|
84 | + * @throws InvalidDataTypeException |
|
85 | + * @throws InvalidInterfaceException |
|
86 | + */ |
|
87 | + public static function getLoader( |
|
88 | + $generator = null, |
|
89 | + ClassInterfaceCache $class_cache = null, |
|
90 | + ObjectIdentifier $object_identifier = null |
|
91 | + ): LoaderInterface { |
|
92 | + if ( |
|
93 | + ! LoaderFactory::$loader instanceof LoaderInterface |
|
94 | + && ($generator instanceof EE_Registry || $generator instanceof CoffeeShop) |
|
95 | + && $class_cache instanceof ClassInterfaceCache |
|
96 | + && $object_identifier instanceof ObjectIdentifier |
|
97 | + ) { |
|
98 | + $core_loader = new CoreLoader($generator); |
|
99 | + LoaderFactory::$loader = new Loader( |
|
100 | + $core_loader, |
|
101 | + new CachingLoader( |
|
102 | + $core_loader, |
|
103 | + new LooseCollection(''), |
|
104 | + $object_identifier |
|
105 | + ), |
|
106 | + $class_cache |
|
107 | + ); |
|
108 | + } |
|
109 | + return LoaderFactory::$loader; |
|
110 | + } |
|
111 | 111 | |
112 | 112 | |
113 | - /** |
|
114 | - * Used for instantiating a new instance of a class |
|
115 | - * |
|
116 | - * @param FullyQualifiedName|string $fqcn |
|
117 | - * @param array $arguments |
|
118 | - * @return mixed |
|
119 | - */ |
|
120 | - public static function getNew($fqcn, array $arguments = []) |
|
121 | - { |
|
122 | - return LoaderFactory::getLoader()->getNew($fqcn, $arguments); |
|
123 | - } |
|
113 | + /** |
|
114 | + * Used for instantiating a new instance of a class |
|
115 | + * |
|
116 | + * @param FullyQualifiedName|string $fqcn |
|
117 | + * @param array $arguments |
|
118 | + * @return mixed |
|
119 | + */ |
|
120 | + public static function getNew($fqcn, array $arguments = []) |
|
121 | + { |
|
122 | + return LoaderFactory::getLoader()->getNew($fqcn, $arguments); |
|
123 | + } |
|
124 | 124 | |
125 | 125 | |
126 | - /** |
|
127 | - * Used for getting a shared instance of a class |
|
128 | - * |
|
129 | - * @param FullyQualifiedName|string $fqcn |
|
130 | - * @param array $arguments |
|
131 | - * @return mixed |
|
132 | - */ |
|
133 | - public static function getShared($fqcn, array $arguments = []) |
|
134 | - { |
|
135 | - return LoaderFactory::getLoader()->getShared($fqcn, $arguments); |
|
136 | - } |
|
126 | + /** |
|
127 | + * Used for getting a shared instance of a class |
|
128 | + * |
|
129 | + * @param FullyQualifiedName|string $fqcn |
|
130 | + * @param array $arguments |
|
131 | + * @return mixed |
|
132 | + */ |
|
133 | + public static function getShared($fqcn, array $arguments = []) |
|
134 | + { |
|
135 | + return LoaderFactory::getLoader()->getShared($fqcn, $arguments); |
|
136 | + } |
|
137 | 137 | } |
@@ -7,58 +7,58 @@ |
||
7 | 7 | |
8 | 8 | interface LoaderInterface |
9 | 9 | { |
10 | - /** |
|
11 | - * Can be for instantiating a new instance of a class, |
|
12 | - * or for getting a shared instance of a class (default) |
|
13 | - * |
|
14 | - * @param FullyQualifiedName|string $fqcn |
|
15 | - * @param array $arguments |
|
16 | - * @param bool $shared |
|
17 | - * @return mixed |
|
18 | - */ |
|
19 | - public function load($fqcn, array $arguments = [], bool $shared = true); |
|
10 | + /** |
|
11 | + * Can be for instantiating a new instance of a class, |
|
12 | + * or for getting a shared instance of a class (default) |
|
13 | + * |
|
14 | + * @param FullyQualifiedName|string $fqcn |
|
15 | + * @param array $arguments |
|
16 | + * @param bool $shared |
|
17 | + * @return mixed |
|
18 | + */ |
|
19 | + public function load($fqcn, array $arguments = [], bool $shared = true); |
|
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * Used for instantiating a new instance of a class |
|
24 | - * |
|
25 | - * @param FullyQualifiedName|string $fqcn |
|
26 | - * @param array $arguments |
|
27 | - * @return mixed |
|
28 | - */ |
|
29 | - public function getNew($fqcn, array $arguments = []); |
|
22 | + /** |
|
23 | + * Used for instantiating a new instance of a class |
|
24 | + * |
|
25 | + * @param FullyQualifiedName|string $fqcn |
|
26 | + * @param array $arguments |
|
27 | + * @return mixed |
|
28 | + */ |
|
29 | + public function getNew($fqcn, array $arguments = []); |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * Used for getting a shared instance of a class |
|
34 | - * |
|
35 | - * @param FullyQualifiedName|string $fqcn |
|
36 | - * @param array $arguments |
|
37 | - * @return mixed |
|
38 | - */ |
|
39 | - public function getShared($fqcn, array $arguments = []); |
|
32 | + /** |
|
33 | + * Used for getting a shared instance of a class |
|
34 | + * |
|
35 | + * @param FullyQualifiedName|string $fqcn |
|
36 | + * @param array $arguments |
|
37 | + * @return mixed |
|
38 | + */ |
|
39 | + public function getShared($fqcn, array $arguments = []); |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * @param FullyQualifiedName|string $fqcn |
|
44 | - * @param mixed $object |
|
45 | - * @param array $arguments |
|
46 | - * @return bool |
|
47 | - * @throws InvalidArgumentException |
|
48 | - */ |
|
49 | - public function share($fqcn, $object, array $arguments = []): bool; |
|
42 | + /** |
|
43 | + * @param FullyQualifiedName|string $fqcn |
|
44 | + * @param mixed $object |
|
45 | + * @param array $arguments |
|
46 | + * @return bool |
|
47 | + * @throws InvalidArgumentException |
|
48 | + */ |
|
49 | + public function share($fqcn, $object, array $arguments = []): bool; |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * @param FullyQualifiedName|string $fqcn |
|
54 | - * @return bool |
|
55 | - * @throws InvalidArgumentException |
|
56 | - */ |
|
57 | - public function remove($fqcn): bool; |
|
52 | + /** |
|
53 | + * @param FullyQualifiedName|string $fqcn |
|
54 | + * @return bool |
|
55 | + * @throws InvalidArgumentException |
|
56 | + */ |
|
57 | + public function remove($fqcn): bool; |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * calls reset() on loader if method exists |
|
62 | - */ |
|
63 | - public function reset(); |
|
60 | + /** |
|
61 | + * calls reset() on loader if method exists |
|
62 | + */ |
|
63 | + public function reset(); |
|
64 | 64 | } |
@@ -16,204 +16,204 @@ |
||
16 | 16 | */ |
17 | 17 | class CachingLoader extends CachingLoaderDecorator |
18 | 18 | { |
19 | - protected bool $bypass = false; |
|
20 | - |
|
21 | - protected CollectionInterface $cache; |
|
22 | - |
|
23 | - protected string $identifier; |
|
24 | - |
|
25 | - private ObjectIdentifier $object_identifier; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * CachingLoader constructor. |
|
30 | - * |
|
31 | - * @param LoaderDecoratorInterface $loader |
|
32 | - * @param CollectionInterface $cache |
|
33 | - * @param ObjectIdentifier $object_identifier |
|
34 | - * @param string $identifier |
|
35 | - * @throws InvalidDataTypeException |
|
36 | - */ |
|
37 | - public function __construct( |
|
38 | - LoaderDecoratorInterface $loader, |
|
39 | - CollectionInterface $cache, |
|
40 | - ObjectIdentifier $object_identifier, |
|
41 | - string $identifier = '' |
|
42 | - ) { |
|
43 | - parent::__construct($loader); |
|
44 | - $this->cache = $cache; |
|
45 | - $this->object_identifier = $object_identifier; |
|
46 | - $this->setIdentifier($identifier); |
|
47 | - if ($this->identifier !== '') { |
|
48 | - // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
49 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
50 | - // where "IDENTIFIER" = the string that was set during construction |
|
51 | - add_action( |
|
52 | - "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__$identifier", |
|
53 | - [$this, 'reset'] |
|
54 | - ); |
|
55 | - } |
|
56 | - // to clear ALL caches, simply do the following: |
|
57 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
58 | - add_action( |
|
59 | - 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
60 | - [$this, 'reset'] |
|
61 | - ); |
|
62 | - // caching can be turned off via the following code: |
|
63 | - // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
64 | - $this->bypass = filter_var( |
|
65 | - apply_filters( |
|
66 | - 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
67 | - false, |
|
68 | - $this |
|
69 | - ), |
|
70 | - FILTER_VALIDATE_BOOLEAN |
|
71 | - ); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public function identifier(): string |
|
79 | - { |
|
80 | - return $this->identifier; |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * @param string|null $identifier |
|
86 | - * @throws InvalidDataTypeException |
|
87 | - */ |
|
88 | - private function setIdentifier(?string $identifier) |
|
89 | - { |
|
90 | - if (! is_string($identifier)) { |
|
91 | - throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
92 | - } |
|
93 | - $this->identifier = $identifier; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @param FullyQualifiedName|string $fqcn |
|
99 | - * @param mixed $object |
|
100 | - * @param array $arguments |
|
101 | - * @return bool |
|
102 | - * @throws InvalidArgumentException |
|
103 | - */ |
|
104 | - public function share($fqcn, $object, array $arguments = []): bool |
|
105 | - { |
|
106 | - if ($object instanceof $fqcn) { |
|
107 | - $added = false; |
|
108 | - if ($arguments) { |
|
109 | - // first cache the object using the identifier that includes the arguments |
|
110 | - $added = $this->cache->add($object, $this->object_identifier->getIdentifier($fqcn, $arguments)); |
|
111 | - } |
|
112 | - // then again using the identifier without the arguments |
|
113 | - // WHY? because most requests for the object will not include arguments |
|
114 | - $object_identifier = $this->object_identifier->getIdentifier($fqcn); |
|
115 | - // but only if the object is not already in the cache |
|
116 | - if (! $this->cache->has($object_identifier)) { |
|
117 | - $added = $this->cache->add($object, $object_identifier) |
|
118 | - ? true |
|
119 | - : $added; |
|
120 | - } |
|
121 | - return $added; |
|
122 | - } |
|
123 | - throw new InvalidArgumentException( |
|
124 | - sprintf( |
|
125 | - esc_html__( |
|
126 | - 'The supplied class name "%1$s" must match the class of the supplied object.', |
|
127 | - 'event_espresso' |
|
128 | - ), |
|
129 | - $fqcn |
|
130 | - ) |
|
131 | - ); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * @param FullyQualifiedName|string $fqcn |
|
137 | - * @param array $arguments |
|
138 | - * @return bool |
|
139 | - * @since 5.0.42 |
|
140 | - */ |
|
141 | - public function isShared($fqcn, array $arguments = []): bool |
|
142 | - { |
|
143 | - $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments); |
|
144 | - return $this->cache->has($object_identifier); |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @param FullyQualifiedName|string $fqcn |
|
150 | - * @param array $arguments |
|
151 | - * @param bool $shared |
|
152 | - * @return mixed |
|
153 | - */ |
|
154 | - public function load($fqcn, array $arguments = [], bool $shared = true) |
|
155 | - { |
|
156 | - $fqcn = ltrim($fqcn, '\\'); |
|
157 | - // caching can be turned off via the following code: |
|
158 | - // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
159 | - if ($this->bypass) { |
|
160 | - // even though $shared might be true, caching could be bypassed for whatever reason, |
|
161 | - // so we don't want the core loader to cache anything, therefore caching is turned off |
|
162 | - return $this->loader->load($fqcn, $arguments, false); |
|
163 | - } |
|
164 | - $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments); |
|
165 | - if ($this->cache->has($object_identifier)) { |
|
166 | - return $this->cache->get($object_identifier); |
|
167 | - } |
|
168 | - $object = $this->loader->load($fqcn, $arguments, $shared); |
|
169 | - if ($object instanceof $fqcn) { |
|
170 | - $this->cache->add($object, $object_identifier); |
|
171 | - } |
|
172 | - return $object; |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * empties cache and calls reset() on loader if method exists |
|
178 | - */ |
|
179 | - public function reset() |
|
180 | - { |
|
181 | - $this->clearCache(); |
|
182 | - $this->loader->reset(); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * unsets and detaches ALL objects from the cache |
|
188 | - * |
|
189 | - * @since 4.9.62.p |
|
190 | - */ |
|
191 | - public function clearCache() |
|
192 | - { |
|
193 | - $cache_class = get_class($this->cache); |
|
194 | - $collection_interface = $this->cache->collectionInterface(); |
|
195 | - $this->cache->trashAndDetachAll(); |
|
196 | - $new_cache = new $cache_class($collection_interface); |
|
197 | - if (! $new_cache instanceof CollectionInterface) { |
|
198 | - throw new InvalidDataTypeException('CachingLoader::$cache', $new_cache, 'CollectionInterface'); |
|
199 | - } |
|
200 | - $this->cache = $new_cache; |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * @param string $fqcn |
|
206 | - * @param array $arguments |
|
207 | - * @return bool |
|
208 | - * @throws InvalidArgumentException |
|
209 | - */ |
|
210 | - public function remove($fqcn, array $arguments = []): bool |
|
211 | - { |
|
212 | - $fqcn = ltrim($fqcn, '\\'); |
|
213 | - $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments); |
|
214 | - $object = $this->cache->has($object_identifier) |
|
215 | - ? $this->cache->get($object_identifier) |
|
216 | - : $this->loader->load($fqcn, $arguments); |
|
217 | - return $this->cache->remove($object); |
|
218 | - } |
|
19 | + protected bool $bypass = false; |
|
20 | + |
|
21 | + protected CollectionInterface $cache; |
|
22 | + |
|
23 | + protected string $identifier; |
|
24 | + |
|
25 | + private ObjectIdentifier $object_identifier; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * CachingLoader constructor. |
|
30 | + * |
|
31 | + * @param LoaderDecoratorInterface $loader |
|
32 | + * @param CollectionInterface $cache |
|
33 | + * @param ObjectIdentifier $object_identifier |
|
34 | + * @param string $identifier |
|
35 | + * @throws InvalidDataTypeException |
|
36 | + */ |
|
37 | + public function __construct( |
|
38 | + LoaderDecoratorInterface $loader, |
|
39 | + CollectionInterface $cache, |
|
40 | + ObjectIdentifier $object_identifier, |
|
41 | + string $identifier = '' |
|
42 | + ) { |
|
43 | + parent::__construct($loader); |
|
44 | + $this->cache = $cache; |
|
45 | + $this->object_identifier = $object_identifier; |
|
46 | + $this->setIdentifier($identifier); |
|
47 | + if ($this->identifier !== '') { |
|
48 | + // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
49 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
50 | + // where "IDENTIFIER" = the string that was set during construction |
|
51 | + add_action( |
|
52 | + "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__$identifier", |
|
53 | + [$this, 'reset'] |
|
54 | + ); |
|
55 | + } |
|
56 | + // to clear ALL caches, simply do the following: |
|
57 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
58 | + add_action( |
|
59 | + 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
60 | + [$this, 'reset'] |
|
61 | + ); |
|
62 | + // caching can be turned off via the following code: |
|
63 | + // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
64 | + $this->bypass = filter_var( |
|
65 | + apply_filters( |
|
66 | + 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
67 | + false, |
|
68 | + $this |
|
69 | + ), |
|
70 | + FILTER_VALIDATE_BOOLEAN |
|
71 | + ); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public function identifier(): string |
|
79 | + { |
|
80 | + return $this->identifier; |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * @param string|null $identifier |
|
86 | + * @throws InvalidDataTypeException |
|
87 | + */ |
|
88 | + private function setIdentifier(?string $identifier) |
|
89 | + { |
|
90 | + if (! is_string($identifier)) { |
|
91 | + throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
92 | + } |
|
93 | + $this->identifier = $identifier; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @param FullyQualifiedName|string $fqcn |
|
99 | + * @param mixed $object |
|
100 | + * @param array $arguments |
|
101 | + * @return bool |
|
102 | + * @throws InvalidArgumentException |
|
103 | + */ |
|
104 | + public function share($fqcn, $object, array $arguments = []): bool |
|
105 | + { |
|
106 | + if ($object instanceof $fqcn) { |
|
107 | + $added = false; |
|
108 | + if ($arguments) { |
|
109 | + // first cache the object using the identifier that includes the arguments |
|
110 | + $added = $this->cache->add($object, $this->object_identifier->getIdentifier($fqcn, $arguments)); |
|
111 | + } |
|
112 | + // then again using the identifier without the arguments |
|
113 | + // WHY? because most requests for the object will not include arguments |
|
114 | + $object_identifier = $this->object_identifier->getIdentifier($fqcn); |
|
115 | + // but only if the object is not already in the cache |
|
116 | + if (! $this->cache->has($object_identifier)) { |
|
117 | + $added = $this->cache->add($object, $object_identifier) |
|
118 | + ? true |
|
119 | + : $added; |
|
120 | + } |
|
121 | + return $added; |
|
122 | + } |
|
123 | + throw new InvalidArgumentException( |
|
124 | + sprintf( |
|
125 | + esc_html__( |
|
126 | + 'The supplied class name "%1$s" must match the class of the supplied object.', |
|
127 | + 'event_espresso' |
|
128 | + ), |
|
129 | + $fqcn |
|
130 | + ) |
|
131 | + ); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * @param FullyQualifiedName|string $fqcn |
|
137 | + * @param array $arguments |
|
138 | + * @return bool |
|
139 | + * @since 5.0.42 |
|
140 | + */ |
|
141 | + public function isShared($fqcn, array $arguments = []): bool |
|
142 | + { |
|
143 | + $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments); |
|
144 | + return $this->cache->has($object_identifier); |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @param FullyQualifiedName|string $fqcn |
|
150 | + * @param array $arguments |
|
151 | + * @param bool $shared |
|
152 | + * @return mixed |
|
153 | + */ |
|
154 | + public function load($fqcn, array $arguments = [], bool $shared = true) |
|
155 | + { |
|
156 | + $fqcn = ltrim($fqcn, '\\'); |
|
157 | + // caching can be turned off via the following code: |
|
158 | + // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
159 | + if ($this->bypass) { |
|
160 | + // even though $shared might be true, caching could be bypassed for whatever reason, |
|
161 | + // so we don't want the core loader to cache anything, therefore caching is turned off |
|
162 | + return $this->loader->load($fqcn, $arguments, false); |
|
163 | + } |
|
164 | + $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments); |
|
165 | + if ($this->cache->has($object_identifier)) { |
|
166 | + return $this->cache->get($object_identifier); |
|
167 | + } |
|
168 | + $object = $this->loader->load($fqcn, $arguments, $shared); |
|
169 | + if ($object instanceof $fqcn) { |
|
170 | + $this->cache->add($object, $object_identifier); |
|
171 | + } |
|
172 | + return $object; |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * empties cache and calls reset() on loader if method exists |
|
178 | + */ |
|
179 | + public function reset() |
|
180 | + { |
|
181 | + $this->clearCache(); |
|
182 | + $this->loader->reset(); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * unsets and detaches ALL objects from the cache |
|
188 | + * |
|
189 | + * @since 4.9.62.p |
|
190 | + */ |
|
191 | + public function clearCache() |
|
192 | + { |
|
193 | + $cache_class = get_class($this->cache); |
|
194 | + $collection_interface = $this->cache->collectionInterface(); |
|
195 | + $this->cache->trashAndDetachAll(); |
|
196 | + $new_cache = new $cache_class($collection_interface); |
|
197 | + if (! $new_cache instanceof CollectionInterface) { |
|
198 | + throw new InvalidDataTypeException('CachingLoader::$cache', $new_cache, 'CollectionInterface'); |
|
199 | + } |
|
200 | + $this->cache = $new_cache; |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * @param string $fqcn |
|
206 | + * @param array $arguments |
|
207 | + * @return bool |
|
208 | + * @throws InvalidArgumentException |
|
209 | + */ |
|
210 | + public function remove($fqcn, array $arguments = []): bool |
|
211 | + { |
|
212 | + $fqcn = ltrim($fqcn, '\\'); |
|
213 | + $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments); |
|
214 | + $object = $this->cache->has($object_identifier) |
|
215 | + ? $this->cache->get($object_identifier) |
|
216 | + : $this->loader->load($fqcn, $arguments); |
|
217 | + return $this->cache->remove($object); |
|
218 | + } |
|
219 | 219 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | private function setIdentifier(?string $identifier) |
89 | 89 | { |
90 | - if (! is_string($identifier)) { |
|
90 | + if ( ! is_string($identifier)) { |
|
91 | 91 | throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
92 | 92 | } |
93 | 93 | $this->identifier = $identifier; |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | // WHY? because most requests for the object will not include arguments |
114 | 114 | $object_identifier = $this->object_identifier->getIdentifier($fqcn); |
115 | 115 | // but only if the object is not already in the cache |
116 | - if (! $this->cache->has($object_identifier)) { |
|
116 | + if ( ! $this->cache->has($object_identifier)) { |
|
117 | 117 | $added = $this->cache->add($object, $object_identifier) |
118 | 118 | ? true |
119 | 119 | : $added; |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | $collection_interface = $this->cache->collectionInterface(); |
195 | 195 | $this->cache->trashAndDetachAll(); |
196 | 196 | $new_cache = new $cache_class($collection_interface); |
197 | - if (! $new_cache instanceof CollectionInterface) { |
|
197 | + if ( ! $new_cache instanceof CollectionInterface) { |
|
198 | 198 | throw new InvalidDataTypeException('CachingLoader::$cache', $new_cache, 'CollectionInterface'); |
199 | 199 | } |
200 | 200 | $this->cache = $new_cache; |
@@ -28,111 +28,111 @@ |
||
28 | 28 | */ |
29 | 29 | class CoreLoader implements LoaderDecoratorInterface |
30 | 30 | { |
31 | - /** |
|
32 | - * @var EE_Registry|CoffeeShop $generator |
|
33 | - */ |
|
34 | - private $generator; |
|
31 | + /** |
|
32 | + * @var EE_Registry|CoffeeShop $generator |
|
33 | + */ |
|
34 | + private $generator; |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * CoreLoader constructor. |
|
39 | - * |
|
40 | - * @param EE_Registry|CoffeeShop $generator |
|
41 | - * @throws InvalidArgumentException |
|
42 | - */ |
|
43 | - public function __construct($generator) |
|
44 | - { |
|
45 | - if (! ($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
46 | - throw new InvalidArgumentException( |
|
47 | - esc_html__( |
|
48 | - 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
49 | - 'event_espresso' |
|
50 | - ) |
|
51 | - ); |
|
52 | - } |
|
53 | - $this->generator = $generator; |
|
54 | - } |
|
37 | + /** |
|
38 | + * CoreLoader constructor. |
|
39 | + * |
|
40 | + * @param EE_Registry|CoffeeShop $generator |
|
41 | + * @throws InvalidArgumentException |
|
42 | + */ |
|
43 | + public function __construct($generator) |
|
44 | + { |
|
45 | + if (! ($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
46 | + throw new InvalidArgumentException( |
|
47 | + esc_html__( |
|
48 | + 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
49 | + 'event_espresso' |
|
50 | + ) |
|
51 | + ); |
|
52 | + } |
|
53 | + $this->generator = $generator; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * Calls the appropriate loading method from the installed generator; |
|
59 | - * If EE_Registry is being used, then the additional parameters for the EE_Registry::create() method |
|
60 | - * can be added to the $arguments array and they will be extracted and passed to EE_Registry::create(), |
|
61 | - * but NOT to the class being instantiated. |
|
62 | - * This is done by adding the parameters to the $arguments array as follows: |
|
63 | - * array( |
|
64 | - * 'EE_Registry::create(from_db)' => true, // boolean value, default = false |
|
65 | - * 'EE_Registry::create(load_only)' => true, // boolean value, default = false |
|
66 | - * 'EE_Registry::create(addon)' => true, // boolean value, default = false |
|
67 | - * ) |
|
68 | - * |
|
69 | - * @param string $fqcn |
|
70 | - * @param array $arguments |
|
71 | - * @param bool $shared |
|
72 | - * @return mixed |
|
73 | - * @throws OutOfBoundsException |
|
74 | - * @throws ServiceExistsException |
|
75 | - * @throws InstantiationException |
|
76 | - * @throws InvalidIdentifierException |
|
77 | - * @throws InvalidDataTypeException |
|
78 | - * @throws InvalidClassException |
|
79 | - * @throws EE_Error |
|
80 | - * @throws ServiceNotFoundException |
|
81 | - * @throws ReflectionException |
|
82 | - * @throws InvalidInterfaceException |
|
83 | - * @throws InvalidArgumentException |
|
84 | - */ |
|
85 | - public function load($fqcn, array $arguments = array(), bool $shared = true) |
|
86 | - { |
|
87 | - $shared = filter_var($shared, FILTER_VALIDATE_BOOLEAN); |
|
88 | - if ($this->generator instanceof EE_Registry) { |
|
89 | - // check if additional EE_Registry::create() arguments have been passed |
|
90 | - // from_db |
|
91 | - $from_db = isset($arguments['EE_Registry::create(from_db)']) |
|
92 | - ? filter_var($arguments['EE_Registry::create(from_db)'], FILTER_VALIDATE_BOOLEAN) |
|
93 | - : false; |
|
94 | - // load_only |
|
95 | - $load_only = isset($arguments['EE_Registry::create(load_only)']) |
|
96 | - ? filter_var($arguments['EE_Registry::create(load_only)'], FILTER_VALIDATE_BOOLEAN) |
|
97 | - : false; |
|
98 | - // addon |
|
99 | - $addon = isset($arguments['EE_Registry::create(addon)']) |
|
100 | - ? filter_var($arguments['EE_Registry::create(addon)'], FILTER_VALIDATE_BOOLEAN) |
|
101 | - : false; |
|
102 | - unset( |
|
103 | - $arguments['EE_Registry::create(from_db)'], |
|
104 | - $arguments['EE_Registry::create(load_only)'], |
|
105 | - $arguments['EE_Registry::create(addon)'] |
|
106 | - ); |
|
107 | - // addons need to be cached on EE_Registry |
|
108 | - $shared = $addon ? true : $shared; |
|
109 | - return $this->generator->create( |
|
110 | - $fqcn, |
|
111 | - $arguments, |
|
112 | - $shared, |
|
113 | - $from_db, |
|
114 | - $load_only, |
|
115 | - $addon |
|
116 | - ); |
|
117 | - } |
|
118 | - return $this->generator->brew( |
|
119 | - $fqcn, |
|
120 | - $arguments, |
|
121 | - $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW |
|
122 | - ); |
|
123 | - } |
|
57 | + /** |
|
58 | + * Calls the appropriate loading method from the installed generator; |
|
59 | + * If EE_Registry is being used, then the additional parameters for the EE_Registry::create() method |
|
60 | + * can be added to the $arguments array and they will be extracted and passed to EE_Registry::create(), |
|
61 | + * but NOT to the class being instantiated. |
|
62 | + * This is done by adding the parameters to the $arguments array as follows: |
|
63 | + * array( |
|
64 | + * 'EE_Registry::create(from_db)' => true, // boolean value, default = false |
|
65 | + * 'EE_Registry::create(load_only)' => true, // boolean value, default = false |
|
66 | + * 'EE_Registry::create(addon)' => true, // boolean value, default = false |
|
67 | + * ) |
|
68 | + * |
|
69 | + * @param string $fqcn |
|
70 | + * @param array $arguments |
|
71 | + * @param bool $shared |
|
72 | + * @return mixed |
|
73 | + * @throws OutOfBoundsException |
|
74 | + * @throws ServiceExistsException |
|
75 | + * @throws InstantiationException |
|
76 | + * @throws InvalidIdentifierException |
|
77 | + * @throws InvalidDataTypeException |
|
78 | + * @throws InvalidClassException |
|
79 | + * @throws EE_Error |
|
80 | + * @throws ServiceNotFoundException |
|
81 | + * @throws ReflectionException |
|
82 | + * @throws InvalidInterfaceException |
|
83 | + * @throws InvalidArgumentException |
|
84 | + */ |
|
85 | + public function load($fqcn, array $arguments = array(), bool $shared = true) |
|
86 | + { |
|
87 | + $shared = filter_var($shared, FILTER_VALIDATE_BOOLEAN); |
|
88 | + if ($this->generator instanceof EE_Registry) { |
|
89 | + // check if additional EE_Registry::create() arguments have been passed |
|
90 | + // from_db |
|
91 | + $from_db = isset($arguments['EE_Registry::create(from_db)']) |
|
92 | + ? filter_var($arguments['EE_Registry::create(from_db)'], FILTER_VALIDATE_BOOLEAN) |
|
93 | + : false; |
|
94 | + // load_only |
|
95 | + $load_only = isset($arguments['EE_Registry::create(load_only)']) |
|
96 | + ? filter_var($arguments['EE_Registry::create(load_only)'], FILTER_VALIDATE_BOOLEAN) |
|
97 | + : false; |
|
98 | + // addon |
|
99 | + $addon = isset($arguments['EE_Registry::create(addon)']) |
|
100 | + ? filter_var($arguments['EE_Registry::create(addon)'], FILTER_VALIDATE_BOOLEAN) |
|
101 | + : false; |
|
102 | + unset( |
|
103 | + $arguments['EE_Registry::create(from_db)'], |
|
104 | + $arguments['EE_Registry::create(load_only)'], |
|
105 | + $arguments['EE_Registry::create(addon)'] |
|
106 | + ); |
|
107 | + // addons need to be cached on EE_Registry |
|
108 | + $shared = $addon ? true : $shared; |
|
109 | + return $this->generator->create( |
|
110 | + $fqcn, |
|
111 | + $arguments, |
|
112 | + $shared, |
|
113 | + $from_db, |
|
114 | + $load_only, |
|
115 | + $addon |
|
116 | + ); |
|
117 | + } |
|
118 | + return $this->generator->brew( |
|
119 | + $fqcn, |
|
120 | + $arguments, |
|
121 | + $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW |
|
122 | + ); |
|
123 | + } |
|
124 | 124 | |
125 | 125 | |
126 | - /** |
|
127 | - * calls reset() on generator if method exists |
|
128 | - * |
|
129 | - * @throws EE_Error |
|
130 | - * @throws ReflectionException |
|
131 | - */ |
|
132 | - public function reset() |
|
133 | - { |
|
134 | - if ($this->generator instanceof ResettableInterface) { |
|
135 | - $this->generator->reset(); |
|
136 | - } |
|
137 | - } |
|
126 | + /** |
|
127 | + * calls reset() on generator if method exists |
|
128 | + * |
|
129 | + * @throws EE_Error |
|
130 | + * @throws ReflectionException |
|
131 | + */ |
|
132 | + public function reset() |
|
133 | + { |
|
134 | + if ($this->generator instanceof ResettableInterface) { |
|
135 | + $this->generator->reset(); |
|
136 | + } |
|
137 | + } |
|
138 | 138 | } |
@@ -12,19 +12,19 @@ |
||
12 | 12 | */ |
13 | 13 | abstract class LoaderDecorator implements LoaderDecoratorInterface |
14 | 14 | { |
15 | - /** |
|
16 | - * @var LoaderDecoratorInterface $loader |
|
17 | - */ |
|
18 | - protected LoaderDecoratorInterface $loader; |
|
15 | + /** |
|
16 | + * @var LoaderDecoratorInterface $loader |
|
17 | + */ |
|
18 | + protected LoaderDecoratorInterface $loader; |
|
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * LoaderDecorator constructor. |
|
23 | - * |
|
24 | - * @param LoaderDecoratorInterface $loader |
|
25 | - */ |
|
26 | - public function __construct(LoaderDecoratorInterface $loader) |
|
27 | - { |
|
28 | - $this->loader = $loader; |
|
29 | - } |
|
21 | + /** |
|
22 | + * LoaderDecorator constructor. |
|
23 | + * |
|
24 | + * @param LoaderDecoratorInterface $loader |
|
25 | + */ |
|
26 | + public function __construct(LoaderDecoratorInterface $loader) |
|
27 | + { |
|
28 | + $this->loader = $loader; |
|
29 | + } |
|
30 | 30 | } |
@@ -11,29 +11,29 @@ |
||
11 | 11 | */ |
12 | 12 | interface CachingLoaderDecoratorInterface extends LoaderDecoratorInterface |
13 | 13 | { |
14 | - /** |
|
15 | - * @param FullyQualifiedName|string $fqcn |
|
16 | - * @param mixed $object |
|
17 | - * @param array $arguments |
|
18 | - * @return bool |
|
19 | - * @throws InvalidArgumentException |
|
20 | - */ |
|
21 | - public function share($fqcn, $object, array $arguments = []): bool; |
|
14 | + /** |
|
15 | + * @param FullyQualifiedName|string $fqcn |
|
16 | + * @param mixed $object |
|
17 | + * @param array $arguments |
|
18 | + * @return bool |
|
19 | + * @throws InvalidArgumentException |
|
20 | + */ |
|
21 | + public function share($fqcn, $object, array $arguments = []): bool; |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * @param FullyQualifiedName|string $fqcn |
|
26 | - * @param array $arguments |
|
27 | - * @return bool |
|
28 | - */ |
|
29 | - public function isShared($fqcn, array $arguments = []): bool; |
|
24 | + /** |
|
25 | + * @param FullyQualifiedName|string $fqcn |
|
26 | + * @param array $arguments |
|
27 | + * @return bool |
|
28 | + */ |
|
29 | + public function isShared($fqcn, array $arguments = []): bool; |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * @param FullyQualifiedName|string $fqcn |
|
34 | - * @param array $arguments |
|
35 | - * @return bool |
|
36 | - * @throws InvalidArgumentException |
|
37 | - */ |
|
38 | - public function remove($fqcn, array $arguments = []): bool; |
|
32 | + /** |
|
33 | + * @param FullyQualifiedName|string $fqcn |
|
34 | + * @param array $arguments |
|
35 | + * @return bool |
|
36 | + * @throws InvalidArgumentException |
|
37 | + */ |
|
38 | + public function remove($fqcn, array $arguments = []): bool; |
|
39 | 39 | } |
@@ -6,18 +6,18 @@ |
||
6 | 6 | |
7 | 7 | interface LoaderDecoratorInterface |
8 | 8 | { |
9 | - /** |
|
10 | - * @param FullyQualifiedName|string $fqcn |
|
11 | - * @param array $arguments |
|
12 | - * @param bool $shared |
|
13 | - * @return mixed |
|
14 | - */ |
|
15 | - public function load($fqcn, array $arguments = array(), bool $shared = true); |
|
9 | + /** |
|
10 | + * @param FullyQualifiedName|string $fqcn |
|
11 | + * @param array $arguments |
|
12 | + * @param bool $shared |
|
13 | + * @return mixed |
|
14 | + */ |
|
15 | + public function load($fqcn, array $arguments = array(), bool $shared = true); |
|
16 | 16 | |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * calls reset() on loader if method exists |
|
21 | - */ |
|
22 | - public function reset(); |
|
19 | + /** |
|
20 | + * calls reset() on loader if method exists |
|
21 | + */ |
|
22 | + public function reset(); |
|
23 | 23 | } |