@@ -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 | } |
@@ -17,165 +17,165 @@ |
||
| 17 | 17 | class ClassInterfaceCache |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * array of interfaces indexed by FQCNs where values are arrays of interface FQNs |
|
| 22 | - * |
|
| 23 | - * @var string[][] $interfaces |
|
| 24 | - */ |
|
| 25 | - private $interfaces = array(); |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @type string[][] $aliases |
|
| 29 | - */ |
|
| 30 | - protected $aliases = array(); |
|
| 31 | - |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @param string $fqn |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function getFqn($fqn) |
|
| 38 | - { |
|
| 39 | - $fqn = $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn; |
|
| 40 | - return ltrim($fqn, '\\'); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @param string $fqn |
|
| 46 | - * @return array |
|
| 47 | - */ |
|
| 48 | - public function getInterfaces($fqn) |
|
| 49 | - { |
|
| 50 | - $fqn = $this->getFqn($fqn); |
|
| 51 | - // have we already seen this FQCN ? |
|
| 52 | - if (! array_key_exists($fqn, $this->interfaces)) { |
|
| 53 | - $this->interfaces[ $fqn ] = array(); |
|
| 54 | - if (class_exists($fqn)) { |
|
| 55 | - $this->interfaces[ $fqn ] = class_implements($fqn, false); |
|
| 56 | - $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false |
|
| 57 | - ? $this->interfaces[ $fqn ] |
|
| 58 | - : array(); |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - return $this->interfaces[ $fqn ]; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @param string $fqn |
|
| 67 | - * @param string $interface |
|
| 68 | - * @return bool |
|
| 69 | - */ |
|
| 70 | - public function hasInterface($fqn, $interface) |
|
| 71 | - { |
|
| 72 | - $fqn = $this->getFqn($fqn); |
|
| 73 | - $interfaces = $this->getInterfaces($fqn); |
|
| 74 | - return in_array($interface, $interfaces, true); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * adds an alias for a classname |
|
| 80 | - * |
|
| 81 | - * @param string $fqn the class name that should be used (concrete class to replace interface) |
|
| 82 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 83 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 84 | - * @throws InvalidAliasException |
|
| 85 | - */ |
|
| 86 | - public function addAlias($fqn, $alias, $for_class = '') |
|
| 87 | - { |
|
| 88 | - $fqn = $this->getFqn($fqn); |
|
| 89 | - $alias = $this->getFqn($alias); |
|
| 90 | - if (strpos($alias, '\\') !== false && ! is_subclass_of($fqn, $alias)) { |
|
| 91 | - throw new InvalidAliasException($fqn, $alias); |
|
| 92 | - } |
|
| 93 | - // are we adding an alias for a specific class? |
|
| 94 | - if ($for_class !== '') { |
|
| 95 | - // make sure it's set up as an array |
|
| 96 | - if (! isset($this->aliases[ $for_class ])) { |
|
| 97 | - $this->aliases[ $for_class ] = array(); |
|
| 98 | - } |
|
| 99 | - $this->aliases[ $for_class ][ $alias ] = $fqn; |
|
| 100 | - return; |
|
| 101 | - } |
|
| 102 | - $this->aliases[ $alias ] = $fqn; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * returns TRUE if the provided FQN is an alias |
|
| 108 | - * |
|
| 109 | - * @param string $fqn |
|
| 110 | - * @param string $for_class |
|
| 111 | - * @return bool |
|
| 112 | - */ |
|
| 113 | - public function isAlias($fqn = '', $for_class = '') |
|
| 114 | - { |
|
| 115 | - $fqn = $this->getFqn($fqn); |
|
| 116 | - if ($this->isAliasForClass($fqn, $for_class)) { |
|
| 117 | - return true; |
|
| 118 | - } |
|
| 119 | - if ($for_class === '' && $this->isDirectAlias($fqn)) { |
|
| 120 | - return true; |
|
| 121 | - } |
|
| 122 | - return false; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * returns TRUE if the provided FQN is an alias |
|
| 128 | - * |
|
| 129 | - * @param string $fqn |
|
| 130 | - * @return bool |
|
| 131 | - */ |
|
| 132 | - protected function isDirectAlias($fqn = '') |
|
| 133 | - { |
|
| 134 | - return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * returns TRUE if the provided FQN is an alias for the specified class |
|
| 140 | - * |
|
| 141 | - * @param string $fqn |
|
| 142 | - * @param string $for_class |
|
| 143 | - * @return bool |
|
| 144 | - */ |
|
| 145 | - protected function isAliasForClass($fqn = '', $for_class = '') |
|
| 146 | - { |
|
| 147 | - return ( |
|
| 148 | - $for_class !== '' |
|
| 149 | - && isset($this->aliases[ (string) $for_class ][ (string) $fqn ]) |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * returns FQN for provided alias if one exists, otherwise returns the original FQN |
|
| 156 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 157 | - * for example: |
|
| 158 | - * if the following two entries were added to the aliases array: |
|
| 159 | - * array( |
|
| 160 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 161 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 162 | - * ) |
|
| 163 | - * then one could use Loader::getNew( 'interface_alias' ) |
|
| 164 | - * to load an instance of 'some\namespace\classname' |
|
| 165 | - * |
|
| 166 | - * @param string $alias |
|
| 167 | - * @param string $for_class |
|
| 168 | - * @return string |
|
| 169 | - */ |
|
| 170 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
| 171 | - { |
|
| 172 | - $alias = $this->getFqn($alias); |
|
| 173 | - if ($this->isAliasForClass($alias, $for_class)) { |
|
| 174 | - return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class); |
|
| 175 | - } |
|
| 176 | - if ($this->isDirectAlias($alias)) { |
|
| 177 | - return $this->getFqnForAlias($this->aliases[ (string) $alias ], ''); |
|
| 178 | - } |
|
| 179 | - return $alias; |
|
| 180 | - } |
|
| 20 | + /** |
|
| 21 | + * array of interfaces indexed by FQCNs where values are arrays of interface FQNs |
|
| 22 | + * |
|
| 23 | + * @var string[][] $interfaces |
|
| 24 | + */ |
|
| 25 | + private $interfaces = array(); |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @type string[][] $aliases |
|
| 29 | + */ |
|
| 30 | + protected $aliases = array(); |
|
| 31 | + |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @param string $fqn |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function getFqn($fqn) |
|
| 38 | + { |
|
| 39 | + $fqn = $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn; |
|
| 40 | + return ltrim($fqn, '\\'); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @param string $fqn |
|
| 46 | + * @return array |
|
| 47 | + */ |
|
| 48 | + public function getInterfaces($fqn) |
|
| 49 | + { |
|
| 50 | + $fqn = $this->getFqn($fqn); |
|
| 51 | + // have we already seen this FQCN ? |
|
| 52 | + if (! array_key_exists($fqn, $this->interfaces)) { |
|
| 53 | + $this->interfaces[ $fqn ] = array(); |
|
| 54 | + if (class_exists($fqn)) { |
|
| 55 | + $this->interfaces[ $fqn ] = class_implements($fqn, false); |
|
| 56 | + $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false |
|
| 57 | + ? $this->interfaces[ $fqn ] |
|
| 58 | + : array(); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + return $this->interfaces[ $fqn ]; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @param string $fqn |
|
| 67 | + * @param string $interface |
|
| 68 | + * @return bool |
|
| 69 | + */ |
|
| 70 | + public function hasInterface($fqn, $interface) |
|
| 71 | + { |
|
| 72 | + $fqn = $this->getFqn($fqn); |
|
| 73 | + $interfaces = $this->getInterfaces($fqn); |
|
| 74 | + return in_array($interface, $interfaces, true); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * adds an alias for a classname |
|
| 80 | + * |
|
| 81 | + * @param string $fqn the class name that should be used (concrete class to replace interface) |
|
| 82 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 83 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 84 | + * @throws InvalidAliasException |
|
| 85 | + */ |
|
| 86 | + public function addAlias($fqn, $alias, $for_class = '') |
|
| 87 | + { |
|
| 88 | + $fqn = $this->getFqn($fqn); |
|
| 89 | + $alias = $this->getFqn($alias); |
|
| 90 | + if (strpos($alias, '\\') !== false && ! is_subclass_of($fqn, $alias)) { |
|
| 91 | + throw new InvalidAliasException($fqn, $alias); |
|
| 92 | + } |
|
| 93 | + // are we adding an alias for a specific class? |
|
| 94 | + if ($for_class !== '') { |
|
| 95 | + // make sure it's set up as an array |
|
| 96 | + if (! isset($this->aliases[ $for_class ])) { |
|
| 97 | + $this->aliases[ $for_class ] = array(); |
|
| 98 | + } |
|
| 99 | + $this->aliases[ $for_class ][ $alias ] = $fqn; |
|
| 100 | + return; |
|
| 101 | + } |
|
| 102 | + $this->aliases[ $alias ] = $fqn; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * returns TRUE if the provided FQN is an alias |
|
| 108 | + * |
|
| 109 | + * @param string $fqn |
|
| 110 | + * @param string $for_class |
|
| 111 | + * @return bool |
|
| 112 | + */ |
|
| 113 | + public function isAlias($fqn = '', $for_class = '') |
|
| 114 | + { |
|
| 115 | + $fqn = $this->getFqn($fqn); |
|
| 116 | + if ($this->isAliasForClass($fqn, $for_class)) { |
|
| 117 | + return true; |
|
| 118 | + } |
|
| 119 | + if ($for_class === '' && $this->isDirectAlias($fqn)) { |
|
| 120 | + return true; |
|
| 121 | + } |
|
| 122 | + return false; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * returns TRUE if the provided FQN is an alias |
|
| 128 | + * |
|
| 129 | + * @param string $fqn |
|
| 130 | + * @return bool |
|
| 131 | + */ |
|
| 132 | + protected function isDirectAlias($fqn = '') |
|
| 133 | + { |
|
| 134 | + return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * returns TRUE if the provided FQN is an alias for the specified class |
|
| 140 | + * |
|
| 141 | + * @param string $fqn |
|
| 142 | + * @param string $for_class |
|
| 143 | + * @return bool |
|
| 144 | + */ |
|
| 145 | + protected function isAliasForClass($fqn = '', $for_class = '') |
|
| 146 | + { |
|
| 147 | + return ( |
|
| 148 | + $for_class !== '' |
|
| 149 | + && isset($this->aliases[ (string) $for_class ][ (string) $fqn ]) |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * returns FQN for provided alias if one exists, otherwise returns the original FQN |
|
| 156 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 157 | + * for example: |
|
| 158 | + * if the following two entries were added to the aliases array: |
|
| 159 | + * array( |
|
| 160 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 161 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 162 | + * ) |
|
| 163 | + * then one could use Loader::getNew( 'interface_alias' ) |
|
| 164 | + * to load an instance of 'some\namespace\classname' |
|
| 165 | + * |
|
| 166 | + * @param string $alias |
|
| 167 | + * @param string $for_class |
|
| 168 | + * @return string |
|
| 169 | + */ |
|
| 170 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
| 171 | + { |
|
| 172 | + $alias = $this->getFqn($alias); |
|
| 173 | + if ($this->isAliasForClass($alias, $for_class)) { |
|
| 174 | + return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class); |
|
| 175 | + } |
|
| 176 | + if ($this->isDirectAlias($alias)) { |
|
| 177 | + return $this->getFqnForAlias($this->aliases[ (string) $alias ], ''); |
|
| 178 | + } |
|
| 179 | + return $alias; |
|
| 180 | + } |
|
| 181 | 181 | } |
@@ -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 | } |
@@ -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 |
@@ -16,26 +16,26 @@ |
||
| 16 | 16 | class ManifestFile extends Asset |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Asset constructor. |
|
| 21 | - * |
|
| 22 | - * @param DomainInterface $domain |
|
| 23 | - * @throws InvalidDataTypeException |
|
| 24 | - */ |
|
| 25 | - public function __construct(DomainInterface $domain) |
|
| 26 | - { |
|
| 27 | - parent::__construct(Asset::TYPE_MANIFEST, $domain->assetNamespace(), $domain); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - public function urlBase() |
|
| 32 | - { |
|
| 33 | - return $this->domain->distributionAssetsUrl(); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - public function filepath() |
|
| 38 | - { |
|
| 39 | - return $this->domain->distributionAssetsPath(); |
|
| 40 | - } |
|
| 19 | + /** |
|
| 20 | + * Asset constructor. |
|
| 21 | + * |
|
| 22 | + * @param DomainInterface $domain |
|
| 23 | + * @throws InvalidDataTypeException |
|
| 24 | + */ |
|
| 25 | + public function __construct(DomainInterface $domain) |
|
| 26 | + { |
|
| 27 | + parent::__construct(Asset::TYPE_MANIFEST, $domain->assetNamespace(), $domain); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + public function urlBase() |
|
| 32 | + { |
|
| 33 | + return $this->domain->distributionAssetsUrl(); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + public function filepath() |
|
| 38 | + { |
|
| 39 | + return $this->domain->distributionAssetsPath(); |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | private function setType($type) |
| 84 | 84 | { |
| 85 | - if (! in_array($type, $this->validAssetTypes(), true)) { |
|
| 85 | + if ( ! in_array($type, $this->validAssetTypes(), true)) { |
|
| 86 | 86 | throw new InvalidDataTypeException( |
| 87 | 87 | 'Asset::$type', |
| 88 | 88 | $type, |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | private function setHandle($handle) |
| 101 | 101 | { |
| 102 | - if (! is_string($handle)) { |
|
| 102 | + if ( ! is_string($handle)) { |
|
| 103 | 103 | throw new InvalidDataTypeException( |
| 104 | 104 | '$handle', |
| 105 | 105 | $handle, |
@@ -16,154 +16,154 @@ |
||
| 16 | 16 | abstract class Asset |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * indicates the file extension for a build distribution CSS file |
|
| 21 | - */ |
|
| 22 | - const FILE_EXTENSION_DISTRIBUTION_CSS = '.dist.css'; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * indicates the file extension for a build distribution JS file |
|
| 26 | - */ |
|
| 27 | - const FILE_EXTENSION_DISTRIBUTION_JS = '.dist.js'; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * indicates a Cascading Style Sheet asset |
|
| 31 | - */ |
|
| 32 | - const TYPE_CSS = 'css'; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * indicates a Javascript asset |
|
| 36 | - */ |
|
| 37 | - const TYPE_JS = 'js'; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * indicates a Javascript manifest file |
|
| 41 | - */ |
|
| 42 | - const TYPE_MANIFEST = 'manifest'; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var DomainInterface $domain |
|
| 46 | - */ |
|
| 47 | - protected $domain; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var string $type |
|
| 51 | - */ |
|
| 52 | - private $type; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @var string $handle |
|
| 56 | - */ |
|
| 57 | - private $handle; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @var bool $registered |
|
| 61 | - */ |
|
| 62 | - private $registered = false; |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Asset constructor. |
|
| 67 | - * |
|
| 68 | - * @param $type |
|
| 69 | - * @param string $handle |
|
| 70 | - * @param DomainInterface $domain |
|
| 71 | - * @throws InvalidDataTypeException |
|
| 72 | - */ |
|
| 73 | - public function __construct($type, $handle, DomainInterface $domain) |
|
| 74 | - { |
|
| 75 | - $this->domain = $domain; |
|
| 76 | - $this->setType($type); |
|
| 77 | - $this->setHandle($handle); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @return array |
|
| 83 | - */ |
|
| 84 | - public function validAssetTypes() |
|
| 85 | - { |
|
| 86 | - return array( |
|
| 87 | - Asset::TYPE_CSS, |
|
| 88 | - Asset::TYPE_JS, |
|
| 89 | - Asset::TYPE_MANIFEST, |
|
| 90 | - ); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @param string $type |
|
| 96 | - * @throws InvalidDataTypeException |
|
| 97 | - */ |
|
| 98 | - private function setType($type) |
|
| 99 | - { |
|
| 100 | - if (! in_array($type, $this->validAssetTypes(), true)) { |
|
| 101 | - throw new InvalidDataTypeException( |
|
| 102 | - 'Asset::$type', |
|
| 103 | - $type, |
|
| 104 | - 'one of the TYPE_* class constants on \EventEspresso\core\domain\values\Asset is required' |
|
| 105 | - ); |
|
| 106 | - } |
|
| 107 | - $this->type = $type; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @param string $handle |
|
| 113 | - * @throws InvalidDataTypeException |
|
| 114 | - */ |
|
| 115 | - private function setHandle($handle) |
|
| 116 | - { |
|
| 117 | - if (! is_string($handle)) { |
|
| 118 | - throw new InvalidDataTypeException( |
|
| 119 | - '$handle', |
|
| 120 | - $handle, |
|
| 121 | - 'string' |
|
| 122 | - ); |
|
| 123 | - } |
|
| 124 | - $this->handle = $handle; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @return string |
|
| 130 | - */ |
|
| 131 | - public function assetNamespace() |
|
| 132 | - { |
|
| 133 | - return $this->domain->assetNamespace(); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @return string |
|
| 139 | - */ |
|
| 140 | - public function type() |
|
| 141 | - { |
|
| 142 | - return $this->type; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @return string |
|
| 148 | - */ |
|
| 149 | - public function handle() |
|
| 150 | - { |
|
| 151 | - return $this->handle; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @return bool |
|
| 156 | - */ |
|
| 157 | - public function isRegistered() |
|
| 158 | - { |
|
| 159 | - return $this->registered; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @param bool $registered |
|
| 164 | - */ |
|
| 165 | - public function setRegistered($registered = true) |
|
| 166 | - { |
|
| 167 | - $this->registered = filter_var($registered, FILTER_VALIDATE_BOOLEAN); |
|
| 168 | - } |
|
| 19 | + /** |
|
| 20 | + * indicates the file extension for a build distribution CSS file |
|
| 21 | + */ |
|
| 22 | + const FILE_EXTENSION_DISTRIBUTION_CSS = '.dist.css'; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * indicates the file extension for a build distribution JS file |
|
| 26 | + */ |
|
| 27 | + const FILE_EXTENSION_DISTRIBUTION_JS = '.dist.js'; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * indicates a Cascading Style Sheet asset |
|
| 31 | + */ |
|
| 32 | + const TYPE_CSS = 'css'; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * indicates a Javascript asset |
|
| 36 | + */ |
|
| 37 | + const TYPE_JS = 'js'; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * indicates a Javascript manifest file |
|
| 41 | + */ |
|
| 42 | + const TYPE_MANIFEST = 'manifest'; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var DomainInterface $domain |
|
| 46 | + */ |
|
| 47 | + protected $domain; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var string $type |
|
| 51 | + */ |
|
| 52 | + private $type; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @var string $handle |
|
| 56 | + */ |
|
| 57 | + private $handle; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @var bool $registered |
|
| 61 | + */ |
|
| 62 | + private $registered = false; |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Asset constructor. |
|
| 67 | + * |
|
| 68 | + * @param $type |
|
| 69 | + * @param string $handle |
|
| 70 | + * @param DomainInterface $domain |
|
| 71 | + * @throws InvalidDataTypeException |
|
| 72 | + */ |
|
| 73 | + public function __construct($type, $handle, DomainInterface $domain) |
|
| 74 | + { |
|
| 75 | + $this->domain = $domain; |
|
| 76 | + $this->setType($type); |
|
| 77 | + $this->setHandle($handle); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @return array |
|
| 83 | + */ |
|
| 84 | + public function validAssetTypes() |
|
| 85 | + { |
|
| 86 | + return array( |
|
| 87 | + Asset::TYPE_CSS, |
|
| 88 | + Asset::TYPE_JS, |
|
| 89 | + Asset::TYPE_MANIFEST, |
|
| 90 | + ); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @param string $type |
|
| 96 | + * @throws InvalidDataTypeException |
|
| 97 | + */ |
|
| 98 | + private function setType($type) |
|
| 99 | + { |
|
| 100 | + if (! in_array($type, $this->validAssetTypes(), true)) { |
|
| 101 | + throw new InvalidDataTypeException( |
|
| 102 | + 'Asset::$type', |
|
| 103 | + $type, |
|
| 104 | + 'one of the TYPE_* class constants on \EventEspresso\core\domain\values\Asset is required' |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | + $this->type = $type; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @param string $handle |
|
| 113 | + * @throws InvalidDataTypeException |
|
| 114 | + */ |
|
| 115 | + private function setHandle($handle) |
|
| 116 | + { |
|
| 117 | + if (! is_string($handle)) { |
|
| 118 | + throw new InvalidDataTypeException( |
|
| 119 | + '$handle', |
|
| 120 | + $handle, |
|
| 121 | + 'string' |
|
| 122 | + ); |
|
| 123 | + } |
|
| 124 | + $this->handle = $handle; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @return string |
|
| 130 | + */ |
|
| 131 | + public function assetNamespace() |
|
| 132 | + { |
|
| 133 | + return $this->domain->assetNamespace(); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @return string |
|
| 139 | + */ |
|
| 140 | + public function type() |
|
| 141 | + { |
|
| 142 | + return $this->type; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @return string |
|
| 148 | + */ |
|
| 149 | + public function handle() |
|
| 150 | + { |
|
| 151 | + return $this->handle; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @return bool |
|
| 156 | + */ |
|
| 157 | + public function isRegistered() |
|
| 158 | + { |
|
| 159 | + return $this->registered; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @param bool $registered |
|
| 164 | + */ |
|
| 165 | + public function setRegistered($registered = true) |
|
| 166 | + { |
|
| 167 | + $this->registered = filter_var($registered, FILTER_VALIDATE_BOOLEAN); |
|
| 168 | + } |
|
| 169 | 169 | } |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | private function setSource($source) |
| 95 | 95 | { |
| 96 | - if (! is_string($source)) { |
|
| 96 | + if ( ! is_string($source)) { |
|
| 97 | 97 | throw new InvalidDataTypeException( |
| 98 | 98 | '$source', |
| 99 | 99 | $source, |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public function setVersion($version = EVENT_ESPRESSO_VERSION) |
| 128 | 128 | { |
| 129 | - if (! is_string($version)) { |
|
| 129 | + if ( ! is_string($version)) { |
|
| 130 | 130 | throw new InvalidDataTypeException( |
| 131 | 131 | '$version', |
| 132 | 132 | $version, |
@@ -16,136 +16,136 @@ |
||
| 16 | 16 | abstract class BrowserAsset extends Asset |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var string $source |
|
| 21 | - */ |
|
| 22 | - private $source; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var array $dependencies |
|
| 26 | - */ |
|
| 27 | - private $dependencies; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var string $version |
|
| 31 | - */ |
|
| 32 | - private $version; |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Asset constructor. |
|
| 37 | - * |
|
| 38 | - * @param string $type |
|
| 39 | - * @param string $handle |
|
| 40 | - * @param string $source |
|
| 41 | - * @param array $dependencies |
|
| 42 | - * @param DomainInterface $domain |
|
| 43 | - * @throws InvalidDataTypeException |
|
| 44 | - */ |
|
| 45 | - public function __construct($type, $handle, $source, array $dependencies, DomainInterface $domain) |
|
| 46 | - { |
|
| 47 | - parent::__construct($type, $handle, $domain); |
|
| 48 | - $this->setSource($source); |
|
| 49 | - $this->setDependencies($dependencies); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @since 4.9.62.p |
|
| 55 | - */ |
|
| 56 | - abstract public function enqueueAsset(); |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @return array |
|
| 61 | - */ |
|
| 62 | - public function dependencies() |
|
| 63 | - { |
|
| 64 | - return $this->dependencies; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @param array $dependencies |
|
| 70 | - */ |
|
| 71 | - private function setDependencies(array $dependencies) |
|
| 72 | - { |
|
| 73 | - $this->dependencies = $dependencies; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @since 4.9.62.p |
|
| 79 | - * @return bool |
|
| 80 | - */ |
|
| 81 | - public function hasDependencies() |
|
| 82 | - { |
|
| 83 | - return count($this->dependencies) > 0; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 90 | - public function source() |
|
| 91 | - { |
|
| 92 | - return $this->source; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @param string $source |
|
| 98 | - * @throws InvalidDataTypeException |
|
| 99 | - */ |
|
| 100 | - private function setSource($source) |
|
| 101 | - { |
|
| 102 | - if (! is_string($source)) { |
|
| 103 | - throw new InvalidDataTypeException( |
|
| 104 | - '$source', |
|
| 105 | - $source, |
|
| 106 | - 'string' |
|
| 107 | - ); |
|
| 108 | - } |
|
| 109 | - $this->source = $source; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @return string |
|
| 115 | - * @throws InvalidDataTypeException |
|
| 116 | - */ |
|
| 117 | - public function version() |
|
| 118 | - { |
|
| 119 | - // if version is NOT set and this asset was NOT built for distribution, |
|
| 120 | - // then set the version equal to the EE core plugin version |
|
| 121 | - if ( |
|
| 122 | - $this->version === null |
|
| 123 | - && ( |
|
| 124 | - substr($this->source, -8) !== Asset::FILE_EXTENSION_DISTRIBUTION_JS |
|
| 125 | - || substr($this->source, -9) !== Asset::FILE_EXTENSION_DISTRIBUTION_CSS |
|
| 126 | - ) |
|
| 127 | - ) { |
|
| 128 | - $this->setVersion(); |
|
| 129 | - } |
|
| 130 | - return $this->version; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @param string $version |
|
| 136 | - * @return BrowserAsset |
|
| 137 | - * @throws InvalidDataTypeException |
|
| 138 | - */ |
|
| 139 | - public function setVersion($version = EVENT_ESPRESSO_VERSION) |
|
| 140 | - { |
|
| 141 | - if (! is_string($version)) { |
|
| 142 | - throw new InvalidDataTypeException( |
|
| 143 | - '$version', |
|
| 144 | - $version, |
|
| 145 | - 'string' |
|
| 146 | - ); |
|
| 147 | - } |
|
| 148 | - $this->version = $version; |
|
| 149 | - return $this; |
|
| 150 | - } |
|
| 19 | + /** |
|
| 20 | + * @var string $source |
|
| 21 | + */ |
|
| 22 | + private $source; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var array $dependencies |
|
| 26 | + */ |
|
| 27 | + private $dependencies; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var string $version |
|
| 31 | + */ |
|
| 32 | + private $version; |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Asset constructor. |
|
| 37 | + * |
|
| 38 | + * @param string $type |
|
| 39 | + * @param string $handle |
|
| 40 | + * @param string $source |
|
| 41 | + * @param array $dependencies |
|
| 42 | + * @param DomainInterface $domain |
|
| 43 | + * @throws InvalidDataTypeException |
|
| 44 | + */ |
|
| 45 | + public function __construct($type, $handle, $source, array $dependencies, DomainInterface $domain) |
|
| 46 | + { |
|
| 47 | + parent::__construct($type, $handle, $domain); |
|
| 48 | + $this->setSource($source); |
|
| 49 | + $this->setDependencies($dependencies); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @since 4.9.62.p |
|
| 55 | + */ |
|
| 56 | + abstract public function enqueueAsset(); |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @return array |
|
| 61 | + */ |
|
| 62 | + public function dependencies() |
|
| 63 | + { |
|
| 64 | + return $this->dependencies; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @param array $dependencies |
|
| 70 | + */ |
|
| 71 | + private function setDependencies(array $dependencies) |
|
| 72 | + { |
|
| 73 | + $this->dependencies = $dependencies; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @since 4.9.62.p |
|
| 79 | + * @return bool |
|
| 80 | + */ |
|
| 81 | + public function hasDependencies() |
|
| 82 | + { |
|
| 83 | + return count($this->dependencies) > 0; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | + public function source() |
|
| 91 | + { |
|
| 92 | + return $this->source; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @param string $source |
|
| 98 | + * @throws InvalidDataTypeException |
|
| 99 | + */ |
|
| 100 | + private function setSource($source) |
|
| 101 | + { |
|
| 102 | + if (! is_string($source)) { |
|
| 103 | + throw new InvalidDataTypeException( |
|
| 104 | + '$source', |
|
| 105 | + $source, |
|
| 106 | + 'string' |
|
| 107 | + ); |
|
| 108 | + } |
|
| 109 | + $this->source = $source; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @return string |
|
| 115 | + * @throws InvalidDataTypeException |
|
| 116 | + */ |
|
| 117 | + public function version() |
|
| 118 | + { |
|
| 119 | + // if version is NOT set and this asset was NOT built for distribution, |
|
| 120 | + // then set the version equal to the EE core plugin version |
|
| 121 | + if ( |
|
| 122 | + $this->version === null |
|
| 123 | + && ( |
|
| 124 | + substr($this->source, -8) !== Asset::FILE_EXTENSION_DISTRIBUTION_JS |
|
| 125 | + || substr($this->source, -9) !== Asset::FILE_EXTENSION_DISTRIBUTION_CSS |
|
| 126 | + ) |
|
| 127 | + ) { |
|
| 128 | + $this->setVersion(); |
|
| 129 | + } |
|
| 130 | + return $this->version; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @param string $version |
|
| 136 | + * @return BrowserAsset |
|
| 137 | + * @throws InvalidDataTypeException |
|
| 138 | + */ |
|
| 139 | + public function setVersion($version = EVENT_ESPRESSO_VERSION) |
|
| 140 | + { |
|
| 141 | + if (! is_string($version)) { |
|
| 142 | + throw new InvalidDataTypeException( |
|
| 143 | + '$version', |
|
| 144 | + $version, |
|
| 145 | + 'string' |
|
| 146 | + ); |
|
| 147 | + } |
|
| 148 | + $this->version = $version; |
|
| 149 | + return $this; |
|
| 150 | + } |
|
| 151 | 151 | } |
@@ -54,7 +54,7 @@ |
||
| 54 | 54 | */ |
| 55 | 55 | private function setMedia($media) |
| 56 | 56 | { |
| 57 | - if (! is_string($media)) { |
|
| 57 | + if ( ! is_string($media)) { |
|
| 58 | 58 | throw new InvalidDataTypeException( |
| 59 | 59 | '$media', |
| 60 | 60 | $media, |
@@ -16,60 +16,60 @@ |
||
| 16 | 16 | class StylesheetAsset extends BrowserAsset |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var string $media |
|
| 21 | - */ |
|
| 22 | - private $media; |
|
| 19 | + /** |
|
| 20 | + * @var string $media |
|
| 21 | + */ |
|
| 22 | + private $media; |
|
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * CssFile constructor. |
|
| 27 | - * |
|
| 28 | - * @param $handle |
|
| 29 | - * @param string $source |
|
| 30 | - * @param array $dependencies |
|
| 31 | - * @param DomainInterface $domain |
|
| 32 | - * @param $media |
|
| 33 | - * @throws InvalidDataTypeException |
|
| 34 | - */ |
|
| 35 | - public function __construct($handle, $source, array $dependencies, DomainInterface $domain, $media = 'all') |
|
| 36 | - { |
|
| 37 | - parent::__construct(Asset::TYPE_CSS, $handle, $source, $dependencies, $domain); |
|
| 38 | - $this->setMedia($media); |
|
| 39 | - } |
|
| 25 | + /** |
|
| 26 | + * CssFile constructor. |
|
| 27 | + * |
|
| 28 | + * @param $handle |
|
| 29 | + * @param string $source |
|
| 30 | + * @param array $dependencies |
|
| 31 | + * @param DomainInterface $domain |
|
| 32 | + * @param $media |
|
| 33 | + * @throws InvalidDataTypeException |
|
| 34 | + */ |
|
| 35 | + public function __construct($handle, $source, array $dependencies, DomainInterface $domain, $media = 'all') |
|
| 36 | + { |
|
| 37 | + parent::__construct(Asset::TYPE_CSS, $handle, $source, $dependencies, $domain); |
|
| 38 | + $this->setMedia($media); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @return string |
|
| 44 | - */ |
|
| 45 | - public function media() |
|
| 46 | - { |
|
| 47 | - return $this->media; |
|
| 48 | - } |
|
| 42 | + /** |
|
| 43 | + * @return string |
|
| 44 | + */ |
|
| 45 | + public function media() |
|
| 46 | + { |
|
| 47 | + return $this->media; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param string $media |
|
| 53 | - * @throws InvalidDataTypeException |
|
| 54 | - */ |
|
| 55 | - private function setMedia($media) |
|
| 56 | - { |
|
| 57 | - if (! is_string($media)) { |
|
| 58 | - throw new InvalidDataTypeException( |
|
| 59 | - '$media', |
|
| 60 | - $media, |
|
| 61 | - 'string' |
|
| 62 | - ); |
|
| 63 | - } |
|
| 64 | - $this->media = $media; |
|
| 65 | - } |
|
| 51 | + /** |
|
| 52 | + * @param string $media |
|
| 53 | + * @throws InvalidDataTypeException |
|
| 54 | + */ |
|
| 55 | + private function setMedia($media) |
|
| 56 | + { |
|
| 57 | + if (! is_string($media)) { |
|
| 58 | + throw new InvalidDataTypeException( |
|
| 59 | + '$media', |
|
| 60 | + $media, |
|
| 61 | + 'string' |
|
| 62 | + ); |
|
| 63 | + } |
|
| 64 | + $this->media = $media; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @since 4.9.62.p |
|
| 70 | - */ |
|
| 71 | - public function enqueueAsset() |
|
| 72 | - { |
|
| 73 | - wp_enqueue_style($this->handle()); |
|
| 74 | - } |
|
| 68 | + /** |
|
| 69 | + * @since 4.9.62.p |
|
| 70 | + */ |
|
| 71 | + public function enqueueAsset() |
|
| 72 | + { |
|
| 73 | + wp_enqueue_style($this->handle()); |
|
| 74 | + } |
|
| 75 | 75 | } |