phpBB

Code Changes

File: phpbb/event/php_exporter.php

  Unmodified   Added   Modified   Removed
Line 117Line 117
		}
ksort($this->events);


		}
ksort($this->events);


		return sizeof($this->events);

		return count($this->events);

	}

/**

	}

/**

Line 196Line 196
		$content = file_get_contents($this->path . $this->current_file);
$num_events_found = 0;


		$content = file_get_contents($this->path . $this->current_file);
$num_events_found = 0;


		if (strpos($content, "dispatcher->trigger_event('") || strpos($content, "dispatcher->dispatch('"))

		if (strpos($content, 'dispatcher->trigger_event(') || strpos($content, 'dispatcher->dispatch('))

		{
$this->set_content(explode("\n", $content));

		{
$this->set_content(explode("\n", $content));

			for ($i = 0, $num_lines = sizeof($this->file_lines); $i < $num_lines; $i++)

			for ($i = 0, $num_lines = count($this->file_lines); $i < $num_lines; $i++)

			{
$event_line = false;

			{
$event_line = false;

				$found_trigger_event = strpos($this->file_lines[$i], "dispatcher->trigger_event('");

				$found_trigger_event = strpos($this->file_lines[$i], 'dispatcher->trigger_event(');

				$arguments = array();
if ($found_trigger_event !== false)
{

				$arguments = array();
if ($found_trigger_event !== false)
{

Line 216Line 216
				}
else
{

				}
else
{

					$found_dispatch = strpos($this->file_lines[$i], "dispatcher->dispatch('");

					$found_dispatch = strpos($this->file_lines[$i], 'dispatcher->dispatch(');

					if ($found_dispatch !== false)
{
$event_line = $i;

					if ($found_dispatch !== false)
{
$event_line = $i;

Line 316Line 316

if ($is_dispatch)
{


if ($is_dispatch)
{

			$regex = '#\$([a-z](?:[a-z0-9_]|->)*)';
$regex .= '->dispatch\(';
$regex .= '\'' . $this->preg_match_event_name() . '\'';
$regex .= '\);#';

			$regex = '#\$[a-z](?:[a-z0-9_]|->)*';
$regex .= '->dispatch\((\[)?';
$regex .= '\'' . $this->preg_match_event_name() . '(?(1)\', \'(?2))+\'';
$regex .= '(?(1)\])\);#';

		}
else
{

		}
else
{

			$regex = '#extract\(\$([a-z](?:[a-z0-9_]|->)*)';
$regex .= '->trigger_event\(';
$regex .= '\'' . $this->preg_match_event_name() . '\'';
$regex .= ', compact\(\$vars\)\)\);#';

			$regex = '#extract\(\$[a-z](?:[a-z0-9_]|->)*';
$regex .= '->trigger_event\((\[)?';
$regex .= '\'' . $this->preg_match_event_name() . '(?(1)\', \'(?2))+\'';
$regex .= '(?(1)\]), compact\(\$vars\)\)\);#';

		}

$match = array();

		}

$match = array();

Line 359Line 359
	public function get_vars_from_array()
{
$line = ltrim($this->file_lines[$this->current_event_line - 1], "\t");

	public function get_vars_from_array()
{
$line = ltrim($this->file_lines[$this->current_event_line - 1], "\t");

		if ($line === ');')

		if ($line === ');' || $line === '];')

		{
$vars_array = $this->get_vars_from_multi_line_array();
}

		{
$vars_array = $this->get_vars_from_multi_line_array();
}

Line 370Line 370

foreach ($vars_array as $var)
{


foreach ($vars_array as $var)
{

			if (!preg_match('#^([a-zA-Z_][a-zA-Z0-9_]*)$#', $var))

			if (!preg_match('#^[a-z_][a-z0-9_]*$#i', $var))

			{
throw new \LogicException("Found invalid var '{$var}' in array for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 3);
}

			{
throw new \LogicException("Found invalid var '{$var}' in array for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 3);
}

Line 392Line 392
	public function get_vars_from_single_line_array($line, $throw_multiline = true)
{
$match = array();

	public function get_vars_from_single_line_array($line, $throw_multiline = true)
{
$match = array();

		preg_match('#^\$vars = array\(\'([a-zA-Z0-9_\' ,]+)\'\);$#', $line, $match);

		preg_match('#^\$vars = (?:(\[)|array\()\'([a-z0-9_\' ,]+)\'(?(1)\]|\));$#i', $line, $match);





		if (isset($match[1]))

		if (isset($match[2]))

		{

		{

			$vars_array = explode("', '", $match[1]);
if ($throw_multiline && sizeof($vars_array) > 6)

			$vars_array = explode("', '", $match[2]);
if ($throw_multiline && count($vars_array) > 6)

			{
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);

			{
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);

Line 420Line 420
	{
$current_vars_line = 2;
$var_lines = array();

	{
$current_vars_line = 2;
$var_lines = array();

		while (ltrim($this->file_lines[$this->current_event_line - $current_vars_line], "\t") !== '$vars = array(')

		while (!in_array(ltrim($this->file_lines[$this->current_event_line - $current_vars_line], "\t"), ['$vars = array(', '$vars = [']))

		{
$var_lines[] = substr(trim($this->file_lines[$this->current_event_line - $current_vars_line]), 0, -1);


		{
$var_lines[] = substr(trim($this->file_lines[$this->current_event_line - $current_vars_line]), 0, -1);


Line 460Line 460
				if (strpos($var_line, '* @var ') === 0)
{
$doc_line = explode(' ', $var_line, 5);

				if (strpos($var_line, '* @var ') === 0)
{
$doc_line = explode(' ', $var_line, 5);

					if (sizeof($doc_line) !== 5)

					if (count($doc_line) !== 5)

					{
throw new \LogicException("Found invalid line '{$this->file_lines[$this->current_event_line - $current_doc_line]}' "
. "for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 1);

					{
throw new \LogicException("Found invalid line '{$this->file_lines[$this->current_event_line - $current_doc_line]}' "
. "for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 1);

Line 485Line 485

foreach ($doc_vars as $var)
{


foreach ($doc_vars as $var)
{

			if (!preg_match('#^([a-zA-Z_][a-zA-Z0-9_]*)$#', $var))

			if (!preg_match('#^[a-z_][a-z0-9_]*$#i', $var))

			{
throw new \LogicException("Found invalid @var '{$var}' in docblock for event "
. "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 4);

			{
throw new \LogicException("Found invalid @var '{$var}' in docblock for event "
. "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 4);

Line 707Line 707
	{
$vars_array = array_unique($vars_array);
$vars_docblock = array_unique($vars_docblock);

	{
$vars_array = array_unique($vars_array);
$vars_docblock = array_unique($vars_docblock);

		$sizeof_vars_array = sizeof($vars_array);

		$sizeof_vars_array = count($vars_array);





		if ($sizeof_vars_array !== sizeof($vars_docblock) || $sizeof_vars_array !== sizeof(array_intersect($vars_array, $vars_docblock)))

		if ($sizeof_vars_array !== count($vars_docblock) || $sizeof_vars_array !== count(array_intersect($vars_array, $vars_docblock)))

		{
throw new \LogicException("\$vars array does not match the list of '@var' tags for event "
. "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'");

		{
throw new \LogicException("\$vars array does not match the list of '@var' tags for event "
. "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'");