function testDependcy() { $items = array('C', 'B', 'F', 'A' => array('B', 'C'), 'E' => array('B'), 'D' => array('A', 'E')); $source = new OA_Algorithm_Dependency_Source_HoA($items); $dep = new OA_Algorithm_Dependency_Ordered($source); // test schedule $ret = $dep->schedule(array('G')); $this->assertFalse($ret); $ret = $dep->schedule(array('B')); $this->assertEqual(array_values($ret), array('B')); $ret = $dep->schedule(array('A')); $this->assertEqual(array_values($ret), array('B', 'C', 'A')); $ret = $dep->schedule(array('D')); $this->assertEqual(array_values($ret), array('B', 'C', 'E', 'A', 'D')); // test schedule all $ret = $dep->scheduleAll(); $this->assertEqual(array_values($ret), array('B', 'C', 'E', 'F', 'A', 'D')); }
/** * Check the dependencies for active delivery log components and * sort the in the correct order so each dependency is resolved. * * @param array $aComponentsToSchedule Array of components Ids which need to be schedules * format: array(hook name => array(components Ids)) * @param array $aAllComponentIdsByHooks Array of all components identifiers * @return array Array of components ids schedules in order of dependency */ function getDependencyOrderedPlugins($aComponentsToSchedule, $aAllComponentIdsByHooks) { $aDeliveryComponentsHooks = $this->filterDeliveryHooks($aAllComponentIdsByHooks); $pluginsDependencies = $this->getComponentsDependencies($aDeliveryComponentsHooks); if (!$pluginsDependencies) { $this->_logError('No dependencies are defined'); return false; } $source = new OA_Algorithm_Dependency_Source_HoA($pluginsDependencies); // should we update this value only if the result of sorting is positive? $dep = new OA_Algorithm_Dependency_Ordered($source, array(), $ignoreOrphans = true); return array_values($dep->schedule($aComponentsToSchedule)); }