original_string: public function sortPluginsAndRespectDependencies(array $plugins, $pluginJsonCache = array())
      {
          $global = $this->getPluginsBundledWithPiwik();
  
          if (empty($global)) {
              return $plugins;
          }
  
          // we need to make sure a possibly disabled plugin will be still loaded before any 3rd party plugin
          $global = array_merge($global, $this->corePluginsDisabledByDefault);
  
          $global = array_values($global);
          $plugins = array_values($plugins);
  
          $defaultPluginsLoadedFirst = array_intersect($global, $plugins);
  
          $otherPluginsToLoadAfterDefaultPlugins = array_diff($plugins, $defaultPluginsLoadedFirst);
  
          // we still want to sort alphabetically by default
          natcasesort($otherPluginsToLoadAfterDefaultPlugins);
  
          $sorted = array();
          foreach ($otherPluginsToLoadAfterDefaultPlugins as $pluginName) {
              $sorted = $this->sortRequiredPlugin($pluginName, $pluginJsonCache, $otherPluginsToLoadAfterDefaultPlugins, $sorted);
          }
  
          $sorted = array_merge($defaultPluginsLoadedFirst, $sorted);
  
          return $sorted;
      }
code: public function sortPluginsAndRespectDependencies(array $plugins, $pluginJsonCache = array())
      {
          $global = $this->getPluginsBundledWithPiwik();
  
          if (empty($global)) {
              return $plugins;
          }
  
          // we need to make sure a possibly disabled plugin will be still loaded before any 3rd party plugin
          $global = array_merge($global, $this->corePluginsDisabledByDefault);
  
          $global = array_values($global);
          $plugins = array_values($plugins);
  
          $defaultPluginsLoadedFirst = array_intersect($global, $plugins);
  
          $otherPluginsToLoadAfterDefaultPlugins = array_diff($plugins, $defaultPluginsLoadedFirst);
  
          // we still want to sort alphabetically by default
          natcasesort($otherPluginsToLoadAfterDefaultPlugins);
  
          $sorted = array();
          foreach ($otherPluginsToLoadAfterDefaultPlugins as $pluginName) {
              $sorted = $this->sortRequiredPlugin($pluginName, $pluginJsonCache, $otherPluginsToLoadAfterDefaultPlugins, $sorted);
          }
  
          $sorted = array_merge($defaultPluginsLoadedFirst, $sorted);
  
          return $sorted;
      }
code_tokens: public function sortPluginsAndRespectDependencies ( array $ plugins , $ pluginJsonCache = array ( ) ) { $ global = $ this -> getPluginsBundledWithPiwik ( ) ; if ( empty ( $ global ) ) { return $ plugins ; } // we need to make sure a possibly disabled plugin will be still loaded before any 3rd party plugin $ global = array_merge ( $ global , $ this -> corePluginsDisabledByDefault ) ; $ global = array_values ( $ global ) ; $ plugins = array_values ( $ plugins ) ; $ defaultPluginsLoadedFirst = array_intersect ( $ global , $ plugins ) ; $ otherPluginsToLoadAfterDefaultPlugins = array_diff ( $ plugins , $ defaultPluginsLoadedFirst ) ; // we still want to sort alphabetically by default natcasesort ( $ otherPluginsToLoadAfterDefaultPlugins ) ; $ sorted = array ( ) ; foreach ( $ otherPluginsToLoadAfterDefaultPlugins as $ pluginName ) { $ sorted = $ this -> sortRequiredPlugin ( $ pluginName , $ pluginJsonCache , $ otherPluginsToLoadAfterDefaultPlugins , $ sorted ) ; } $ sorted = array_merge ( $ defaultPluginsLoadedFirst , $ sorted ) ; return $ sorted ; }
docstring: Sorts an array of plugins in the order they should be saved in config.ini.php. This basically influences
  the order of the plugin config.php and which config will be loaded first. We want to make sure to require the
  config or a required plugin first before loading the plugin that requires it.
  
  We do not sort using this logic on each request since it is much slower than `sortPlugins()`. The order
  of plugins in config.ini.php is only important for the ContainerFactory. During a regular request it is otherwise
  fine to load the plugins in the order of `sortPlugins()` since we will make sure that required plugins will be
  loaded first in plugin manager.
  
  @param string[] $plugins
  @param array[] $pluginJsonCache  For internal testing only
  @return \string[]
docstring_tokens: Sorts an array of plugins in the order they should be saved in config . ini . php . This basically influences the order of the plugin config . php and which config will be loaded first . We want to make sure to require the config or a required plugin first before loading the plugin that requires it .