mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/12273] Move grabbing the $vars array line to a method
PHPBB3-12273
This commit is contained in:
parent
5387511f89
commit
4a3756741c
1 changed files with 45 additions and 15 deletions
|
@ -110,21 +110,15 @@ class event_exporter
|
||||||
$lines = explode("\n", $content);
|
$lines = explode("\n", $content);
|
||||||
for ($i = 0, $num_lines = sizeof($lines); $i < $num_lines; $i++)
|
for ($i = 0, $num_lines = sizeof($lines); $i < $num_lines; $i++)
|
||||||
{
|
{
|
||||||
$event_line = 0;
|
$event_line = false;
|
||||||
$found_trigger_event = strpos($lines[$i], "dispatcher->trigger_event('");
|
$found_trigger_event = strpos($lines[$i], "dispatcher->trigger_event('");
|
||||||
if ($found_trigger_event !== false)
|
if ($found_trigger_event !== false)
|
||||||
{
|
{
|
||||||
$event_line = $i;
|
$event_line = $i;
|
||||||
$event_name = $this->get_trigger_event_name($file, $lines[$event_line]);
|
$event_name = $this->get_trigger_event_name($file, $lines[$event_line]);
|
||||||
|
|
||||||
// Find $vars array lines
|
// Find $vars array
|
||||||
$vars_line = ltrim($lines[$event_line - 1], "\t");
|
$arguments = $this->get_vars_from_array($file, $event_name, $lines, $event_line);
|
||||||
if (strpos($vars_line, "\$vars = array('") !== 0)
|
|
||||||
{
|
|
||||||
throw new LogicException('Can not find "$vars = array()"-line for event "' . $event_name . '" in file "' . $file . '"');
|
|
||||||
}
|
|
||||||
$varsarray = substr($vars_line, strlen("\$vars = array('"), 0 - strlen('\');'));
|
|
||||||
$arguments = explode("', '", $varsarray);
|
|
||||||
|
|
||||||
// Validate $vars array with @var
|
// Validate $vars array with @var
|
||||||
$find_vars_line = 3;
|
$find_vars_line = 3;
|
||||||
|
@ -143,13 +137,13 @@ class event_exporter
|
||||||
}
|
}
|
||||||
$find_vars_line++;
|
$find_vars_line++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sizeof($arguments) !== sizeof($doc_vars) && array_intersect($arguments, $doc_vars))
|
if (sizeof($arguments) !== sizeof($doc_vars) && array_intersect($arguments, $doc_vars))
|
||||||
{
|
{
|
||||||
throw new LogicException('$vars array does not match the list of @var tags for event "' . $event_name . '" in file "' . $file . '"');
|
throw new LogicException('$vars array does not match the list of @var tags for event "' . $event_name . '" in file "' . $file . '"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (!$event_line)
|
|
||||||
{
|
{
|
||||||
$found_dispatch = strpos($lines[$i], "dispatcher->dispatch('");
|
$found_dispatch = strpos($lines[$i], "dispatcher->dispatch('");
|
||||||
if ($found_dispatch !== false)
|
if ($found_dispatch !== false)
|
||||||
|
@ -250,12 +244,48 @@ class event_exporter
|
||||||
return '([a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+)';
|
return '([a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+)';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the $vars array
|
||||||
|
*
|
||||||
|
* @param string $file
|
||||||
|
* @param string $event_name
|
||||||
|
* @param array $lines
|
||||||
|
* @param int $event_line Index of the event call in $lines
|
||||||
|
* @return array List of variables
|
||||||
|
*/
|
||||||
|
public function get_vars_from_array($file, $event_name, $lines, $event_line)
|
||||||
|
{
|
||||||
|
$vars_line = ltrim($lines[$event_line - 1], "\t");
|
||||||
|
if (strpos($vars_line, "\$vars = array('") !== 0 || substr($vars_line, -3) !== '\');')
|
||||||
|
{
|
||||||
|
throw new LogicException('Can not find "$vars = array();"-line for event "' . $event_name . '" in file "' . $file . '"', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$vars_array = substr($vars_line, strlen("\$vars = array('"), 0 - strlen('\');'));
|
||||||
|
if ($vars_array === '')
|
||||||
|
{
|
||||||
|
throw new LogicException('Found empty $vars array for event "' . $event_name . '" in file "' . $file . '"', 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
$vars_array = explode("', '", $vars_array);
|
||||||
|
|
||||||
|
foreach ($vars_array as $var)
|
||||||
|
{
|
||||||
|
if (!preg_match('#^([a-zA-Z_][a-zA-Z0-9_]*)$#', $var))
|
||||||
|
{
|
||||||
|
throw new LogicException('Found invalid var "' . $var . '" in array for event "' . $event_name . '" in file "' . $file . '"', 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $vars_array;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the "@since" Information line
|
* Find the "@since" Information line
|
||||||
*
|
*
|
||||||
* @param string $file
|
* @param string $file
|
||||||
* @param string $event_name
|
* @param string $event_name
|
||||||
* @param string $lines
|
* @param array $lines
|
||||||
* @param int $event_line Index of the event call in $lines
|
* @param int $event_line Index of the event call in $lines
|
||||||
* @return int Absolute line number
|
* @return int Absolute line number
|
||||||
*/
|
*/
|
||||||
|
@ -269,7 +299,7 @@ class event_exporter
|
||||||
*
|
*
|
||||||
* @param string $file
|
* @param string $file
|
||||||
* @param string $event_name
|
* @param string $event_name
|
||||||
* @param string $lines
|
* @param array $lines
|
||||||
* @param int $event_line Index of the event call in $lines
|
* @param int $event_line Index of the event call in $lines
|
||||||
* @return int Absolute line number
|
* @return int Absolute line number
|
||||||
*/
|
*/
|
||||||
|
@ -283,7 +313,7 @@ class event_exporter
|
||||||
*
|
*
|
||||||
* @param string $file
|
* @param string $file
|
||||||
* @param string $event_name
|
* @param string $event_name
|
||||||
* @param string $lines
|
* @param array $lines
|
||||||
* @param int $event_line Index of the event call in $lines
|
* @param int $event_line Index of the event call in $lines
|
||||||
* @param string $find_tag Name of the tag we are trying to find
|
* @param string $find_tag Name of the tag we are trying to find
|
||||||
* @param array $disallowed_tags List of tags that must not appear between
|
* @param array $disallowed_tags List of tags that must not appear between
|
||||||
|
@ -332,7 +362,7 @@ class event_exporter
|
||||||
*
|
*
|
||||||
* @param string $file
|
* @param string $file
|
||||||
* @param string $event_name
|
* @param string $event_name
|
||||||
* @param string $lines
|
* @param array $lines
|
||||||
* @param int $event_line Index of the event call in $lines
|
* @param int $event_line Index of the event call in $lines
|
||||||
* @return int Absolute line number
|
* @return int Absolute line number
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue