original_string: public static function getComponentIf($componentTypeClass, $pluginName, $predicate)
      {
          $pluginManager = PluginManager::getInstance();
  
          // get components to search through
          $subnamespace = $componentTypeClass::COMPONENT_SUBNAMESPACE;
          if (empty($pluginName)) {
              $components = $pluginManager->findMultipleComponents($subnamespace, $componentTypeClass);
          } else {
              $plugin = self::getActivatedPlugin(__FUNCTION__, $pluginName);
              if (empty($plugin)) {
                  return null;
              }
  
              $components = $plugin->findMultipleComponents($subnamespace, $componentTypeClass);
          }
  
          // find component that satisfieds predicate
          foreach ($components as $class) {
              $component = new $class();
              if ($predicate($component)) {
                  return $component;
              }
          }
  
          Log::debug("ComponentFactory::%s: Could not find component that satisfies predicate (args = ['%s', '%s', '%s']).",
              __FUNCTION__, $componentTypeClass, $pluginName, get_class($predicate));
  
          return null;
      }
code: public static function getComponentIf($componentTypeClass, $pluginName, $predicate)
      {
          $pluginManager = PluginManager::getInstance();
  
          // get components to search through
          $subnamespace = $componentTypeClass::COMPONENT_SUBNAMESPACE;
          if (empty($pluginName)) {
              $components = $pluginManager->findMultipleComponents($subnamespace, $componentTypeClass);
          } else {
              $plugin = self::getActivatedPlugin(__FUNCTION__, $pluginName);
              if (empty($plugin)) {
                  return null;
              }
  
              $components = $plugin->findMultipleComponents($subnamespace, $componentTypeClass);
          }
  
          // find component that satisfieds predicate
          foreach ($components as $class) {
              $component = new $class();
              if ($predicate($component)) {
                  return $component;
              }
          }
  
          Log::debug("ComponentFactory::%s: Could not find component that satisfies predicate (args = ['%s', '%s', '%s']).",
              __FUNCTION__, $componentTypeClass, $pluginName, get_class($predicate));
  
          return null;
      }
code_tokens: public static function getComponentIf ( $ componentTypeClass , $ pluginName , $ predicate ) { $ pluginManager = PluginManager :: getInstance ( ) ; // get components to search through $ subnamespace = $ componentTypeClass :: COMPONENT_SUBNAMESPACE ; if ( empty ( $ pluginName ) ) { $ components = $ pluginManager -> findMultipleComponents ( $ subnamespace , $ componentTypeClass ) ; } else { $ plugin = self :: getActivatedPlugin ( __FUNCTION__ , $ pluginName ) ; if ( empty ( $ plugin ) ) { return null ; } $ components = $ plugin -> findMultipleComponents ( $ subnamespace , $ componentTypeClass ) ; } // find component that satisfieds predicate foreach ( $ components as $ class ) { $ component = new $ class ( ) ; if ( $ predicate ( $ component ) ) { return $ component ; } } Log :: debug ( "ComponentFactory::%s: Could not find component that satisfies predicate (args = ['%s', '%s', '%s'])." , __FUNCTION__ , $ componentTypeClass , $ pluginName , get_class ( $ predicate ) ) ; return null ; }
docstring: Finds a component instance that satisfies a given predicate.
  
  @param string $componentTypeClass The fully qualified class name of the component type, eg,
  `"Piwik\Plugin\Report"`.
  @param string $pluginName|false The name of the plugin the component is expected to belong to,
  eg, `'DevicesDetection'`.
  @param callback $predicate
  @return mixed The component that satisfies $predicate or null if not found.
docstring_tokens: Finds a component instance that satisfies a given predicate .