public static function extensionOrdering( array $activeExtensions )
    {
        $activeExtensionsSet = array_flip( $activeExtensions );

        $dependencies = array();
        foreach ( $activeExtensions as $extension )
        {
            $loadingOrderData = ezpExtension::getInstance( $extension )->getLoadingOrder();

            // The extension should appear even without dependencies to be taken into account
            if ( ! isset( $dependencies[$extension] ) )
                $dependencies[$extension] = array();

            if ( isset( $loadingOrderData['after'] ) )
            {
                foreach ( $loadingOrderData['after'] as $dependency )
                {
                    if ( isset( $activeExtensionsSet[$dependency] ) )
                        $dependencies[$extension][] = $dependency;
                }
            }
            if ( isset( $loadingOrderData['before'] ) )
            {
                foreach ( $loadingOrderData['before'] as $dependency )
                {
                    if ( isset( $activeExtensionsSet[$dependency] ) )
                        $dependencies[$dependency][] = $extension;
                }
            }
        }

        $topologySort = new ezpTopologicalSort( $dependencies );
        $activeExtensionsSorted = $topologySort->sort();

        return $activeExtensionsSorted !== false ? $activeExtensionsSorted : $activeExtensions;
    }