private function __findDatasourceOrder($dependenciesList)
    {
        if (!is_array($dependenciesList) || empty($dependenciesList)) {
            return;
        }

        foreach ($dependenciesList as $handle => $dependencies) {
            foreach ($dependencies as $i => $dependency) {
                $dependency = explode('.', $dependency);
                $dependenciesList[$handle][$i] = reset($dependency);
            }
        }

        $orderedList = array();
        $dsKeyArray = $this->__buildDatasourcePooledParamList(array_keys($dependenciesList));

        // 1. First do a cleanup of each dependency list, removing non-existant DS's and find
        //    the ones that have no dependencies, removing them from the list
        foreach ($dependenciesList as $handle => $dependencies) {
            $dependenciesList[$handle] = @array_intersect($dsKeyArray, $dependencies);

            if (empty($dependenciesList[$handle])) {
                unset($dependenciesList[$handle]);
                $orderedList[] = str_replace('_', '-', $handle);
            }
        }

        // 2. Iterate over the remaining DS's. Find if all their dependencies are
        //    in the $orderedList array. Keep iterating until all DS's are in that list
        //    or there are circular dependencies (list doesn't change between iterations
        //    of the while loop)
        do {
            $last_count = count($dependenciesList);

            foreach ($dependenciesList as $handle => $dependencies) {
                if (General::in_array_all(array_map(function($a) {return str_replace('$ds-', '', $a);}, $dependencies), $orderedList)) {
                    $orderedList[] = str_replace('_', '-', $handle);
                    unset($dependenciesList[$handle]);
                }
            }
        } while (!empty($dependenciesList) && $last_count > count($dependenciesList));

        if (!empty($dependenciesList)) {
            $orderedList = array_merge($orderedList, array_keys($dependenciesList));
        }

        return array_map(function($a) {return str_replace('-', '_', $a);}, $orderedList);
    }
private function __findDatasourceOrder($dependenciesList)
    {
        if (!is_array($dependenciesList) || empty($dependenciesList)) {
            return;
        }

        foreach ($dependenciesList as $handle => $dependencies) {
            foreach ($dependencies as $i => $dependency) {
                $dependency = explode('.', $dependency);
                $dependenciesList[$handle][$i] = reset($dependency);
            }
        }

        $orderedList = array();
        $dsKeyArray = $this->__buildDatasourcePooledParamList(array_keys($dependenciesList));

        // 1. First do a cleanup of each dependency list, removing non-existant DS's and find
        //    the ones that have no dependencies, removing them from the list
        foreach ($dependenciesList as $handle => $dependencies) {
            $dependenciesList[$handle] = @array_intersect($dsKeyArray, $dependencies);

            if (empty($dependenciesList[$handle])) {
                unset($dependenciesList[$handle]);
                $orderedList[] = str_replace('_', '-', $handle);
            }
        }

        // 2. Iterate over the remaining DS's. Find if all their dependencies are
        //    in the $orderedList array. Keep iterating until all DS's are in that list
        //    or there are circular dependencies (list doesn't change between iterations
        //    of the while loop)
        do {
            $last_count = count($dependenciesList);

            foreach ($dependenciesList as $handle => $dependencies) {
                if (General::in_array_all(array_map(function($a) {return str_replace('$ds-', '', $a);}, $dependencies), $orderedList)) {
                    $orderedList[] = str_replace('_', '-', $handle);
                    unset($dependenciesList[$handle]);
                }
            }
        } while (!empty($dependenciesList) && $last_count > count($dependenciesList));

        if (!empty($dependenciesList)) {
            $orderedList = array_merge($orderedList, array_keys($dependenciesList));
        }

        return array_map(function($a) {return str_replace('-', '_', $a);}, $orderedList);
    }
private function __findDatasourceOrder ( $ dependenciesList ) { if ( ! is_array ( $ dependenciesList ) || empty ( $ dependenciesList ) ) { return ; } foreach ( $ dependenciesList as $ handle => $ dependencies ) { foreach ( $ dependencies as $ i => $ dependency ) { $ dependency = explode ( '.' , $ dependency ) ; $ dependenciesList [ $ handle ] [ $ i ] = reset ( $ dependency ) ; } } $ orderedList = array ( ) ; $ dsKeyArray = $ this -> __buildDatasourcePooledParamList ( array_keys ( $ dependenciesList ) ) ; // 1. First do a cleanup of each dependency list, removing non-existant DS's and find //    the ones that have no dependencies, removing them from the list foreach ( $ dependenciesList as $ handle => $ dependencies ) { $ dependenciesList [ $ handle ] = @ array_intersect ( $ dsKeyArray , $ dependencies ) ; if ( empty ( $ dependenciesList [ $ handle ] ) ) { unset ( $ dependenciesList [ $ handle ] ) ; $ orderedList [ ] = str_replace ( '_' , '-' , $ handle ) ; } } // 2. Iterate over the remaining DS's. Find if all their dependencies are //    in the $orderedList array. Keep iterating until all DS's are in that list //    or there are circular dependencies (list doesn't change between iterations //    of the while loop) do { $ last_count = count ( $ dependenciesList ) ; foreach ( $ dependenciesList as $ handle => $ dependencies ) { if ( General :: in_array_all ( array_map ( function ( $ a ) { return str_replace ( '$ds-' , '' , $ a ) ; } , $ dependencies ) , $ orderedList ) ) { $ orderedList [ ] = str_replace ( '_' , '-' , $ handle ) ; unset ( $ dependenciesList [ $ handle ] ) ; } } } while ( ! empty ( $ dependenciesList ) && $ last_count > count ( $ dependenciesList ) ) ; if ( ! empty ( $ dependenciesList ) ) { $ orderedList = array_merge ( $ orderedList , array_keys ( $ dependenciesList ) ) ; } return array_map ( function ( $ a ) { return str_replace ( '-' , '_' , $ a ) ; } , $ orderedList ) ; }
The function finds the correct order Datasources need to be processed in to
satisfy all dependencies that parameters can resolve correctly and in time for
other Datasources to filter on.

@param array $dependenciesList
An associative array with the key being the Datasource handle and the values
being it's dependencies.
@return array
The sorted array of Datasources in order of how they should be executed
The function finds the correct order Datasources need to be processed in to satisfy all dependencies that parameters can resolve correctly and in time for other Datasources to filter on .