From 6c04a6715c08c1e224aeea8c4889c0258a832524 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Wed, 4 Oct 2017 20:12:34 +0200 Subject: [ticket/15389] Match multiple events in dispatcher in php_exporter I've also improved some regular expressions PHPBB3-15389 --- phpBB/phpbb/event/php_exporter.php | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'phpBB/phpbb/event/php_exporter.php') diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 26d7e2b426..7b80863305 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -196,13 +196,13 @@ class php_exporter $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)); for ($i = 0, $num_lines = sizeof($this->file_lines); $i < $num_lines; $i++) { $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) { @@ -216,7 +216,7 @@ class php_exporter } 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; @@ -316,17 +316,17 @@ class php_exporter 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 { - $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(); @@ -359,7 +359,7 @@ class php_exporter 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(); } @@ -370,7 +370,7 @@ class php_exporter 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); } @@ -392,11 +392,11 @@ class php_exporter 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]); + $vars_array = explode("', '", $match[2]); if ($throw_multiline && sizeof($vars_array) > 6) { throw new \LogicException('Should use multiple lines for $vars definition ' @@ -420,7 +420,7 @@ class php_exporter { $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); @@ -485,7 +485,7 @@ class php_exporter 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); -- cgit v1.2.1 From f8fbe3793680af1dae2db2829cfc84068831c52f Mon Sep 17 00:00:00 2001 From: rxu Date: Wed, 28 Jun 2017 00:58:03 +0700 Subject: [ticket/14972] replace all occurrences of sizeof() with the count() PHPBB3-14972 --- phpBB/phpbb/event/php_exporter.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/event/php_exporter.php') diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 7b80863305..64d1e429b7 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -117,7 +117,7 @@ class php_exporter } ksort($this->events); - return sizeof($this->events); + return count($this->events); } /** @@ -199,7 +199,7 @@ class php_exporter if (strpos($content, 'dispatcher->trigger_event(') || strpos($content, 'dispatcher->dispatch(')) { $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; $found_trigger_event = strpos($this->file_lines[$i], 'dispatcher->trigger_event('); @@ -397,7 +397,7 @@ class php_exporter if (isset($match[2])) { $vars_array = explode("', '", $match[2]); - if ($throw_multiline && sizeof($vars_array) > 6) + 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); @@ -460,7 +460,7 @@ class php_exporter 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); @@ -707,9 +707,9 @@ class php_exporter { $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}'"); -- cgit v1.2.1 From 0aea8ecd8314dcd33f7ed6e86f4a44ebaf27edc0 Mon Sep 17 00:00:00 2001 From: kasimi Date: Sun, 15 Apr 2018 18:43:21 +0200 Subject: [ticket/15637] Extract multi-line PHP event descriptions PHPBB3-15637 --- phpBB/phpbb/event/php_exporter.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/event/php_exporter.php') diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 64d1e429b7..b798d60481 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -264,7 +264,23 @@ class php_exporter // Find event description line $description_line_num = $this->find_description(); - $description = substr(trim($this->file_lines[$description_line_num]), strlen('* ')); + $description_lines = array(); + + while (true) + { + $description_line = substr(trim($this->file_lines[$description_line_num]), strlen('* ')); + + // Reached end of description if line is empty or a tag + if (!strlen($description_line) || $description_line[0] == '@') + { + break; + } + + $description_lines[] = $description_line; + $description_line_num++; + } + + $description = implode(' ', $description_lines); if (isset($this->events[$this->current_event])) { -- cgit v1.2.1 From 21faf69d3123b666a19731e318e07417f45b5325 Mon Sep 17 00:00:00 2001 From: kasimi Date: Sat, 7 Jul 2018 16:09:29 +0200 Subject: [ticket/15637] Extract all lines before the first @tag PHPBB3-15637 --- phpBB/phpbb/event/php_exporter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/event/php_exporter.php') diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index b798d60481..5ab0baa684 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -270,8 +270,8 @@ class php_exporter { $description_line = substr(trim($this->file_lines[$description_line_num]), strlen('* ')); - // Reached end of description if line is empty or a tag - if (!strlen($description_line) || $description_line[0] == '@') + // Reached end of description if line is a tag + if (strlen($description_line) && $description_line[0] == '@') { break; } -- cgit v1.2.1 From 1c8570d0f5111255f9cac793a8404f6af551ce3e Mon Sep 17 00:00:00 2001 From: kasimi Date: Sat, 7 Jul 2018 16:10:23 +0200 Subject: [ticket/15637] Fixed removing white-spaces from description line PHPBB3-15637 --- phpBB/phpbb/event/php_exporter.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/event/php_exporter.php') diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 5ab0baa684..0c105af0d9 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -268,7 +268,8 @@ class php_exporter while (true) { - $description_line = substr(trim($this->file_lines[$description_line_num]), strlen('* ')); + $description_line = substr(trim($this->file_lines[$description_line_num]), strlen('*')); + $description_line = trim(str_replace("\t", " ", $description_line)); // Reached end of description if line is a tag if (strlen($description_line) && $description_line[0] == '@') -- cgit v1.2.1 From 83a8280554652d5456849c69d8f3d0d6e59d1dc1 Mon Sep 17 00:00:00 2001 From: kasimi Date: Sat, 7 Jul 2018 20:12:35 +0200 Subject: [ticket/15637] Remove trailing space from description PHPBB3-15637 --- phpBB/phpbb/event/php_exporter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/event/php_exporter.php') diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 0c105af0d9..eae6a7bf28 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -281,7 +281,7 @@ class php_exporter $description_line_num++; } - $description = implode(' ', $description_lines); + $description = trim(implode(' ', $description_lines)); if (isset($this->events[$this->current_event])) { -- cgit v1.2.1 From 245f4df47c0d33ef8fe83bc5fd049a1afda79bb1 Mon Sep 17 00:00:00 2001 From: kasimi Date: Sat, 7 Jul 2018 21:25:29 +0200 Subject: [ticket/15637] Preserve line breaks in event descriptions PHPBB3-15637 --- phpBB/phpbb/event/php_exporter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/event/php_exporter.php') diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index eae6a7bf28..15dd13190e 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -281,7 +281,7 @@ class php_exporter $description_line_num++; } - $description = trim(implode(' ', $description_lines)); + $description = trim(implode('
', $description_lines)); if (isset($this->events[$this->current_event])) { -- cgit v1.2.1 From eedcb3bbe14c6745c10a959da31657f36d8914c3 Mon Sep 17 00:00:00 2001 From: kasimi Date: Sat, 7 Jul 2018 21:53:26 +0200 Subject: [ticket/15637] Remove trailing space from description PHPBB3-15637 --- phpBB/phpbb/event/php_exporter.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'phpBB/phpbb/event/php_exporter.php') diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 15dd13190e..71c94a681d 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -281,6 +281,12 @@ class php_exporter $description_line_num++; } + // If there is an empty line between description and first tag, remove it + if (!strlen(end($description_lines))) + { + array_pop($description_lines); + } + $description = trim(implode('
', $description_lines)); if (isset($this->events[$this->current_event])) -- cgit v1.2.1