public function testSelfCycle() { $aParts = array(); $aParts['test/1'] = SystemPart::getPart('test/1'); $aParts['test/1']->dependOn($aParts['test/1']); $this->setExpectedException('Exception'); $aParts = SystemPart::orderedParts($aParts); }
public static function allParts() { $oCache = new Cache("system_parts", DIRNAME_CONFIG, CachingStrategyFile::create()); if ($oCache->entryExists()) { return $oCache->getContentsAsVariable(); } $oBasePart = new BasePart(); $oSitePart = new SitePart(); $aParts = array(DIRNAME_BASE => $oBasePart); // Get all plugins foreach (ResourceFinder::pluginFinder()->returnObjects()->find() as $oPath) { $oPluginPart = SystemPart::getPart($oPath->getRelativePath()); // Plugins depend on base implicitly $oPluginPart->dependOn($oBasePart); // Site depends on plugins implicitly $oSitePart->dependOn($oPluginPart); $aParts[$oPath->getRelativePath()] = $oPluginPart; } $oSitePart->dependOn($oBasePart); $aParts[DIRNAME_SITE] = $oSitePart; // Add dependencies from info foreach ($aParts as $oPart) { $aInfo = $oPart->getInfo(); foreach ($aInfo['dependencies'] as $sDependencyPrefix => $sVersion) { if (isset($aParts[$sDependencyPrefix])) { $oPart->dependOn($aParts[$sDependencyPrefix]); } else { throw new Exception("Dependency of {$oPart->getPrefix()} on {$sDependencyPrefix} can not be satisfied"); } } foreach ($aInfo['optional_dependencies'] as $sDependencyPrefix => $sVersion) { if (isset($aParts[$sDependencyPrefix])) { $oPart->dependOn($aParts[$sDependencyPrefix]); } } } // Order list by dependencies $aParts = self::orderedParts($aParts); // Cache ordered list $oCache->setContents($aParts); return $aParts; }