-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Alchemy CMS to the scanner (#40)
- Loading branch information
1 parent
6f0eec0
commit 42f4f24
Showing
4 changed files
with
542 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
/** | ||
* @package CMSScanner | ||
* @copyright Copyright (C) 2014 CMS-Garden.org | ||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> | ||
* @link http://www.cms-garden.org | ||
*/ | ||
|
||
namespace Cmsgarden\Cmsscanner\Detector\Adapter; | ||
|
||
use Cmsgarden\Cmsscanner\Detector\System; | ||
use Cmsgarden\Cmsscanner\Detector\Module; | ||
use Symfony\Component\Finder\Finder; | ||
use Symfony\Component\Finder\SplFileInfo; | ||
|
||
/** | ||
* Class AlchemyCmsAdapter | ||
* @package Cmsgarden\Cmsscanner\Detector\Adapter | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
class AlchemyCmsAdapter implements AdapterInterface | ||
{ | ||
|
||
# The Gemfile.lock includes the fixed version number of Alchemy CMS | ||
# the host application is curently using. | ||
protected $version_file = "Gemfile.lock"; | ||
protected $version_regex = "/\s{2,}specs:\n\s{4,}alchemy_cms\s\((\d+\.\d+\..*)\)\n/"; | ||
|
||
/** | ||
* look for the Gemfile.lock with a proper version format | ||
* | ||
* @param Finder $finder finder instance to append the criteria | ||
* | ||
* @return Finder | ||
*/ | ||
public function appendDetectionCriteria(Finder $finder) | ||
{ | ||
$finder->name($this->version_file); | ||
|
||
return $finder; | ||
} | ||
|
||
/** | ||
* verify a search result by making sure that the file has the correct name and alchemy_cms is in there | ||
* | ||
* @param SplFileInfo $file file to examine | ||
* | ||
* @return bool|System | ||
*/ | ||
public function detectSystem(SplFileInfo $file) | ||
{ | ||
if ($file->getFilename() != $this->version_file) { | ||
return false; | ||
} | ||
|
||
if (stripos($file->getContents(), 'alchemy_cms') === false) { | ||
return false; | ||
} | ||
|
||
$path = new \SplFileInfo($file->getPath()); | ||
|
||
return new System($this->getName(), $path); | ||
} | ||
|
||
/** | ||
* determine version number of a Alchemy CMS installation | ||
* | ||
* @param \SplFileInfo $path directory where the system is installed | ||
* | ||
* @return null | ||
*/ | ||
public function detectVersion(\SplFileInfo $path) | ||
{ | ||
$versionFile = $path->getRealPath() . "/" . $this->version_file; | ||
|
||
if (!file_exists($versionFile) || !is_readable($versionFile)) { | ||
return null; // @codeCoverageIgnore | ||
} | ||
|
||
preg_match($this->version_regex, file_get_contents($versionFile), $matches); | ||
|
||
if (count($matches)) { | ||
return $matches[1]; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @InheritDoc | ||
*/ | ||
public function detectModules(\SplFileInfo $path) | ||
{ | ||
// TODO implement this function | ||
return array(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return 'Alchemy CMS'; | ||
} | ||
} |
Oops, something went wrong.