@@ -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,113 +16,113 @@ |
||
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 $argument) { |
|
113 | - switch (true) { |
|
114 | - case is_object($argument): |
|
115 | - case $argument instanceof Closure: |
|
116 | - $identifier .= spl_object_hash($argument); |
|
117 | - break; |
|
118 | - case is_array($argument): |
|
119 | - $identifier .= $this->getIdentifierForArguments($argument); |
|
120 | - break; |
|
121 | - default: |
|
122 | - $identifier .= $argument; |
|
123 | - break; |
|
124 | - } |
|
125 | - } |
|
126 | - return $identifier; |
|
127 | - } |
|
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 $argument) { |
|
113 | + switch (true) { |
|
114 | + case is_object($argument): |
|
115 | + case $argument instanceof Closure: |
|
116 | + $identifier .= spl_object_hash($argument); |
|
117 | + break; |
|
118 | + case is_array($argument): |
|
119 | + $identifier .= $this->getIdentifierForArguments($argument); |
|
120 | + break; |
|
121 | + default: |
|
122 | + $identifier .= $argument; |
|
123 | + break; |
|
124 | + } |
|
125 | + } |
|
126 | + return $identifier; |
|
127 | + } |
|
128 | 128 | } |
@@ -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,160 +20,160 @@ |
||
20 | 20 | class ClassInterfaceCache |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * array of interfaces indexed by FQCNs where values are arrays of interface FQNs |
|
25 | - * |
|
26 | - * @var string[][] $interfaces |
|
27 | - */ |
|
28 | - private $interfaces = array(); |
|
29 | - |
|
30 | - /** |
|
31 | - * @type string[][] $aliases |
|
32 | - */ |
|
33 | - protected $aliases = array(); |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @param string $fqn |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - public function getFqn($fqn) |
|
41 | - { |
|
42 | - return $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn; |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * @param string $fqn |
|
48 | - * @return array |
|
49 | - */ |
|
50 | - public function getInterfaces($fqn) |
|
51 | - { |
|
52 | - $fqn = $this->getFqn($fqn); |
|
53 | - // have we already seen this FQCN ? |
|
54 | - if (! array_key_exists($fqn, $this->interfaces)) { |
|
55 | - $this->interfaces[ $fqn ] = array(); |
|
56 | - if (class_exists($fqn)) { |
|
57 | - $this->interfaces[ $fqn ] = class_implements($fqn, false); |
|
58 | - $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false |
|
59 | - ? $this->interfaces[ $fqn ] |
|
60 | - : array(); |
|
61 | - } |
|
62 | - } |
|
63 | - return $this->interfaces[ $fqn ]; |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @param string $fqn |
|
69 | - * @param string $interface |
|
70 | - * @return bool |
|
71 | - */ |
|
72 | - public function hasInterface($fqn, $interface) |
|
73 | - { |
|
74 | - $fqn = $this->getFqn($fqn); |
|
75 | - $interfaces = $this->getInterfaces($fqn); |
|
76 | - return in_array($interface, $interfaces, true); |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * adds an alias for a classname |
|
82 | - * |
|
83 | - * @param string $fqn the class name that should be used (concrete class to replace interface) |
|
84 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
85 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
86 | - */ |
|
87 | - public function addAlias($fqn, $alias, $for_class = '') |
|
88 | - { |
|
89 | - $fqn = $this->getFqn($fqn); |
|
90 | - $alias = $this->getFqn($alias); |
|
91 | - // are we adding an alias for a specific class? |
|
92 | - if ($for_class !== '') { |
|
93 | - // make sure it's set up as an array |
|
94 | - if (! isset($this->aliases[ $for_class ])) { |
|
95 | - $this->aliases[ $for_class ] = array(); |
|
96 | - } |
|
97 | - $this->aliases[ $for_class ][ $alias ] = $fqn; |
|
98 | - return; |
|
99 | - } |
|
100 | - $this->aliases[ $alias ] = $fqn; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * returns TRUE if the provided FQN is an alias |
|
106 | - * |
|
107 | - * @param string $fqn |
|
108 | - * @param string $for_class |
|
109 | - * @return bool |
|
110 | - */ |
|
111 | - public function isAlias($fqn = '', $for_class = '') |
|
112 | - { |
|
113 | - $fqn = $this->getFqn($fqn); |
|
114 | - if ($this->isAliasForClass($fqn, $for_class)) { |
|
115 | - return true; |
|
116 | - } |
|
117 | - if ($for_class === '' && $this->isDirectAlias($fqn)) { |
|
118 | - return true; |
|
119 | - } |
|
120 | - return false; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * returns TRUE if the provided FQN is an alias |
|
126 | - * |
|
127 | - * @param string $fqn |
|
128 | - * @return bool |
|
129 | - */ |
|
130 | - protected function isDirectAlias($fqn = '') |
|
131 | - { |
|
132 | - return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * returns TRUE if the provided FQN is an alias for the specified class |
|
138 | - * |
|
139 | - * @param string $fqn |
|
140 | - * @param string $for_class |
|
141 | - * @return bool |
|
142 | - */ |
|
143 | - protected function isAliasForClass($fqn = '', $for_class = '') |
|
144 | - { |
|
145 | - return ( |
|
146 | - $for_class !== '' |
|
147 | - && isset($this->aliases[ (string) $for_class ][ (string) $fqn ]) |
|
148 | - ); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * returns FQN for provided alias if one exists, otherwise returns the original FQN |
|
154 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
155 | - * for example: |
|
156 | - * if the following two entries were added to the aliases array: |
|
157 | - * array( |
|
158 | - * 'interface_alias' => 'some\namespace\interface' |
|
159 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
160 | - * ) |
|
161 | - * then one could use Loader::getNew( 'interface_alias' ) |
|
162 | - * to load an instance of 'some\namespace\classname' |
|
163 | - * |
|
164 | - * @param string $alias |
|
165 | - * @param string $for_class |
|
166 | - * @return string |
|
167 | - */ |
|
168 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
169 | - { |
|
170 | - $alias = $this->getFqn($alias); |
|
171 | - if ($this->isAliasForClass($alias, $for_class)) { |
|
172 | - return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class); |
|
173 | - } |
|
174 | - if ($this->isDirectAlias($alias)) { |
|
175 | - return $this->getFqnForAlias($this->aliases[ (string) $alias ], ''); |
|
176 | - } |
|
177 | - return $alias; |
|
178 | - } |
|
23 | + /** |
|
24 | + * array of interfaces indexed by FQCNs where values are arrays of interface FQNs |
|
25 | + * |
|
26 | + * @var string[][] $interfaces |
|
27 | + */ |
|
28 | + private $interfaces = array(); |
|
29 | + |
|
30 | + /** |
|
31 | + * @type string[][] $aliases |
|
32 | + */ |
|
33 | + protected $aliases = array(); |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @param string $fqn |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + public function getFqn($fqn) |
|
41 | + { |
|
42 | + return $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn; |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * @param string $fqn |
|
48 | + * @return array |
|
49 | + */ |
|
50 | + public function getInterfaces($fqn) |
|
51 | + { |
|
52 | + $fqn = $this->getFqn($fqn); |
|
53 | + // have we already seen this FQCN ? |
|
54 | + if (! array_key_exists($fqn, $this->interfaces)) { |
|
55 | + $this->interfaces[ $fqn ] = array(); |
|
56 | + if (class_exists($fqn)) { |
|
57 | + $this->interfaces[ $fqn ] = class_implements($fqn, false); |
|
58 | + $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false |
|
59 | + ? $this->interfaces[ $fqn ] |
|
60 | + : array(); |
|
61 | + } |
|
62 | + } |
|
63 | + return $this->interfaces[ $fqn ]; |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @param string $fqn |
|
69 | + * @param string $interface |
|
70 | + * @return bool |
|
71 | + */ |
|
72 | + public function hasInterface($fqn, $interface) |
|
73 | + { |
|
74 | + $fqn = $this->getFqn($fqn); |
|
75 | + $interfaces = $this->getInterfaces($fqn); |
|
76 | + return in_array($interface, $interfaces, true); |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * adds an alias for a classname |
|
82 | + * |
|
83 | + * @param string $fqn the class name that should be used (concrete class to replace interface) |
|
84 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
85 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
86 | + */ |
|
87 | + public function addAlias($fqn, $alias, $for_class = '') |
|
88 | + { |
|
89 | + $fqn = $this->getFqn($fqn); |
|
90 | + $alias = $this->getFqn($alias); |
|
91 | + // are we adding an alias for a specific class? |
|
92 | + if ($for_class !== '') { |
|
93 | + // make sure it's set up as an array |
|
94 | + if (! isset($this->aliases[ $for_class ])) { |
|
95 | + $this->aliases[ $for_class ] = array(); |
|
96 | + } |
|
97 | + $this->aliases[ $for_class ][ $alias ] = $fqn; |
|
98 | + return; |
|
99 | + } |
|
100 | + $this->aliases[ $alias ] = $fqn; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * returns TRUE if the provided FQN is an alias |
|
106 | + * |
|
107 | + * @param string $fqn |
|
108 | + * @param string $for_class |
|
109 | + * @return bool |
|
110 | + */ |
|
111 | + public function isAlias($fqn = '', $for_class = '') |
|
112 | + { |
|
113 | + $fqn = $this->getFqn($fqn); |
|
114 | + if ($this->isAliasForClass($fqn, $for_class)) { |
|
115 | + return true; |
|
116 | + } |
|
117 | + if ($for_class === '' && $this->isDirectAlias($fqn)) { |
|
118 | + return true; |
|
119 | + } |
|
120 | + return false; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * returns TRUE if the provided FQN is an alias |
|
126 | + * |
|
127 | + * @param string $fqn |
|
128 | + * @return bool |
|
129 | + */ |
|
130 | + protected function isDirectAlias($fqn = '') |
|
131 | + { |
|
132 | + return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * returns TRUE if the provided FQN is an alias for the specified class |
|
138 | + * |
|
139 | + * @param string $fqn |
|
140 | + * @param string $for_class |
|
141 | + * @return bool |
|
142 | + */ |
|
143 | + protected function isAliasForClass($fqn = '', $for_class = '') |
|
144 | + { |
|
145 | + return ( |
|
146 | + $for_class !== '' |
|
147 | + && isset($this->aliases[ (string) $for_class ][ (string) $fqn ]) |
|
148 | + ); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * returns FQN for provided alias if one exists, otherwise returns the original FQN |
|
154 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
155 | + * for example: |
|
156 | + * if the following two entries were added to the aliases array: |
|
157 | + * array( |
|
158 | + * 'interface_alias' => 'some\namespace\interface' |
|
159 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
160 | + * ) |
|
161 | + * then one could use Loader::getNew( 'interface_alias' ) |
|
162 | + * to load an instance of 'some\namespace\classname' |
|
163 | + * |
|
164 | + * @param string $alias |
|
165 | + * @param string $for_class |
|
166 | + * @return string |
|
167 | + */ |
|
168 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
169 | + { |
|
170 | + $alias = $this->getFqn($alias); |
|
171 | + if ($this->isAliasForClass($alias, $for_class)) { |
|
172 | + return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class); |
|
173 | + } |
|
174 | + if ($this->isDirectAlias($alias)) { |
|
175 | + return $this->getFqnForAlias($this->aliases[ (string) $alias ], ''); |
|
176 | + } |
|
177 | + return $alias; |
|
178 | + } |
|
179 | 179 | } |
@@ -51,16 +51,16 @@ discard block |
||
51 | 51 | { |
52 | 52 | $fqn = $this->getFqn($fqn); |
53 | 53 | // have we already seen this FQCN ? |
54 | - if (! array_key_exists($fqn, $this->interfaces)) { |
|
55 | - $this->interfaces[ $fqn ] = array(); |
|
54 | + if ( ! array_key_exists($fqn, $this->interfaces)) { |
|
55 | + $this->interfaces[$fqn] = array(); |
|
56 | 56 | if (class_exists($fqn)) { |
57 | - $this->interfaces[ $fqn ] = class_implements($fqn, false); |
|
58 | - $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false |
|
59 | - ? $this->interfaces[ $fqn ] |
|
57 | + $this->interfaces[$fqn] = class_implements($fqn, false); |
|
58 | + $this->interfaces[$fqn] = $this->interfaces[$fqn] !== false |
|
59 | + ? $this->interfaces[$fqn] |
|
60 | 60 | : array(); |
61 | 61 | } |
62 | 62 | } |
63 | - return $this->interfaces[ $fqn ]; |
|
63 | + return $this->interfaces[$fqn]; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | |
@@ -91,13 +91,13 @@ discard block |
||
91 | 91 | // are we adding an alias for a specific class? |
92 | 92 | if ($for_class !== '') { |
93 | 93 | // make sure it's set up as an array |
94 | - if (! isset($this->aliases[ $for_class ])) { |
|
95 | - $this->aliases[ $for_class ] = array(); |
|
94 | + if ( ! isset($this->aliases[$for_class])) { |
|
95 | + $this->aliases[$for_class] = array(); |
|
96 | 96 | } |
97 | - $this->aliases[ $for_class ][ $alias ] = $fqn; |
|
97 | + $this->aliases[$for_class][$alias] = $fqn; |
|
98 | 98 | return; |
99 | 99 | } |
100 | - $this->aliases[ $alias ] = $fqn; |
|
100 | + $this->aliases[$alias] = $fqn; |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | */ |
130 | 130 | protected function isDirectAlias($fqn = '') |
131 | 131 | { |
132 | - return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]); |
|
132 | + return isset($this->aliases[(string) $fqn]) && ! is_array($this->aliases[(string) $fqn]); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | { |
145 | 145 | return ( |
146 | 146 | $for_class !== '' |
147 | - && isset($this->aliases[ (string) $for_class ][ (string) $fqn ]) |
|
147 | + && isset($this->aliases[(string) $for_class][(string) $fqn]) |
|
148 | 148 | ); |
149 | 149 | } |
150 | 150 | |
@@ -169,10 +169,10 @@ discard block |
||
169 | 169 | { |
170 | 170 | $alias = $this->getFqn($alias); |
171 | 171 | if ($this->isAliasForClass($alias, $for_class)) { |
172 | - return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class); |
|
172 | + return $this->getFqnForAlias($this->aliases[(string) $for_class][(string) $alias], $for_class); |
|
173 | 173 | } |
174 | 174 | if ($this->isDirectAlias($alias)) { |
175 | - return $this->getFqnForAlias($this->aliases[ (string) $alias ], ''); |
|
175 | + return $this->getFqnForAlias($this->aliases[(string) $alias], ''); |
|
176 | 176 | } |
177 | 177 | return $alias; |
178 | 178 | } |
@@ -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,240 +18,240 @@ |
||
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 | - esc_html_x('Add %s', 'Add Event', 'event_espresso'), |
|
172 | - $singular_name |
|
173 | - ), |
|
174 | - 'add_new_item' => sprintf( |
|
175 | - esc_html_x('Add New %s', 'Add New Event', 'event_espresso'), |
|
176 | - $singular_name |
|
177 | - ), |
|
178 | - 'edit_item' => sprintf( |
|
179 | - esc_html_x('Edit %s', 'Edit Event', 'event_espresso'), |
|
180 | - $singular_name |
|
181 | - ), |
|
182 | - 'new_item' => sprintf( |
|
183 | - esc_html_x('New %s', 'New Event', 'event_espresso'), |
|
184 | - $singular_name |
|
185 | - ), |
|
186 | - 'all_items' => sprintf( |
|
187 | - esc_html_x('All %s', 'All Events', 'event_espresso'), |
|
188 | - $plural_name |
|
189 | - ), |
|
190 | - 'view_item' => sprintf( |
|
191 | - esc_html_x('View %s', 'View Event', 'event_espresso'), |
|
192 | - $singular_name |
|
193 | - ), |
|
194 | - 'search_items' => sprintf( |
|
195 | - esc_html_x('Search %s', 'Search Events', 'event_espresso'), |
|
196 | - $plural_name |
|
197 | - ), |
|
198 | - 'not_found' => sprintf( |
|
199 | - esc_html_x('No %s found', 'No Events found', 'event_espresso'), |
|
200 | - $plural_name |
|
201 | - ), |
|
202 | - 'not_found_in_trash' => sprintf( |
|
203 | - esc_html_x('No %s found in Trash', 'No Events found in Trash', 'event_espresso'), |
|
204 | - $plural_name |
|
205 | - ), |
|
206 | - 'parent_item_colon' => '', |
|
207 | - 'menu_name' => $plural_name, |
|
208 | - ); |
|
209 | - } |
|
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 | + esc_html_x('Add %s', 'Add Event', 'event_espresso'), |
|
172 | + $singular_name |
|
173 | + ), |
|
174 | + 'add_new_item' => sprintf( |
|
175 | + esc_html_x('Add New %s', 'Add New Event', 'event_espresso'), |
|
176 | + $singular_name |
|
177 | + ), |
|
178 | + 'edit_item' => sprintf( |
|
179 | + esc_html_x('Edit %s', 'Edit Event', 'event_espresso'), |
|
180 | + $singular_name |
|
181 | + ), |
|
182 | + 'new_item' => sprintf( |
|
183 | + esc_html_x('New %s', 'New Event', 'event_espresso'), |
|
184 | + $singular_name |
|
185 | + ), |
|
186 | + 'all_items' => sprintf( |
|
187 | + esc_html_x('All %s', 'All Events', 'event_espresso'), |
|
188 | + $plural_name |
|
189 | + ), |
|
190 | + 'view_item' => sprintf( |
|
191 | + esc_html_x('View %s', 'View Event', 'event_espresso'), |
|
192 | + $singular_name |
|
193 | + ), |
|
194 | + 'search_items' => sprintf( |
|
195 | + esc_html_x('Search %s', 'Search Events', 'event_espresso'), |
|
196 | + $plural_name |
|
197 | + ), |
|
198 | + 'not_found' => sprintf( |
|
199 | + esc_html_x('No %s found', 'No Events found', 'event_espresso'), |
|
200 | + $plural_name |
|
201 | + ), |
|
202 | + 'not_found_in_trash' => sprintf( |
|
203 | + esc_html_x('No %s found in Trash', 'No Events found in Trash', 'event_espresso'), |
|
204 | + $plural_name |
|
205 | + ), |
|
206 | + 'parent_item_colon' => '', |
|
207 | + 'menu_name' => $plural_name, |
|
208 | + ); |
|
209 | + } |
|
210 | 210 | |
211 | 211 | |
212 | - /** |
|
213 | - * @param array $labels |
|
214 | - * @param string $post_type |
|
215 | - * @param string $plural_slug |
|
216 | - * @return array |
|
217 | - */ |
|
218 | - private function getDefaultArguments(array $labels, $post_type, $plural_slug) |
|
219 | - { |
|
220 | - return array( |
|
221 | - 'labels' => $labels, |
|
222 | - 'public' => true, |
|
223 | - 'publicly_queryable' => true, |
|
224 | - 'show_ui' => false, |
|
225 | - 'show_ee_ui' => true, |
|
226 | - 'show_in_menu' => false, |
|
227 | - 'show_in_nav_menus' => false, |
|
228 | - 'query_var' => true, |
|
229 | - 'rewrite' => apply_filters( |
|
230 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_RegisterCustomPostTypes__getDefaultArguments__rewrite', |
|
231 | - // legacy filter applied for now, |
|
232 | - // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice |
|
233 | - apply_filters( |
|
234 | - 'FHEE__EE_Register_CPTs__register_CPT__rewrite', |
|
235 | - array('slug' => $plural_slug), |
|
236 | - $post_type |
|
237 | - ), |
|
238 | - $post_type, |
|
239 | - $plural_slug |
|
240 | - ), |
|
241 | - 'capability_type' => 'post', |
|
242 | - 'map_meta_cap' => true, |
|
243 | - 'has_archive' => true, |
|
244 | - 'hierarchical' => false, |
|
245 | - 'menu_position' => null, |
|
246 | - 'supports' => array( |
|
247 | - 'title', |
|
248 | - 'editor', |
|
249 | - 'author', |
|
250 | - 'thumbnail', |
|
251 | - 'excerpt', |
|
252 | - 'custom-fields', |
|
253 | - 'comments', |
|
254 | - ), |
|
255 | - ); |
|
256 | - } |
|
212 | + /** |
|
213 | + * @param array $labels |
|
214 | + * @param string $post_type |
|
215 | + * @param string $plural_slug |
|
216 | + * @return array |
|
217 | + */ |
|
218 | + private function getDefaultArguments(array $labels, $post_type, $plural_slug) |
|
219 | + { |
|
220 | + return array( |
|
221 | + 'labels' => $labels, |
|
222 | + 'public' => true, |
|
223 | + 'publicly_queryable' => true, |
|
224 | + 'show_ui' => false, |
|
225 | + 'show_ee_ui' => true, |
|
226 | + 'show_in_menu' => false, |
|
227 | + 'show_in_nav_menus' => false, |
|
228 | + 'query_var' => true, |
|
229 | + 'rewrite' => apply_filters( |
|
230 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_RegisterCustomPostTypes__getDefaultArguments__rewrite', |
|
231 | + // legacy filter applied for now, |
|
232 | + // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice |
|
233 | + apply_filters( |
|
234 | + 'FHEE__EE_Register_CPTs__register_CPT__rewrite', |
|
235 | + array('slug' => $plural_slug), |
|
236 | + $post_type |
|
237 | + ), |
|
238 | + $post_type, |
|
239 | + $plural_slug |
|
240 | + ), |
|
241 | + 'capability_type' => 'post', |
|
242 | + 'map_meta_cap' => true, |
|
243 | + 'has_archive' => true, |
|
244 | + 'hierarchical' => false, |
|
245 | + 'menu_position' => null, |
|
246 | + 'supports' => array( |
|
247 | + 'title', |
|
248 | + 'editor', |
|
249 | + 'author', |
|
250 | + 'thumbnail', |
|
251 | + 'excerpt', |
|
252 | + 'custom-fields', |
|
253 | + 'comments', |
|
254 | + ), |
|
255 | + ); |
|
256 | + } |
|
257 | 257 | } |
@@ -16,26 +16,26 @@ |
||
16 | 16 | class InvalidCollectionIdentifierException extends OutOfBoundsException |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * InvalidCollectionIdentifierException constructor. |
|
21 | - * |
|
22 | - * @param $identifier |
|
23 | - * @param string $message |
|
24 | - * @param int $code |
|
25 | - * @param Exception|null $previous |
|
26 | - */ |
|
27 | - public function __construct($identifier, $message = '', $code = 0, Exception $previous = null) |
|
28 | - { |
|
29 | - if (empty($message)) { |
|
30 | - $message = sprintf( |
|
31 | - __( |
|
32 | - 'The supplied identifier "%1$s" does not exist within this collection. |
|
19 | + /** |
|
20 | + * InvalidCollectionIdentifierException constructor. |
|
21 | + * |
|
22 | + * @param $identifier |
|
23 | + * @param string $message |
|
24 | + * @param int $code |
|
25 | + * @param Exception|null $previous |
|
26 | + */ |
|
27 | + public function __construct($identifier, $message = '', $code = 0, Exception $previous = null) |
|
28 | + { |
|
29 | + if (empty($message)) { |
|
30 | + $message = sprintf( |
|
31 | + __( |
|
32 | + 'The supplied identifier "%1$s" does not exist within this collection. |
|
33 | 33 | You may need to delay adding this asset until the required dependency has been added.', |
34 | - 'event_espresso' |
|
35 | - ), |
|
36 | - $identifier |
|
37 | - ); |
|
38 | - } |
|
39 | - parent::__construct($message, $code, $previous); |
|
40 | - } |
|
34 | + 'event_espresso' |
|
35 | + ), |
|
36 | + $identifier |
|
37 | + ); |
|
38 | + } |
|
39 | + parent::__construct($message, $code, $previous); |
|
40 | + } |
|
41 | 41 | } |
@@ -16,25 +16,25 @@ |
||
16 | 16 | class DuplicateCollectionIdentifierException extends OutOfRangeException |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * DuplicateCollectionIdentifierException constructor. |
|
21 | - * |
|
22 | - * @param $identifier |
|
23 | - * @param string $message |
|
24 | - * @param int $code |
|
25 | - * @param Exception|null $previous |
|
26 | - */ |
|
27 | - public function __construct($identifier, $message = '', $code = 0, Exception $previous = null) |
|
28 | - { |
|
29 | - if (empty($message)) { |
|
30 | - $message = sprintf( |
|
31 | - __( |
|
32 | - 'The supplied identifier "%1$s" already exists within this collection.', |
|
33 | - 'event_espresso' |
|
34 | - ), |
|
35 | - $identifier |
|
36 | - ); |
|
37 | - } |
|
38 | - parent::__construct($message, $code, $previous); |
|
39 | - } |
|
19 | + /** |
|
20 | + * DuplicateCollectionIdentifierException constructor. |
|
21 | + * |
|
22 | + * @param $identifier |
|
23 | + * @param string $message |
|
24 | + * @param int $code |
|
25 | + * @param Exception|null $previous |
|
26 | + */ |
|
27 | + public function __construct($identifier, $message = '', $code = 0, Exception $previous = null) |
|
28 | + { |
|
29 | + if (empty($message)) { |
|
30 | + $message = sprintf( |
|
31 | + __( |
|
32 | + 'The supplied identifier "%1$s" already exists within this collection.', |
|
33 | + 'event_espresso' |
|
34 | + ), |
|
35 | + $identifier |
|
36 | + ); |
|
37 | + } |
|
38 | + parent::__construct($message, $code, $previous); |
|
39 | + } |
|
40 | 40 | } |
@@ -21,86 +21,86 @@ |
||
21 | 21 | { |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * AssetCollection constructor |
|
26 | - * |
|
27 | - * @throws InvalidInterfaceException |
|
28 | - */ |
|
29 | - public function __construct() |
|
30 | - { |
|
31 | - parent::__construct('EventEspresso\core\domain\values\assets\Asset'); |
|
32 | - } |
|
24 | + /** |
|
25 | + * AssetCollection constructor |
|
26 | + * |
|
27 | + * @throws InvalidInterfaceException |
|
28 | + */ |
|
29 | + public function __construct() |
|
30 | + { |
|
31 | + parent::__construct('EventEspresso\core\domain\values\assets\Asset'); |
|
32 | + } |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * @return StylesheetAsset[] |
|
37 | - * @since $VID:$ |
|
38 | - */ |
|
39 | - public function getStylesheetAssets() |
|
40 | - { |
|
41 | - return $this->getAssetsOfType(Asset::TYPE_CSS); |
|
42 | - } |
|
35 | + /** |
|
36 | + * @return StylesheetAsset[] |
|
37 | + * @since $VID:$ |
|
38 | + */ |
|
39 | + public function getStylesheetAssets() |
|
40 | + { |
|
41 | + return $this->getAssetsOfType(Asset::TYPE_CSS); |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @return JavascriptAsset[] |
|
47 | - * @since $VID:$ |
|
48 | - */ |
|
49 | - public function getJavascriptAssets() |
|
50 | - { |
|
51 | - return $this->getAssetsOfType(Asset::TYPE_JS); |
|
52 | - } |
|
45 | + /** |
|
46 | + * @return JavascriptAsset[] |
|
47 | + * @since $VID:$ |
|
48 | + */ |
|
49 | + public function getJavascriptAssets() |
|
50 | + { |
|
51 | + return $this->getAssetsOfType(Asset::TYPE_JS); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * @return ManifestFile[] |
|
57 | - * @since $VID:$ |
|
58 | - */ |
|
59 | - public function getManifestFiles() |
|
60 | - { |
|
61 | - return $this->getAssetsOfType(Asset::TYPE_MANIFEST); |
|
62 | - } |
|
55 | + /** |
|
56 | + * @return ManifestFile[] |
|
57 | + * @since $VID:$ |
|
58 | + */ |
|
59 | + public function getManifestFiles() |
|
60 | + { |
|
61 | + return $this->getAssetsOfType(Asset::TYPE_MANIFEST); |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * @param $type |
|
67 | - * @return array |
|
68 | - * @since $VID:$ |
|
69 | - */ |
|
70 | - protected function getAssetsOfType($type) |
|
71 | - { |
|
72 | - $files = array(); |
|
73 | - $this->rewind(); |
|
74 | - while ($this->valid()) { |
|
75 | - /** @var \EventEspresso\core\domain\values\assets\Asset $asset */ |
|
76 | - $asset = $this->current(); |
|
77 | - if ($asset->type() === $type) { |
|
78 | - $files[ $asset->handle() ] = $asset; |
|
79 | - } |
|
80 | - $this->next(); |
|
81 | - } |
|
82 | - $this->rewind(); |
|
83 | - return $files; |
|
84 | - } |
|
65 | + /** |
|
66 | + * @param $type |
|
67 | + * @return array |
|
68 | + * @since $VID:$ |
|
69 | + */ |
|
70 | + protected function getAssetsOfType($type) |
|
71 | + { |
|
72 | + $files = array(); |
|
73 | + $this->rewind(); |
|
74 | + while ($this->valid()) { |
|
75 | + /** @var \EventEspresso\core\domain\values\assets\Asset $asset */ |
|
76 | + $asset = $this->current(); |
|
77 | + if ($asset->type() === $type) { |
|
78 | + $files[ $asset->handle() ] = $asset; |
|
79 | + } |
|
80 | + $this->next(); |
|
81 | + } |
|
82 | + $this->rewind(); |
|
83 | + return $files; |
|
84 | + } |
|
85 | 85 | |
86 | 86 | |
87 | - /** |
|
88 | - * @return JavascriptAsset[] |
|
89 | - * @since $VID:$ |
|
90 | - */ |
|
91 | - public function getJavascriptAssetsWithData() |
|
92 | - { |
|
93 | - $files = array(); |
|
94 | - $this->rewind(); |
|
95 | - while ($this->valid()) { |
|
96 | - /** @var \EventEspresso\core\domain\values\assets\JavascriptAsset $asset */ |
|
97 | - $asset = $this->current(); |
|
98 | - if ($asset->type() === Asset::TYPE_JS && $asset->hasLocalizedData()) { |
|
99 | - $files[ $asset->handle() ] = $asset; |
|
100 | - } |
|
101 | - $this->next(); |
|
102 | - } |
|
103 | - $this->rewind(); |
|
104 | - return $files; |
|
105 | - } |
|
87 | + /** |
|
88 | + * @return JavascriptAsset[] |
|
89 | + * @since $VID:$ |
|
90 | + */ |
|
91 | + public function getJavascriptAssetsWithData() |
|
92 | + { |
|
93 | + $files = array(); |
|
94 | + $this->rewind(); |
|
95 | + while ($this->valid()) { |
|
96 | + /** @var \EventEspresso\core\domain\values\assets\JavascriptAsset $asset */ |
|
97 | + $asset = $this->current(); |
|
98 | + if ($asset->type() === Asset::TYPE_JS && $asset->hasLocalizedData()) { |
|
99 | + $files[ $asset->handle() ] = $asset; |
|
100 | + } |
|
101 | + $this->next(); |
|
102 | + } |
|
103 | + $this->rewind(); |
|
104 | + return $files; |
|
105 | + } |
|
106 | 106 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | /** @var \EventEspresso\core\domain\values\assets\Asset $asset */ |
76 | 76 | $asset = $this->current(); |
77 | 77 | if ($asset->type() === $type) { |
78 | - $files[ $asset->handle() ] = $asset; |
|
78 | + $files[$asset->handle()] = $asset; |
|
79 | 79 | } |
80 | 80 | $this->next(); |
81 | 81 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | /** @var \EventEspresso\core\domain\values\assets\JavascriptAsset $asset */ |
97 | 97 | $asset = $this->current(); |
98 | 98 | if ($asset->type() === Asset::TYPE_JS && $asset->hasLocalizedData()) { |
99 | - $files[ $asset->handle() ] = $asset; |
|
99 | + $files[$asset->handle()] = $asset; |
|
100 | 100 | } |
101 | 101 | $this->next(); |
102 | 102 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $this->removeAlreadyRegisteredDataForScriptHandles(); |
146 | 146 | wp_add_inline_script( |
147 | 147 | 'eejs-core', |
148 | - 'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)), |
|
148 | + 'var eejsdata='.wp_json_encode(array('data' => $this->jsdata)), |
|
149 | 149 | 'before' |
150 | 150 | ); |
151 | 151 | $scripts = $this->assets->getJavascriptAssetsWithData(); |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | public function addData($key, $value) |
175 | 175 | { |
176 | 176 | if ($this->verifyDataNotExisting($key)) { |
177 | - $this->jsdata[ $key ] = $value; |
|
177 | + $this->jsdata[$key] = $value; |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
@@ -195,8 +195,8 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function pushData($key, $value) |
197 | 197 | { |
198 | - if (isset($this->jsdata[ $key ]) |
|
199 | - && ! is_array($this->jsdata[ $key ]) |
|
198 | + if (isset($this->jsdata[$key]) |
|
199 | + && ! is_array($this->jsdata[$key]) |
|
200 | 200 | ) { |
201 | 201 | throw new InvalidArgumentException( |
202 | 202 | sprintf( |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | ) |
211 | 211 | ); |
212 | 212 | } |
213 | - $this->jsdata[ $key ][] = $value; |
|
213 | + $this->jsdata[$key][] = $value; |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | |
@@ -224,11 +224,11 @@ discard block |
||
224 | 224 | */ |
225 | 225 | public function addTemplate($template_reference, $template_content) |
226 | 226 | { |
227 | - if (! isset($this->jsdata['templates'])) { |
|
227 | + if ( ! isset($this->jsdata['templates'])) { |
|
228 | 228 | $this->jsdata['templates'] = array(); |
229 | 229 | } |
230 | 230 | //no overrides allowed. |
231 | - if (isset($this->jsdata['templates'][ $template_reference ])) { |
|
231 | + if (isset($this->jsdata['templates'][$template_reference])) { |
|
232 | 232 | throw new InvalidArgumentException( |
233 | 233 | sprintf( |
234 | 234 | __( |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | ) |
240 | 240 | ); |
241 | 241 | } |
242 | - $this->jsdata['templates'][ $template_reference ] = $template_content; |
|
242 | + $this->jsdata['templates'][$template_reference] = $template_content; |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | */ |
252 | 252 | public function getTemplate($template_reference) |
253 | 253 | { |
254 | - return isset($this->jsdata['templates'][ $template_reference ]) |
|
255 | - ? $this->jsdata['templates'][ $template_reference ] |
|
254 | + return isset($this->jsdata['templates'][$template_reference]) |
|
255 | + ? $this->jsdata['templates'][$template_reference] |
|
256 | 256 | : ''; |
257 | 257 | } |
258 | 258 | |
@@ -265,8 +265,8 @@ discard block |
||
265 | 265 | */ |
266 | 266 | public function getData($key) |
267 | 267 | { |
268 | - return isset($this->jsdata[ $key ]) |
|
269 | - ? $this->jsdata[ $key ] |
|
268 | + return isset($this->jsdata[$key]) |
|
269 | + ? $this->jsdata[$key] |
|
270 | 270 | : false; |
271 | 271 | } |
272 | 272 | |
@@ -281,8 +281,8 @@ discard block |
||
281 | 281 | */ |
282 | 282 | protected function verifyDataNotExisting($key) |
283 | 283 | { |
284 | - if (isset($this->jsdata[ $key ])) { |
|
285 | - if (is_array($this->jsdata[ $key ])) { |
|
284 | + if (isset($this->jsdata[$key])) { |
|
285 | + if (is_array($this->jsdata[$key])) { |
|
286 | 286 | throw new InvalidArgumentException( |
287 | 287 | sprintf( |
288 | 288 | __( |
@@ -325,11 +325,11 @@ discard block |
||
325 | 325 | public function getAssetUrl($namespace, $chunk_name, $asset_type) |
326 | 326 | { |
327 | 327 | $url = isset( |
328 | - $this->manifest_data[ $namespace ][ $chunk_name ][ $asset_type ], |
|
329 | - $this->manifest_data[ $namespace ]['url_base'] |
|
328 | + $this->manifest_data[$namespace][$chunk_name][$asset_type], |
|
329 | + $this->manifest_data[$namespace]['url_base'] |
|
330 | 330 | ) |
331 | - ? $this->manifest_data[ $namespace ]['url_base'] |
|
332 | - . $this->manifest_data[ $namespace ][ $chunk_name ][ $asset_type ] |
|
331 | + ? $this->manifest_data[$namespace]['url_base'] |
|
332 | + . $this->manifest_data[$namespace][$chunk_name][$asset_type] |
|
333 | 333 | : $chunk_name; |
334 | 334 | return apply_filters( |
335 | 335 | 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | $this->registerManifestFile( |
380 | 380 | $manifest_file->assetNamespace(), |
381 | 381 | $manifest_file->urlBase(), |
382 | - $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST |
|
382 | + $manifest_file->filepath().Registry::FILE_NAME_BUILD_MANIFEST |
|
383 | 383 | ); |
384 | 384 | } |
385 | 385 | } |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | */ |
398 | 398 | public function registerManifestFile($namespace, $url_base, $manifest_file) |
399 | 399 | { |
400 | - if (isset($this->manifest_data[ $namespace ])) { |
|
400 | + if (isset($this->manifest_data[$namespace])) { |
|
401 | 401 | throw new InvalidArgumentException( |
402 | 402 | sprintf( |
403 | 403 | esc_html__( |
@@ -428,9 +428,9 @@ discard block |
||
428 | 428 | } |
429 | 429 | return; |
430 | 430 | } |
431 | - $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file); |
|
432 | - if (! isset($this->manifest_data[ $namespace ]['url_base'])) { |
|
433 | - $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base); |
|
431 | + $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file); |
|
432 | + if ( ! isset($this->manifest_data[$namespace]['url_base'])) { |
|
433 | + $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base); |
|
434 | 434 | } |
435 | 435 | } |
436 | 436 | |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | */ |
446 | 446 | private function decodeManifestFile($manifest_file) |
447 | 447 | { |
448 | - if (! file_exists($manifest_file)) { |
|
448 | + if ( ! file_exists($manifest_file)) { |
|
449 | 449 | throw new InvalidFilePathException($manifest_file); |
450 | 450 | } |
451 | 451 | return json_decode(file_get_contents($manifest_file), true); |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | */ |
460 | 460 | private function addRegisteredScriptHandlesWithData($script_handle) |
461 | 461 | { |
462 | - $this->script_handles_with_data[ $script_handle ] = $script_handle; |
|
462 | + $this->script_handles_with_data[$script_handle] = $script_handle; |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | |
@@ -485,23 +485,23 @@ discard block |
||
485 | 485 | */ |
486 | 486 | private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
487 | 487 | { |
488 | - if (isset($this->script_handles_with_data[ $script_handle ])) { |
|
488 | + if (isset($this->script_handles_with_data[$script_handle])) { |
|
489 | 489 | global $wp_scripts; |
490 | 490 | $unset_handle = false; |
491 | 491 | if ($wp_scripts->get_data($script_handle, 'data')) { |
492 | - unset($wp_scripts->registered[ $script_handle ]->extra['data']); |
|
492 | + unset($wp_scripts->registered[$script_handle]->extra['data']); |
|
493 | 493 | $unset_handle = true; |
494 | 494 | } |
495 | 495 | //deal with inline_scripts |
496 | 496 | if ($wp_scripts->get_data($script_handle, 'before')) { |
497 | - unset($wp_scripts->registered[ $script_handle ]->extra['before']); |
|
497 | + unset($wp_scripts->registered[$script_handle]->extra['before']); |
|
498 | 498 | $unset_handle = true; |
499 | 499 | } |
500 | 500 | if ($wp_scripts->get_data($script_handle, 'after')) { |
501 | - unset($wp_scripts->registered[ $script_handle ]->extra['after']); |
|
501 | + unset($wp_scripts->registered[$script_handle]->extra['after']); |
|
502 | 502 | } |
503 | 503 | if ($unset_handle) { |
504 | - unset($this->script_handles_with_data[ $script_handle ]); |
|
504 | + unset($this->script_handles_with_data[$script_handle]); |
|
505 | 505 | } |
506 | 506 | } |
507 | 507 | } |
@@ -23,559 +23,559 @@ |
||
23 | 23 | class Registry |
24 | 24 | { |
25 | 25 | |
26 | - const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json'; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var AssetCollection $assets |
|
30 | - */ |
|
31 | - protected $assets; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var I18nRegistry |
|
35 | - */ |
|
36 | - private $i18n_registry; |
|
37 | - |
|
38 | - /** |
|
39 | - * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
40 | - * |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - protected $jsdata = array(); |
|
44 | - |
|
45 | - /** |
|
46 | - * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
47 | - * page source. |
|
48 | - * |
|
49 | - * @var array |
|
50 | - */ |
|
51 | - private $script_handles_with_data = array(); |
|
52 | - |
|
53 | - /** |
|
54 | - * Holds the manifest data obtained from registered manifest files. |
|
55 | - * Manifests are maps of asset chunk name to actual built asset file names. |
|
56 | - * Shape of this array is: |
|
57 | - * array( |
|
58 | - * 'some_namespace_slug' => array( |
|
59 | - * 'some_chunk_name' => array( |
|
60 | - * 'js' => 'filename.js' |
|
61 | - * 'css' => 'filename.js' |
|
62 | - * ), |
|
63 | - * 'url_base' => 'https://baseurl.com/to/assets |
|
64 | - * ) |
|
65 | - * ) |
|
66 | - * |
|
67 | - * @var array |
|
68 | - */ |
|
69 | - private $manifest_data = array(); |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * Registry constructor. |
|
74 | - * Hooking into WP actions for script registry. |
|
75 | - * |
|
76 | - * @param AssetCollection $assets |
|
77 | - * @param I18nRegistry $i18n_registry |
|
78 | - */ |
|
79 | - public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry) |
|
80 | - { |
|
81 | - $this->assets = $assets; |
|
82 | - $this->i18n_registry = $i18n_registry; |
|
83 | - add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
84 | - add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
85 | - add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
86 | - add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
87 | - add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
88 | - add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
89 | - add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
90 | - add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n |
|
96 | - * translation handling. |
|
97 | - * |
|
98 | - * @return I18nRegistry |
|
99 | - */ |
|
100 | - public function getI18nRegistry() |
|
101 | - { |
|
102 | - return $this->i18n_registry; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * Callback for the wp_enqueue_scripts actions used to register assets. |
|
108 | - * |
|
109 | - * @since $VID:$ |
|
110 | - * @throws Exception |
|
111 | - */ |
|
112 | - public function registerScriptsAndStyles() |
|
113 | - { |
|
114 | - try { |
|
115 | - $this->registerScripts($this->assets->getJavascriptAssets()); |
|
116 | - $this->registerStyles($this->assets->getStylesheetAssets()); |
|
117 | - } catch (Exception $exception) { |
|
118 | - new ExceptionStackTraceDisplay($exception); |
|
119 | - } |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * Registers JS assets with WP core |
|
125 | - * |
|
126 | - * @since $VID:$ |
|
127 | - * @param JavascriptAsset[] $scripts |
|
128 | - * @throws AssetRegistrationException |
|
129 | - * @throws InvalidDataTypeException |
|
130 | - */ |
|
131 | - public function registerScripts(array $scripts) |
|
132 | - { |
|
133 | - foreach ($scripts as $script) { |
|
134 | - // skip to next script if this has already been done |
|
135 | - if ($script->isRegistered()) { |
|
136 | - continue; |
|
137 | - } |
|
138 | - do_action( |
|
139 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
140 | - $script |
|
141 | - ); |
|
142 | - $registered = wp_register_script( |
|
143 | - $script->handle(), |
|
144 | - $script->source(), |
|
145 | - $script->dependencies(), |
|
146 | - $script->version(), |
|
147 | - $script->loadInFooter() |
|
148 | - ); |
|
149 | - if (defined('EE_DEBUG') && EE_DEBUG && ! $registered) { |
|
150 | - throw new AssetRegistrationException($script->handle()); |
|
151 | - } |
|
152 | - $script->setRegistered($registered); |
|
153 | - if ($script->requiresTranslation()) { |
|
154 | - $this->registerTranslation($script->handle()); |
|
155 | - } |
|
156 | - do_action( |
|
157 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script', |
|
158 | - $script |
|
159 | - ); |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * Registers CSS assets with WP core |
|
166 | - * |
|
167 | - * @since $VID:$ |
|
168 | - * @param StylesheetAsset[] $styles |
|
169 | - * @throws InvalidDataTypeException |
|
170 | - */ |
|
171 | - public function registerStyles(array $styles) |
|
172 | - { |
|
173 | - foreach ($styles as $style) { |
|
174 | - // skip to next style if this has already been done |
|
175 | - if ($style->isRegistered()) { |
|
176 | - continue; |
|
177 | - } |
|
178 | - do_action( |
|
179 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style', |
|
180 | - $style |
|
181 | - ); |
|
182 | - wp_enqueue_style( |
|
183 | - $style->handle(), |
|
184 | - $style->source(), |
|
185 | - $style->dependencies(), |
|
186 | - $style->version(), |
|
187 | - $style->media() |
|
188 | - ); |
|
189 | - $style->setRegistered(); |
|
190 | - do_action( |
|
191 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style', |
|
192 | - $style |
|
193 | - ); |
|
194 | - } |
|
195 | - } |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * Call back for the script print in frontend and backend. |
|
200 | - * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
201 | - * |
|
202 | - * @since 4.9.31.rc.015 |
|
203 | - */ |
|
204 | - public function enqueueData() |
|
205 | - { |
|
206 | - $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
207 | - wp_add_inline_script( |
|
208 | - 'eejs-core', |
|
209 | - 'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)), |
|
210 | - 'before' |
|
211 | - ); |
|
212 | - $scripts = $this->assets->getJavascriptAssetsWithData(); |
|
213 | - foreach ($scripts as $script) { |
|
214 | - $this->addRegisteredScriptHandlesWithData($script->handle()); |
|
215 | - if ($script->hasLocalizationCallback()) { |
|
216 | - $localize = $script->localizationCallback(); |
|
217 | - $localize(); |
|
218 | - } |
|
219 | - } |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * Used to add data to eejs.data object. |
|
225 | - * Note: Overriding existing data is not allowed. |
|
226 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
227 | - * If the data you add is something like this: |
|
228 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
229 | - * It will be exposed in the page source as: |
|
230 | - * eejs.data.my_plugin_data.foo == gar |
|
231 | - * |
|
232 | - * @param string $key Key used to access your data |
|
233 | - * @param string|array $value Value to attach to key |
|
234 | - * @throws InvalidArgumentException |
|
235 | - */ |
|
236 | - public function addData($key, $value) |
|
237 | - { |
|
238 | - if ($this->verifyDataNotExisting($key)) { |
|
239 | - $this->jsdata[ $key ] = $value; |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
246 | - * elements in an array. |
|
247 | - * When you use this method, the value you include will be appended to the end of an array on $key. |
|
248 | - * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
249 | - * object like this, eejs.data.test = [ my_data, |
|
250 | - * ] |
|
251 | - * If there has already been a scalar value attached to the data object given key, then |
|
252 | - * this will throw an exception. |
|
253 | - * |
|
254 | - * @param string $key Key to attach data to. |
|
255 | - * @param string|array $value Value being registered. |
|
256 | - * @throws InvalidArgumentException |
|
257 | - */ |
|
258 | - public function pushData($key, $value) |
|
259 | - { |
|
260 | - if (isset($this->jsdata[ $key ]) |
|
261 | - && ! is_array($this->jsdata[ $key ]) |
|
262 | - ) { |
|
263 | - throw new InvalidArgumentException( |
|
264 | - sprintf( |
|
265 | - __( |
|
266 | - 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
26 | + const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json'; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var AssetCollection $assets |
|
30 | + */ |
|
31 | + protected $assets; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var I18nRegistry |
|
35 | + */ |
|
36 | + private $i18n_registry; |
|
37 | + |
|
38 | + /** |
|
39 | + * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
40 | + * |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + protected $jsdata = array(); |
|
44 | + |
|
45 | + /** |
|
46 | + * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
47 | + * page source. |
|
48 | + * |
|
49 | + * @var array |
|
50 | + */ |
|
51 | + private $script_handles_with_data = array(); |
|
52 | + |
|
53 | + /** |
|
54 | + * Holds the manifest data obtained from registered manifest files. |
|
55 | + * Manifests are maps of asset chunk name to actual built asset file names. |
|
56 | + * Shape of this array is: |
|
57 | + * array( |
|
58 | + * 'some_namespace_slug' => array( |
|
59 | + * 'some_chunk_name' => array( |
|
60 | + * 'js' => 'filename.js' |
|
61 | + * 'css' => 'filename.js' |
|
62 | + * ), |
|
63 | + * 'url_base' => 'https://baseurl.com/to/assets |
|
64 | + * ) |
|
65 | + * ) |
|
66 | + * |
|
67 | + * @var array |
|
68 | + */ |
|
69 | + private $manifest_data = array(); |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * Registry constructor. |
|
74 | + * Hooking into WP actions for script registry. |
|
75 | + * |
|
76 | + * @param AssetCollection $assets |
|
77 | + * @param I18nRegistry $i18n_registry |
|
78 | + */ |
|
79 | + public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry) |
|
80 | + { |
|
81 | + $this->assets = $assets; |
|
82 | + $this->i18n_registry = $i18n_registry; |
|
83 | + add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
84 | + add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
85 | + add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
86 | + add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
87 | + add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
88 | + add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
89 | + add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
90 | + add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n |
|
96 | + * translation handling. |
|
97 | + * |
|
98 | + * @return I18nRegistry |
|
99 | + */ |
|
100 | + public function getI18nRegistry() |
|
101 | + { |
|
102 | + return $this->i18n_registry; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * Callback for the wp_enqueue_scripts actions used to register assets. |
|
108 | + * |
|
109 | + * @since $VID:$ |
|
110 | + * @throws Exception |
|
111 | + */ |
|
112 | + public function registerScriptsAndStyles() |
|
113 | + { |
|
114 | + try { |
|
115 | + $this->registerScripts($this->assets->getJavascriptAssets()); |
|
116 | + $this->registerStyles($this->assets->getStylesheetAssets()); |
|
117 | + } catch (Exception $exception) { |
|
118 | + new ExceptionStackTraceDisplay($exception); |
|
119 | + } |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * Registers JS assets with WP core |
|
125 | + * |
|
126 | + * @since $VID:$ |
|
127 | + * @param JavascriptAsset[] $scripts |
|
128 | + * @throws AssetRegistrationException |
|
129 | + * @throws InvalidDataTypeException |
|
130 | + */ |
|
131 | + public function registerScripts(array $scripts) |
|
132 | + { |
|
133 | + foreach ($scripts as $script) { |
|
134 | + // skip to next script if this has already been done |
|
135 | + if ($script->isRegistered()) { |
|
136 | + continue; |
|
137 | + } |
|
138 | + do_action( |
|
139 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
140 | + $script |
|
141 | + ); |
|
142 | + $registered = wp_register_script( |
|
143 | + $script->handle(), |
|
144 | + $script->source(), |
|
145 | + $script->dependencies(), |
|
146 | + $script->version(), |
|
147 | + $script->loadInFooter() |
|
148 | + ); |
|
149 | + if (defined('EE_DEBUG') && EE_DEBUG && ! $registered) { |
|
150 | + throw new AssetRegistrationException($script->handle()); |
|
151 | + } |
|
152 | + $script->setRegistered($registered); |
|
153 | + if ($script->requiresTranslation()) { |
|
154 | + $this->registerTranslation($script->handle()); |
|
155 | + } |
|
156 | + do_action( |
|
157 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script', |
|
158 | + $script |
|
159 | + ); |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * Registers CSS assets with WP core |
|
166 | + * |
|
167 | + * @since $VID:$ |
|
168 | + * @param StylesheetAsset[] $styles |
|
169 | + * @throws InvalidDataTypeException |
|
170 | + */ |
|
171 | + public function registerStyles(array $styles) |
|
172 | + { |
|
173 | + foreach ($styles as $style) { |
|
174 | + // skip to next style if this has already been done |
|
175 | + if ($style->isRegistered()) { |
|
176 | + continue; |
|
177 | + } |
|
178 | + do_action( |
|
179 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style', |
|
180 | + $style |
|
181 | + ); |
|
182 | + wp_enqueue_style( |
|
183 | + $style->handle(), |
|
184 | + $style->source(), |
|
185 | + $style->dependencies(), |
|
186 | + $style->version(), |
|
187 | + $style->media() |
|
188 | + ); |
|
189 | + $style->setRegistered(); |
|
190 | + do_action( |
|
191 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style', |
|
192 | + $style |
|
193 | + ); |
|
194 | + } |
|
195 | + } |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * Call back for the script print in frontend and backend. |
|
200 | + * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
201 | + * |
|
202 | + * @since 4.9.31.rc.015 |
|
203 | + */ |
|
204 | + public function enqueueData() |
|
205 | + { |
|
206 | + $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
207 | + wp_add_inline_script( |
|
208 | + 'eejs-core', |
|
209 | + 'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)), |
|
210 | + 'before' |
|
211 | + ); |
|
212 | + $scripts = $this->assets->getJavascriptAssetsWithData(); |
|
213 | + foreach ($scripts as $script) { |
|
214 | + $this->addRegisteredScriptHandlesWithData($script->handle()); |
|
215 | + if ($script->hasLocalizationCallback()) { |
|
216 | + $localize = $script->localizationCallback(); |
|
217 | + $localize(); |
|
218 | + } |
|
219 | + } |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * Used to add data to eejs.data object. |
|
225 | + * Note: Overriding existing data is not allowed. |
|
226 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
227 | + * If the data you add is something like this: |
|
228 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
229 | + * It will be exposed in the page source as: |
|
230 | + * eejs.data.my_plugin_data.foo == gar |
|
231 | + * |
|
232 | + * @param string $key Key used to access your data |
|
233 | + * @param string|array $value Value to attach to key |
|
234 | + * @throws InvalidArgumentException |
|
235 | + */ |
|
236 | + public function addData($key, $value) |
|
237 | + { |
|
238 | + if ($this->verifyDataNotExisting($key)) { |
|
239 | + $this->jsdata[ $key ] = $value; |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
246 | + * elements in an array. |
|
247 | + * When you use this method, the value you include will be appended to the end of an array on $key. |
|
248 | + * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
249 | + * object like this, eejs.data.test = [ my_data, |
|
250 | + * ] |
|
251 | + * If there has already been a scalar value attached to the data object given key, then |
|
252 | + * this will throw an exception. |
|
253 | + * |
|
254 | + * @param string $key Key to attach data to. |
|
255 | + * @param string|array $value Value being registered. |
|
256 | + * @throws InvalidArgumentException |
|
257 | + */ |
|
258 | + public function pushData($key, $value) |
|
259 | + { |
|
260 | + if (isset($this->jsdata[ $key ]) |
|
261 | + && ! is_array($this->jsdata[ $key ]) |
|
262 | + ) { |
|
263 | + throw new InvalidArgumentException( |
|
264 | + sprintf( |
|
265 | + __( |
|
266 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
267 | 267 | push values to this data element when it is an array.', |
268 | - 'event_espresso' |
|
269 | - ), |
|
270 | - $key, |
|
271 | - __METHOD__ |
|
272 | - ) |
|
273 | - ); |
|
274 | - } |
|
275 | - $this->jsdata[ $key ][] = $value; |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * Used to set content used by javascript for a template. |
|
281 | - * Note: Overrides of existing registered templates are not allowed. |
|
282 | - * |
|
283 | - * @param string $template_reference |
|
284 | - * @param string $template_content |
|
285 | - * @throws InvalidArgumentException |
|
286 | - */ |
|
287 | - public function addTemplate($template_reference, $template_content) |
|
288 | - { |
|
289 | - if (! isset($this->jsdata['templates'])) { |
|
290 | - $this->jsdata['templates'] = array(); |
|
291 | - } |
|
292 | - //no overrides allowed. |
|
293 | - if (isset($this->jsdata['templates'][ $template_reference ])) { |
|
294 | - throw new InvalidArgumentException( |
|
295 | - sprintf( |
|
296 | - __( |
|
297 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
298 | - 'event_espresso' |
|
299 | - ), |
|
300 | - $template_reference |
|
301 | - ) |
|
302 | - ); |
|
303 | - } |
|
304 | - $this->jsdata['templates'][ $template_reference ] = $template_content; |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * Retrieve the template content already registered for the given reference. |
|
310 | - * |
|
311 | - * @param string $template_reference |
|
312 | - * @return string |
|
313 | - */ |
|
314 | - public function getTemplate($template_reference) |
|
315 | - { |
|
316 | - return isset($this->jsdata['templates'][ $template_reference ]) |
|
317 | - ? $this->jsdata['templates'][ $template_reference ] |
|
318 | - : ''; |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * Retrieve registered data. |
|
324 | - * |
|
325 | - * @param string $key Name of key to attach data to. |
|
326 | - * @return mixed If there is no for the given key, then false is returned. |
|
327 | - */ |
|
328 | - public function getData($key) |
|
329 | - { |
|
330 | - return isset($this->jsdata[ $key ]) |
|
331 | - ? $this->jsdata[ $key ] |
|
332 | - : false; |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * Verifies whether the given data exists already on the jsdata array. |
|
338 | - * Overriding data is not allowed. |
|
339 | - * |
|
340 | - * @param string $key Index for data. |
|
341 | - * @return bool If valid then return true. |
|
342 | - * @throws InvalidArgumentException if data already exists. |
|
343 | - */ |
|
344 | - protected function verifyDataNotExisting($key) |
|
345 | - { |
|
346 | - if (isset($this->jsdata[ $key ])) { |
|
347 | - if (is_array($this->jsdata[ $key ])) { |
|
348 | - throw new InvalidArgumentException( |
|
349 | - sprintf( |
|
350 | - __( |
|
351 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
268 | + 'event_espresso' |
|
269 | + ), |
|
270 | + $key, |
|
271 | + __METHOD__ |
|
272 | + ) |
|
273 | + ); |
|
274 | + } |
|
275 | + $this->jsdata[ $key ][] = $value; |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * Used to set content used by javascript for a template. |
|
281 | + * Note: Overrides of existing registered templates are not allowed. |
|
282 | + * |
|
283 | + * @param string $template_reference |
|
284 | + * @param string $template_content |
|
285 | + * @throws InvalidArgumentException |
|
286 | + */ |
|
287 | + public function addTemplate($template_reference, $template_content) |
|
288 | + { |
|
289 | + if (! isset($this->jsdata['templates'])) { |
|
290 | + $this->jsdata['templates'] = array(); |
|
291 | + } |
|
292 | + //no overrides allowed. |
|
293 | + if (isset($this->jsdata['templates'][ $template_reference ])) { |
|
294 | + throw new InvalidArgumentException( |
|
295 | + sprintf( |
|
296 | + __( |
|
297 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
298 | + 'event_espresso' |
|
299 | + ), |
|
300 | + $template_reference |
|
301 | + ) |
|
302 | + ); |
|
303 | + } |
|
304 | + $this->jsdata['templates'][ $template_reference ] = $template_content; |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * Retrieve the template content already registered for the given reference. |
|
310 | + * |
|
311 | + * @param string $template_reference |
|
312 | + * @return string |
|
313 | + */ |
|
314 | + public function getTemplate($template_reference) |
|
315 | + { |
|
316 | + return isset($this->jsdata['templates'][ $template_reference ]) |
|
317 | + ? $this->jsdata['templates'][ $template_reference ] |
|
318 | + : ''; |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * Retrieve registered data. |
|
324 | + * |
|
325 | + * @param string $key Name of key to attach data to. |
|
326 | + * @return mixed If there is no for the given key, then false is returned. |
|
327 | + */ |
|
328 | + public function getData($key) |
|
329 | + { |
|
330 | + return isset($this->jsdata[ $key ]) |
|
331 | + ? $this->jsdata[ $key ] |
|
332 | + : false; |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * Verifies whether the given data exists already on the jsdata array. |
|
338 | + * Overriding data is not allowed. |
|
339 | + * |
|
340 | + * @param string $key Index for data. |
|
341 | + * @return bool If valid then return true. |
|
342 | + * @throws InvalidArgumentException if data already exists. |
|
343 | + */ |
|
344 | + protected function verifyDataNotExisting($key) |
|
345 | + { |
|
346 | + if (isset($this->jsdata[ $key ])) { |
|
347 | + if (is_array($this->jsdata[ $key ])) { |
|
348 | + throw new InvalidArgumentException( |
|
349 | + sprintf( |
|
350 | + __( |
|
351 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
352 | 352 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
353 | 353 | %2$s method to push your value to the array.', |
354 | - 'event_espresso' |
|
355 | - ), |
|
356 | - $key, |
|
357 | - 'pushData()' |
|
358 | - ) |
|
359 | - ); |
|
360 | - } |
|
361 | - throw new InvalidArgumentException( |
|
362 | - sprintf( |
|
363 | - __( |
|
364 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
354 | + 'event_espresso' |
|
355 | + ), |
|
356 | + $key, |
|
357 | + 'pushData()' |
|
358 | + ) |
|
359 | + ); |
|
360 | + } |
|
361 | + throw new InvalidArgumentException( |
|
362 | + sprintf( |
|
363 | + __( |
|
364 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
365 | 365 | allowed. Consider attaching your value to a different key', |
366 | - 'event_espresso' |
|
367 | - ), |
|
368 | - $key |
|
369 | - ) |
|
370 | - ); |
|
371 | - } |
|
372 | - return true; |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * Get the actual asset path for asset manifests. |
|
378 | - * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
379 | - * |
|
380 | - * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
381 | - * asset file location. |
|
382 | - * @param string $chunk_name |
|
383 | - * @param string $asset_type |
|
384 | - * @return string |
|
385 | - * @since 4.9.59.p |
|
386 | - */ |
|
387 | - public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
388 | - { |
|
389 | - $url = isset( |
|
390 | - $this->manifest_data[ $namespace ][ $chunk_name ][ $asset_type ], |
|
391 | - $this->manifest_data[ $namespace ]['url_base'] |
|
392 | - ) |
|
393 | - ? $this->manifest_data[ $namespace ]['url_base'] |
|
394 | - . $this->manifest_data[ $namespace ][ $chunk_name ][ $asset_type ] |
|
395 | - : $chunk_name; |
|
396 | - return apply_filters( |
|
397 | - 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
398 | - $url, |
|
399 | - $namespace, |
|
400 | - $chunk_name, |
|
401 | - $asset_type |
|
402 | - ); |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * Return the url to a js file for the given namespace and chunk name. |
|
408 | - * |
|
409 | - * @param string $namespace |
|
410 | - * @param string $chunk_name |
|
411 | - * @return string |
|
412 | - */ |
|
413 | - public function getJsUrl($namespace, $chunk_name) |
|
414 | - { |
|
415 | - return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS); |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * Return the url to a css file for the given namespace and chunk name. |
|
421 | - * |
|
422 | - * @param string $namespace |
|
423 | - * @param string $chunk_name |
|
424 | - * @return string |
|
425 | - */ |
|
426 | - public function getCssUrl($namespace, $chunk_name) |
|
427 | - { |
|
428 | - return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS); |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * @since $VID:$ |
|
434 | - * @throws InvalidArgumentException |
|
435 | - * @throws InvalidFilePathException |
|
436 | - */ |
|
437 | - public function registerManifestFiles() |
|
438 | - { |
|
439 | - $manifest_files = $this->assets->getManifestFiles(); |
|
440 | - foreach ($manifest_files as $manifest_file) { |
|
441 | - $this->registerManifestFile( |
|
442 | - $manifest_file->assetNamespace(), |
|
443 | - $manifest_file->urlBase(), |
|
444 | - $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST |
|
445 | - ); |
|
446 | - } |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * Used to register a js/css manifest file with the registered_manifest_files property. |
|
452 | - * |
|
453 | - * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
454 | - * @param string $url_base The url base for the manifest file location. |
|
455 | - * @param string $manifest_file The absolute path to the manifest file. |
|
456 | - * @throws InvalidArgumentException |
|
457 | - * @throws InvalidFilePathException |
|
458 | - * @since 4.9.59.p |
|
459 | - */ |
|
460 | - public function registerManifestFile($namespace, $url_base, $manifest_file) |
|
461 | - { |
|
462 | - if (isset($this->manifest_data[ $namespace ])) { |
|
463 | - throw new InvalidArgumentException( |
|
464 | - sprintf( |
|
465 | - esc_html__( |
|
466 | - 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
467 | - 'event_espresso' |
|
468 | - ), |
|
469 | - $namespace |
|
470 | - ) |
|
471 | - ); |
|
472 | - } |
|
473 | - if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
474 | - if (is_admin()) { |
|
475 | - EE_Error::add_error( |
|
476 | - sprintf( |
|
477 | - esc_html__( |
|
478 | - 'The url given for %1$s assets is invalid. The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant', |
|
479 | - 'event_espresso' |
|
480 | - ), |
|
481 | - 'Event Espresso', |
|
482 | - $url_base, |
|
483 | - 'plugins_url', |
|
484 | - 'WP_PLUGIN_URL' |
|
485 | - ), |
|
486 | - __FILE__, |
|
487 | - __FUNCTION__, |
|
488 | - __LINE__ |
|
489 | - ); |
|
490 | - } |
|
491 | - return; |
|
492 | - } |
|
493 | - $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file); |
|
494 | - if (! isset($this->manifest_data[ $namespace ]['url_base'])) { |
|
495 | - $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base); |
|
496 | - } |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * Decodes json from the provided manifest file. |
|
502 | - * |
|
503 | - * @since 4.9.59.p |
|
504 | - * @param string $manifest_file Path to manifest file. |
|
505 | - * @return array |
|
506 | - * @throws InvalidFilePathException |
|
507 | - */ |
|
508 | - private function decodeManifestFile($manifest_file) |
|
509 | - { |
|
510 | - if (! file_exists($manifest_file)) { |
|
511 | - throw new InvalidFilePathException($manifest_file); |
|
512 | - } |
|
513 | - return json_decode(file_get_contents($manifest_file), true); |
|
514 | - } |
|
515 | - |
|
516 | - |
|
517 | - /** |
|
518 | - * This is used to set registered script handles that have data. |
|
519 | - * |
|
520 | - * @param string $script_handle |
|
521 | - */ |
|
522 | - private function addRegisteredScriptHandlesWithData($script_handle) |
|
523 | - { |
|
524 | - $this->script_handles_with_data[ $script_handle ] = $script_handle; |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - /**i |
|
366 | + 'event_espresso' |
|
367 | + ), |
|
368 | + $key |
|
369 | + ) |
|
370 | + ); |
|
371 | + } |
|
372 | + return true; |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * Get the actual asset path for asset manifests. |
|
378 | + * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
379 | + * |
|
380 | + * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
381 | + * asset file location. |
|
382 | + * @param string $chunk_name |
|
383 | + * @param string $asset_type |
|
384 | + * @return string |
|
385 | + * @since 4.9.59.p |
|
386 | + */ |
|
387 | + public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
388 | + { |
|
389 | + $url = isset( |
|
390 | + $this->manifest_data[ $namespace ][ $chunk_name ][ $asset_type ], |
|
391 | + $this->manifest_data[ $namespace ]['url_base'] |
|
392 | + ) |
|
393 | + ? $this->manifest_data[ $namespace ]['url_base'] |
|
394 | + . $this->manifest_data[ $namespace ][ $chunk_name ][ $asset_type ] |
|
395 | + : $chunk_name; |
|
396 | + return apply_filters( |
|
397 | + 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
398 | + $url, |
|
399 | + $namespace, |
|
400 | + $chunk_name, |
|
401 | + $asset_type |
|
402 | + ); |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * Return the url to a js file for the given namespace and chunk name. |
|
408 | + * |
|
409 | + * @param string $namespace |
|
410 | + * @param string $chunk_name |
|
411 | + * @return string |
|
412 | + */ |
|
413 | + public function getJsUrl($namespace, $chunk_name) |
|
414 | + { |
|
415 | + return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS); |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * Return the url to a css file for the given namespace and chunk name. |
|
421 | + * |
|
422 | + * @param string $namespace |
|
423 | + * @param string $chunk_name |
|
424 | + * @return string |
|
425 | + */ |
|
426 | + public function getCssUrl($namespace, $chunk_name) |
|
427 | + { |
|
428 | + return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS); |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * @since $VID:$ |
|
434 | + * @throws InvalidArgumentException |
|
435 | + * @throws InvalidFilePathException |
|
436 | + */ |
|
437 | + public function registerManifestFiles() |
|
438 | + { |
|
439 | + $manifest_files = $this->assets->getManifestFiles(); |
|
440 | + foreach ($manifest_files as $manifest_file) { |
|
441 | + $this->registerManifestFile( |
|
442 | + $manifest_file->assetNamespace(), |
|
443 | + $manifest_file->urlBase(), |
|
444 | + $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST |
|
445 | + ); |
|
446 | + } |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * Used to register a js/css manifest file with the registered_manifest_files property. |
|
452 | + * |
|
453 | + * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
454 | + * @param string $url_base The url base for the manifest file location. |
|
455 | + * @param string $manifest_file The absolute path to the manifest file. |
|
456 | + * @throws InvalidArgumentException |
|
457 | + * @throws InvalidFilePathException |
|
458 | + * @since 4.9.59.p |
|
459 | + */ |
|
460 | + public function registerManifestFile($namespace, $url_base, $manifest_file) |
|
461 | + { |
|
462 | + if (isset($this->manifest_data[ $namespace ])) { |
|
463 | + throw new InvalidArgumentException( |
|
464 | + sprintf( |
|
465 | + esc_html__( |
|
466 | + 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
467 | + 'event_espresso' |
|
468 | + ), |
|
469 | + $namespace |
|
470 | + ) |
|
471 | + ); |
|
472 | + } |
|
473 | + if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
474 | + if (is_admin()) { |
|
475 | + EE_Error::add_error( |
|
476 | + sprintf( |
|
477 | + esc_html__( |
|
478 | + 'The url given for %1$s assets is invalid. The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant', |
|
479 | + 'event_espresso' |
|
480 | + ), |
|
481 | + 'Event Espresso', |
|
482 | + $url_base, |
|
483 | + 'plugins_url', |
|
484 | + 'WP_PLUGIN_URL' |
|
485 | + ), |
|
486 | + __FILE__, |
|
487 | + __FUNCTION__, |
|
488 | + __LINE__ |
|
489 | + ); |
|
490 | + } |
|
491 | + return; |
|
492 | + } |
|
493 | + $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file); |
|
494 | + if (! isset($this->manifest_data[ $namespace ]['url_base'])) { |
|
495 | + $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base); |
|
496 | + } |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * Decodes json from the provided manifest file. |
|
502 | + * |
|
503 | + * @since 4.9.59.p |
|
504 | + * @param string $manifest_file Path to manifest file. |
|
505 | + * @return array |
|
506 | + * @throws InvalidFilePathException |
|
507 | + */ |
|
508 | + private function decodeManifestFile($manifest_file) |
|
509 | + { |
|
510 | + if (! file_exists($manifest_file)) { |
|
511 | + throw new InvalidFilePathException($manifest_file); |
|
512 | + } |
|
513 | + return json_decode(file_get_contents($manifest_file), true); |
|
514 | + } |
|
515 | + |
|
516 | + |
|
517 | + /** |
|
518 | + * This is used to set registered script handles that have data. |
|
519 | + * |
|
520 | + * @param string $script_handle |
|
521 | + */ |
|
522 | + private function addRegisteredScriptHandlesWithData($script_handle) |
|
523 | + { |
|
524 | + $this->script_handles_with_data[ $script_handle ] = $script_handle; |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + /**i |
|
529 | 529 | * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
530 | 530 | * Dependency stored in WP_Scripts if its set. |
531 | 531 | */ |
532 | - private function removeAlreadyRegisteredDataForScriptHandles() |
|
533 | - { |
|
534 | - if (empty($this->script_handles_with_data)) { |
|
535 | - return; |
|
536 | - } |
|
537 | - foreach ($this->script_handles_with_data as $script_handle) { |
|
538 | - $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
539 | - } |
|
540 | - } |
|
541 | - |
|
542 | - |
|
543 | - /** |
|
544 | - * Removes any data dependency registered in WP_Scripts if its set. |
|
545 | - * |
|
546 | - * @param string $script_handle |
|
547 | - */ |
|
548 | - private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
549 | - { |
|
550 | - if (isset($this->script_handles_with_data[ $script_handle ])) { |
|
551 | - global $wp_scripts; |
|
552 | - $unset_handle = false; |
|
553 | - if ($wp_scripts->get_data($script_handle, 'data')) { |
|
554 | - unset($wp_scripts->registered[ $script_handle ]->extra['data']); |
|
555 | - $unset_handle = true; |
|
556 | - } |
|
557 | - //deal with inline_scripts |
|
558 | - if ($wp_scripts->get_data($script_handle, 'before')) { |
|
559 | - unset($wp_scripts->registered[ $script_handle ]->extra['before']); |
|
560 | - $unset_handle = true; |
|
561 | - } |
|
562 | - if ($wp_scripts->get_data($script_handle, 'after')) { |
|
563 | - unset($wp_scripts->registered[ $script_handle ]->extra['after']); |
|
564 | - } |
|
565 | - if ($unset_handle) { |
|
566 | - unset($this->script_handles_with_data[ $script_handle ]); |
|
567 | - } |
|
568 | - } |
|
569 | - } |
|
570 | - |
|
571 | - |
|
572 | - /** |
|
573 | - * register translations for a registered script |
|
574 | - * |
|
575 | - * @param string $handle |
|
576 | - */ |
|
577 | - public function registerTranslation($handle) |
|
578 | - { |
|
579 | - $this->i18n_registry->registerScriptI18n($handle); |
|
580 | - } |
|
532 | + private function removeAlreadyRegisteredDataForScriptHandles() |
|
533 | + { |
|
534 | + if (empty($this->script_handles_with_data)) { |
|
535 | + return; |
|
536 | + } |
|
537 | + foreach ($this->script_handles_with_data as $script_handle) { |
|
538 | + $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
539 | + } |
|
540 | + } |
|
541 | + |
|
542 | + |
|
543 | + /** |
|
544 | + * Removes any data dependency registered in WP_Scripts if its set. |
|
545 | + * |
|
546 | + * @param string $script_handle |
|
547 | + */ |
|
548 | + private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
549 | + { |
|
550 | + if (isset($this->script_handles_with_data[ $script_handle ])) { |
|
551 | + global $wp_scripts; |
|
552 | + $unset_handle = false; |
|
553 | + if ($wp_scripts->get_data($script_handle, 'data')) { |
|
554 | + unset($wp_scripts->registered[ $script_handle ]->extra['data']); |
|
555 | + $unset_handle = true; |
|
556 | + } |
|
557 | + //deal with inline_scripts |
|
558 | + if ($wp_scripts->get_data($script_handle, 'before')) { |
|
559 | + unset($wp_scripts->registered[ $script_handle ]->extra['before']); |
|
560 | + $unset_handle = true; |
|
561 | + } |
|
562 | + if ($wp_scripts->get_data($script_handle, 'after')) { |
|
563 | + unset($wp_scripts->registered[ $script_handle ]->extra['after']); |
|
564 | + } |
|
565 | + if ($unset_handle) { |
|
566 | + unset($this->script_handles_with_data[ $script_handle ]); |
|
567 | + } |
|
568 | + } |
|
569 | + } |
|
570 | + |
|
571 | + |
|
572 | + /** |
|
573 | + * register translations for a registered script |
|
574 | + * |
|
575 | + * @param string $handle |
|
576 | + */ |
|
577 | + public function registerTranslation($handle) |
|
578 | + { |
|
579 | + $this->i18n_registry->registerScriptI18n($handle); |
|
580 | + } |
|
581 | 581 | } |
@@ -16,28 +16,28 @@ |
||
16 | 16 | class InvalidIdentifierException extends InvalidArgumentException |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * InvalidIdentifierException constructor. |
|
21 | - * |
|
22 | - * @param string $actual the identifier that was supplied |
|
23 | - * @param string $expected example of an acceptable identifier |
|
24 | - * @param string $message |
|
25 | - * @param int $code |
|
26 | - * @param Exception $previous |
|
27 | - */ |
|
28 | - public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null) |
|
29 | - { |
|
30 | - if (empty($message)) { |
|
31 | - $message = sprintf( |
|
32 | - __( |
|
33 | - 'The supplied identifier "%1$s" is invalid. A value like "%2$s" was expected.', |
|
34 | - 'event_espresso' |
|
35 | - ), |
|
36 | - $actual, |
|
37 | - $expected |
|
38 | - ); |
|
39 | - } |
|
40 | - parent::__construct($message, $code, $previous); |
|
41 | - } |
|
19 | + /** |
|
20 | + * InvalidIdentifierException constructor. |
|
21 | + * |
|
22 | + * @param string $actual the identifier that was supplied |
|
23 | + * @param string $expected example of an acceptable identifier |
|
24 | + * @param string $message |
|
25 | + * @param int $code |
|
26 | + * @param Exception $previous |
|
27 | + */ |
|
28 | + public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null) |
|
29 | + { |
|
30 | + if (empty($message)) { |
|
31 | + $message = sprintf( |
|
32 | + __( |
|
33 | + 'The supplied identifier "%1$s" is invalid. A value like "%2$s" was expected.', |
|
34 | + 'event_espresso' |
|
35 | + ), |
|
36 | + $actual, |
|
37 | + $expected |
|
38 | + ); |
|
39 | + } |
|
40 | + parent::__construct($message, $code, $previous); |
|
41 | + } |
|
42 | 42 | } |
43 | 43 | // Location: core/exceptions/InvalidIdentifierException.php |