Skip to content

Commit

Permalink
Merge pull request #5397 from Quetzacoalt91/module-repository-check-c…
Browse files Browse the repository at this point in the history
…lass

// CORE : Move require of module class to handle more potential issues
  • Loading branch information
tchauviere committed Apr 15, 2016
2 parents eb0195f + 202b8a4 commit 828feed
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Adapter/Module/ModuleDataProvider.php
Expand Up @@ -91,7 +91,8 @@ public function isInstalled($name)
public function isModuleMainClassValid($name)
{
$file_path = _PS_MODULE_DIR_.$name.'/'.$name.'.php';
if (!file_exists($file_path)) {
// Check if file exists (slightly faster than file_exists)
if (!(int)@filemtime($file_path)) {
return false;
}

Expand All @@ -112,7 +113,19 @@ public function isModuleMainClassValid($name)
// But namespace and use statements need to be removed
$content = preg_replace('/\n[\s\t]*?use\s.*?;/', '', $file);
$content = preg_replace('/\n[\s\t]*?namespace\s.*?;/', '', $content);
return (eval('if (false){ '.$content.' }') !== false);
if (eval('if (false){ '.$content.' }') === false) {
return false;
}

// Even if we do not detect any parse error in the file, we may have issues
// when trying to load the file. (i.e with additionnal require_once)
try {
require_once $file_path;
} catch (\Exception $e) {
return false;
}

return true;
}

/**
Expand Down

0 comments on commit 828feed

Please sign in to comment.