aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/event
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-04-25 11:45:54 +0200
committerJoas Schilling <nickvergessen@gmx.de>2014-04-25 11:45:54 +0200
commit142fe1a0e57797aa77059edda42ebedd91b11397 (patch)
tree2dffdd194aad0460de0511c6d9be878b5c7f6ebf /phpBB/phpbb/event
parentc2dace762ec295c7a2d67758006b1fff56f1f573 (diff)
downloadforums-142fe1a0e57797aa77059edda42ebedd91b11397.tar
forums-142fe1a0e57797aa77059edda42ebedd91b11397.tar.gz
forums-142fe1a0e57797aa77059edda42ebedd91b11397.tar.bz2
forums-142fe1a0e57797aa77059edda42ebedd91b11397.tar.xz
forums-142fe1a0e57797aa77059edda42ebedd91b11397.zip
[ticket/12273] Use multiline arrays instead of array_merge()
PHPBB3-12273
Diffstat (limited to 'phpBB/phpbb/event')
-rw-r--r--phpBB/phpbb/event/php_exporter.php84
1 files changed, 58 insertions, 26 deletions
diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php
index 8de3051d9b..2a69f15802 100644
--- a/phpBB/phpbb/event/php_exporter.php
+++ b/phpBB/phpbb/event/php_exporter.php
@@ -295,48 +295,80 @@ class php_exporter
*/
public function get_vars_from_array()
{
- $vars_array_line = 1;
- $found_vars_array = false;
- $vars_array = array();
- while (ltrim($this->file_lines[$this->current_event_line - $vars_array_line], "\t") !== '*/')
+ $line = ltrim($this->file_lines[$this->current_event_line - 1], "\t");
+ if ($line === ');')
{
- $line = ltrim($this->file_lines[$this->current_event_line - $vars_array_line], "\t");
- $match = array();
- preg_match('#^\$vars = (array_merge\(\$vars, )?array\(\'([a-zA-Z0-9_\' ,]+)\'\)(?(1)\));$#', $line, $match);
+ $vars_array = $this->get_vars_from_multi_line_array();
+ }
+ else
+ {
+ $vars_array = $this->get_vars_from_single_line_array($line);
+ }
- if (isset($match[2]))
+ foreach ($vars_array as $var)
+ {
+ if (!preg_match('#^([a-zA-Z_][a-zA-Z0-9_]*)$#', $var))
{
- $found_vars_array = true;
- if (strlen($match[2]) > 90)
- {
- throw new \LogicException('Should use multiple lines for $vars definition '
- . "for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 3);
- }
- $vars_array = array_merge($vars_array, explode("', '", $match[2]));
+ throw new \LogicException("Found invalid var '{$var}' in array for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 3);
}
+ }
+
+ sort($vars_array);
+ return $vars_array;
+ }
+
+ /**
+ * Find the variables in single line array
+ *
+ * @param string $line
+ * @return array List of variables
+ * @throws \LogicException
+ */
+ public function get_vars_from_single_line_array($line, $throw_multiline = true)
+ {
+ $match = array();
+ preg_match('#^\$vars = array\(\'([a-zA-Z0-9_\' ,]+)\'\);$#', $line, $match);
- $vars_array_line++;
- if ($this->current_event_line - $vars_array_line === 0)
+ if (isset($match[1]))
+ {
+ $vars_array = explode("', '", $match[1]);
+ if ($throw_multiline && sizeof($vars_array) > 6)
{
- throw new \LogicException("Can not find '\$vars = array();'-line for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 2);
+ throw new \LogicException('Should use multiple lines for $vars definition '
+ . "for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 2);
}
+ return $vars_array;
}
-
- if (!$found_vars_array)
+ else
{
- throw new \LogicException("Can not find '\$vars = array();'-line for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 3);
+ throw new \LogicException("Can not find '\$vars = array();'-line for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 1);
}
+ }
- foreach ($vars_array as $var)
+ /**
+ * Find the variables in single line array
+ *
+ * @param string $line
+ * @return array List of variables
+ * @throws \LogicException
+ */
+ public function get_vars_from_multi_line_array()
+ {
+ $current_vars_line = 2;
+ $var_lines = array();
+ while (ltrim($this->file_lines[$this->current_event_line - $current_vars_line], "\t") !== '$vars = array(')
{
- if (!preg_match('#^([a-zA-Z_][a-zA-Z0-9_]*)$#', $var))
+ $var_lines[] = substr(trim($this->file_lines[$this->current_event_line - $current_vars_line]), 0, -1);
+
+ $current_vars_line++;
+ if ($current_vars_line > $this->current_event_line)
{
- throw new \LogicException("Found invalid var '{$var}' in array for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 4);
+ // Reached the start of the file
+ throw new \LogicException("Can not find end of \$vars array for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 2);
}
}
- sort($vars_array);
- return $vars_array;
+ return $this->get_vars_from_single_line_array('$vars = array(' . implode(", ", $var_lines) . ');', false);
}
/**