@@ -21,142 +21,142 @@ |
||
| 21 | 21 | abstract class AssetManager implements AssetManagerInterface |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var AssetCollection $assets |
|
| 26 | - */ |
|
| 27 | - protected $assets; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var DomainInterface |
|
| 31 | - */ |
|
| 32 | - protected $domain; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var Registry $registry |
|
| 36 | - */ |
|
| 37 | - protected $registry; |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * AssetRegister constructor. |
|
| 42 | - * |
|
| 43 | - * @param DomainInterface $domain |
|
| 44 | - * @param AssetCollection $assets |
|
| 45 | - * @param Registry $registry |
|
| 46 | - */ |
|
| 47 | - public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry) |
|
| 48 | - { |
|
| 49 | - $this->domain = $domain; |
|
| 50 | - $this->assets = $assets; |
|
| 51 | - $this->registry = $registry; |
|
| 52 | - add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
| 53 | - add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
| 54 | - add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2); |
|
| 55 | - add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @return void |
|
| 61 | - * @throws DuplicateCollectionIdentifierException |
|
| 62 | - * @throws InvalidDataTypeException |
|
| 63 | - * @throws InvalidEntityException |
|
| 64 | - * @since 4.9.62.p |
|
| 65 | - */ |
|
| 66 | - public function addManifestFile() |
|
| 67 | - { |
|
| 68 | - // if a manifest file has already been added for this domain, then just return that one |
|
| 69 | - if ($this->assets->has($this->domain->assetNamespace())) { |
|
| 70 | - return; |
|
| 71 | - } |
|
| 72 | - $asset = new ManifestFile($this->domain); |
|
| 73 | - $this->assets->add($asset, $this->domain->assetNamespace()); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @return ManifestFile[] |
|
| 79 | - * @since 4.9.62.p |
|
| 80 | - */ |
|
| 81 | - public function getManifestFile() |
|
| 82 | - { |
|
| 83 | - return $this->assets->getManifestFiles(); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param string $handle |
|
| 89 | - * @param string $source |
|
| 90 | - * @param array $dependencies |
|
| 91 | - * @param bool $load_in_footer |
|
| 92 | - * @return JavascriptAsset |
|
| 93 | - * @throws DuplicateCollectionIdentifierException |
|
| 94 | - * @throws InvalidDataTypeException |
|
| 95 | - * @throws InvalidEntityException |
|
| 96 | - * @since 4.9.62.p |
|
| 97 | - */ |
|
| 98 | - public function addJavascript( |
|
| 99 | - $handle, |
|
| 100 | - $source, |
|
| 101 | - array $dependencies = array(), |
|
| 102 | - $load_in_footer = true |
|
| 103 | - ) { |
|
| 104 | - $asset = new JavascriptAsset( |
|
| 105 | - $handle, |
|
| 106 | - $source, |
|
| 107 | - $dependencies, |
|
| 108 | - $load_in_footer, |
|
| 109 | - $this->domain |
|
| 110 | - ); |
|
| 111 | - $this->assets->add($asset, $handle); |
|
| 112 | - return $asset; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @param string $handle |
|
| 119 | - * @param string $source |
|
| 120 | - * @param array $dependencies |
|
| 121 | - * @param string $media |
|
| 122 | - * @return StylesheetAsset |
|
| 123 | - * @throws DuplicateCollectionIdentifierException |
|
| 124 | - * @throws InvalidDataTypeException |
|
| 125 | - * @throws InvalidEntityException |
|
| 126 | - * @since 4.9.62.p |
|
| 127 | - */ |
|
| 128 | - public function addStylesheet( |
|
| 129 | - $handle, |
|
| 130 | - $source, |
|
| 131 | - array $dependencies = array(), |
|
| 132 | - $media = 'all' |
|
| 133 | - ) { |
|
| 134 | - $asset = new StylesheetAsset( |
|
| 135 | - $handle, |
|
| 136 | - $source, |
|
| 137 | - $dependencies, |
|
| 138 | - $this->domain, |
|
| 139 | - $media |
|
| 140 | - ); |
|
| 141 | - $this->assets->add($asset, $handle); |
|
| 142 | - return $asset; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @param string $handle |
|
| 148 | - * @return bool |
|
| 149 | - * @since 4.9.62.p |
|
| 150 | - */ |
|
| 151 | - public function enqueueAsset($handle) |
|
| 152 | - { |
|
| 153 | - if ($this->assets->has($handle)) { |
|
| 154 | - $asset = $this->assets->get($handle); |
|
| 155 | - if ($asset->isRegistered()) { |
|
| 156 | - $asset->enqueueAsset(); |
|
| 157 | - return true; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - return false; |
|
| 161 | - } |
|
| 24 | + /** |
|
| 25 | + * @var AssetCollection $assets |
|
| 26 | + */ |
|
| 27 | + protected $assets; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var DomainInterface |
|
| 31 | + */ |
|
| 32 | + protected $domain; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var Registry $registry |
|
| 36 | + */ |
|
| 37 | + protected $registry; |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * AssetRegister constructor. |
|
| 42 | + * |
|
| 43 | + * @param DomainInterface $domain |
|
| 44 | + * @param AssetCollection $assets |
|
| 45 | + * @param Registry $registry |
|
| 46 | + */ |
|
| 47 | + public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry) |
|
| 48 | + { |
|
| 49 | + $this->domain = $domain; |
|
| 50 | + $this->assets = $assets; |
|
| 51 | + $this->registry = $registry; |
|
| 52 | + add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
| 53 | + add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
| 54 | + add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2); |
|
| 55 | + add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @return void |
|
| 61 | + * @throws DuplicateCollectionIdentifierException |
|
| 62 | + * @throws InvalidDataTypeException |
|
| 63 | + * @throws InvalidEntityException |
|
| 64 | + * @since 4.9.62.p |
|
| 65 | + */ |
|
| 66 | + public function addManifestFile() |
|
| 67 | + { |
|
| 68 | + // if a manifest file has already been added for this domain, then just return that one |
|
| 69 | + if ($this->assets->has($this->domain->assetNamespace())) { |
|
| 70 | + return; |
|
| 71 | + } |
|
| 72 | + $asset = new ManifestFile($this->domain); |
|
| 73 | + $this->assets->add($asset, $this->domain->assetNamespace()); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @return ManifestFile[] |
|
| 79 | + * @since 4.9.62.p |
|
| 80 | + */ |
|
| 81 | + public function getManifestFile() |
|
| 82 | + { |
|
| 83 | + return $this->assets->getManifestFiles(); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param string $handle |
|
| 89 | + * @param string $source |
|
| 90 | + * @param array $dependencies |
|
| 91 | + * @param bool $load_in_footer |
|
| 92 | + * @return JavascriptAsset |
|
| 93 | + * @throws DuplicateCollectionIdentifierException |
|
| 94 | + * @throws InvalidDataTypeException |
|
| 95 | + * @throws InvalidEntityException |
|
| 96 | + * @since 4.9.62.p |
|
| 97 | + */ |
|
| 98 | + public function addJavascript( |
|
| 99 | + $handle, |
|
| 100 | + $source, |
|
| 101 | + array $dependencies = array(), |
|
| 102 | + $load_in_footer = true |
|
| 103 | + ) { |
|
| 104 | + $asset = new JavascriptAsset( |
|
| 105 | + $handle, |
|
| 106 | + $source, |
|
| 107 | + $dependencies, |
|
| 108 | + $load_in_footer, |
|
| 109 | + $this->domain |
|
| 110 | + ); |
|
| 111 | + $this->assets->add($asset, $handle); |
|
| 112 | + return $asset; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @param string $handle |
|
| 119 | + * @param string $source |
|
| 120 | + * @param array $dependencies |
|
| 121 | + * @param string $media |
|
| 122 | + * @return StylesheetAsset |
|
| 123 | + * @throws DuplicateCollectionIdentifierException |
|
| 124 | + * @throws InvalidDataTypeException |
|
| 125 | + * @throws InvalidEntityException |
|
| 126 | + * @since 4.9.62.p |
|
| 127 | + */ |
|
| 128 | + public function addStylesheet( |
|
| 129 | + $handle, |
|
| 130 | + $source, |
|
| 131 | + array $dependencies = array(), |
|
| 132 | + $media = 'all' |
|
| 133 | + ) { |
|
| 134 | + $asset = new StylesheetAsset( |
|
| 135 | + $handle, |
|
| 136 | + $source, |
|
| 137 | + $dependencies, |
|
| 138 | + $this->domain, |
|
| 139 | + $media |
|
| 140 | + ); |
|
| 141 | + $this->assets->add($asset, $handle); |
|
| 142 | + return $asset; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @param string $handle |
|
| 148 | + * @return bool |
|
| 149 | + * @since 4.9.62.p |
|
| 150 | + */ |
|
| 151 | + public function enqueueAsset($handle) |
|
| 152 | + { |
|
| 153 | + if ($this->assets->has($handle)) { |
|
| 154 | + $asset = $this->assets->get($handle); |
|
| 155 | + if ($asset->isRegistered()) { |
|
| 156 | + $asset->enqueueAsset(); |
|
| 157 | + return true; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + return false; |
|
| 161 | + } |
|
| 162 | 162 | } |
@@ -20,72 +20,72 @@ |
||
| 20 | 20 | interface AssetManagerInterface |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @since 4.9.62.p |
|
| 25 | - */ |
|
| 26 | - public function addAssets(); |
|
| 23 | + /** |
|
| 24 | + * @since 4.9.62.p |
|
| 25 | + */ |
|
| 26 | + public function addAssets(); |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @return ManifestFile |
|
| 31 | - * @throws DuplicateCollectionIdentifierException |
|
| 32 | - * @throws InvalidDataTypeException |
|
| 33 | - * @throws InvalidEntityException |
|
| 34 | - * @since 4.9.62.p |
|
| 35 | - */ |
|
| 36 | - public function addManifestFile(); |
|
| 29 | + /** |
|
| 30 | + * @return ManifestFile |
|
| 31 | + * @throws DuplicateCollectionIdentifierException |
|
| 32 | + * @throws InvalidDataTypeException |
|
| 33 | + * @throws InvalidEntityException |
|
| 34 | + * @since 4.9.62.p |
|
| 35 | + */ |
|
| 36 | + public function addManifestFile(); |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @return ManifestFile[] |
|
| 41 | - * @since 4.9.62.p |
|
| 42 | - */ |
|
| 43 | - public function getManifestFile(); |
|
| 39 | + /** |
|
| 40 | + * @return ManifestFile[] |
|
| 41 | + * @since 4.9.62.p |
|
| 42 | + */ |
|
| 43 | + public function getManifestFile(); |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @param string $handle |
|
| 48 | - * @param string $source |
|
| 49 | - * @param array $dependencies |
|
| 50 | - * @param bool $load_in_footer |
|
| 51 | - * @return JavascriptAsset |
|
| 52 | - * @throws DuplicateCollectionIdentifierException |
|
| 53 | - * @throws InvalidDataTypeException |
|
| 54 | - * @throws InvalidEntityException |
|
| 55 | - * @since 4.9.62.p |
|
| 56 | - */ |
|
| 57 | - public function addJavascript( |
|
| 58 | - $handle, |
|
| 59 | - $source, |
|
| 60 | - array $dependencies = array(), |
|
| 61 | - $load_in_footer = true |
|
| 62 | - ); |
|
| 46 | + /** |
|
| 47 | + * @param string $handle |
|
| 48 | + * @param string $source |
|
| 49 | + * @param array $dependencies |
|
| 50 | + * @param bool $load_in_footer |
|
| 51 | + * @return JavascriptAsset |
|
| 52 | + * @throws DuplicateCollectionIdentifierException |
|
| 53 | + * @throws InvalidDataTypeException |
|
| 54 | + * @throws InvalidEntityException |
|
| 55 | + * @since 4.9.62.p |
|
| 56 | + */ |
|
| 57 | + public function addJavascript( |
|
| 58 | + $handle, |
|
| 59 | + $source, |
|
| 60 | + array $dependencies = array(), |
|
| 61 | + $load_in_footer = true |
|
| 62 | + ); |
|
| 63 | 63 | |
| 64 | 64 | |
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @param string $handle |
|
| 68 | - * @param string $source |
|
| 69 | - * @param array $dependencies |
|
| 70 | - * @param string $media |
|
| 71 | - * @return StylesheetAsset |
|
| 72 | - * @throws DuplicateCollectionIdentifierException |
|
| 73 | - * @throws InvalidDataTypeException |
|
| 74 | - * @throws InvalidEntityException |
|
| 75 | - * @since 4.9.62.p |
|
| 76 | - */ |
|
| 77 | - public function addStylesheet( |
|
| 78 | - $handle, |
|
| 79 | - $source, |
|
| 80 | - array $dependencies = array(), |
|
| 81 | - $media = 'all' |
|
| 82 | - ); |
|
| 66 | + /** |
|
| 67 | + * @param string $handle |
|
| 68 | + * @param string $source |
|
| 69 | + * @param array $dependencies |
|
| 70 | + * @param string $media |
|
| 71 | + * @return StylesheetAsset |
|
| 72 | + * @throws DuplicateCollectionIdentifierException |
|
| 73 | + * @throws InvalidDataTypeException |
|
| 74 | + * @throws InvalidEntityException |
|
| 75 | + * @since 4.9.62.p |
|
| 76 | + */ |
|
| 77 | + public function addStylesheet( |
|
| 78 | + $handle, |
|
| 79 | + $source, |
|
| 80 | + array $dependencies = array(), |
|
| 81 | + $media = 'all' |
|
| 82 | + ); |
|
| 83 | 83 | |
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @param string $handle |
|
| 87 | - * @return bool |
|
| 88 | - * @since 4.9.62.p |
|
| 89 | - */ |
|
| 90 | - public function enqueueAsset($handle); |
|
| 85 | + /** |
|
| 86 | + * @param string $handle |
|
| 87 | + * @return bool |
|
| 88 | + * @since 4.9.62.p |
|
| 89 | + */ |
|
| 90 | + public function enqueueAsset($handle); |
|
| 91 | 91 | } |