Make FilesPluginInformation class only try to load PHP files.

Closes #638
This commit is contained in:
Artjom Kurapov 2014-11-07 17:39:01 +02:00 committed by Dan Cryer
parent 207411d5fc
commit 91f29fb22b

View file

@ -67,7 +67,7 @@ class FilesPluginInformation implements InstalledPluginInformation
$this->pluginInfo = array();
foreach ($this->files as $fileInfo) {
if ($fileInfo instanceof \SplFileInfo) {
if ($fileInfo->isFile()) {
if ($fileInfo->isFile() && $fileInfo->getExtension()=='php') {
$this->addPluginFromFile($fileInfo);
}
}
@ -76,13 +76,17 @@ class FilesPluginInformation implements InstalledPluginInformation
protected function addPluginFromFile(\SplFileInfo $fileInfo)
{
$newPlugin = new \stdClass();
$newPlugin->class = $this->getFullClassFromFile($fileInfo);
$newPlugin->source = "core";
$parts = explode('\\', $newPlugin->class);
$newPlugin->name = end($parts);
$class = $this->getFullClassFromFile($fileInfo);
$this->pluginInfo[] = $newPlugin;
if (!is_null($class)) {
$newPlugin = new \stdClass();
$newPlugin->class = $class;
$newPlugin->source = "core";
$parts = explode('\\', $newPlugin->class);
$newPlugin->name = end($parts);
$this->pluginInfo[] = $newPlugin;
}
}
protected function getFullClassFromFile(\SplFileInfo $fileInfo)
@ -90,15 +94,20 @@ class FilesPluginInformation implements InstalledPluginInformation
//TODO: Something less horrible than a regular expression
// on the contents of a file
$contents = file_get_contents($fileInfo->getRealPath());
$matches = array();
preg_match('#class +([A-Za-z]+) +implements#i', $contents, $matches);
$className = $matches[1];
$matches = array();
preg_match('#namespace +([A-Za-z\\\\]+);#i', $contents, $matches);
$namespace = $matches[1];
return $namespace . '\\' . $className;
if (isset($matches[1])) {
$className = $matches[1];
$matches = array();
preg_match('#namespace +([A-Za-z\\\\]+);#i', $contents, $matches);
$namespace = $matches[1];
return $namespace . '\\' . $className;
} else {
return null;
}
}
}