original_string: public function findComponent($componentName, $expectedSubclass)
      {
          $this->createCacheIfNeeded();
  
          $cacheId = 'Plugin' . $this->pluginName . $componentName . $expectedSubclass;
  
          $pluginsDir = Manager::getPluginDirectory($this->pluginName);
  
          $componentFile = sprintf('%s/%s.php', $pluginsDir, $componentName);
  
          if ($this->cache->contains($cacheId)) {
              $classname = $this->cache->fetch($cacheId);
  
              if (empty($classname)) {
                  return null; // might by "false" in case has no menu, widget, ...
              }
  
              if (file_exists($componentFile)) {
                  include_once $componentFile;
              }
          } else {
              $this->cache->save($cacheId, false); // prevent from trying to load over and over again for instance if there is no Menu for a plugin
  
              if (!file_exists($componentFile)) {
                  return null;
              }
  
              require_once $componentFile;
  
              $classname = sprintf('Piwik\\Plugins\\%s\\%s', $this->pluginName, $componentName);
  
              if (!class_exists($classname)) {
                  return null;
              }
  
              if (!empty($expectedSubclass) && !is_subclass_of($classname, $expectedSubclass)) {
                  Log::warning(sprintf('Cannot use component %s for plugin %s, class %s does not extend %s',
                      $componentName, $this->pluginName, $classname, $expectedSubclass));
                  return null;
              }
  
              $this->cache->save($cacheId, $classname);
          }
  
          return $classname;
      }
code: public function findComponent($componentName, $expectedSubclass)
      {
          $this->createCacheIfNeeded();
  
          $cacheId = 'Plugin' . $this->pluginName . $componentName . $expectedSubclass;
  
          $pluginsDir = Manager::getPluginDirectory($this->pluginName);
  
          $componentFile = sprintf('%s/%s.php', $pluginsDir, $componentName);
  
          if ($this->cache->contains($cacheId)) {
              $classname = $this->cache->fetch($cacheId);
  
              if (empty($classname)) {
                  return null; // might by "false" in case has no menu, widget, ...
              }
  
              if (file_exists($componentFile)) {
                  include_once $componentFile;
              }
          } else {
              $this->cache->save($cacheId, false); // prevent from trying to load over and over again for instance if there is no Menu for a plugin
  
              if (!file_exists($componentFile)) {
                  return null;
              }
  
              require_once $componentFile;
  
              $classname = sprintf('Piwik\\Plugins\\%s\\%s', $this->pluginName, $componentName);
  
              if (!class_exists($classname)) {
                  return null;
              }
  
              if (!empty($expectedSubclass) && !is_subclass_of($classname, $expectedSubclass)) {
                  Log::warning(sprintf('Cannot use component %s for plugin %s, class %s does not extend %s',
                      $componentName, $this->pluginName, $classname, $expectedSubclass));
                  return null;
              }
  
              $this->cache->save($cacheId, $classname);
          }
  
          return $classname;
      }
code_tokens: public function findComponent ( $ componentName , $ expectedSubclass ) { $ this -> createCacheIfNeeded ( ) ; $ cacheId = 'Plugin' . $ this -> pluginName . $ componentName . $ expectedSubclass ; $ pluginsDir = Manager :: getPluginDirectory ( $ this -> pluginName ) ; $ componentFile = sprintf ( '%s/%s.php' , $ pluginsDir , $ componentName ) ; if ( $ this -> cache -> contains ( $ cacheId ) ) { $ classname = $ this -> cache -> fetch ( $ cacheId ) ; if ( empty ( $ classname ) ) { return null ; // might by "false" in case has no menu, widget, ... } if ( file_exists ( $ componentFile ) ) { include_once $ componentFile ; } } else { $ this -> cache -> save ( $ cacheId , false ) ; // prevent from trying to load over and over again for instance if there is no Menu for a plugin if ( ! file_exists ( $ componentFile ) ) { return null ; } require_once $ componentFile ; $ classname = sprintf ( 'Piwik\\Plugins\\%s\\%s' , $ this -> pluginName , $ componentName ) ; if ( ! class_exists ( $ classname ) ) { return null ; } if ( ! empty ( $ expectedSubclass ) && ! is_subclass_of ( $ classname , $ expectedSubclass ) ) { Log :: warning ( sprintf ( 'Cannot use component %s for plugin %s, class %s does not extend %s' , $ componentName , $ this -> pluginName , $ classname , $ expectedSubclass ) ) ; return null ; } $ this -> cache -> save ( $ cacheId , $ classname ) ; } return $ classname ; }
docstring: Tries to find a component such as a Menu or Tasks within this plugin.
  
  @param string $componentName      The name of the component you want to look for. In case you request a
  component named 'Menu' it'll look for a file named 'Menu.php' within the
  root of the plugin folder that implements a class named
  Piwik\Plugin\$PluginName\Menu . If such a file exists but does not implement
  this class it'll silently ignored.
  @param string $expectedSubclass   If not empty, a check will be performed whether a found file extends the
  given subclass. If the requested file exists but does not extend this class
  a warning will be shown to advice a developer to extend this certain class.
  
  @return string|null  Null if the requested component does not exist or an instance of the found
  component.
docstring_tokens: Tries to find a component such as a Menu or Tasks within this plugin .