public function findComponent($componentName, $expectedSubclass)
{
$this->createCacheIfNeeded();
$cacheId = 'Plugin' . $this->pluginName . $componentName . $expectedSubclass;
$componentFile = sprintf('%s/plugins/%s/%s.php', PIWIK_INCLUDE_PATH, $this->pluginName, $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;
}