Skip to content

Commit

Permalink
Add Alchemy CMS to the scanner (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinboening authored and SniperSister committed Apr 2, 2017
1 parent 6f0eec0 commit 42f4f24
Show file tree
Hide file tree
Showing 4 changed files with 542 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This tool is developed by the CMS-Garden project. It's designed to scan a local
* TYPO3 CMS
* WordPress
* Prestashop
* Alchemy CMS

It is designed to work on Linux, OS X and FreeBSD.

Expand Down
106 changes: 106 additions & 0 deletions src/Detector/Adapter/AlchemyCmsAdapter.php
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';
}
}
Loading

0 comments on commit 42f4f24

Please sign in to comment.