UIAsset
1 year ago
UIAssetFetcher
1 month ago
UIAssetMerger
1 month ago
UIAsset.php
2 years ago
UIAssetCacheBuster.php
7 months ago
UIAssetCatalog.php
5 months ago
UIAssetCatalogSorter.php
2 years ago
UIAssetFetcher.php
1 year ago
UIAssetMerger.php
1 year ago
UIAssetMinifier.php
1 year ago
UIAssetCatalog.php
66 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Matomo - free/libre analytics platform |
| 5 | * |
| 6 | * @link https://matomo.org |
| 7 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 8 | */ |
| 9 | namespace Piwik\AssetManager; |
| 10 | |
| 11 | class UIAssetCatalog |
| 12 | { |
| 13 | /** |
| 14 | * @var UIAsset[] |
| 15 | */ |
| 16 | private $uiAssets = array(); |
| 17 | /** |
| 18 | * @var UIAssetCatalogSorter |
| 19 | */ |
| 20 | private $catalogSorter; |
| 21 | /** |
| 22 | * @var string[] Absolute file locations |
| 23 | */ |
| 24 | private $existingAssetLocations = array(); |
| 25 | /** |
| 26 | * @param UIAssetCatalogSorter $catalogSorter |
| 27 | */ |
| 28 | public function __construct($catalogSorter) |
| 29 | { |
| 30 | $this->catalogSorter = $catalogSorter; |
| 31 | } |
| 32 | /** |
| 33 | * @param UIAsset $uiAsset |
| 34 | */ |
| 35 | public function addUIAsset($uiAsset) |
| 36 | { |
| 37 | $location = $uiAsset->getAbsoluteLocation(); |
| 38 | if (!$this->assetAlreadyInCatalog($location)) { |
| 39 | $this->existingAssetLocations[] = $location; |
| 40 | $this->uiAssets[] = $uiAsset; |
| 41 | } |
| 42 | } |
| 43 | /** |
| 44 | * @return UIAsset[] |
| 45 | */ |
| 46 | public function getAssets() |
| 47 | { |
| 48 | return $this->uiAssets; |
| 49 | } |
| 50 | /** |
| 51 | * @return UIAssetCatalog |
| 52 | */ |
| 53 | public function getSortedCatalog() |
| 54 | { |
| 55 | return $this->catalogSorter->sortUIAssetCatalog($this); |
| 56 | } |
| 57 | /** |
| 58 | * @param string $location |
| 59 | * @return boolean |
| 60 | */ |
| 61 | private function assetAlreadyInCatalog($location) |
| 62 | { |
| 63 | return in_array($location, $this->existingAssetLocations); |
| 64 | } |
| 65 | } |
| 66 |