Skip to content

Commit

Permalink
Added support for custom extensions of php files. It's important for …
Browse files Browse the repository at this point in the history
…some frameworks (like Drupal).
  • Loading branch information
jsobiecki committed Dec 8, 2011
1 parent 88abd1c commit d0ed50f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
32 changes: 28 additions & 4 deletions src/CLIController.php
Expand Up @@ -172,7 +172,7 @@ class CbCLIController
public function __construct($logPath, Array $projectSource,
$htmlOutputDir, Array $excludeExpressions,
Array $excludePatterns, Array $pluginOptions,
$ioHelper, $debugLog)
$ioHelper, $debugLog, $phpSuffixes = null)
{
$this->_logDir = $logPath;
$this->_projectSource = $projectSource;
Expand All @@ -185,6 +185,7 @@ public function __construct($logPath, Array $projectSource,
$this->_ioHelper = $ioHelper;
$this->_debugLog = $debugLog;
$this->_registeredPlugins = array();
$this->_phpSuffixes = $phpSuffixes;
}

/**
Expand Down Expand Up @@ -229,7 +230,9 @@ public function run()
$cbViewReview = new CbViewReview(
PHPCB_TEMPLATE_DIR,
$this->_htmlOutputDir,
$this->_ioHelper
$this->_ioHelper,
isset($this->_phpSuffixes) ? explode(',', $this->_phpSuffixes)
: array('php')
);

$sourceHandler = new CbSourceHandler($this->_debugLog);
Expand Down Expand Up @@ -259,9 +262,18 @@ public function run()
if (is_dir($source)) {
$factory = new File_Iterator_Factory;

$phpSuffixes = !isset($this->_phpSuffixes) ?
array() :
explode(',', $this->_phpSuffixes);

$suffixes = array_merge(
$phpSuffixes,
array('php','js','css', 'html')
);

$sourceHandler->addSourceFiles(
$factory->getFileIterator(
$source, array('php','js','css', 'html')
$source, $suffixes
)
);
} else {
Expand Down Expand Up @@ -355,7 +367,8 @@ public static function main()
: array(),
new CbIOHelper(),
$opts['debugExcludes'] ? Log::factory('console', '', 'PHPCB')
: Log::factory('null')
: Log::factory('null'),
$opts['phpSuffixes']
);

$plugins = self::getAvailablePlugins();
Expand Down Expand Up @@ -475,6 +488,17 @@ private static function createCommandLineParser()
)
);

$parser->addOption(
'phpSuffixes',
array(
'description' => 'A comma separated list of php file extensions'
.' to include.',
'short_name' => '-S',
'long_name' => '--extensions',
'help_name' => '<extensions>'
)
);

$parser->addOption(
'output',
array(
Expand Down
13 changes: 9 additions & 4 deletions src/View/ViewReview.php
Expand Up @@ -76,6 +76,7 @@ class CbViewReview extends CbViewAbstract
* @var Array
*/
protected $_phpHighlightColorMap;
protected $_phpFilesSuffixes;

/**
* Default constructor
Expand All @@ -85,8 +86,11 @@ class CbViewReview extends CbViewAbstract
* @param String $templateDir The directory containing the templates.
* @param String $outputDir The directory where the reviews should be.
* @param CbIOHelper $ioHelper The CbIOHelper object to use for I/O.
* @param Array $phpSuffixes The array with extensions of php files.
*/
public function __construct($templateDir, $outputDir, $ioHelper)
public function __construct($templateDir, $outputDir, $ioHelper,
$phpSuffixes = array('php')
)
{
parent::__construct($templateDir, $outputDir, $ioHelper);
$this->_phpHighlightColorMap = array(
Expand All @@ -95,7 +99,8 @@ public function __construct($templateDir, $outputDir, $ioHelper)
ini_get('highlight.keyword') => 'keyword',
ini_get('highlight.default') => 'default',
ini_get('highlight.html') => 'html',
);
);
$this->phpSuffixes = $phpSuffixes;
}

/**
Expand Down Expand Up @@ -331,8 +336,8 @@ protected function _highlightCode($file)

$extension = strrchr($file, '.');
$sourceCode = $this->_ioHelper->loadFile($file);

if ('.php' === $extension) {
$extensionWhPeriod = str_replace('.', '', $extension);
if (in_array($extensionWhPeriod, $this->phpSuffixes)) {
return $this->_highlightPhpCode($sourceCode);
} else if (class_exists('Text_Highlighter', false)
&& isset($highlightMap[$extension])) {
Expand Down

0 comments on commit d0ed50f

Please sign in to comment.