Skip to content

Commit

Permalink
Fix php_arg_with and php_arg_enable parsing with preg_match_all
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Nov 5, 2014
1 parent 0f9d3ab commit 05a1b17
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 27 deletions.
18 changes: 13 additions & 5 deletions src/PhpBrew/Extension/ConfigureOption.php
Expand Up @@ -9,25 +9,33 @@ class ConfigureOption

public $valueHint;

public $defaultValue;

public function __construct($option, $desc, $valueHint = NULL)
{
$this->option = $option;
$this->desc = $desc;
$this->valueHint = $valueHint;
}

public function getOption() {
public function getOption()
{
return $this->option;
}

public function getDescription() {
public function getDescription()
{
return $this->desc;
}

public function getValueHint() {
public function getValueHint()
{
return $this->valueHint;
}
}


public function setDefaultValue($value)
{
$this->defaultValue = $value;
}
}

70 changes: 48 additions & 22 deletions src/PhpBrew/Extension/ExtensionFactory.php
Expand Up @@ -190,7 +190,7 @@ static public function createM4Extension($packageName, $m4Path) {
PHP_ARG_ENABLE(calendar,whether to enable calendar conversion support,
[ --enable-calendar Enable support for calendar conversion])
*/
if (preg_match('/
if (preg_match_all('/
PHP_ARG_ENABLE\(
\s*([^,]*)
(?:
Expand All @@ -208,15 +208,15 @@ static public function createM4Extension($packageName, $m4Path) {
\s*
\]
)?
)?/x', $m4, $matches)) {

// shift the first match
array_shift($matches);
$name = array_shift($matches);
$desc = array_shift($matches);
$option = array_shift($matches);
$optionDesc = array_shift($matches);
$ext->addConfigureOption(new ConfigureOption($option ?: '--enable-' . $name, $desc ?: $optionDesc));
)?/x', $m4, $allMatches))
{
for( $i = 0; $i < count($allMatches[0]) ; $i++ ) {
$name = $allMatches[1][$i];
$desc = $allMatches[2][$i];
$option = $allMatches[3][$i];
$optionDesc = $allMatches[4][$i];
$ext->addConfigureOption(new ConfigureOption($option ?: '--enable-' . $name, $desc ?: $optionDesc));
}
}

/*
Expand All @@ -232,14 +232,18 @@ static public function createM4Extension($packageName, $m4Path) {
--with-yaml[[=DIR]]
--with-mysql-sock[=SOCKPATH]
*/
if (preg_match('/
if (preg_match_all('/
PHP_ARG_WITH\(
\s*([^,]*)
\s*
([^,]*)
(?:
\s*,\s*
\[?
([^,\)]*)
\]?
(?:
\s*,\s*
Expand All @@ -262,17 +266,39 @@ static public function createM4Extension($packageName, $m4Path) {
([^,\)]*) # option description
\s*
\]
(?:
\s*,\s*
([^,\)]*)
(?:
\s*,\s*
([^,\)]*)
)?
)?
)?
)?/x', $m4, $matches)) {

// shift the first match
array_shift($matches);
$name = array_shift($matches);
$desc = array_shift($matches);
$option = array_shift($matches);
$optionValueHint = array_shift($matches);
$optionDesc = array_shift($matches);
$ext->addConfigureOption(new ConfigureOption(( $option ?: '--with-' . $name), ($desc ?: $optionDesc), $optionValueHint));
)?/x', $m4, $allMatches))
{
// Parsing the M4 statement:
//
// dnl PHP_ARG_WITH(arg-name, check message, help text[, default-val[, extension-or-not]])
//
for( $i = 0; $i < count($allMatches[0]) ; $i++ ) {
$name = $allMatches[1][$i];
$desc = $allMatches[2][$i];

$option = $allMatches[3][$i];
$optionValueHint = $allMatches[4][$i];
$optionDesc = $allMatches[5][$i];

$defaultValue = $allMatches[6][$i];

$opt = new ConfigureOption(( $option ?: '--with-' . $name), ($desc ?: $optionDesc), $optionValueHint);
if ($defaultValue) {
$opt->setDefaultValue($opt);
}
$ext->addConfigureOption($opt);
}
}

return $ext;
Expand Down

0 comments on commit 05a1b17

Please sign in to comment.