@@ -16,133 +16,133 @@ |
||
| 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 | - /** |
|
| 61 | - * Asset constructor. |
|
| 62 | - * |
|
| 63 | - * @param $type |
|
| 64 | - * @param string $handle |
|
| 65 | - * @param DomainInterface $domain |
|
| 66 | - * @throws InvalidDataTypeException |
|
| 67 | - */ |
|
| 68 | - public function __construct($type, $handle, DomainInterface $domain) |
|
| 69 | - { |
|
| 70 | - $this->domain = $domain; |
|
| 71 | - $this->setType($type); |
|
| 72 | - $this->setHandle($handle); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @return array |
|
| 78 | - */ |
|
| 79 | - public function validAssetTypes() |
|
| 80 | - { |
|
| 81 | - return array( |
|
| 82 | - Asset::TYPE_CSS, |
|
| 83 | - Asset::TYPE_JS, |
|
| 84 | - Asset::TYPE_MANIFEST, |
|
| 85 | - ); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @param string $type |
|
| 91 | - * @throws InvalidDataTypeException |
|
| 92 | - */ |
|
| 93 | - private function setType($type) |
|
| 94 | - { |
|
| 95 | - if (! in_array($type, $this->validAssetTypes(), true)) { |
|
| 96 | - throw new InvalidDataTypeException( |
|
| 97 | - 'Asset::$type', |
|
| 98 | - $type, |
|
| 99 | - 'one of the TYPE_* class constants on \EventEspresso\core\domain\values\Asset is required' |
|
| 100 | - ); |
|
| 101 | - } |
|
| 102 | - $this->type = $type; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @param string $handle |
|
| 108 | - * @throws InvalidDataTypeException |
|
| 109 | - */ |
|
| 110 | - private function setHandle($handle) |
|
| 111 | - { |
|
| 112 | - if (! is_string($handle)) { |
|
| 113 | - throw new InvalidDataTypeException( |
|
| 114 | - '$handle', |
|
| 115 | - $handle, |
|
| 116 | - 'string' |
|
| 117 | - ); |
|
| 118 | - } |
|
| 119 | - $this->handle = $handle; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @return string |
|
| 125 | - */ |
|
| 126 | - public function assetNamespace() |
|
| 127 | - { |
|
| 128 | - return $this->domain->assetNamespace(); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @return string |
|
| 134 | - */ |
|
| 135 | - public function type() |
|
| 136 | - { |
|
| 137 | - return $this->type; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @return string |
|
| 143 | - */ |
|
| 144 | - public function handle() |
|
| 145 | - { |
|
| 146 | - return $this->handle; |
|
| 147 | - } |
|
| 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 | + /** |
|
| 61 | + * Asset constructor. |
|
| 62 | + * |
|
| 63 | + * @param $type |
|
| 64 | + * @param string $handle |
|
| 65 | + * @param DomainInterface $domain |
|
| 66 | + * @throws InvalidDataTypeException |
|
| 67 | + */ |
|
| 68 | + public function __construct($type, $handle, DomainInterface $domain) |
|
| 69 | + { |
|
| 70 | + $this->domain = $domain; |
|
| 71 | + $this->setType($type); |
|
| 72 | + $this->setHandle($handle); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @return array |
|
| 78 | + */ |
|
| 79 | + public function validAssetTypes() |
|
| 80 | + { |
|
| 81 | + return array( |
|
| 82 | + Asset::TYPE_CSS, |
|
| 83 | + Asset::TYPE_JS, |
|
| 84 | + Asset::TYPE_MANIFEST, |
|
| 85 | + ); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @param string $type |
|
| 91 | + * @throws InvalidDataTypeException |
|
| 92 | + */ |
|
| 93 | + private function setType($type) |
|
| 94 | + { |
|
| 95 | + if (! in_array($type, $this->validAssetTypes(), true)) { |
|
| 96 | + throw new InvalidDataTypeException( |
|
| 97 | + 'Asset::$type', |
|
| 98 | + $type, |
|
| 99 | + 'one of the TYPE_* class constants on \EventEspresso\core\domain\values\Asset is required' |
|
| 100 | + ); |
|
| 101 | + } |
|
| 102 | + $this->type = $type; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @param string $handle |
|
| 108 | + * @throws InvalidDataTypeException |
|
| 109 | + */ |
|
| 110 | + private function setHandle($handle) |
|
| 111 | + { |
|
| 112 | + if (! is_string($handle)) { |
|
| 113 | + throw new InvalidDataTypeException( |
|
| 114 | + '$handle', |
|
| 115 | + $handle, |
|
| 116 | + 'string' |
|
| 117 | + ); |
|
| 118 | + } |
|
| 119 | + $this->handle = $handle; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @return string |
|
| 125 | + */ |
|
| 126 | + public function assetNamespace() |
|
| 127 | + { |
|
| 128 | + return $this->domain->assetNamespace(); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @return string |
|
| 134 | + */ |
|
| 135 | + public function type() |
|
| 136 | + { |
|
| 137 | + return $this->type; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @return string |
|
| 143 | + */ |
|
| 144 | + public function handle() |
|
| 145 | + { |
|
| 146 | + return $this->handle; |
|
| 147 | + } |
|
| 148 | 148 | } |
@@ -16,130 +16,130 @@ |
||
| 16 | 16 | 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 | - * @return array |
|
| 55 | - */ |
|
| 56 | - public function dependencies() |
|
| 57 | - { |
|
| 58 | - return $this->dependencies; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @param array $dependencies |
|
| 64 | - */ |
|
| 65 | - private function setDependencies(array $dependencies) |
|
| 66 | - { |
|
| 67 | - $this->dependencies = $dependencies; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @since $VID:$ |
|
| 73 | - * @return bool |
|
| 74 | - */ |
|
| 75 | - public function hasDependencies() |
|
| 76 | - { |
|
| 77 | - return count($this->dependencies) > 0; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @return string |
|
| 83 | - */ |
|
| 84 | - public function source() |
|
| 85 | - { |
|
| 86 | - return $this->source; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @param string $source |
|
| 92 | - * @throws InvalidDataTypeException |
|
| 93 | - */ |
|
| 94 | - private function setSource($source) |
|
| 95 | - { |
|
| 96 | - if (! is_string($source)) { |
|
| 97 | - throw new InvalidDataTypeException( |
|
| 98 | - '$source', |
|
| 99 | - $source, |
|
| 100 | - 'string' |
|
| 101 | - ); |
|
| 102 | - } |
|
| 103 | - $this->source = $source; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @return string |
|
| 109 | - * @throws InvalidDataTypeException |
|
| 110 | - */ |
|
| 111 | - public function version() |
|
| 112 | - { |
|
| 113 | - // if version is NOT set and this asset was NOT built for distribution, |
|
| 114 | - // then set the version equal to the EE core plugin version |
|
| 115 | - if ( |
|
| 116 | - $this->version === null |
|
| 117 | - && ( |
|
| 118 | - substr($this->source, -8) !== Asset::FILE_EXTENSION_DISTRIBUTION_JS |
|
| 119 | - || substr($this->source, -9) !== Asset::FILE_EXTENSION_DISTRIBUTION_CSS |
|
| 120 | - ) |
|
| 121 | - ) { |
|
| 122 | - $this->setVersion(); |
|
| 123 | - } |
|
| 124 | - return $this->version; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @param string $version |
|
| 130 | - * @return BrowserAsset |
|
| 131 | - * @throws InvalidDataTypeException |
|
| 132 | - */ |
|
| 133 | - public function setVersion($version = EVENT_ESPRESSO_VERSION) |
|
| 134 | - { |
|
| 135 | - if (! is_string($version)) { |
|
| 136 | - throw new InvalidDataTypeException( |
|
| 137 | - '$version', |
|
| 138 | - $version, |
|
| 139 | - 'string' |
|
| 140 | - ); |
|
| 141 | - } |
|
| 142 | - $this->version = $version; |
|
| 143 | - return $this; |
|
| 144 | - } |
|
| 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 | + * @return array |
|
| 55 | + */ |
|
| 56 | + public function dependencies() |
|
| 57 | + { |
|
| 58 | + return $this->dependencies; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @param array $dependencies |
|
| 64 | + */ |
|
| 65 | + private function setDependencies(array $dependencies) |
|
| 66 | + { |
|
| 67 | + $this->dependencies = $dependencies; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @since $VID:$ |
|
| 73 | + * @return bool |
|
| 74 | + */ |
|
| 75 | + public function hasDependencies() |
|
| 76 | + { |
|
| 77 | + return count($this->dependencies) > 0; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @return string |
|
| 83 | + */ |
|
| 84 | + public function source() |
|
| 85 | + { |
|
| 86 | + return $this->source; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @param string $source |
|
| 92 | + * @throws InvalidDataTypeException |
|
| 93 | + */ |
|
| 94 | + private function setSource($source) |
|
| 95 | + { |
|
| 96 | + if (! is_string($source)) { |
|
| 97 | + throw new InvalidDataTypeException( |
|
| 98 | + '$source', |
|
| 99 | + $source, |
|
| 100 | + 'string' |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | + $this->source = $source; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @return string |
|
| 109 | + * @throws InvalidDataTypeException |
|
| 110 | + */ |
|
| 111 | + public function version() |
|
| 112 | + { |
|
| 113 | + // if version is NOT set and this asset was NOT built for distribution, |
|
| 114 | + // then set the version equal to the EE core plugin version |
|
| 115 | + if ( |
|
| 116 | + $this->version === null |
|
| 117 | + && ( |
|
| 118 | + substr($this->source, -8) !== Asset::FILE_EXTENSION_DISTRIBUTION_JS |
|
| 119 | + || substr($this->source, -9) !== Asset::FILE_EXTENSION_DISTRIBUTION_CSS |
|
| 120 | + ) |
|
| 121 | + ) { |
|
| 122 | + $this->setVersion(); |
|
| 123 | + } |
|
| 124 | + return $this->version; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @param string $version |
|
| 130 | + * @return BrowserAsset |
|
| 131 | + * @throws InvalidDataTypeException |
|
| 132 | + */ |
|
| 133 | + public function setVersion($version = EVENT_ESPRESSO_VERSION) |
|
| 134 | + { |
|
| 135 | + if (! is_string($version)) { |
|
| 136 | + throw new InvalidDataTypeException( |
|
| 137 | + '$version', |
|
| 138 | + $version, |
|
| 139 | + 'string' |
|
| 140 | + ); |
|
| 141 | + } |
|
| 142 | + $this->version = $version; |
|
| 143 | + return $this; |
|
| 144 | + } |
|
| 145 | 145 | } |