public function sortByDependencies($plugins = null)
    {
        if (!is_array($plugins)) {
            $plugins = $this->getPlugins();
        }

        $result = [];
        $checklist = $plugins;

        $loopCount = 0;
        while (count($checklist)) {

            if (++$loopCount > 999) {
                throw new ApplicationException('Too much recursion');
            }

            foreach ($checklist as $code => $plugin) {

                /*
                 * Get dependencies and remove any aliens
                 */
                $depends = $this->getDependencies($plugin) ?: [];
                $depends = array_filter($depends, function ($pluginCode) use ($plugins) {
                    return isset($plugins[$pluginCode]);
                });

                /*
                 * No dependencies
                 */
                if (!$depends) {
                    array_push($result, $code);
                    unset($checklist[$code]);
                    continue;
                }

                /*
                 * Find dependencies that have not been checked
                 */
                $depends = array_diff($depends, $result);
                if (count($depends) > 0) {
                    continue;
                }

                /*
                 * All dependencies are checked
                 */
                array_push($result, $code);
                unset($checklist[$code]);
            }

        }

        return $result;
    }
public function sortByDependencies($plugins = null)
    {
        if (!is_array($plugins)) {
            $plugins = $this->getPlugins();
        }

        $result = [];
        $checklist = $plugins;

        $loopCount = 0;
        while (count($checklist)) {

            if (++$loopCount > 999) {
                throw new ApplicationException('Too much recursion');
            }

            foreach ($checklist as $code => $plugin) {

                /*
                 * Get dependencies and remove any aliens
                 */
                $depends = $this->getDependencies($plugin) ?: [];
                $depends = array_filter($depends, function ($pluginCode) use ($plugins) {
                    return isset($plugins[$pluginCode]);
                });

                /*
                 * No dependencies
                 */
                if (!$depends) {
                    array_push($result, $code);
                    unset($checklist[$code]);
                    continue;
                }

                /*
                 * Find dependencies that have not been checked
                 */
                $depends = array_diff($depends, $result);
                if (count($depends) > 0) {
                    continue;
                }

                /*
                 * All dependencies are checked
                 */
                array_push($result, $code);
                unset($checklist[$code]);
            }

        }

        return $result;
    }
public function sortByDependencies ( $ plugins = null ) { if ( ! is_array ( $ plugins ) ) { $ plugins = $ this -> getPlugins ( ) ; } $ result = [ ] ; $ checklist = $ plugins ; $ loopCount = 0 ; while ( count ( $ checklist ) ) { if ( ++ $ loopCount > 999 ) { throw new ApplicationException ( 'Too much recursion' ) ; } foreach ( $ checklist as $ code => $ plugin ) { /*
                 * Get dependencies and remove any aliens
                 */ $ depends = $ this -> getDependencies ( $ plugin ) ? : [ ] ; $ depends = array_filter ( $ depends , function ( $ pluginCode ) use ( $ plugins ) { return isset ( $ plugins [ $ pluginCode ] ) ; } ) ; /*
                 * No dependencies
                 */ if ( ! $ depends ) { array_push ( $ result , $ code ) ; unset ( $ checklist [ $ code ] ) ; continue ; } /*
                 * Find dependencies that have not been checked
                 */ $ depends = array_diff ( $ depends , $ result ) ; if ( count ( $ depends ) > 0 ) { continue ; } /*
                 * All dependencies are checked
                 */ array_push ( $ result , $ code ) ; unset ( $ checklist [ $ code ] ) ; } } return $ result ; }
Sorts a collection of plugins, in the order that they should be actioned,
according to their given dependencies. Least dependent come first.
@param  array $plugins Object collection to sort, or null to sort all.
@return array Collection of sorted plugin identifiers
Sorts a collection of plugins in the order that they should be actioned according to their given dependencies . Least dependent come first .