private function _parseDependencies($dependency) { $ret = array(); $deps = Kwf_Assets_CommonJs_Parser::parse($dependency->getAbsoluteFileName()); foreach ($deps as $dep) { if (substr($dep, 0, 2) == './') { $fn = $dependency->getFileNameWithType(); $dir = substr($fn, 0, strrpos($fn, '/') + 1); $dep = $dir . substr($dep, 2); } $d = $this->_providerList->findDependency($dep); if (!$d) { throw new Kwf_Exception("Can't resolve dependency: require '{$dep}' for {$dependency}"); } $ret[$dep] = $d; foreach ($this->_parseDependencies($d) as $i) { $d->addDependency(Kwf_Assets_Dependency_Abstract::DEPENDENCY_TYPE_COMMONJS, $i); } } return $ret; }
private function _parseDependencies($dependency) { if (in_array($dependency, $this->_parsed, true)) { return array(); } $this->_parsed[] = $dependency; $ret = array(); $deps = array(); $src = $dependency->getContentsSource(); if ($src['type'] == 'file') { $deps = Kwf_Assets_CommonJs_Parser::parse($src['file']); } else { if ($src['type'] == 'contents') { $temp = tempnam('temp/', 'commonjs'); file_put_contents($temp, $src['contents']); $deps = Kwf_Assets_CommonJs_Parser::parse($temp); unlink($temp); } else { throw new Kwf_Exception_NotYetImplemented(); } } foreach ($deps as $dep) { if (substr($dep, 0, 2) == './') { $fn = $dependency->getFileNameWithType(); $dir = substr($fn, 0, strrpos($fn, '/') + 1); $dep = $dir . substr($dep, 2); } $d = $this->_providerList->findDependency($dep); if (!$d) { throw new Kwf_Exception("Can't resolve dependency: require '{$dep}' for {$dependency}"); } $ret[$dep] = $d; foreach ($this->_parseDependencies($d) as $index => $i) { $d->addDependency(Kwf_Assets_Dependency_Abstract::DEPENDENCY_TYPE_COMMONJS, $i, $index); } } return $ret; }