Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@googlemail.com>2014-06-20 06:33:59 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-06-20 06:33:59 +0400
commit76c1a324aeaf5ab6b0230a18d355ee04bbc575f0 (patch)
treefea104ef610a3a0462e0646a35a3e0273bcd91ab /core/Plugin.php
parent98101dfad422287c2fd9b9e1dfab0d3d51a9c4a6 (diff)
this should cache all "find plugin components" calls when trying to find components in the plugin directory
Diffstat (limited to 'core/Plugin.php')
-rw-r--r--core/Plugin.php63
1 files changed, 51 insertions, 12 deletions
diff --git a/core/Plugin.php b/core/Plugin.php
index 967d23b0ec..e938a9a1fe 100644
--- a/core/Plugin.php
+++ b/core/Plugin.php
@@ -105,6 +105,8 @@ class Plugin
*/
private $pluginInformation;
+ private static $cachedPluginComponents = array();
+
/**
* Constructor.
*
@@ -293,22 +295,29 @@ class Plugin
*/
public function findComponent($componentName, $expectedSubclass)
{
- $componentFile = sprintf('%s/plugins/%s/%s.php', PIWIK_INCLUDE_PATH, $this->pluginName, $componentName);
+ $cacheKey = $componentName . $expectedSubclass;
+ $klassName = $this->getCachedComponent($cacheKey);
- if (!file_exists($componentFile)) {
- return;
- }
+ if (null === $klassName) {
+ $componentFile = sprintf('%s/plugins/%s/%s.php', PIWIK_INCLUDE_PATH, $this->pluginName, $componentName);
- $klassName = sprintf('Piwik\\Plugins\\%s\\%s', $this->pluginName, $componentName);
+ if (!file_exists($componentFile)) {
+ return;
+ }
- if (!class_exists($klassName)) {
- return;
- }
+ $klassName = sprintf('Piwik\\Plugins\\%s\\%s', $this->pluginName, $componentName);
+
+ if (!class_exists($klassName)) {
+ return;
+ }
- if (!empty($expectedSubclass) && !is_subclass_of($klassName, $expectedSubclass)) {
- Log::warning(sprintf('Cannot use component %s for plugin %s, class %s does not extend %s',
- $componentName, $this->pluginName, $klassName, $expectedSubclass));
- return;
+ if (!empty($expectedSubclass) && !is_subclass_of($klassName, $expectedSubclass)) {
+ Log::warning(sprintf('Cannot use component %s for plugin %s, class %s does not extend %s',
+ $componentName, $this->pluginName, $klassName, $expectedSubclass));
+ return;
+ }
+
+ $this->cacheComponent($cacheKey, $klassName);
}
return new $klassName;
@@ -316,6 +325,13 @@ class Plugin
public function findMultipleComponents($directoryWithinPlugin, $expectedSubclass)
{
+ $cacheKey = $directoryWithinPlugin . $expectedSubclass;
+ $cached = $this->getCachedComponent($cacheKey);
+
+ if (null !== $cached) {
+ return $cached;
+ }
+
$components = array();
$files = Filesystem::globr(PIWIK_INCLUDE_PATH . '/plugins/' . $this->pluginName .'/' . $directoryWithinPlugin, '*.php');
@@ -340,9 +356,32 @@ class Plugin
$components[] = $klassName;
}
+ $this->cacheComponent($cacheKey, $components);
+
return $components;
}
+ private function getCachedComponent($cacheKey)
+ {
+ if (empty(self::$cachedPluginComponents[$this->pluginName])) {
+ return null;
+ }
+
+ if (!array_key_exists($cacheKey, self::$cachedPluginComponents[$this->pluginName])) {
+ return null;
+ }
+
+ return self::$cachedPluginComponents[$this->pluginName][$cacheKey];
+ }
+
+ private function cacheComponent($cacheKey, $foundComponents)
+ {
+ if (!array_key_exists($this->pluginName, self::$cachedPluginComponents)) {
+ self::$cachedPluginComponents[$this->pluginName] = array();
+ }
+
+ self::$cachedPluginComponents[$this->pluginName][$cacheKey] = $foundComponents;
+ }
/**
* Detect whether there are any missing dependencies.