コード例 #1
0
ファイル: Collection.php プロジェクト: jbzoo/assets
 /**
  * Adds asset to collection.
  *
  * @param Asset $asset
  * @return $this
  */
 public function add(Asset $asset)
 {
     $this->_assets[$asset->getAlias()] = $asset;
     return $this;
 }
コード例 #2
0
ファイル: Manager.php プロジェクト: jbzoo/assets
 /**
  * Resolves asset dependencies.
  *
  * @param Asset|null $asset
  * @param Asset[]    $resolved
  * @param Asset[]    $unresolved
  * @return Asset[]
  * @throws Exception
  */
 protected function _resolveDependencies(Asset $asset, &$resolved = [], &$unresolved = [])
 {
     $unresolved[$asset->getAlias()] = $asset;
     foreach ($asset->getDependencies() as $dependency) {
         if (!Arr::key($dependency, $resolved)) {
             if (isset($unresolved[$dependency])) {
                 throw new Exception(sprintf('Circular asset dependency "%s > %s" detected.', $asset->getAlias(), $dependency));
             }
             if ($dep = $this->_collection->get($dependency)) {
                 $this->_resolveDependencies($dep, $resolved, $unresolved);
             }
         }
     }
     $resolved[$asset->getAlias()] = $asset;
     unset($unresolved[$asset->getAlias()]);
     return $resolved;
 }