@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $identifier = '' |
54 | 54 | ) { |
55 | 55 | parent::__construct($loader); |
56 | - $this->cache = $cache; |
|
56 | + $this->cache = $cache; |
|
57 | 57 | $this->object_identifier = $object_identifier; |
58 | 58 | $this->setIdentifier($identifier); |
59 | 59 | if ($this->identifier !== '') { |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | private function setIdentifier($identifier) |
91 | 91 | { |
92 | - if (! is_string($identifier)) { |
|
92 | + if ( ! is_string($identifier)) { |
|
93 | 93 | throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
94 | 94 | } |
95 | 95 | $this->identifier = $identifier; |
@@ -17,186 +17,186 @@ |
||
17 | 17 | class CachingLoader extends CachingLoaderDecorator |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var bool |
|
22 | - */ |
|
23 | - protected $bypass; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var CollectionInterface |
|
27 | - */ |
|
28 | - protected $cache; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - protected $identifier; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var ObjectIdentifier |
|
37 | - */ |
|
38 | - private $object_identifier; |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * CachingLoader constructor. |
|
43 | - * |
|
44 | - * @param LoaderDecoratorInterface $loader |
|
45 | - * @param CollectionInterface $cache |
|
46 | - * @param ObjectIdentifier $object_identifier |
|
47 | - * @param string $identifier |
|
48 | - * @throws InvalidDataTypeException |
|
49 | - */ |
|
50 | - public function __construct( |
|
51 | - LoaderDecoratorInterface $loader, |
|
52 | - CollectionInterface $cache, |
|
53 | - ObjectIdentifier $object_identifier, |
|
54 | - $identifier = '' |
|
55 | - ) { |
|
56 | - parent::__construct($loader); |
|
57 | - $this->cache = $cache; |
|
58 | - $this->object_identifier = $object_identifier; |
|
59 | - $this->setIdentifier($identifier); |
|
60 | - if ($this->identifier !== '') { |
|
61 | - // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
62 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
63 | - // where "IDENTIFIER" = the string that was set during construction |
|
64 | - add_action( |
|
65 | - "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
66 | - array($this, 'reset') |
|
67 | - ); |
|
68 | - } |
|
69 | - // to clear ALL caches, simply do the following: |
|
70 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
71 | - add_action( |
|
72 | - 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
73 | - array($this, 'reset') |
|
74 | - ); |
|
75 | - // caching can be turned off via the following code: |
|
76 | - // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
77 | - $this->bypass = filter_var( |
|
78 | - apply_filters( |
|
79 | - 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
80 | - false, |
|
81 | - $this |
|
82 | - ), |
|
83 | - FILTER_VALIDATE_BOOLEAN |
|
84 | - ); |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function identifier() |
|
92 | - { |
|
93 | - return $this->identifier; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @param string $identifier |
|
99 | - * @throws InvalidDataTypeException |
|
100 | - */ |
|
101 | - private function setIdentifier($identifier) |
|
102 | - { |
|
103 | - if (! is_string($identifier)) { |
|
104 | - throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
105 | - } |
|
106 | - $this->identifier = $identifier; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @param FullyQualifiedName|string $fqcn |
|
112 | - * @param mixed $object |
|
113 | - * @param array $arguments |
|
114 | - * @return bool |
|
115 | - * @throws InvalidArgumentException |
|
116 | - */ |
|
117 | - public function share($fqcn, $object, array $arguments = array()) |
|
118 | - { |
|
119 | - if ($object instanceof $fqcn) { |
|
120 | - return $this->cache->add( |
|
121 | - $object, |
|
122 | - $this->object_identifier->getIdentifier($fqcn, $arguments) |
|
123 | - ); |
|
124 | - } |
|
125 | - throw new InvalidArgumentException( |
|
126 | - sprintf( |
|
127 | - esc_html__( |
|
128 | - 'The supplied class name "%1$s" must match the class of the supplied object.', |
|
129 | - 'event_espresso' |
|
130 | - ), |
|
131 | - $fqcn |
|
132 | - ) |
|
133 | - ); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @param FullyQualifiedName|string $fqcn |
|
139 | - * @param array $arguments |
|
140 | - * @param bool $shared |
|
141 | - * @param array $interfaces |
|
142 | - * @return mixed |
|
143 | - */ |
|
144 | - public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array()) |
|
145 | - { |
|
146 | - $fqcn = ltrim($fqcn, '\\'); |
|
147 | - // caching can be turned off via the following code: |
|
148 | - // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
149 | - if ($this->bypass) { |
|
150 | - // even though $shared might be true, caching could be bypassed for whatever reason, |
|
151 | - // so we don't want the core loader to cache anything, therefore caching is turned off |
|
152 | - return $this->loader->load($fqcn, $arguments, false); |
|
153 | - } |
|
154 | - $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments); |
|
155 | - if ($this->cache->has($object_identifier)) { |
|
156 | - return $this->cache->get($object_identifier); |
|
157 | - } |
|
158 | - $object = $this->loader->load($fqcn, $arguments, $shared); |
|
159 | - if ($object instanceof $fqcn) { |
|
160 | - $this->cache->add($object, $object_identifier); |
|
161 | - } |
|
162 | - return $object; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * empties cache and calls reset() on loader if method exists |
|
168 | - */ |
|
169 | - public function reset() |
|
170 | - { |
|
171 | - $this->clearCache(); |
|
172 | - $this->loader->reset(); |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * unsets and detaches ALL objects from the cache |
|
178 | - * |
|
179 | - * @since 4.9.62.p |
|
180 | - */ |
|
181 | - public function clearCache() |
|
182 | - { |
|
183 | - $this->cache->trashAndDetachAll(); |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * @param string $fqcn |
|
189 | - * @param array $arguments |
|
190 | - * @return bool |
|
191 | - * @throws InvalidArgumentException |
|
192 | - */ |
|
193 | - public function remove($fqcn, array $arguments = []) |
|
194 | - { |
|
195 | - $fqcn = ltrim($fqcn, '\\'); |
|
196 | - $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments); |
|
197 | - $object = $this->cache->has($object_identifier) |
|
198 | - ? $this->cache->get($object_identifier) |
|
199 | - : $this->loader->load($fqcn, $arguments); |
|
200 | - return $this->cache->remove($object); |
|
201 | - } |
|
20 | + /** |
|
21 | + * @var bool |
|
22 | + */ |
|
23 | + protected $bypass; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var CollectionInterface |
|
27 | + */ |
|
28 | + protected $cache; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + protected $identifier; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var ObjectIdentifier |
|
37 | + */ |
|
38 | + private $object_identifier; |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * CachingLoader constructor. |
|
43 | + * |
|
44 | + * @param LoaderDecoratorInterface $loader |
|
45 | + * @param CollectionInterface $cache |
|
46 | + * @param ObjectIdentifier $object_identifier |
|
47 | + * @param string $identifier |
|
48 | + * @throws InvalidDataTypeException |
|
49 | + */ |
|
50 | + public function __construct( |
|
51 | + LoaderDecoratorInterface $loader, |
|
52 | + CollectionInterface $cache, |
|
53 | + ObjectIdentifier $object_identifier, |
|
54 | + $identifier = '' |
|
55 | + ) { |
|
56 | + parent::__construct($loader); |
|
57 | + $this->cache = $cache; |
|
58 | + $this->object_identifier = $object_identifier; |
|
59 | + $this->setIdentifier($identifier); |
|
60 | + if ($this->identifier !== '') { |
|
61 | + // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
62 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
63 | + // where "IDENTIFIER" = the string that was set during construction |
|
64 | + add_action( |
|
65 | + "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
66 | + array($this, 'reset') |
|
67 | + ); |
|
68 | + } |
|
69 | + // to clear ALL caches, simply do the following: |
|
70 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
71 | + add_action( |
|
72 | + 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
73 | + array($this, 'reset') |
|
74 | + ); |
|
75 | + // caching can be turned off via the following code: |
|
76 | + // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
77 | + $this->bypass = filter_var( |
|
78 | + apply_filters( |
|
79 | + 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
80 | + false, |
|
81 | + $this |
|
82 | + ), |
|
83 | + FILTER_VALIDATE_BOOLEAN |
|
84 | + ); |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function identifier() |
|
92 | + { |
|
93 | + return $this->identifier; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @param string $identifier |
|
99 | + * @throws InvalidDataTypeException |
|
100 | + */ |
|
101 | + private function setIdentifier($identifier) |
|
102 | + { |
|
103 | + if (! is_string($identifier)) { |
|
104 | + throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
105 | + } |
|
106 | + $this->identifier = $identifier; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @param FullyQualifiedName|string $fqcn |
|
112 | + * @param mixed $object |
|
113 | + * @param array $arguments |
|
114 | + * @return bool |
|
115 | + * @throws InvalidArgumentException |
|
116 | + */ |
|
117 | + public function share($fqcn, $object, array $arguments = array()) |
|
118 | + { |
|
119 | + if ($object instanceof $fqcn) { |
|
120 | + return $this->cache->add( |
|
121 | + $object, |
|
122 | + $this->object_identifier->getIdentifier($fqcn, $arguments) |
|
123 | + ); |
|
124 | + } |
|
125 | + throw new InvalidArgumentException( |
|
126 | + sprintf( |
|
127 | + esc_html__( |
|
128 | + 'The supplied class name "%1$s" must match the class of the supplied object.', |
|
129 | + 'event_espresso' |
|
130 | + ), |
|
131 | + $fqcn |
|
132 | + ) |
|
133 | + ); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @param FullyQualifiedName|string $fqcn |
|
139 | + * @param array $arguments |
|
140 | + * @param bool $shared |
|
141 | + * @param array $interfaces |
|
142 | + * @return mixed |
|
143 | + */ |
|
144 | + public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array()) |
|
145 | + { |
|
146 | + $fqcn = ltrim($fqcn, '\\'); |
|
147 | + // caching can be turned off via the following code: |
|
148 | + // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
149 | + if ($this->bypass) { |
|
150 | + // even though $shared might be true, caching could be bypassed for whatever reason, |
|
151 | + // so we don't want the core loader to cache anything, therefore caching is turned off |
|
152 | + return $this->loader->load($fqcn, $arguments, false); |
|
153 | + } |
|
154 | + $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments); |
|
155 | + if ($this->cache->has($object_identifier)) { |
|
156 | + return $this->cache->get($object_identifier); |
|
157 | + } |
|
158 | + $object = $this->loader->load($fqcn, $arguments, $shared); |
|
159 | + if ($object instanceof $fqcn) { |
|
160 | + $this->cache->add($object, $object_identifier); |
|
161 | + } |
|
162 | + return $object; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * empties cache and calls reset() on loader if method exists |
|
168 | + */ |
|
169 | + public function reset() |
|
170 | + { |
|
171 | + $this->clearCache(); |
|
172 | + $this->loader->reset(); |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * unsets and detaches ALL objects from the cache |
|
178 | + * |
|
179 | + * @since 4.9.62.p |
|
180 | + */ |
|
181 | + public function clearCache() |
|
182 | + { |
|
183 | + $this->cache->trashAndDetachAll(); |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * @param string $fqcn |
|
189 | + * @param array $arguments |
|
190 | + * @return bool |
|
191 | + * @throws InvalidArgumentException |
|
192 | + */ |
|
193 | + public function remove($fqcn, array $arguments = []) |
|
194 | + { |
|
195 | + $fqcn = ltrim($fqcn, '\\'); |
|
196 | + $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments); |
|
197 | + $object = $this->cache->has($object_identifier) |
|
198 | + ? $this->cache->get($object_identifier) |
|
199 | + : $this->loader->load($fqcn, $arguments); |
|
200 | + return $this->cache->remove($object); |
|
201 | + } |
|
202 | 202 | } |
@@ -80,47 +80,47 @@ |
||
80 | 80 | class LoaderFactory |
81 | 81 | { |
82 | 82 | |
83 | - /** |
|
84 | - * @var LoaderInterface $loader ; |
|
85 | - */ |
|
86 | - private static $loader; |
|
83 | + /** |
|
84 | + * @var LoaderInterface $loader ; |
|
85 | + */ |
|
86 | + private static $loader; |
|
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * @param EE_Registry|CoffeeShop $generator provided during very first instantiation in |
|
91 | - * BootstrapDependencyInjectionContainer::buildLoader() |
|
92 | - * otherwise can be left null |
|
93 | - * @param ClassInterfaceCache|null $class_cache also provided during first instantiation |
|
94 | - * @param ObjectIdentifier|null $object_identifier |
|
95 | - * @return LoaderInterface |
|
96 | - * @throws InvalidArgumentException |
|
97 | - * @throws InvalidDataTypeException |
|
98 | - * @throws InvalidInterfaceException |
|
99 | - */ |
|
100 | - public static function getLoader( |
|
101 | - $generator = null, |
|
102 | - ClassInterfaceCache $class_cache = null, |
|
103 | - ObjectIdentifier $object_identifier = null |
|
104 | - ) { |
|
105 | - if ( |
|
106 | - ! LoaderFactory::$loader instanceof LoaderInterface |
|
107 | - && ($generator instanceof EE_Registry || $generator instanceof CoffeeShop) |
|
108 | - && $class_cache instanceof ClassInterfaceCache |
|
109 | - && $object_identifier instanceof ObjectIdentifier |
|
110 | - ) { |
|
111 | - $core_loader = new CoreLoader($generator); |
|
112 | - LoaderFactory::$loader = new Loader( |
|
113 | - $core_loader, |
|
114 | - new CachingLoader( |
|
115 | - $core_loader, |
|
116 | - new LooseCollection(''), |
|
117 | - $object_identifier |
|
118 | - ), |
|
119 | - $class_cache |
|
120 | - ); |
|
121 | - } |
|
122 | - return LoaderFactory::$loader; |
|
123 | - } |
|
89 | + /** |
|
90 | + * @param EE_Registry|CoffeeShop $generator provided during very first instantiation in |
|
91 | + * BootstrapDependencyInjectionContainer::buildLoader() |
|
92 | + * otherwise can be left null |
|
93 | + * @param ClassInterfaceCache|null $class_cache also provided during first instantiation |
|
94 | + * @param ObjectIdentifier|null $object_identifier |
|
95 | + * @return LoaderInterface |
|
96 | + * @throws InvalidArgumentException |
|
97 | + * @throws InvalidDataTypeException |
|
98 | + * @throws InvalidInterfaceException |
|
99 | + */ |
|
100 | + public static function getLoader( |
|
101 | + $generator = null, |
|
102 | + ClassInterfaceCache $class_cache = null, |
|
103 | + ObjectIdentifier $object_identifier = null |
|
104 | + ) { |
|
105 | + if ( |
|
106 | + ! LoaderFactory::$loader instanceof LoaderInterface |
|
107 | + && ($generator instanceof EE_Registry || $generator instanceof CoffeeShop) |
|
108 | + && $class_cache instanceof ClassInterfaceCache |
|
109 | + && $object_identifier instanceof ObjectIdentifier |
|
110 | + ) { |
|
111 | + $core_loader = new CoreLoader($generator); |
|
112 | + LoaderFactory::$loader = new Loader( |
|
113 | + $core_loader, |
|
114 | + new CachingLoader( |
|
115 | + $core_loader, |
|
116 | + new LooseCollection(''), |
|
117 | + $object_identifier |
|
118 | + ), |
|
119 | + $class_cache |
|
120 | + ); |
|
121 | + } |
|
122 | + return LoaderFactory::$loader; |
|
123 | + } |
|
124 | 124 | |
125 | 125 | |
126 | 126 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | public function fqcnMatchesObjectIdentifier($fqcn, $object_identifier) |
74 | 74 | { |
75 | 75 | return $fqcn === $object_identifier |
76 | - || strpos($object_identifier, $fqcn . ObjectIdentifier::DELIMITER) === 0; |
|
76 | + || strpos($object_identifier, $fqcn.ObjectIdentifier::DELIMITER) === 0; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | ) |
94 | 94 | ? $this->getIdentifierForArguments($arguments) |
95 | 95 | : ''; |
96 | - if (! empty($identifier)) { |
|
97 | - $fqcn .= ObjectIdentifier::DELIMITER . md5($identifier); |
|
96 | + if ( ! empty($identifier)) { |
|
97 | + $fqcn .= ObjectIdentifier::DELIMITER.md5($identifier); |
|
98 | 98 | } |
99 | 99 | return $fqcn; |
100 | 100 | } |
@@ -16,117 +16,117 @@ |
||
16 | 16 | class ObjectIdentifier |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * used to separate the FQCN from the class's arguments identifier |
|
21 | - */ |
|
22 | - const DELIMITER = '____'; |
|
19 | + /** |
|
20 | + * used to separate the FQCN from the class's arguments identifier |
|
21 | + */ |
|
22 | + const DELIMITER = '____'; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @var ClassInterfaceCache $class_cache |
|
26 | - */ |
|
27 | - private $class_cache; |
|
24 | + /** |
|
25 | + * @var ClassInterfaceCache $class_cache |
|
26 | + */ |
|
27 | + private $class_cache; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * ObjectIdentifier constructor. |
|
32 | - * |
|
33 | - * @param ClassInterfaceCache $class_cache |
|
34 | - */ |
|
35 | - public function __construct(ClassInterfaceCache $class_cache) |
|
36 | - { |
|
37 | - $this->class_cache = $class_cache; |
|
38 | - } |
|
30 | + /** |
|
31 | + * ObjectIdentifier constructor. |
|
32 | + * |
|
33 | + * @param ClassInterfaceCache $class_cache |
|
34 | + */ |
|
35 | + public function __construct(ClassInterfaceCache $class_cache) |
|
36 | + { |
|
37 | + $this->class_cache = $class_cache; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * Returns true if the supplied $object_identifier contains |
|
43 | - * the delimiter used to separate an fqcn from the arguments hash |
|
44 | - * |
|
45 | - * @param string $object_identifier |
|
46 | - * @return bool |
|
47 | - */ |
|
48 | - public function hasArguments($object_identifier) |
|
49 | - { |
|
50 | - // type casting to bool instead of using strpos() !== false |
|
51 | - // because an object identifier should never begin with the delimiter |
|
52 | - // therefore the delimiter should NOT be found at position 0 |
|
53 | - return (bool) strpos($object_identifier, ObjectIdentifier::DELIMITER); |
|
54 | - } |
|
41 | + /** |
|
42 | + * Returns true if the supplied $object_identifier contains |
|
43 | + * the delimiter used to separate an fqcn from the arguments hash |
|
44 | + * |
|
45 | + * @param string $object_identifier |
|
46 | + * @return bool |
|
47 | + */ |
|
48 | + public function hasArguments($object_identifier) |
|
49 | + { |
|
50 | + // type casting to bool instead of using strpos() !== false |
|
51 | + // because an object identifier should never begin with the delimiter |
|
52 | + // therefore the delimiter should NOT be found at position 0 |
|
53 | + return (bool) strpos($object_identifier, ObjectIdentifier::DELIMITER); |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * Returns true if the supplied FQCN equals the supplied $object_identifier |
|
59 | - * OR the supplied FQCN matches the FQCN portion of the supplied $object_identifier |
|
60 | - * AND that $object_identifier is for an object with arguments. |
|
61 | - * This allows a request for an object using a FQCN to match |
|
62 | - * a previously instantiated object with arguments |
|
63 | - * without having to know those arguments. |
|
64 | - * |
|
65 | - * @param string $fqcn |
|
66 | - * @param string $object_identifier |
|
67 | - * @return bool |
|
68 | - */ |
|
69 | - public function fqcnMatchesObjectIdentifier($fqcn, $object_identifier) |
|
70 | - { |
|
71 | - return $fqcn === $object_identifier |
|
72 | - || strpos($object_identifier, $fqcn . ObjectIdentifier::DELIMITER) === 0; |
|
73 | - } |
|
57 | + /** |
|
58 | + * Returns true if the supplied FQCN equals the supplied $object_identifier |
|
59 | + * OR the supplied FQCN matches the FQCN portion of the supplied $object_identifier |
|
60 | + * AND that $object_identifier is for an object with arguments. |
|
61 | + * This allows a request for an object using a FQCN to match |
|
62 | + * a previously instantiated object with arguments |
|
63 | + * without having to know those arguments. |
|
64 | + * |
|
65 | + * @param string $fqcn |
|
66 | + * @param string $object_identifier |
|
67 | + * @return bool |
|
68 | + */ |
|
69 | + public function fqcnMatchesObjectIdentifier($fqcn, $object_identifier) |
|
70 | + { |
|
71 | + return $fqcn === $object_identifier |
|
72 | + || strpos($object_identifier, $fqcn . ObjectIdentifier::DELIMITER) === 0; |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * build a string representation of an object's FQCN and arguments |
|
78 | - * |
|
79 | - * @param string $fqcn |
|
80 | - * @param array $arguments |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function getIdentifier($fqcn, array $arguments = array()) |
|
84 | - { |
|
85 | - // only build identifier from arguments if class is not ReservedInstanceInterface |
|
86 | - $identifier = ! $this->class_cache->hasInterface( |
|
87 | - $fqcn, |
|
88 | - 'EventEspresso\core\interfaces\ReservedInstanceInterface' |
|
89 | - ) |
|
90 | - ? $this->getIdentifierForArguments($arguments) |
|
91 | - : ''; |
|
92 | - if (! empty($identifier)) { |
|
93 | - $fqcn .= ObjectIdentifier::DELIMITER . md5($identifier); |
|
94 | - } |
|
95 | - return $fqcn; |
|
96 | - } |
|
76 | + /** |
|
77 | + * build a string representation of an object's FQCN and arguments |
|
78 | + * |
|
79 | + * @param string $fqcn |
|
80 | + * @param array $arguments |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function getIdentifier($fqcn, array $arguments = array()) |
|
84 | + { |
|
85 | + // only build identifier from arguments if class is not ReservedInstanceInterface |
|
86 | + $identifier = ! $this->class_cache->hasInterface( |
|
87 | + $fqcn, |
|
88 | + 'EventEspresso\core\interfaces\ReservedInstanceInterface' |
|
89 | + ) |
|
90 | + ? $this->getIdentifierForArguments($arguments) |
|
91 | + : ''; |
|
92 | + if (! empty($identifier)) { |
|
93 | + $fqcn .= ObjectIdentifier::DELIMITER . md5($identifier); |
|
94 | + } |
|
95 | + return $fqcn; |
|
96 | + } |
|
97 | 97 | |
98 | 98 | |
99 | - /** |
|
100 | - * build a string representation of a object's arguments |
|
101 | - * (mostly because Closures can't be serialized) |
|
102 | - * |
|
103 | - * @param array $arguments |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - protected function getIdentifierForArguments(array $arguments) |
|
107 | - { |
|
108 | - if (empty($arguments)) { |
|
109 | - return ''; |
|
110 | - } |
|
111 | - $identifier = ''; |
|
112 | - foreach ($arguments as $key => $argument) { |
|
113 | - // don't include arguments used to assist with loading legacy classes |
|
114 | - if (is_string($key) && strpos($key, 'EE_Registry::create') === 0) { |
|
115 | - continue; |
|
116 | - } |
|
117 | - switch (true) { |
|
118 | - case is_object($argument): |
|
119 | - case $argument instanceof Closure: |
|
120 | - $identifier .= spl_object_hash($argument); |
|
121 | - break; |
|
122 | - case is_array($argument): |
|
123 | - $identifier .= $this->getIdentifierForArguments($argument); |
|
124 | - break; |
|
125 | - default: |
|
126 | - $identifier .= $argument; |
|
127 | - break; |
|
128 | - } |
|
129 | - } |
|
130 | - return $identifier; |
|
131 | - } |
|
99 | + /** |
|
100 | + * build a string representation of a object's arguments |
|
101 | + * (mostly because Closures can't be serialized) |
|
102 | + * |
|
103 | + * @param array $arguments |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + protected function getIdentifierForArguments(array $arguments) |
|
107 | + { |
|
108 | + if (empty($arguments)) { |
|
109 | + return ''; |
|
110 | + } |
|
111 | + $identifier = ''; |
|
112 | + foreach ($arguments as $key => $argument) { |
|
113 | + // don't include arguments used to assist with loading legacy classes |
|
114 | + if (is_string($key) && strpos($key, 'EE_Registry::create') === 0) { |
|
115 | + continue; |
|
116 | + } |
|
117 | + switch (true) { |
|
118 | + case is_object($argument): |
|
119 | + case $argument instanceof Closure: |
|
120 | + $identifier .= spl_object_hash($argument); |
|
121 | + break; |
|
122 | + case is_array($argument): |
|
123 | + $identifier .= $this->getIdentifierForArguments($argument); |
|
124 | + break; |
|
125 | + default: |
|
126 | + $identifier .= $argument; |
|
127 | + break; |
|
128 | + } |
|
129 | + } |
|
130 | + return $identifier; |
|
131 | + } |
|
132 | 132 | } |
@@ -16,55 +16,55 @@ |
||
16 | 16 | interface DomainInterface extends InterminableInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @return string |
|
21 | - * @throws DomainException |
|
22 | - */ |
|
23 | - public function pluginFile(); |
|
19 | + /** |
|
20 | + * @return string |
|
21 | + * @throws DomainException |
|
22 | + */ |
|
23 | + public function pluginFile(); |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * @return string |
|
28 | - * @throws DomainException |
|
29 | - */ |
|
30 | - public function pluginBasename(); |
|
26 | + /** |
|
27 | + * @return string |
|
28 | + * @throws DomainException |
|
29 | + */ |
|
30 | + public function pluginBasename(); |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * @return string |
|
35 | - */ |
|
36 | - public function pluginPath(); |
|
33 | + /** |
|
34 | + * @return string |
|
35 | + */ |
|
36 | + public function pluginPath(); |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * @return string |
|
41 | - * @throws DomainException |
|
42 | - */ |
|
43 | - public function pluginUrl(); |
|
39 | + /** |
|
40 | + * @return string |
|
41 | + * @throws DomainException |
|
42 | + */ |
|
43 | + public function pluginUrl(); |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * @return string |
|
48 | - * @throws DomainException |
|
49 | - */ |
|
50 | - public function version(); |
|
46 | + /** |
|
47 | + * @return string |
|
48 | + * @throws DomainException |
|
49 | + */ |
|
50 | + public function version(); |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - public function distributionAssetsPath(); |
|
53 | + /** |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + public function distributionAssetsPath(); |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public function distributionAssetsUrl(); |
|
59 | + /** |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public function distributionAssetsUrl(); |
|
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function assetNamespace(); |
|
65 | + /** |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function assetNamespace(); |
|
69 | 69 | |
70 | 70 | } |
@@ -20,55 +20,55 @@ |
||
20 | 20 | class BlockCollection extends Collection |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * Collection constructor |
|
25 | - * |
|
26 | - * @throws InvalidInterfaceException |
|
27 | - */ |
|
28 | - public function __construct() |
|
29 | - { |
|
30 | - parent::__construct('EventEspresso\core\domain\entities\editor\BlockInterface'); |
|
31 | - } |
|
23 | + /** |
|
24 | + * Collection constructor |
|
25 | + * |
|
26 | + * @throws InvalidInterfaceException |
|
27 | + */ |
|
28 | + public function __construct() |
|
29 | + { |
|
30 | + parent::__construct('EventEspresso\core\domain\entities\editor\BlockInterface'); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * unRegisterBlock |
|
36 | - * finds block in the Collection based on the identifier that was set using addObject() |
|
37 | - * and calls unRegisterBlock() on it. Returns block if successful and false if block was not found. |
|
38 | - * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards |
|
39 | - * |
|
40 | - * @param mixed $identifier |
|
41 | - * @return boolean |
|
42 | - */ |
|
43 | - public function unRegisterBlock($identifier) |
|
44 | - { |
|
45 | - $this->rewind(); |
|
46 | - while ($this->valid()) { |
|
47 | - if ($identifier === $this->getInfo()) { |
|
48 | - $object = $this->current(); |
|
49 | - $this->rewind(); |
|
50 | - return $object->unRegisterBlock(); |
|
51 | - } |
|
52 | - $this->next(); |
|
53 | - } |
|
54 | - return false; |
|
55 | - } |
|
34 | + /** |
|
35 | + * unRegisterBlock |
|
36 | + * finds block in the Collection based on the identifier that was set using addObject() |
|
37 | + * and calls unRegisterBlock() on it. Returns block if successful and false if block was not found. |
|
38 | + * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards |
|
39 | + * |
|
40 | + * @param mixed $identifier |
|
41 | + * @return boolean |
|
42 | + */ |
|
43 | + public function unRegisterBlock($identifier) |
|
44 | + { |
|
45 | + $this->rewind(); |
|
46 | + while ($this->valid()) { |
|
47 | + if ($identifier === $this->getInfo()) { |
|
48 | + $object = $this->current(); |
|
49 | + $this->rewind(); |
|
50 | + return $object->unRegisterBlock(); |
|
51 | + } |
|
52 | + $this->next(); |
|
53 | + } |
|
54 | + return false; |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * unRegisterAllBlocks |
|
60 | - * calls unRegisterBlock() on all blocks in Collection. |
|
61 | - * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards |
|
62 | - * |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - public function unRegisterAllBlocks() |
|
66 | - { |
|
67 | - $this->rewind(); |
|
68 | - while ($this->valid()) { |
|
69 | - $this->current()->unRegisterBlock(); |
|
70 | - $this->next(); |
|
71 | - } |
|
72 | - $this->rewind(); |
|
73 | - } |
|
58 | + /** |
|
59 | + * unRegisterAllBlocks |
|
60 | + * calls unRegisterBlock() on all blocks in Collection. |
|
61 | + * PLZ NOTE: the pointer is reset to the beginning of the collection afterwards |
|
62 | + * |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + public function unRegisterAllBlocks() |
|
66 | + { |
|
67 | + $this->rewind(); |
|
68 | + while ($this->valid()) { |
|
69 | + $this->current()->unRegisterBlock(); |
|
70 | + $this->next(); |
|
71 | + } |
|
72 | + $this->rewind(); |
|
73 | + } |
|
74 | 74 | } |
@@ -61,7 +61,7 @@ |
||
61 | 61 | { |
62 | 62 | $custom_post_types = $this->custom_post_types->getDefinitions(); |
63 | 63 | foreach ($custom_post_types as $custom_post_type => $CPT) { |
64 | - $this->wp_post_types[ $custom_post_type ] = $this->registerCustomPostType( |
|
64 | + $this->wp_post_types[$custom_post_type] = $this->registerCustomPostType( |
|
65 | 65 | $custom_post_type, |
66 | 66 | $CPT['singular_name'], |
67 | 67 | $CPT['plural_name'], |
@@ -18,314 +18,314 @@ |
||
18 | 18 | class RegisterCustomPostTypes |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var CustomPostTypeDefinitions $custom_post_types |
|
23 | - */ |
|
24 | - public $custom_post_types; |
|
21 | + /** |
|
22 | + * @var CustomPostTypeDefinitions $custom_post_types |
|
23 | + */ |
|
24 | + public $custom_post_types; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var WP_Post_Type[] $wp_post_types |
|
28 | - */ |
|
29 | - public $wp_post_types = array(); |
|
26 | + /** |
|
27 | + * @var WP_Post_Type[] $wp_post_types |
|
28 | + */ |
|
29 | + public $wp_post_types = array(); |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * RegisterCustomPostTypes constructor. |
|
34 | - * |
|
35 | - * @param CustomPostTypeDefinitions $custom_post_types |
|
36 | - */ |
|
37 | - public function __construct(CustomPostTypeDefinitions $custom_post_types) |
|
38 | - { |
|
39 | - $this->custom_post_types = $custom_post_types; |
|
40 | - } |
|
32 | + /** |
|
33 | + * RegisterCustomPostTypes constructor. |
|
34 | + * |
|
35 | + * @param CustomPostTypeDefinitions $custom_post_types |
|
36 | + */ |
|
37 | + public function __construct(CustomPostTypeDefinitions $custom_post_types) |
|
38 | + { |
|
39 | + $this->custom_post_types = $custom_post_types; |
|
40 | + } |
|
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * @return WP_Post_Type[] |
|
45 | - */ |
|
46 | - public function getRegisteredCustomPostTypes() |
|
47 | - { |
|
48 | - return $this->wp_post_types; |
|
49 | - } |
|
43 | + /** |
|
44 | + * @return WP_Post_Type[] |
|
45 | + */ |
|
46 | + public function getRegisteredCustomPostTypes() |
|
47 | + { |
|
48 | + return $this->wp_post_types; |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * @return void |
|
54 | - * @throws DomainException |
|
55 | - */ |
|
56 | - public function registerCustomPostTypes() |
|
57 | - { |
|
58 | - $custom_post_types = $this->custom_post_types->getDefinitions(); |
|
59 | - foreach ($custom_post_types as $custom_post_type => $CPT) { |
|
60 | - $this->wp_post_types[ $custom_post_type ] = $this->registerCustomPostType( |
|
61 | - $custom_post_type, |
|
62 | - $CPT['singular_name'], |
|
63 | - $CPT['plural_name'], |
|
64 | - $CPT['singular_slug'], |
|
65 | - $CPT['plural_slug'], |
|
66 | - $CPT['args'] |
|
67 | - ); |
|
68 | - } |
|
69 | - } |
|
52 | + /** |
|
53 | + * @return void |
|
54 | + * @throws DomainException |
|
55 | + */ |
|
56 | + public function registerCustomPostTypes() |
|
57 | + { |
|
58 | + $custom_post_types = $this->custom_post_types->getDefinitions(); |
|
59 | + foreach ($custom_post_types as $custom_post_type => $CPT) { |
|
60 | + $this->wp_post_types[ $custom_post_type ] = $this->registerCustomPostType( |
|
61 | + $custom_post_type, |
|
62 | + $CPT['singular_name'], |
|
63 | + $CPT['plural_name'], |
|
64 | + $CPT['singular_slug'], |
|
65 | + $CPT['plural_slug'], |
|
66 | + $CPT['args'] |
|
67 | + ); |
|
68 | + } |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * Registers a new custom post type. Sets default settings given only the following params. |
|
74 | - * Returns the registered post type object, or an error object. |
|
75 | - * |
|
76 | - * @param string $post_type the actual post type name |
|
77 | - * IMPORTANT: |
|
78 | - * this must match what the slug is for admin pages related to this CPT |
|
79 | - * Also any models must use this slug as well |
|
80 | - * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
81 | - * @param string $plural_name a pre-internationalized string for the plural name of the objects |
|
82 | - * @param string $singular_slug |
|
83 | - * @param string $plural_slug |
|
84 | - * @param array $override_arguments exactly like $args as described in |
|
85 | - * http://codex.wordpress.org/Function_Reference/register_post_type |
|
86 | - * @return WP_Post_Type|WP_Error |
|
87 | - * @throws DomainException |
|
88 | - */ |
|
89 | - public function registerCustomPostType( |
|
90 | - $post_type, |
|
91 | - $singular_name, |
|
92 | - $plural_name, |
|
93 | - $singular_slug = '', |
|
94 | - $plural_slug = '', |
|
95 | - array $override_arguments = array() |
|
96 | - ) { |
|
97 | - $wp_post_type = register_post_type( |
|
98 | - $post_type, |
|
99 | - $this->prepareArguments( |
|
100 | - $post_type, |
|
101 | - $singular_name, |
|
102 | - $plural_name, |
|
103 | - $singular_slug, |
|
104 | - $plural_slug, |
|
105 | - $override_arguments |
|
106 | - ) |
|
107 | - ); |
|
108 | - if ($wp_post_type instanceof WP_Error) { |
|
109 | - throw new DomainException($wp_post_type->get_error_message()); |
|
110 | - } |
|
111 | - return $wp_post_type; |
|
112 | - } |
|
72 | + /** |
|
73 | + * Registers a new custom post type. Sets default settings given only the following params. |
|
74 | + * Returns the registered post type object, or an error object. |
|
75 | + * |
|
76 | + * @param string $post_type the actual post type name |
|
77 | + * IMPORTANT: |
|
78 | + * this must match what the slug is for admin pages related to this CPT |
|
79 | + * Also any models must use this slug as well |
|
80 | + * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
81 | + * @param string $plural_name a pre-internationalized string for the plural name of the objects |
|
82 | + * @param string $singular_slug |
|
83 | + * @param string $plural_slug |
|
84 | + * @param array $override_arguments exactly like $args as described in |
|
85 | + * http://codex.wordpress.org/Function_Reference/register_post_type |
|
86 | + * @return WP_Post_Type|WP_Error |
|
87 | + * @throws DomainException |
|
88 | + */ |
|
89 | + public function registerCustomPostType( |
|
90 | + $post_type, |
|
91 | + $singular_name, |
|
92 | + $plural_name, |
|
93 | + $singular_slug = '', |
|
94 | + $plural_slug = '', |
|
95 | + array $override_arguments = array() |
|
96 | + ) { |
|
97 | + $wp_post_type = register_post_type( |
|
98 | + $post_type, |
|
99 | + $this->prepareArguments( |
|
100 | + $post_type, |
|
101 | + $singular_name, |
|
102 | + $plural_name, |
|
103 | + $singular_slug, |
|
104 | + $plural_slug, |
|
105 | + $override_arguments |
|
106 | + ) |
|
107 | + ); |
|
108 | + if ($wp_post_type instanceof WP_Error) { |
|
109 | + throw new DomainException($wp_post_type->get_error_message()); |
|
110 | + } |
|
111 | + return $wp_post_type; |
|
112 | + } |
|
113 | 113 | |
114 | 114 | |
115 | - /** |
|
116 | - * @param string $post_type the actual post type name |
|
117 | - * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
118 | - * @param string $plural_name a pre-internationalized string for the plural name of the objects |
|
119 | - * @param string $singular_slug |
|
120 | - * @param string $plural_slug |
|
121 | - * @param array $override_arguments The default values set in this function will be overridden |
|
122 | - * by whatever you set in $override_arguments |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - protected function prepareArguments( |
|
126 | - $post_type, |
|
127 | - $singular_name, |
|
128 | - $plural_name, |
|
129 | - $singular_slug, |
|
130 | - $plural_slug, |
|
131 | - array $override_arguments = array() |
|
132 | - ) { |
|
133 | - // verify plural slug and singular slug, if they aren't we'll use $singular_name and $plural_name |
|
134 | - $singular_slug = ! empty($singular_slug) ? $singular_slug : $singular_name; |
|
135 | - $plural_slug = ! empty($plural_slug) ? $plural_slug : $plural_name; |
|
136 | - $labels = $this->getLabels( |
|
137 | - $singular_name, |
|
138 | - $plural_name, |
|
139 | - $singular_slug, |
|
140 | - $plural_slug |
|
141 | - ); |
|
142 | - // note the page_templates arg in the supports index is something specific to EE. |
|
143 | - // WordPress doesn't actually have that in their register_post_type api. |
|
144 | - $arguments = $this->getDefaultArguments($labels, $post_type, $plural_slug); |
|
145 | - if ($override_arguments) { |
|
146 | - if (isset($override_arguments['labels'])) { |
|
147 | - $labels = array_merge($arguments['labels'], $override_arguments['labels']); |
|
148 | - } |
|
149 | - $arguments = array_merge($arguments, $override_arguments); |
|
150 | - $arguments['labels'] = $labels; |
|
151 | - } |
|
152 | - return $arguments; |
|
153 | - } |
|
115 | + /** |
|
116 | + * @param string $post_type the actual post type name |
|
117 | + * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
118 | + * @param string $plural_name a pre-internationalized string for the plural name of the objects |
|
119 | + * @param string $singular_slug |
|
120 | + * @param string $plural_slug |
|
121 | + * @param array $override_arguments The default values set in this function will be overridden |
|
122 | + * by whatever you set in $override_arguments |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + protected function prepareArguments( |
|
126 | + $post_type, |
|
127 | + $singular_name, |
|
128 | + $plural_name, |
|
129 | + $singular_slug, |
|
130 | + $plural_slug, |
|
131 | + array $override_arguments = array() |
|
132 | + ) { |
|
133 | + // verify plural slug and singular slug, if they aren't we'll use $singular_name and $plural_name |
|
134 | + $singular_slug = ! empty($singular_slug) ? $singular_slug : $singular_name; |
|
135 | + $plural_slug = ! empty($plural_slug) ? $plural_slug : $plural_name; |
|
136 | + $labels = $this->getLabels( |
|
137 | + $singular_name, |
|
138 | + $plural_name, |
|
139 | + $singular_slug, |
|
140 | + $plural_slug |
|
141 | + ); |
|
142 | + // note the page_templates arg in the supports index is something specific to EE. |
|
143 | + // WordPress doesn't actually have that in their register_post_type api. |
|
144 | + $arguments = $this->getDefaultArguments($labels, $post_type, $plural_slug); |
|
145 | + if ($override_arguments) { |
|
146 | + if (isset($override_arguments['labels'])) { |
|
147 | + $labels = array_merge($arguments['labels'], $override_arguments['labels']); |
|
148 | + } |
|
149 | + $arguments = array_merge($arguments, $override_arguments); |
|
150 | + $arguments['labels'] = $labels; |
|
151 | + } |
|
152 | + return $arguments; |
|
153 | + } |
|
154 | 154 | |
155 | 155 | |
156 | - /** |
|
157 | - * @param string $singular_name |
|
158 | - * @param string $plural_name |
|
159 | - * @param string $singular_slug |
|
160 | - * @param string $plural_slug |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - private function getLabels($singular_name, $plural_name, $singular_slug, $plural_slug) |
|
164 | - { |
|
165 | - return array( |
|
166 | - 'name' => $plural_name, |
|
167 | - 'singular_name' => $singular_name, |
|
168 | - 'singular_slug' => $singular_slug, |
|
169 | - 'plural_slug' => $plural_slug, |
|
170 | - 'add_new' => sprintf( |
|
171 | - /* Translators: Post Type Label */ |
|
172 | - esc_html_x('Add %s', 'Add Event', 'event_espresso'), |
|
173 | - $singular_name |
|
174 | - ), |
|
175 | - 'add_new_item' => sprintf( |
|
176 | - /* Translators: Post Type Label */ |
|
177 | - esc_html_x('Add New %s', 'Add New Event', 'event_espresso'), |
|
178 | - $singular_name |
|
179 | - ), |
|
180 | - 'edit_item' => sprintf( |
|
181 | - /* Translators: Post Type Label */ |
|
182 | - esc_html_x('Edit %s', 'Edit Event', 'event_espresso'), |
|
183 | - $singular_name |
|
184 | - ), |
|
185 | - 'new_item' => sprintf( |
|
186 | - /* Translators: Post Type Label */ |
|
187 | - esc_html_x('New %s', 'New Event', 'event_espresso'), |
|
188 | - $singular_name |
|
189 | - ), |
|
190 | - 'all_items' => sprintf( |
|
191 | - /* Translators: Post Type Label */ |
|
192 | - esc_html_x('All %s', 'All Events', 'event_espresso'), |
|
193 | - $plural_name |
|
194 | - ), |
|
195 | - 'view_item' => sprintf( |
|
196 | - /* Translators: Post Type Label */ |
|
197 | - esc_html_x('View %s', 'View Event', 'event_espresso'), |
|
198 | - $singular_name |
|
199 | - ), |
|
200 | - 'view_items' => sprintf( |
|
201 | - /* Translators: Post Type Label */ |
|
202 | - esc_html_x('View %s', 'View Events', 'event_espresso'), |
|
203 | - $plural_name |
|
204 | - ), |
|
205 | - 'archives' => sprintf( |
|
206 | - /* Translators: Post Type Label */ |
|
207 | - esc_html_x('%s Archives', 'Event Archives', 'event_espresso'), |
|
208 | - $singular_name |
|
209 | - ), |
|
210 | - 'attributes' => sprintf( |
|
211 | - /* Translators: Post Type Label */ |
|
212 | - esc_html_x('%s Attributes', 'Event Attributes', 'event_espresso'), |
|
213 | - $singular_name |
|
214 | - ), |
|
215 | - 'insert_into_item' => sprintf( |
|
216 | - /* Translators: Post Type Label */ |
|
217 | - esc_html_x('Insert into this %s', 'Insert into this Event', 'event_espresso'), |
|
218 | - $singular_name |
|
219 | - ), |
|
220 | - 'uploaded_to_this_item' => sprintf( |
|
221 | - /* Translators: Post Type Label */ |
|
222 | - esc_html_x('Uploaded to this %s', 'Uploaded to this Event', 'event_espresso'), |
|
223 | - $singular_name |
|
224 | - ), |
|
225 | - 'filter_items_list' => sprintf( |
|
226 | - /* Translators: Post Type Label */ |
|
227 | - esc_html_x('Filter %s list', 'Filter Events list', 'event_espresso'), |
|
228 | - $plural_name |
|
229 | - ), |
|
230 | - 'items_list_navigation' => sprintf( |
|
231 | - /* Translators: Post Type Label */ |
|
232 | - esc_html_x('%s list navigation', 'Events list navigation', 'event_espresso'), |
|
233 | - $plural_name |
|
234 | - ), |
|
235 | - 'items_list' => sprintf( |
|
236 | - /* Translators: Post Type Label */ |
|
237 | - esc_html_x('%s list', 'Events list', 'event_espresso'), |
|
238 | - $plural_name |
|
239 | - ), |
|
240 | - 'item_published' => sprintf( |
|
241 | - /* Translators: Post Type Label */ |
|
242 | - esc_html_x('%s published', 'Event published', 'event_espresso'), |
|
243 | - $singular_name |
|
244 | - ), |
|
245 | - 'item_published_privately' => sprintf( |
|
246 | - /* Translators: Post Type Label */ |
|
247 | - esc_html_x('%s published privately', 'Event published privately', 'event_espresso'), |
|
248 | - $singular_name |
|
249 | - ), |
|
250 | - 'item_reverted_to_draft' => sprintf( |
|
251 | - /* Translators: Post Type Label */ |
|
252 | - esc_html_x('%s reverted to draft', 'Event reverted to draft', 'event_espresso'), |
|
253 | - $singular_name |
|
254 | - ), |
|
255 | - 'item_scheduled' => sprintf( |
|
256 | - /* Translators: Post Type Label */ |
|
257 | - esc_html_x('%s scheduled', 'Event scheduled', 'event_espresso'), |
|
258 | - $singular_name |
|
259 | - ), |
|
260 | - 'item_updated' => sprintf( |
|
261 | - /* Translators: Post Type Label */ |
|
262 | - esc_html_x('%s updated', 'Event updated', 'event_espresso'), |
|
263 | - $singular_name |
|
264 | - ), |
|
265 | - 'search_items' => sprintf( |
|
266 | - /* Translators: Post Type Label */ |
|
267 | - esc_html_x('Search %s', 'Search Events', 'event_espresso'), |
|
268 | - $plural_name |
|
269 | - ), |
|
270 | - 'not_found' => sprintf( |
|
271 | - /* Translators: Post Type Label */ |
|
272 | - esc_html_x('No %s found', 'No Events found', 'event_espresso'), |
|
273 | - $plural_name |
|
274 | - ), |
|
275 | - 'not_found_in_trash' => sprintf( |
|
276 | - /* Translators: Post Type Label */ |
|
277 | - esc_html_x('No %s found in Trash', 'No Events found in Trash', 'event_espresso'), |
|
278 | - $plural_name |
|
279 | - ), |
|
280 | - 'parent_item_colon' => '', |
|
281 | - 'menu_name' => $plural_name, |
|
282 | - ); |
|
283 | - } |
|
156 | + /** |
|
157 | + * @param string $singular_name |
|
158 | + * @param string $plural_name |
|
159 | + * @param string $singular_slug |
|
160 | + * @param string $plural_slug |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + private function getLabels($singular_name, $plural_name, $singular_slug, $plural_slug) |
|
164 | + { |
|
165 | + return array( |
|
166 | + 'name' => $plural_name, |
|
167 | + 'singular_name' => $singular_name, |
|
168 | + 'singular_slug' => $singular_slug, |
|
169 | + 'plural_slug' => $plural_slug, |
|
170 | + 'add_new' => sprintf( |
|
171 | + /* Translators: Post Type Label */ |
|
172 | + esc_html_x('Add %s', 'Add Event', 'event_espresso'), |
|
173 | + $singular_name |
|
174 | + ), |
|
175 | + 'add_new_item' => sprintf( |
|
176 | + /* Translators: Post Type Label */ |
|
177 | + esc_html_x('Add New %s', 'Add New Event', 'event_espresso'), |
|
178 | + $singular_name |
|
179 | + ), |
|
180 | + 'edit_item' => sprintf( |
|
181 | + /* Translators: Post Type Label */ |
|
182 | + esc_html_x('Edit %s', 'Edit Event', 'event_espresso'), |
|
183 | + $singular_name |
|
184 | + ), |
|
185 | + 'new_item' => sprintf( |
|
186 | + /* Translators: Post Type Label */ |
|
187 | + esc_html_x('New %s', 'New Event', 'event_espresso'), |
|
188 | + $singular_name |
|
189 | + ), |
|
190 | + 'all_items' => sprintf( |
|
191 | + /* Translators: Post Type Label */ |
|
192 | + esc_html_x('All %s', 'All Events', 'event_espresso'), |
|
193 | + $plural_name |
|
194 | + ), |
|
195 | + 'view_item' => sprintf( |
|
196 | + /* Translators: Post Type Label */ |
|
197 | + esc_html_x('View %s', 'View Event', 'event_espresso'), |
|
198 | + $singular_name |
|
199 | + ), |
|
200 | + 'view_items' => sprintf( |
|
201 | + /* Translators: Post Type Label */ |
|
202 | + esc_html_x('View %s', 'View Events', 'event_espresso'), |
|
203 | + $plural_name |
|
204 | + ), |
|
205 | + 'archives' => sprintf( |
|
206 | + /* Translators: Post Type Label */ |
|
207 | + esc_html_x('%s Archives', 'Event Archives', 'event_espresso'), |
|
208 | + $singular_name |
|
209 | + ), |
|
210 | + 'attributes' => sprintf( |
|
211 | + /* Translators: Post Type Label */ |
|
212 | + esc_html_x('%s Attributes', 'Event Attributes', 'event_espresso'), |
|
213 | + $singular_name |
|
214 | + ), |
|
215 | + 'insert_into_item' => sprintf( |
|
216 | + /* Translators: Post Type Label */ |
|
217 | + esc_html_x('Insert into this %s', 'Insert into this Event', 'event_espresso'), |
|
218 | + $singular_name |
|
219 | + ), |
|
220 | + 'uploaded_to_this_item' => sprintf( |
|
221 | + /* Translators: Post Type Label */ |
|
222 | + esc_html_x('Uploaded to this %s', 'Uploaded to this Event', 'event_espresso'), |
|
223 | + $singular_name |
|
224 | + ), |
|
225 | + 'filter_items_list' => sprintf( |
|
226 | + /* Translators: Post Type Label */ |
|
227 | + esc_html_x('Filter %s list', 'Filter Events list', 'event_espresso'), |
|
228 | + $plural_name |
|
229 | + ), |
|
230 | + 'items_list_navigation' => sprintf( |
|
231 | + /* Translators: Post Type Label */ |
|
232 | + esc_html_x('%s list navigation', 'Events list navigation', 'event_espresso'), |
|
233 | + $plural_name |
|
234 | + ), |
|
235 | + 'items_list' => sprintf( |
|
236 | + /* Translators: Post Type Label */ |
|
237 | + esc_html_x('%s list', 'Events list', 'event_espresso'), |
|
238 | + $plural_name |
|
239 | + ), |
|
240 | + 'item_published' => sprintf( |
|
241 | + /* Translators: Post Type Label */ |
|
242 | + esc_html_x('%s published', 'Event published', 'event_espresso'), |
|
243 | + $singular_name |
|
244 | + ), |
|
245 | + 'item_published_privately' => sprintf( |
|
246 | + /* Translators: Post Type Label */ |
|
247 | + esc_html_x('%s published privately', 'Event published privately', 'event_espresso'), |
|
248 | + $singular_name |
|
249 | + ), |
|
250 | + 'item_reverted_to_draft' => sprintf( |
|
251 | + /* Translators: Post Type Label */ |
|
252 | + esc_html_x('%s reverted to draft', 'Event reverted to draft', 'event_espresso'), |
|
253 | + $singular_name |
|
254 | + ), |
|
255 | + 'item_scheduled' => sprintf( |
|
256 | + /* Translators: Post Type Label */ |
|
257 | + esc_html_x('%s scheduled', 'Event scheduled', 'event_espresso'), |
|
258 | + $singular_name |
|
259 | + ), |
|
260 | + 'item_updated' => sprintf( |
|
261 | + /* Translators: Post Type Label */ |
|
262 | + esc_html_x('%s updated', 'Event updated', 'event_espresso'), |
|
263 | + $singular_name |
|
264 | + ), |
|
265 | + 'search_items' => sprintf( |
|
266 | + /* Translators: Post Type Label */ |
|
267 | + esc_html_x('Search %s', 'Search Events', 'event_espresso'), |
|
268 | + $plural_name |
|
269 | + ), |
|
270 | + 'not_found' => sprintf( |
|
271 | + /* Translators: Post Type Label */ |
|
272 | + esc_html_x('No %s found', 'No Events found', 'event_espresso'), |
|
273 | + $plural_name |
|
274 | + ), |
|
275 | + 'not_found_in_trash' => sprintf( |
|
276 | + /* Translators: Post Type Label */ |
|
277 | + esc_html_x('No %s found in Trash', 'No Events found in Trash', 'event_espresso'), |
|
278 | + $plural_name |
|
279 | + ), |
|
280 | + 'parent_item_colon' => '', |
|
281 | + 'menu_name' => $plural_name, |
|
282 | + ); |
|
283 | + } |
|
284 | 284 | |
285 | 285 | |
286 | - /** |
|
287 | - * @param array $labels |
|
288 | - * @param string $post_type |
|
289 | - * @param string $plural_slug |
|
290 | - * @return array |
|
291 | - */ |
|
292 | - private function getDefaultArguments(array $labels, $post_type, $plural_slug) |
|
293 | - { |
|
294 | - return array( |
|
295 | - 'labels' => $labels, |
|
296 | - 'public' => true, |
|
297 | - 'publicly_queryable' => true, |
|
298 | - 'show_ui' => false, |
|
299 | - 'show_ee_ui' => true, |
|
300 | - 'show_in_menu' => false, |
|
301 | - 'show_in_nav_menus' => false, |
|
302 | - 'query_var' => true, |
|
303 | - 'rewrite' => apply_filters( |
|
304 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_RegisterCustomPostTypes__getDefaultArguments__rewrite', |
|
305 | - // legacy filter applied for now, |
|
306 | - // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice |
|
307 | - apply_filters( |
|
308 | - 'FHEE__EE_Register_CPTs__register_CPT__rewrite', |
|
309 | - array('slug' => $plural_slug), |
|
310 | - $post_type |
|
311 | - ), |
|
312 | - $post_type, |
|
313 | - $plural_slug |
|
314 | - ), |
|
315 | - 'capability_type' => 'post', |
|
316 | - 'map_meta_cap' => true, |
|
317 | - 'has_archive' => true, |
|
318 | - 'hierarchical' => false, |
|
319 | - 'menu_position' => null, |
|
320 | - 'supports' => array( |
|
321 | - 'title', |
|
322 | - 'editor', |
|
323 | - 'author', |
|
324 | - 'thumbnail', |
|
325 | - 'excerpt', |
|
326 | - 'custom-fields', |
|
327 | - 'comments', |
|
328 | - ), |
|
329 | - ); |
|
330 | - } |
|
286 | + /** |
|
287 | + * @param array $labels |
|
288 | + * @param string $post_type |
|
289 | + * @param string $plural_slug |
|
290 | + * @return array |
|
291 | + */ |
|
292 | + private function getDefaultArguments(array $labels, $post_type, $plural_slug) |
|
293 | + { |
|
294 | + return array( |
|
295 | + 'labels' => $labels, |
|
296 | + 'public' => true, |
|
297 | + 'publicly_queryable' => true, |
|
298 | + 'show_ui' => false, |
|
299 | + 'show_ee_ui' => true, |
|
300 | + 'show_in_menu' => false, |
|
301 | + 'show_in_nav_menus' => false, |
|
302 | + 'query_var' => true, |
|
303 | + 'rewrite' => apply_filters( |
|
304 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_RegisterCustomPostTypes__getDefaultArguments__rewrite', |
|
305 | + // legacy filter applied for now, |
|
306 | + // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice |
|
307 | + apply_filters( |
|
308 | + 'FHEE__EE_Register_CPTs__register_CPT__rewrite', |
|
309 | + array('slug' => $plural_slug), |
|
310 | + $post_type |
|
311 | + ), |
|
312 | + $post_type, |
|
313 | + $plural_slug |
|
314 | + ), |
|
315 | + 'capability_type' => 'post', |
|
316 | + 'map_meta_cap' => true, |
|
317 | + 'has_archive' => true, |
|
318 | + 'hierarchical' => false, |
|
319 | + 'menu_position' => null, |
|
320 | + 'supports' => array( |
|
321 | + 'title', |
|
322 | + 'editor', |
|
323 | + 'author', |
|
324 | + 'thumbnail', |
|
325 | + 'excerpt', |
|
326 | + 'custom-fields', |
|
327 | + 'comments', |
|
328 | + ), |
|
329 | + ); |
|
330 | + } |
|
331 | 331 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function distributionAssetsPath() |
138 | 138 | { |
139 | - return $this->pluginPath() . 'assets/dist/'; |
|
139 | + return $this->pluginPath().'assets/dist/'; |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | */ |
146 | 146 | public function distributionAssetsUrl() |
147 | 147 | { |
148 | - return $this->pluginUrl() . 'assets/dist/'; |
|
148 | + return $this->pluginUrl().'assets/dist/'; |
|
149 | 149 | } |
150 | 150 | |
151 | 151 |
@@ -16,153 +16,153 @@ |
||
16 | 16 | abstract class DomainBase implements DomainInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * Equivalent to `__FILE__` for main plugin file. |
|
21 | - * |
|
22 | - * @var FilePath |
|
23 | - */ |
|
24 | - private $plugin_file; |
|
25 | - |
|
26 | - /** |
|
27 | - * String indicating version for plugin |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - private $version; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var string $plugin_basename |
|
35 | - */ |
|
36 | - private $plugin_basename; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var string $plugin_path |
|
40 | - */ |
|
41 | - private $plugin_path; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var string $plugin_url |
|
45 | - */ |
|
46 | - private $plugin_url; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var string $asset_namespace |
|
50 | - */ |
|
51 | - private $asset_namespace; |
|
52 | - |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * Initializes internal properties. |
|
57 | - * |
|
58 | - * @param FilePath $plugin_file |
|
59 | - * @param Version $version |
|
60 | - */ |
|
61 | - public function __construct(FilePath $plugin_file, Version $version) |
|
62 | - { |
|
63 | - $this->plugin_file = $plugin_file; |
|
64 | - $this->version = $version; |
|
65 | - $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
66 | - $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
67 | - $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
68 | - $this->setAssetNamespace(); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function pluginFile() |
|
76 | - { |
|
77 | - return (string) $this->plugin_file; |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function pluginBasename() |
|
86 | - { |
|
87 | - return $this->plugin_basename; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function pluginPath() |
|
96 | - { |
|
97 | - return $this->plugin_path; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - public function pluginUrl() |
|
106 | - { |
|
107 | - return $this->plugin_url; |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @return string |
|
114 | - */ |
|
115 | - public function version() |
|
116 | - { |
|
117 | - return (string) $this->version; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return Version |
|
124 | - */ |
|
125 | - public function versionValueObject() |
|
126 | - { |
|
127 | - return $this->version; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function distributionAssetsPath() |
|
135 | - { |
|
136 | - return $this->pluginPath() . 'assets/dist/'; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function distributionAssetsUrl() |
|
144 | - { |
|
145 | - return $this->pluginUrl() . 'assets/dist/'; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * @return string |
|
151 | - */ |
|
152 | - public function assetNamespace() |
|
153 | - { |
|
154 | - return $this->asset_namespace; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * @return void |
|
160 | - */ |
|
161 | - private function setAssetNamespace() |
|
162 | - { |
|
163 | - $this->asset_namespace = sanitize_key( |
|
164 | - // convert directory separators to dashes and remove file extension |
|
165 | - str_replace(array('/', '.php'), array('-', ''), $this->plugin_basename) |
|
166 | - ); |
|
167 | - } |
|
19 | + /** |
|
20 | + * Equivalent to `__FILE__` for main plugin file. |
|
21 | + * |
|
22 | + * @var FilePath |
|
23 | + */ |
|
24 | + private $plugin_file; |
|
25 | + |
|
26 | + /** |
|
27 | + * String indicating version for plugin |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + private $version; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var string $plugin_basename |
|
35 | + */ |
|
36 | + private $plugin_basename; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var string $plugin_path |
|
40 | + */ |
|
41 | + private $plugin_path; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var string $plugin_url |
|
45 | + */ |
|
46 | + private $plugin_url; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var string $asset_namespace |
|
50 | + */ |
|
51 | + private $asset_namespace; |
|
52 | + |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * Initializes internal properties. |
|
57 | + * |
|
58 | + * @param FilePath $plugin_file |
|
59 | + * @param Version $version |
|
60 | + */ |
|
61 | + public function __construct(FilePath $plugin_file, Version $version) |
|
62 | + { |
|
63 | + $this->plugin_file = $plugin_file; |
|
64 | + $this->version = $version; |
|
65 | + $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
66 | + $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
67 | + $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
68 | + $this->setAssetNamespace(); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function pluginFile() |
|
76 | + { |
|
77 | + return (string) $this->plugin_file; |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function pluginBasename() |
|
86 | + { |
|
87 | + return $this->plugin_basename; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function pluginPath() |
|
96 | + { |
|
97 | + return $this->plugin_path; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + public function pluginUrl() |
|
106 | + { |
|
107 | + return $this->plugin_url; |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @return string |
|
114 | + */ |
|
115 | + public function version() |
|
116 | + { |
|
117 | + return (string) $this->version; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return Version |
|
124 | + */ |
|
125 | + public function versionValueObject() |
|
126 | + { |
|
127 | + return $this->version; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function distributionAssetsPath() |
|
135 | + { |
|
136 | + return $this->pluginPath() . 'assets/dist/'; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public function distributionAssetsUrl() |
|
144 | + { |
|
145 | + return $this->pluginUrl() . 'assets/dist/'; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * @return string |
|
151 | + */ |
|
152 | + public function assetNamespace() |
|
153 | + { |
|
154 | + return $this->asset_namespace; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * @return void |
|
160 | + */ |
|
161 | + private function setAssetNamespace() |
|
162 | + { |
|
163 | + $this->asset_namespace = sanitize_key( |
|
164 | + // convert directory separators to dashes and remove file extension |
|
165 | + str_replace(array('/', '.php'), array('-', ''), $this->plugin_basename) |
|
166 | + ); |
|
167 | + } |
|
168 | 168 | } |
@@ -16,26 +16,26 @@ |
||
16 | 16 | class ManifestFile extends Asset |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * Asset constructor. |
|
21 | - * |
|
22 | - * @param DomainInterface $domain |
|
23 | - * @throws InvalidDataTypeException |
|
24 | - */ |
|
25 | - public function __construct(DomainInterface $domain) |
|
26 | - { |
|
27 | - parent::__construct(Asset::TYPE_MANIFEST, $domain->assetNamespace(), $domain); |
|
28 | - } |
|
29 | - |
|
30 | - |
|
31 | - public function urlBase() |
|
32 | - { |
|
33 | - return $this->domain->distributionAssetsUrl(); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - public function filepath() |
|
38 | - { |
|
39 | - return $this->domain->distributionAssetsPath(); |
|
40 | - } |
|
19 | + /** |
|
20 | + * Asset constructor. |
|
21 | + * |
|
22 | + * @param DomainInterface $domain |
|
23 | + * @throws InvalidDataTypeException |
|
24 | + */ |
|
25 | + public function __construct(DomainInterface $domain) |
|
26 | + { |
|
27 | + parent::__construct(Asset::TYPE_MANIFEST, $domain->assetNamespace(), $domain); |
|
28 | + } |
|
29 | + |
|
30 | + |
|
31 | + public function urlBase() |
|
32 | + { |
|
33 | + return $this->domain->distributionAssetsUrl(); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + public function filepath() |
|
38 | + { |
|
39 | + return $this->domain->distributionAssetsPath(); |
|
40 | + } |
|
41 | 41 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | private function setType($type) |
84 | 84 | { |
85 | - if (! in_array($type, $this->validAssetTypes(), true)) { |
|
85 | + if ( ! in_array($type, $this->validAssetTypes(), true)) { |
|
86 | 86 | throw new InvalidDataTypeException( |
87 | 87 | 'Asset::$type', |
88 | 88 | $type, |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | private function setHandle($handle) |
101 | 101 | { |
102 | - if (! is_string($handle)) { |
|
102 | + if ( ! is_string($handle)) { |
|
103 | 103 | throw new InvalidDataTypeException( |
104 | 104 | '$handle', |
105 | 105 | $handle, |
@@ -16,168 +16,168 @@ |
||
16 | 16 | abstract class Asset |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * indicates the file extension for a build distribution CSS file |
|
21 | - */ |
|
22 | - const FILE_EXTENSION_DISTRIBUTION_CSS = '.dist.css'; |
|
23 | - |
|
24 | - /** |
|
25 | - * indicates the file extension for a build distribution JS file |
|
26 | - */ |
|
27 | - const FILE_EXTENSION_DISTRIBUTION_JS = '.dist.js'; |
|
28 | - |
|
29 | - /** |
|
30 | - * Indicates the file extension for a build distribution dependencies json file. |
|
31 | - */ |
|
32 | - const FILE_EXTENSION_DISTRIBUTION_DEPS = '.dist.deps.php'; |
|
33 | - |
|
34 | - /** |
|
35 | - * indicates a Cascading Style Sheet asset |
|
36 | - */ |
|
37 | - const TYPE_CSS = 'css'; |
|
38 | - |
|
39 | - /** |
|
40 | - * indicates a Javascript asset |
|
41 | - */ |
|
42 | - const TYPE_JS = 'js'; |
|
43 | - |
|
44 | - /** |
|
45 | - * indicates a JSON asset |
|
46 | - */ |
|
47 | - CONST TYPE_JSON = 'json'; |
|
48 | - /** |
|
49 | - * indicates a PHP asset |
|
50 | - */ |
|
51 | - CONST TYPE_PHP = 'php'; |
|
52 | - |
|
53 | - /** |
|
54 | - * indicates a Javascript manifest file |
|
55 | - */ |
|
56 | - const TYPE_MANIFEST = 'manifest'; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var DomainInterface $domain |
|
60 | - */ |
|
61 | - protected $domain; |
|
62 | - |
|
63 | - /** |
|
64 | - * @var string $type |
|
65 | - */ |
|
66 | - private $type; |
|
67 | - |
|
68 | - /** |
|
69 | - * @var string $handle |
|
70 | - */ |
|
71 | - private $handle; |
|
72 | - |
|
73 | - /** |
|
74 | - * @var bool $registered |
|
75 | - */ |
|
76 | - private $registered = false; |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Asset constructor. |
|
81 | - * |
|
82 | - * @param $type |
|
83 | - * @param string $handle |
|
84 | - * @param DomainInterface $domain |
|
85 | - * @throws InvalidDataTypeException |
|
86 | - */ |
|
87 | - public function __construct($type, $handle, DomainInterface $domain) |
|
88 | - { |
|
89 | - $this->domain = $domain; |
|
90 | - $this->setType($type); |
|
91 | - $this->setHandle($handle); |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @return array |
|
97 | - */ |
|
98 | - public function validAssetTypes() |
|
99 | - { |
|
100 | - return array( |
|
101 | - Asset::TYPE_CSS, |
|
102 | - Asset::TYPE_JS, |
|
103 | - Asset::TYPE_MANIFEST, |
|
104 | - ); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * @param string $type |
|
110 | - * @throws InvalidDataTypeException |
|
111 | - */ |
|
112 | - private function setType($type) |
|
113 | - { |
|
114 | - if (! in_array($type, $this->validAssetTypes(), true)) { |
|
115 | - throw new InvalidDataTypeException( |
|
116 | - 'Asset::$type', |
|
117 | - $type, |
|
118 | - 'one of the TYPE_* class constants on \EventEspresso\core\domain\values\Asset is required' |
|
119 | - ); |
|
120 | - } |
|
121 | - $this->type = $type; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @param string $handle |
|
127 | - * @throws InvalidDataTypeException |
|
128 | - */ |
|
129 | - private function setHandle($handle) |
|
130 | - { |
|
131 | - if (! is_string($handle)) { |
|
132 | - throw new InvalidDataTypeException( |
|
133 | - '$handle', |
|
134 | - $handle, |
|
135 | - 'string' |
|
136 | - ); |
|
137 | - } |
|
138 | - $this->handle = $handle; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public function assetNamespace() |
|
146 | - { |
|
147 | - return $this->domain->assetNamespace(); |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @return string |
|
153 | - */ |
|
154 | - public function type() |
|
155 | - { |
|
156 | - return $this->type; |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @return string |
|
162 | - */ |
|
163 | - public function handle() |
|
164 | - { |
|
165 | - return $this->handle; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * @return bool |
|
170 | - */ |
|
171 | - public function isRegistered() |
|
172 | - { |
|
173 | - return $this->registered; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @param bool $registered |
|
178 | - */ |
|
179 | - public function setRegistered($registered = true) |
|
180 | - { |
|
181 | - $this->registered = filter_var($registered, FILTER_VALIDATE_BOOLEAN); |
|
182 | - } |
|
19 | + /** |
|
20 | + * indicates the file extension for a build distribution CSS file |
|
21 | + */ |
|
22 | + const FILE_EXTENSION_DISTRIBUTION_CSS = '.dist.css'; |
|
23 | + |
|
24 | + /** |
|
25 | + * indicates the file extension for a build distribution JS file |
|
26 | + */ |
|
27 | + const FILE_EXTENSION_DISTRIBUTION_JS = '.dist.js'; |
|
28 | + |
|
29 | + /** |
|
30 | + * Indicates the file extension for a build distribution dependencies json file. |
|
31 | + */ |
|
32 | + const FILE_EXTENSION_DISTRIBUTION_DEPS = '.dist.deps.php'; |
|
33 | + |
|
34 | + /** |
|
35 | + * indicates a Cascading Style Sheet asset |
|
36 | + */ |
|
37 | + const TYPE_CSS = 'css'; |
|
38 | + |
|
39 | + /** |
|
40 | + * indicates a Javascript asset |
|
41 | + */ |
|
42 | + const TYPE_JS = 'js'; |
|
43 | + |
|
44 | + /** |
|
45 | + * indicates a JSON asset |
|
46 | + */ |
|
47 | + CONST TYPE_JSON = 'json'; |
|
48 | + /** |
|
49 | + * indicates a PHP asset |
|
50 | + */ |
|
51 | + CONST TYPE_PHP = 'php'; |
|
52 | + |
|
53 | + /** |
|
54 | + * indicates a Javascript manifest file |
|
55 | + */ |
|
56 | + const TYPE_MANIFEST = 'manifest'; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var DomainInterface $domain |
|
60 | + */ |
|
61 | + protected $domain; |
|
62 | + |
|
63 | + /** |
|
64 | + * @var string $type |
|
65 | + */ |
|
66 | + private $type; |
|
67 | + |
|
68 | + /** |
|
69 | + * @var string $handle |
|
70 | + */ |
|
71 | + private $handle; |
|
72 | + |
|
73 | + /** |
|
74 | + * @var bool $registered |
|
75 | + */ |
|
76 | + private $registered = false; |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Asset constructor. |
|
81 | + * |
|
82 | + * @param $type |
|
83 | + * @param string $handle |
|
84 | + * @param DomainInterface $domain |
|
85 | + * @throws InvalidDataTypeException |
|
86 | + */ |
|
87 | + public function __construct($type, $handle, DomainInterface $domain) |
|
88 | + { |
|
89 | + $this->domain = $domain; |
|
90 | + $this->setType($type); |
|
91 | + $this->setHandle($handle); |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @return array |
|
97 | + */ |
|
98 | + public function validAssetTypes() |
|
99 | + { |
|
100 | + return array( |
|
101 | + Asset::TYPE_CSS, |
|
102 | + Asset::TYPE_JS, |
|
103 | + Asset::TYPE_MANIFEST, |
|
104 | + ); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * @param string $type |
|
110 | + * @throws InvalidDataTypeException |
|
111 | + */ |
|
112 | + private function setType($type) |
|
113 | + { |
|
114 | + if (! in_array($type, $this->validAssetTypes(), true)) { |
|
115 | + throw new InvalidDataTypeException( |
|
116 | + 'Asset::$type', |
|
117 | + $type, |
|
118 | + 'one of the TYPE_* class constants on \EventEspresso\core\domain\values\Asset is required' |
|
119 | + ); |
|
120 | + } |
|
121 | + $this->type = $type; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @param string $handle |
|
127 | + * @throws InvalidDataTypeException |
|
128 | + */ |
|
129 | + private function setHandle($handle) |
|
130 | + { |
|
131 | + if (! is_string($handle)) { |
|
132 | + throw new InvalidDataTypeException( |
|
133 | + '$handle', |
|
134 | + $handle, |
|
135 | + 'string' |
|
136 | + ); |
|
137 | + } |
|
138 | + $this->handle = $handle; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public function assetNamespace() |
|
146 | + { |
|
147 | + return $this->domain->assetNamespace(); |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @return string |
|
153 | + */ |
|
154 | + public function type() |
|
155 | + { |
|
156 | + return $this->type; |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @return string |
|
162 | + */ |
|
163 | + public function handle() |
|
164 | + { |
|
165 | + return $this->handle; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * @return bool |
|
170 | + */ |
|
171 | + public function isRegistered() |
|
172 | + { |
|
173 | + return $this->registered; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @param bool $registered |
|
178 | + */ |
|
179 | + public function setRegistered($registered = true) |
|
180 | + { |
|
181 | + $this->registered = filter_var($registered, FILTER_VALIDATE_BOOLEAN); |
|
182 | + } |
|
183 | 183 | } |