/** * @param AssetInterface $asset * @param array $properties * @return array */ public function getFilteredProperties(AssetInterface $asset, $properties = []) { $properties = array_filter($properties); $properties[self::PROPERTY_CONTENT_TYPE] = $asset->getContentType(); $properties[self::PROPERTY_CAN_MERGE] = $asset instanceof MergeableInterface; return $properties; }
/** * Replace asset in collection. * * @param string $name * @param AssetInterface $asset */ public function replace($name, AssetInterface $asset) { $assets = []; foreach ($this->assets as $key => $val) { if ($key == $name) { $assets[$asset->getName()] = $asset; } else { $assets[$key] = $val; } } $this->assets = $assets; }
/** * Returns minifier decorator class name for given asset * * @param AssetInterface $asset * @param bool $isDirectRequest * @return string */ protected function getDecoratorClass(AssetInterface $asset, $isDirectRequest) { if ($isDirectRequest || $asset->getContentType() == 'css') { $result = 'Magento\\Framework\\View\\Asset\\Minified\\ImmutablePathAsset'; } else { $result = 'Magento\\Framework\\View\\Asset\\Minified\\MutablePathAsset'; } return $result; }
/** * Add asset to collection. * * @param AssetInterface $asset */ public function add(AssetInterface $asset) { $this->assets[$asset->getName()] = $asset; }
/** * Resolves asset dependencies. * * @param AssetInterface $asset * @param AssetInterface[] $resolved * @param AssetInterface[] $unresolved * @return AssetInterface[] * @throws \RuntimeException */ protected function resolveDependencies($asset, &$resolved = [], &$unresolved = []) { $name = $asset->getName(); $unresolved[$name] = $asset; foreach ($asset->getDependencies() as $dependency) { if ($dependency[0] === '~' && !isset($resolved[$dependency = ltrim($dependency, '~')])) { continue; } if (!isset($resolved[$dependency])) { if (isset($unresolved[$dependency])) { throw new \RuntimeException(sprintf('Circular asset dependency "%s > %s" detected.', $name, $dependency)); } if ($d = $this->registered->get($dependency)) { $this->resolveDependencies($d, $resolved, $unresolved); } } } $resolved[$name] = $asset; unset($unresolved[$name]); if (isset($this->lazy[$name])) { foreach ($this->lazy[$name] as $dependency) { if ($d = $this->registered->get($dependency)) { $this->resolveDependencies($d, $resolved, $unresolved); } } } return $resolved; }