@@ -33,7 +33,7 @@ |
||
33 | 33 | /** |
34 | 34 | * CoreLoader constructor. |
35 | 35 | * |
36 | - * @param EE_Registry|CoffeeShop $generator |
|
36 | + * @param EE_Registry $generator |
|
37 | 37 | * @throws InvalidArgumentException |
38 | 38 | */ |
39 | 39 | public function __construct($generator) |
@@ -23,58 +23,58 @@ |
||
23 | 23 | class CoreLoader implements LoaderInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var EE_Registry|CoffeeShop $generator |
|
28 | - */ |
|
29 | - private $generator; |
|
30 | - |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * CoreLoader constructor. |
|
35 | - * |
|
36 | - * @param EE_Registry|CoffeeShop $generator |
|
37 | - * @throws InvalidArgumentException |
|
38 | - */ |
|
39 | - public function __construct($generator) |
|
40 | - { |
|
41 | - if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
42 | - throw new InvalidArgumentException( |
|
43 | - esc_html__( |
|
44 | - 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
45 | - 'event_espresso' |
|
46 | - ) |
|
47 | - ); |
|
48 | - } |
|
49 | - $this->generator = $generator; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @param string $fqcn |
|
56 | - * @param array $arguments |
|
57 | - * @return mixed |
|
58 | - * @throws ServiceNotFoundException |
|
59 | - */ |
|
60 | - public function load($fqcn, $arguments = array()) |
|
61 | - { |
|
62 | - return $this->generator instanceof EE_Registry |
|
63 | - ? $this->generator->create($fqcn, $arguments) |
|
64 | - : $this->generator->brew($fqcn, $arguments); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * calls reset() on generator if method exists |
|
71 | - */ |
|
72 | - public function reset() |
|
73 | - { |
|
74 | - if (method_exists($this->generator, 'reset')) { |
|
75 | - $this->generator->reset(); |
|
76 | - } |
|
77 | - } |
|
26 | + /** |
|
27 | + * @var EE_Registry|CoffeeShop $generator |
|
28 | + */ |
|
29 | + private $generator; |
|
30 | + |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * CoreLoader constructor. |
|
35 | + * |
|
36 | + * @param EE_Registry|CoffeeShop $generator |
|
37 | + * @throws InvalidArgumentException |
|
38 | + */ |
|
39 | + public function __construct($generator) |
|
40 | + { |
|
41 | + if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
42 | + throw new InvalidArgumentException( |
|
43 | + esc_html__( |
|
44 | + 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
45 | + 'event_espresso' |
|
46 | + ) |
|
47 | + ); |
|
48 | + } |
|
49 | + $this->generator = $generator; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @param string $fqcn |
|
56 | + * @param array $arguments |
|
57 | + * @return mixed |
|
58 | + * @throws ServiceNotFoundException |
|
59 | + */ |
|
60 | + public function load($fqcn, $arguments = array()) |
|
61 | + { |
|
62 | + return $this->generator instanceof EE_Registry |
|
63 | + ? $this->generator->create($fqcn, $arguments) |
|
64 | + : $this->generator->brew($fqcn, $arguments); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * calls reset() on generator if method exists |
|
71 | + */ |
|
72 | + public function reset() |
|
73 | + { |
|
74 | + if (method_exists($this->generator, 'reset')) { |
|
75 | + $this->generator->reset(); |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | 79 | } |
80 | 80 | // End of file CoreLoader.php |
@@ -113,12 +113,12 @@ discard block |
||
113 | 113 | public function previous(); |
114 | 114 | |
115 | 115 | /** |
116 | - * Returns the index of a given object, or false if not found |
|
117 | - * |
|
118 | - * @see http://stackoverflow.com/a/8736013 |
|
119 | - * @param $object |
|
120 | - * @return boolean|int|string |
|
121 | - */ |
|
116 | + * Returns the index of a given object, or false if not found |
|
117 | + * |
|
118 | + * @see http://stackoverflow.com/a/8736013 |
|
119 | + * @param $object |
|
120 | + * @return boolean|int|string |
|
121 | + */ |
|
122 | 122 | public function indexOf( $object ); |
123 | 123 | |
124 | 124 | |
@@ -160,10 +160,10 @@ discard block |
||
160 | 160 | |
161 | 161 | |
162 | 162 | |
163 | - /** |
|
164 | - * detaches ALL objects from the Collection |
|
165 | - */ |
|
166 | - public function detachAll(); |
|
163 | + /** |
|
164 | + * detaches ALL objects from the Collection |
|
165 | + */ |
|
166 | + public function detachAll(); |
|
167 | 167 | |
168 | 168 | } |
169 | 169 | // End of file CollectionInterface.php |
@@ -83,7 +83,6 @@ discard block |
||
83 | 83 | |
84 | 84 | /** |
85 | 85 | * setIdentifier |
86 | - |
|
87 | 86 | * Sets the data associated with an object in the Collection |
88 | 87 | * if no $identifier is supplied, then the spl_object_hash() is used |
89 | 88 | * |
@@ -352,18 +351,18 @@ discard block |
||
352 | 351 | |
353 | 352 | |
354 | 353 | |
355 | - /** |
|
356 | - * detaches ALL objects from the Collection |
|
357 | - */ |
|
358 | - public function detachAll() |
|
359 | - { |
|
360 | - $this->rewind(); |
|
361 | - while ($this->valid()) { |
|
362 | - $object = $this->current(); |
|
363 | - $this->next(); |
|
364 | - $this->detach($object); |
|
365 | - } |
|
366 | - } |
|
354 | + /** |
|
355 | + * detaches ALL objects from the Collection |
|
356 | + */ |
|
357 | + public function detachAll() |
|
358 | + { |
|
359 | + $this->rewind(); |
|
360 | + while ($this->valid()) { |
|
361 | + $object = $this->current(); |
|
362 | + $this->next(); |
|
363 | + $this->detach($object); |
|
364 | + } |
|
365 | + } |
|
367 | 366 | |
368 | 367 | |
369 | 368 |
@@ -24,140 +24,140 @@ |
||
24 | 24 | { |
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * @var LoaderInterface $new_loader |
|
29 | - */ |
|
30 | - private $new_loader; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * @var LoaderInterface $shared_loader |
|
35 | - */ |
|
36 | - private $shared_loader; |
|
37 | - |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * Loader constructor. |
|
42 | - * |
|
43 | - * @param LoaderInterface|null $new_loader |
|
44 | - * @param LoaderInterface|null $shared_loader |
|
45 | - * @throws InvalidInterfaceException |
|
46 | - * @throws InvalidArgumentException |
|
47 | - * @throws InvalidDataTypeException |
|
48 | - */ |
|
49 | - public function __construct(LoaderInterface $new_loader = null, LoaderInterface $shared_loader = null) |
|
50 | - { |
|
51 | - $this->new_loader = $this->setupNewLoader($new_loader); |
|
52 | - $this->shared_loader = $this->setupSharedLoader($shared_loader); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @param LoaderInterface|null $new_loader |
|
59 | - * @return CoreLoader|LoaderInterface |
|
60 | - * @throws InvalidArgumentException |
|
61 | - */ |
|
62 | - private function setupNewLoader(LoaderInterface $new_loader = null) |
|
63 | - { |
|
64 | - // if not already generated, create a standard loader |
|
65 | - if (! $new_loader instanceof LoaderInterface) { |
|
66 | - $new_loader = new CoreLoader(EE_Registry::instance()); |
|
67 | - } |
|
68 | - return $new_loader; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @param LoaderInterface|null $shared_loader |
|
75 | - * @return CoreLoader|LoaderInterface |
|
76 | - * @throws InvalidDataTypeException |
|
77 | - * @throws InvalidInterfaceException |
|
78 | - * @throws InvalidArgumentException |
|
79 | - */ |
|
80 | - private function setupSharedLoader(LoaderInterface $shared_loader = null) |
|
81 | - { |
|
82 | - // if not already generated, create a caching loader |
|
83 | - if (! $shared_loader instanceof LoaderInterface) { |
|
84 | - $shared_loader = new CachingLoader( |
|
85 | - new CoreLoader(EE_Registry::instance()), |
|
86 | - new LooseCollection('') |
|
87 | - ); |
|
88 | - } |
|
89 | - return $shared_loader; |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * @return LoaderInterface |
|
96 | - */ |
|
97 | - public function getNewLoader() |
|
98 | - { |
|
99 | - return $this->new_loader; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @return LoaderInterface |
|
106 | - */ |
|
107 | - public function getSharedLoader() |
|
108 | - { |
|
109 | - return $this->shared_loader; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @param string $fqcn |
|
116 | - * @param array $arguments |
|
117 | - * @param bool $shared |
|
118 | - * @return mixed |
|
119 | - */ |
|
120 | - public function load($fqcn, $arguments = array(), $shared = true) |
|
121 | - { |
|
122 | - return $shared |
|
123 | - ? $this->getSharedLoader()->load($fqcn, $arguments) |
|
124 | - : $this->getNewLoader()->load($fqcn, $arguments); |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * @param string $fqcn |
|
131 | - * @param array $arguments |
|
132 | - * @return mixed |
|
133 | - */ |
|
134 | - public function getNew($fqcn, $arguments = array()) |
|
135 | - { |
|
136 | - return $this->getNewLoader()->load($fqcn, $arguments); |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @param string $fqcn |
|
143 | - * @param array $arguments |
|
144 | - * @return mixed |
|
145 | - */ |
|
146 | - public function getShared($fqcn, $arguments = array()) |
|
147 | - { |
|
148 | - return $this->getSharedLoader()->load($fqcn, $arguments); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * calls reset() on loaders if that method exists |
|
155 | - */ |
|
156 | - public function reset() |
|
157 | - { |
|
158 | - $this->new_loader->reset(); |
|
159 | - $this->shared_loader->reset(); |
|
160 | - } |
|
27 | + /** |
|
28 | + * @var LoaderInterface $new_loader |
|
29 | + */ |
|
30 | + private $new_loader; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * @var LoaderInterface $shared_loader |
|
35 | + */ |
|
36 | + private $shared_loader; |
|
37 | + |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * Loader constructor. |
|
42 | + * |
|
43 | + * @param LoaderInterface|null $new_loader |
|
44 | + * @param LoaderInterface|null $shared_loader |
|
45 | + * @throws InvalidInterfaceException |
|
46 | + * @throws InvalidArgumentException |
|
47 | + * @throws InvalidDataTypeException |
|
48 | + */ |
|
49 | + public function __construct(LoaderInterface $new_loader = null, LoaderInterface $shared_loader = null) |
|
50 | + { |
|
51 | + $this->new_loader = $this->setupNewLoader($new_loader); |
|
52 | + $this->shared_loader = $this->setupSharedLoader($shared_loader); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @param LoaderInterface|null $new_loader |
|
59 | + * @return CoreLoader|LoaderInterface |
|
60 | + * @throws InvalidArgumentException |
|
61 | + */ |
|
62 | + private function setupNewLoader(LoaderInterface $new_loader = null) |
|
63 | + { |
|
64 | + // if not already generated, create a standard loader |
|
65 | + if (! $new_loader instanceof LoaderInterface) { |
|
66 | + $new_loader = new CoreLoader(EE_Registry::instance()); |
|
67 | + } |
|
68 | + return $new_loader; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @param LoaderInterface|null $shared_loader |
|
75 | + * @return CoreLoader|LoaderInterface |
|
76 | + * @throws InvalidDataTypeException |
|
77 | + * @throws InvalidInterfaceException |
|
78 | + * @throws InvalidArgumentException |
|
79 | + */ |
|
80 | + private function setupSharedLoader(LoaderInterface $shared_loader = null) |
|
81 | + { |
|
82 | + // if not already generated, create a caching loader |
|
83 | + if (! $shared_loader instanceof LoaderInterface) { |
|
84 | + $shared_loader = new CachingLoader( |
|
85 | + new CoreLoader(EE_Registry::instance()), |
|
86 | + new LooseCollection('') |
|
87 | + ); |
|
88 | + } |
|
89 | + return $shared_loader; |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * @return LoaderInterface |
|
96 | + */ |
|
97 | + public function getNewLoader() |
|
98 | + { |
|
99 | + return $this->new_loader; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @return LoaderInterface |
|
106 | + */ |
|
107 | + public function getSharedLoader() |
|
108 | + { |
|
109 | + return $this->shared_loader; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @param string $fqcn |
|
116 | + * @param array $arguments |
|
117 | + * @param bool $shared |
|
118 | + * @return mixed |
|
119 | + */ |
|
120 | + public function load($fqcn, $arguments = array(), $shared = true) |
|
121 | + { |
|
122 | + return $shared |
|
123 | + ? $this->getSharedLoader()->load($fqcn, $arguments) |
|
124 | + : $this->getNewLoader()->load($fqcn, $arguments); |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * @param string $fqcn |
|
131 | + * @param array $arguments |
|
132 | + * @return mixed |
|
133 | + */ |
|
134 | + public function getNew($fqcn, $arguments = array()) |
|
135 | + { |
|
136 | + return $this->getNewLoader()->load($fqcn, $arguments); |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @param string $fqcn |
|
143 | + * @param array $arguments |
|
144 | + * @return mixed |
|
145 | + */ |
|
146 | + public function getShared($fqcn, $arguments = array()) |
|
147 | + { |
|
148 | + return $this->getSharedLoader()->load($fqcn, $arguments); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * calls reset() on loaders if that method exists |
|
155 | + */ |
|
156 | + public function reset() |
|
157 | + { |
|
158 | + $this->new_loader->reset(); |
|
159 | + $this->shared_loader->reset(); |
|
160 | + } |
|
161 | 161 | |
162 | 162 | } |
163 | 163 | // End of file Loader.php |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | private function setupNewLoader(LoaderInterface $new_loader = null) |
63 | 63 | { |
64 | 64 | // if not already generated, create a standard loader |
65 | - if (! $new_loader instanceof LoaderInterface) { |
|
65 | + if ( ! $new_loader instanceof LoaderInterface) { |
|
66 | 66 | $new_loader = new CoreLoader(EE_Registry::instance()); |
67 | 67 | } |
68 | 68 | return $new_loader; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | private function setupSharedLoader(LoaderInterface $shared_loader = null) |
81 | 81 | { |
82 | 82 | // if not already generated, create a caching loader |
83 | - if (! $shared_loader instanceof LoaderInterface) { |
|
83 | + if ( ! $shared_loader instanceof LoaderInterface) { |
|
84 | 84 | $shared_loader = new CachingLoader( |
85 | 85 | new CoreLoader(EE_Registry::instance()), |
86 | 86 | new LooseCollection('') |
@@ -22,114 +22,114 @@ |
||
22 | 22 | class CachingLoader extends LoaderDecorator |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var CollectionInterface $cache |
|
27 | - */ |
|
28 | - protected $cache; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string $identifier |
|
32 | - */ |
|
33 | - protected $identifier; |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * CachingLoader constructor. |
|
39 | - * |
|
40 | - * @param LoaderInterface $loader |
|
41 | - * @param CollectionInterface $cache |
|
42 | - * @param string $identifier |
|
43 | - * @throws InvalidDataTypeException |
|
44 | - */ |
|
45 | - public function __construct(LoaderInterface $loader, CollectionInterface $cache, $identifier = '') |
|
46 | - { |
|
47 | - parent::__construct($loader); |
|
48 | - $this->cache = $cache; |
|
49 | - $this->identifier = $this->setIdentifier($identifier); |
|
50 | - if ($this->identifier !== '') { |
|
51 | - // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
52 | - // do_action('AHEE__EventEspresso\core\services\loaders\CachingLoader__resetCache__IDENTIFIER'); |
|
53 | - // where "IDENTIFIER" = the string that was set during construction |
|
54 | - add_action( |
|
55 | - "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
56 | - array($this, 'reset') |
|
57 | - ); |
|
58 | - } |
|
59 | - // to clear ALL caches, simply do the following: |
|
60 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
61 | - add_action( |
|
62 | - 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
63 | - array($this, 'reset') |
|
64 | - ); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function identifier() |
|
73 | - { |
|
74 | - return $this->identifier; |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @param string $identifier |
|
81 | - * @throws InvalidDataTypeException |
|
82 | - */ |
|
83 | - private function setIdentifier($identifier) |
|
84 | - { |
|
85 | - if ( ! is_string($identifier)) { |
|
86 | - throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
87 | - } |
|
88 | - $this->identifier = $identifier; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * @param string $fqcn |
|
95 | - * @param array $arguments |
|
96 | - * @return mixed |
|
97 | - * @throws InvalidEntityException |
|
98 | - * @throws ServiceNotFoundException |
|
99 | - */ |
|
100 | - public function load($fqcn, $arguments = array()) |
|
101 | - { |
|
102 | - $fqcn = ltrim($fqcn, '\\'); |
|
103 | - // caching can be turned off via the following code: |
|
104 | - // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
105 | - if( |
|
106 | - apply_filters( |
|
107 | - 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
108 | - false, |
|
109 | - $this |
|
110 | - ) |
|
111 | - ){ |
|
112 | - return $this->loader->load($fqcn, $arguments); |
|
113 | - } |
|
114 | - $identifier = md5($fqcn . serialize($arguments)); |
|
115 | - if($this->cache->has($identifier)){ |
|
116 | - return $this->cache->get($identifier); |
|
117 | - } |
|
118 | - $object = $this->loader->load($fqcn, $arguments); |
|
119 | - $this->cache->add($object, $identifier); |
|
120 | - return $object; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * empties cache and calls reset() on loader if method exists |
|
127 | - */ |
|
128 | - public function reset() |
|
129 | - { |
|
130 | - $this->cache->detachAll(); |
|
131 | - $this->loader->reset(); |
|
132 | - } |
|
25 | + /** |
|
26 | + * @var CollectionInterface $cache |
|
27 | + */ |
|
28 | + protected $cache; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string $identifier |
|
32 | + */ |
|
33 | + protected $identifier; |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * CachingLoader constructor. |
|
39 | + * |
|
40 | + * @param LoaderInterface $loader |
|
41 | + * @param CollectionInterface $cache |
|
42 | + * @param string $identifier |
|
43 | + * @throws InvalidDataTypeException |
|
44 | + */ |
|
45 | + public function __construct(LoaderInterface $loader, CollectionInterface $cache, $identifier = '') |
|
46 | + { |
|
47 | + parent::__construct($loader); |
|
48 | + $this->cache = $cache; |
|
49 | + $this->identifier = $this->setIdentifier($identifier); |
|
50 | + if ($this->identifier !== '') { |
|
51 | + // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
52 | + // do_action('AHEE__EventEspresso\core\services\loaders\CachingLoader__resetCache__IDENTIFIER'); |
|
53 | + // where "IDENTIFIER" = the string that was set during construction |
|
54 | + add_action( |
|
55 | + "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
56 | + array($this, 'reset') |
|
57 | + ); |
|
58 | + } |
|
59 | + // to clear ALL caches, simply do the following: |
|
60 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
61 | + add_action( |
|
62 | + 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
63 | + array($this, 'reset') |
|
64 | + ); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function identifier() |
|
73 | + { |
|
74 | + return $this->identifier; |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @param string $identifier |
|
81 | + * @throws InvalidDataTypeException |
|
82 | + */ |
|
83 | + private function setIdentifier($identifier) |
|
84 | + { |
|
85 | + if ( ! is_string($identifier)) { |
|
86 | + throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
87 | + } |
|
88 | + $this->identifier = $identifier; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * @param string $fqcn |
|
95 | + * @param array $arguments |
|
96 | + * @return mixed |
|
97 | + * @throws InvalidEntityException |
|
98 | + * @throws ServiceNotFoundException |
|
99 | + */ |
|
100 | + public function load($fqcn, $arguments = array()) |
|
101 | + { |
|
102 | + $fqcn = ltrim($fqcn, '\\'); |
|
103 | + // caching can be turned off via the following code: |
|
104 | + // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
105 | + if( |
|
106 | + apply_filters( |
|
107 | + 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
108 | + false, |
|
109 | + $this |
|
110 | + ) |
|
111 | + ){ |
|
112 | + return $this->loader->load($fqcn, $arguments); |
|
113 | + } |
|
114 | + $identifier = md5($fqcn . serialize($arguments)); |
|
115 | + if($this->cache->has($identifier)){ |
|
116 | + return $this->cache->get($identifier); |
|
117 | + } |
|
118 | + $object = $this->loader->load($fqcn, $arguments); |
|
119 | + $this->cache->add($object, $identifier); |
|
120 | + return $object; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * empties cache and calls reset() on loader if method exists |
|
127 | + */ |
|
128 | + public function reset() |
|
129 | + { |
|
130 | + $this->cache->detachAll(); |
|
131 | + $this->loader->reset(); |
|
132 | + } |
|
133 | 133 | |
134 | 134 | |
135 | 135 | } |
@@ -102,17 +102,17 @@ |
||
102 | 102 | $fqcn = ltrim($fqcn, '\\'); |
103 | 103 | // caching can be turned off via the following code: |
104 | 104 | // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
105 | - if( |
|
105 | + if ( |
|
106 | 106 | apply_filters( |
107 | 107 | 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
108 | 108 | false, |
109 | 109 | $this |
110 | 110 | ) |
111 | - ){ |
|
111 | + ) { |
|
112 | 112 | return $this->loader->load($fqcn, $arguments); |
113 | 113 | } |
114 | - $identifier = md5($fqcn . serialize($arguments)); |
|
115 | - if($this->cache->has($identifier)){ |
|
114 | + $identifier = md5($fqcn.serialize($arguments)); |
|
115 | + if ($this->cache->has($identifier)) { |
|
116 | 116 | return $this->cache->get($identifier); |
117 | 117 | } |
118 | 118 | $object = $this->loader->load($fqcn, $arguments); |
@@ -9,19 +9,19 @@ |
||
9 | 9 | interface LoaderInterface |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * @param string $fqcn |
|
14 | - * @param array $arguments |
|
15 | - * @return mixed |
|
16 | - */ |
|
17 | - public function load($fqcn, $arguments = array()); |
|
12 | + /** |
|
13 | + * @param string $fqcn |
|
14 | + * @param array $arguments |
|
15 | + * @return mixed |
|
16 | + */ |
|
17 | + public function load($fqcn, $arguments = array()); |
|
18 | 18 | |
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * calls reset() on loader if method exists |
|
23 | - */ |
|
24 | - public function reset(); |
|
21 | + /** |
|
22 | + * calls reset() on loader if method exists |
|
23 | + */ |
|
24 | + public function reset(); |
|
25 | 25 | |
26 | 26 | } |
27 | 27 | // End of file LoaderInterface.php |