From 22de4a5927eccf05d614a6da7f6eb6f993838487 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Apr 2014 15:00:14 +0200 Subject: [PATCH 01/55] [ticket/12273] Add a basic set of tests for the exporter PHPBB3-12273 --- phpBB/develop/event_exporter.php | 424 ++++++++++++++++++ tests/event/exporter_test.php | 341 ++++++++++++++ tests/event/fixtures/default.test | 9 + tests/event/fixtures/extra_description.test | 11 + .../event/fixtures/legacy_alpha1_version.test | 9 + 5 files changed, 794 insertions(+) create mode 100644 phpBB/develop/event_exporter.php create mode 100644 tests/event/exporter_test.php create mode 100644 tests/event/fixtures/default.test create mode 100644 tests/event/fixtures/extra_description.test create mode 100644 tests/event/fixtures/legacy_alpha1_version.test diff --git a/phpBB/develop/event_exporter.php b/phpBB/develop/event_exporter.php new file mode 100644 index 0000000000..6277433423 --- /dev/null +++ b/phpBB/develop/event_exporter.php @@ -0,0 +1,424 @@ +root_path = $phpbb_root_path; + } + + function export_from_eventsmd($filter) + { + $file_content = file_get_contents($this->root_path . 'docs/events.md'); + + $events = explode("\n\n", $file_content); + foreach ($events as $event) + { + // Last row of the file + if (strpos($event, "\n===\n") === false) continue; + + list($event_name, $details) = explode("\n===\n", $event); + + if ($filter == 'acp' && strpos($event_name, 'acp_') !== 0) continue; + if ($filter == 'styles' && strpos($event_name, 'acp_') === 0) continue; + + list($file_details, $details) = explode("\n* Since: ", $details); + list($version, $explanition) = explode("\n* Purpose: ", $details); + + echo "|- id=\"{$event_name}\"\n"; + echo "| [[#{$event_name}|{$event_name}]] || "; + + if (strpos($file_details, "* Locations:\n + ") === 0) + { + $file_details = substr($file_details, strlen("* Locations:\n + ")); + $files = explode("\n + ", $file_details); + $prosilver = $subsilver2 = $adm = array(); + foreach ($files as $file) + { + if (strpos($file, 'styles/prosilver/template/') === 0) + { + $prosilver[] = substr($file, strlen('styles/prosilver/template/')); + } + if (strpos($file, 'styles/subsilver2/template/') === 0) + { + $subsilver2[] = substr($file, strlen('styles/subsilver2/template/')); + } + if (strpos($file, 'adm/style/') === 0) + { + $adm[] = substr($file, strlen('adm/style/')); + } + } + if ($filter == 'acp') + { + echo implode(', ', $adm); + } + else + { + echo implode(', ', $prosilver) . ' || ' . implode(', ', $subsilver2); + } + } + else if ($filter == 'acp') + { + echo substr($file_details, strlen("* Location: adm/style/")); + } + echo " || {$version} || " . str_replace("\n", ' ', $explanition) . "\n"; + + } + } + + function export_from_php() + { + $files = $this->get_file_list($this->root_path); + $events = array(); + foreach ($files as $file) + { + $file_events = $this->check_for_events($file); + if (!empty($file_events)) + { + $events = array_merge($events, $file_events); + } + } + ksort($events); + + foreach ($events as $event) + { + echo '|- id="' . $event['event'] . '"' . "\n"; + echo '| [[#' . $event['event'] . '|' . $event['event'] . ']] || ' . $event['file'] . ' || ' . implode(', ', $event['arguments']) . ' || ' . $event['since'] . ' || ' . $event['description'] . "\n"; + } + } + + public function check_for_events($file) + { + $events = array(); + $content = file_get_contents($this->root_path . $file); + + if (strpos($content, "phpbb_dispatcher->trigger_event('") || strpos($content, "phpbb_dispatcher->dispatch('")) + { + $lines = explode("\n", $content); + for ($i = 0, $num_lines = sizeof($lines); $i < $num_lines; $i++) + { + $event_line = 0; + $found_trigger_event = strpos($lines[$i], "phpbb_dispatcher->trigger_event('"); + if ($found_trigger_event !== false) + { + $event_line = $i; + $event_name = $lines[$event_line]; + $event_name = substr($event_name, $found_trigger_event + strlen("phpbb_dispatcher->trigger_event('")); + $event_name = substr($event_name, 0, strpos($event_name, "'")); + + $current_line = trim($lines[$event_line]); + $arguments = array(); + $found_inline_array = strpos($current_line, "', compact(array('"); + if ($found_inline_array !== false) + { + $varsarray = substr($current_line, $found_inline_array + strlen("', compact(array('"), -6); + $arguments = explode("', '", $varsarray); + } + + if (empty($arguments)) + { + // Find $vars array lines + $find_varsarray_line = 1; + while (strpos($lines[$event_line - $find_varsarray_line], "\$vars = array('") === false) + { + $find_varsarray_line++; + + if ($find_varsarray_line > min(50, $event_line)) + { + throw new LogicException('Can not find "$vars = array()"-line for event "' . $event_name . '" in file "' . $file . '"'); + } + } + $varsarray = substr(trim($lines[$event_line - $find_varsarray_line]), strlen("\$vars = array('"), -3); + $arguments = explode("', '", $varsarray); + } + + // Validate $vars array with @var + $find_vars_line = 3; + $doc_vars = array(); + while (strpos(trim($lines[$event_line - $find_vars_line]), '*') === 0) + { + $var_line = trim($lines[$event_line - $find_vars_line]); + $var_line = preg_replace('!\s+!', ' ', $var_line); + if (strpos($var_line, '* @var ') === 0) + { + $doc_line = explode(' ', $var_line); + if (isset($doc_line[3])) + { + $doc_vars[] = $doc_line[3]; + } + } + $find_vars_line++; + } + 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 . '"'); + } + } + $found_dispatch = strpos($lines[$i], "phpbb_dispatcher->dispatch('"); + if ($found_dispatch !== false) + { + $event_line = $i; + $event_name = $lines[$event_line]; + $event_name = substr($event_name, $found_dispatch + strlen("phpbb_dispatcher->dispatch('")); + $event_name = substr($event_name, 0, strpos($event_name, "'")); + $arguments = array(); + } + + if ($event_line) + { + // Validate @event + $event_line_num = $this->find_event($file, $event_name, $lines, $event_line); + $this->validate_event($file, $event_name, $lines[$event_line_num]); + + // Validate @since + $since_line_num = $this->find_since($file, $event_name, $lines, $event_line); + $since = $this->validate_since($file, $event_name, $lines[$since_line_num]); + + // Find event description line + $description_line_num = $this->find_description($file, $event_name, $lines, $event_line); + $description = substr(trim($lines[$description_line_num]), strlen('* ')); + + $events[$event_name] = array( + 'event' => $event_name, + 'file' => $file, + 'arguments' => $arguments, + 'since' => $since, + 'description' => $description, + ); + } + } + } + + return $events; + } + + /** + * Find the "@since" Information line + * + * @param string $file + * @param string $event_name + * @param string $lines + * @param int $event_line Index of the event call in $lines + * @return int Absolute line number + */ + public function find_since($file, $event_name, $lines, $event_line) + { + return $this->find_tag($file, $event_name, $lines, $event_line, 'since', array('event', 'var')); + } + + /** + * Find the "@event" Information line + * + * @param string $file + * @param string $event_name + * @param string $lines + * @param int $event_line Index of the event call in $lines + * @return int Absolute line number + */ + public function find_event($file, $event_name, $lines, $event_line) + { + return $this->find_tag($file, $event_name, $lines, $event_line, 'event', array()); + } + + /** + * Find a "@*" Information line + * + * @param string $file + * @param string $event_name + * @param string $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 array $disallowed_tags List of tags that must not appear between + * the tag and the actual event + * @return int Absolute line number + */ + public function find_tag($file, $event_name, $lines, $event_line, $find_tag, $disallowed_tags) + { + $find_tag_line = 0; + $found_comment_end = false; + while (strpos(ltrim($lines[$event_line - $find_tag_line], "\t"), '* @' . $find_tag . ' ') !== 0) + { + if ($found_comment_end && ltrim($lines[$event_line - $find_tag_line], "\t") === '/**') + { + // Reached the start of this doc block + throw new LogicException('Can not find @' . $find_tag . ' information for event "' . $event_name . '" in file "' . $file . '"', 1); + } + + foreach ($disallowed_tags as $disallowed_tag) + { + if ($found_comment_end && strpos(ltrim($lines[$event_line - $find_tag_line], "\t"), '* @' . $disallowed_tag) === 0) + { + // Found @var after the @since + throw new LogicException('Found @' . $disallowed_tag . ' information after @' . $find_tag . ' for event "' . $event_name . '" in file "' . $file . '"', 3); + } + } + + if (ltrim($lines[$event_line - $find_tag_line], "\t") === '*/') + { + $found_comment_end = true; + } + + $find_tag_line++; + if ($find_tag_line >= $event_line) + { + // Reached the start of the file + throw new LogicException('Can not find @' . $find_tag . ' information for event "' . $event_name . '" in file "' . $file . '"', 2); + } + } + + return $event_line - $find_tag_line; + } + + /** + * Find a "@*" Information line + * + * @param string $file + * @param string $event_name + * @param string $lines + * @param int $event_line Index of the event call in $lines + * @return int Absolute line number + */ + public function find_description($file, $event_name, $lines, $event_line) + { + $find_desc_line = 0; + while (ltrim($lines[$event_line - $find_desc_line], "\t") !== '/**') + { + $find_desc_line++; + if ($find_desc_line > $event_line) + { + // Reached the start of the file + throw new LogicException('Can not find a description for event "' . $event_name . '" in file "' . $file . '"', 1); + } + } + + $find_desc_line = $event_line - $find_desc_line + 1; + + $desc = trim($lines[$find_desc_line]); + if (strpos($desc, '* @') === 0 || $desc[0] !== '*' || substr($desc, 1) == '') + { + // First line of the doc block is a @-line, empty or only contains "*" + throw new LogicException('Can not find a description for event "' . $event_name . '" in file "' . $file . '"', 2); + } + + return $find_desc_line; + } + + /** + * Validate "@since" Information + * + * @param string $file + * @param string $event_name + * @param string $line + * @return string + */ + public function validate_since($file, $event_name, $line) + { + $since = substr(ltrim($line, "\t"), strlen('* @since ')); + + if ($since !== trim($since)) + { + throw new LogicException('Invalid @since information for event "' . $event_name . '" in file "' . $file . '"', 1); + } + + $since = ($since === '3.1-A1') ? '3.1.0-a1' : $since; + + if (!preg_match('#^\d+\.\d+\.\d+(?:-(?:a|b|rc|pl)\d+)?$#', $since)) + { + throw new LogicException('Invalid @since information for event "' . $event_name . '" in file "' . $file . '"', 2); + } + + return $since; + } + + /** + * Validate "@event" Information + * + * @param string $file + * @param string $event_name + * @param string $line + * @return string + */ + public function validate_event($file, $event_name, $line) + { + $event = substr(ltrim($line, "\t"), strlen('* @event ')); + + if ($event !== trim($event)) + { + throw new LogicException('Invalid @event information for event "' . $event_name . '" in file "' . $file . '"', 1); + } + + if ($event !== $event_name) + { + throw new LogicException('Event name does not match @event tag for event "' . $event_name . '" in file "' . $file . '"', 2); + } + + return $event; + } + + /** + * Returns a list of files in that directory + * + * Works recursive with any depth + * + * @param string $dir Directory to go through + * @return array List of files (including directories from within $dir + */ + function get_file_list($dir, $path = '') + { + try + { + $iterator = new \DirectoryIterator($dir); + } + catch (Exception $e) + { + return array(); + } + + $files = array(); + foreach ($iterator as $file_info) + { + if ($file_info->isDot()) + { + continue; + } + + // Do not scan some directories + if ($file_info->isDir() && ( + ($path == '' && in_array($file_info->getFilename(), array('cache', 'develop', 'ext', 'files', 'language', 'store', 'vendor'))) + || ($path == '/includes' && in_array($file_info->getFilename(), array('utf'))) + || ($path == '/phpbb/db/migration' && in_array($file_info->getFilename(), array('data'))) + || ($path == '/phpbb' && in_array($file_info->getFilename(), array('event'))) + )) + { + continue; + } + else if ($file_info->isDir()) + { + $sub_dir = $this->get_file_list($file_info->getPath() . '/' . $file_info->getFilename(), $path . '/' . $file_info->getFilename()); + foreach ($sub_dir as $file) + { + $files[] = $file_info->getFilename() . '/' . $file; + } + } + else if (substr($file_info->getFilename(), -4) == '.php') + { + $files[] = $file_info->getFilename(); + } + } + + return $files; + } +} diff --git a/tests/event/exporter_test.php b/tests/event/exporter_test.php new file mode 100644 index 0000000000..ee9c9267b2 --- /dev/null +++ b/tests/event/exporter_test.php @@ -0,0 +1,341 @@ +exporter = new \event_exporter(dirname(__FILE__) . '/fixtures/'); + } + + static public function check_for_events_data() + { + return array( + array( + 'default.test', + array( + 'default.dispatch' => array( + 'event' => 'default.dispatch', + 'file' => 'default.test', + 'arguments' => array(), + 'since' => '3.1.0-b2', + 'description' => 'Description', + ), + ), + ), + array( + 'extra_description.test', + array( + 'extra_description.dispatch' => array( + 'event' => 'extra_description.dispatch', + 'file' => 'extra_description.test', + 'arguments' => array(), + 'since' => '3.1.0-b2', + 'description' => 'Description', + ), + ), + ), + array( + 'legacy_alpha1_version.test', + array( + 'legacy_alpha1_version.dispatch' => array( + 'event' => 'legacy_alpha1_version.dispatch', + 'file' => 'legacy_alpha1_version.test', + 'arguments' => array(), + 'since' => '3.1.0-a1', + 'description' => 'Description', + ), + ), + ), + ); + } + + /** + * @dataProvider check_for_events_data + */ + public function test_check_for_events($file, $expected) + { + $this->assertEquals($expected, $this->exporter->check_for_events($file)); + } + + static public function validate_since_data() + { + return array( + array('* @since 3.1.0-a1', '3.1.0-a1'), + array('* @since 3.1.0-b3', '3.1.0-b3'), + array(' * @since 3.1.0-b3', '3.1.0-b3'), + array('* @since 3.1-A1', '3.1.0-a1'), + ); + } + + /** + * @dataProvider validate_since_data + */ + public function test_validate_since($since, $expected) + { + $this->assertEquals($expected, $this->exporter->validate_since('', '', $since)); + } + + static public function validate_since_throws_data() + { + return array( + array(' * @since 3.1.0-a1', 1), + array('* @since 3.1.0-a1 ', 1), + array('* @since 3.1.0-a1 bertie is cool', 2), + array('bertie* @since 3.1.0-a1', 2), + array('* @since 3.1-A2', 2), + array('* @since 3.1-B3', 2), + ); + } + + /** + * @dataProvider validate_since_throws_data + * @expectedException LogicException + */ + public function test_validate_since_throws($since, $exception_code) + { + $this->setExpectedException('LogicException', '', $exception_code); + $this->exporter->validate_since('', '', $since); + } + + static public function validate_event_data() + { + return array( + array('test.event', '* @event test.event', 'test.event'), + array('test.event2', ' * @event test.event2', 'test.event2'), + ); + } + + /** + * @dataProvider validate_event_data + */ + public function test_validate_event($event_name, $event, $expected) + { + $this->assertEquals($expected, $this->exporter->validate_event('', $event_name, $event)); + } + + static public function validate_event_throws_data() + { + return array( + array('test.event', ' * @event test.event', 1), + array('test.event', '* @event test.event bertie is cool', 2), + array('test.event', 'bertie* @event test.event', 2), + ); + } + + /** + * @dataProvider validate_event_throws_data + * @expectedException LogicException + */ + public function test_validate_event_throws($event_name, $event, $exception_code) + { + $this->setExpectedException('LogicException', '', $exception_code); + $this->exporter->validate_event('', $event_name, $event); + } + + static public function find_since_data() + { + return array( + array( + array( + '/**', + '* @since 3.1.0-a1', + '*/', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 3, + 1, + ), + array( + array( + '* @since 3.1.0-a1', + '/**', + '* @since 3.1.0-a1', + '* @changed 3.1.0-a2', + '*/', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 5, + 2, + ), + ); + } + + /** + * @dataProvider find_since_data + */ + public function test_find_since($lines, $event_line, $expected) + { + $this->assertEquals($expected, $this->exporter->find_since('', '', $lines, $event_line)); + } + + static public function find_since_throws_data() + { + return array( + array( + array( + '/**', + '* @since 3.1.0-a1', + '*/', + '/**', + '*/', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 5, + 1, + ), + array( + array( + '/**', + '* @changed 3.1.0-a1', + '* @changed 3.1.0-a2', + '* @changed 3.1.0-a3', + '*/', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 5, + 2, + ), + array( + array( + '/**', + '* @since 3.1.0-a2', + '* @var', + '*/', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 4, + 3, + ), + array( + array( + '/**', + '* @since 3.1.0-a2', + '* @event', + '*/', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 4, + 3, + ), + ); + } + + /** + * @dataProvider find_since_throws_data + * @expectedException LogicException + */ + public function test_find_since_throws($lines, $event_line, $exception_code) + { + $this->setExpectedException('LogicException', '', $exception_code); + $this->exporter->find_since('', '', $lines, $event_line); + } + + static public function find_description_data() + { + return array( + array( + array( + '/**', + '* Hello Bertie!', + '* @since 3.1.0-a1', + '*/', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 4, + 1, + ), + array( + array( + ' /**', + ' * Hello Bertie!', + ' *', + ' * @since 3.1.0-a1', + ' * @changed 3.1.0-a2', + ' */', + ' $phpbb_dispatcher->dispatch(\'test\');', + ), + 6, + 1, + ), + ); + } + + /** + * @dataProvider find_description_data + */ + public function test_find_description($lines, $event_line, $expected) + { + $this->assertEquals($expected, $this->exporter->find_description('', '', $lines, $event_line)); + } + + static public function find_description_throws_data() + { + return array( + array( + array( + '$vars = array();', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 1, + 1, + ), + array( + array( + '/**', + '* @changed 3.1.0-a1', + '* @changed 3.1.0-a2', + '* @changed 3.1.0-a3', + '*/', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 5, + 2, + ), + array( + array( + '/**', + '*', + '* @since 3.1.0-a2', + '*/', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 4, + 2, + ), + array( + array( + '/**', + '* ', + '* @event', + '*/', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 4, + 2, + ), + ); + } + + /** + * @dataProvider find_description_throws_data + * @expectedException LogicException + */ + public function test_find_description_throws($lines, $event_line, $exception_code) + { + $this->setExpectedException('LogicException', '', $exception_code); + $this->exporter->find_description('', '', $lines, $event_line); + } +} diff --git a/tests/event/fixtures/default.test b/tests/event/fixtures/default.test new file mode 100644 index 0000000000..edfe4823dc --- /dev/null +++ b/tests/event/fixtures/default.test @@ -0,0 +1,9 @@ +dispatch('default.dispatch'); diff --git a/tests/event/fixtures/extra_description.test b/tests/event/fixtures/extra_description.test new file mode 100644 index 0000000000..ce8f97ce89 --- /dev/null +++ b/tests/event/fixtures/extra_description.test @@ -0,0 +1,11 @@ +dispatch('extra_description.dispatch'); diff --git a/tests/event/fixtures/legacy_alpha1_version.test b/tests/event/fixtures/legacy_alpha1_version.test new file mode 100644 index 0000000000..064af4daf8 --- /dev/null +++ b/tests/event/fixtures/legacy_alpha1_version.test @@ -0,0 +1,9 @@ +dispatch('legacy_alpha1_version.dispatch'); From 6c57edf3a3f9ff260ef0b1d5dbe7db004dd9a51d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Apr 2014 15:03:48 +0200 Subject: [PATCH 02/55] [ticket/12273] Use the new class PHPBB3-12273 --- phpBB/develop/export_events_for_wiki.php | 280 +---------------------- 1 file changed, 5 insertions(+), 275 deletions(-) diff --git a/phpBB/develop/export_events_for_wiki.php b/phpBB/develop/export_events_for_wiki.php index 3021b64e05..0c4f14a4b4 100644 --- a/phpBB/develop/export_events_for_wiki.php +++ b/phpBB/develop/export_events_for_wiki.php @@ -13,6 +13,7 @@ if (php_sapi_name() != 'cli') $phpEx = substr(strrchr(__FILE__, '.'), 1); $phpbb_root_path = __DIR__ . '/../'; +require __DIR__ . '/event_exporter.' . $phpEx; function usage() { @@ -29,278 +30,6 @@ function usage() exit(2); } -function export_from_eventsmd($phpbb_root_path, $filter) -{ - $file_content = file_get_contents($phpbb_root_path . 'docs/events.md'); - - $events = explode("\n\n", $file_content); - foreach ($events as $event) - { - // Last row of the file - if (strpos($event, "\n===\n") === false) continue; - - list($event_name, $details) = explode("\n===\n", $event); - - if ($filter == 'acp' && strpos($event_name, 'acp_') !== 0) continue; - if ($filter == 'styles' && strpos($event_name, 'acp_') === 0) continue; - - list($file_details, $details) = explode("\n* Since: ", $details); - list($version, $explanition) = explode("\n* Purpose: ", $details); - - echo "|- id=\"{$event_name}\"\n"; - echo "| [[#{$event_name}|{$event_name}]] || "; - - if (strpos($file_details, "* Locations:\n + ") === 0) - { - $file_details = substr($file_details, strlen("* Locations:\n + ")); - $files = explode("\n + ", $file_details); - $prosilver = $subsilver2 = $adm = array(); - foreach ($files as $file) - { - if (strpos($file, 'styles/prosilver/template/') === 0) - { - $prosilver[] = substr($file, strlen('styles/prosilver/template/')); - } - if (strpos($file, 'styles/subsilver2/template/') === 0) - { - $subsilver2[] = substr($file, strlen('styles/subsilver2/template/')); - } - if (strpos($file, 'adm/style/') === 0) - { - $adm[] = substr($file, strlen('adm/style/')); - } - } - if ($filter == 'acp') - { - echo implode(', ', $adm); - } - else - { - echo implode(', ', $prosilver) . ' || ' . implode(', ', $subsilver2); - } - } - else if ($filter == 'acp') - { - echo substr($file_details, strlen("* Location: adm/style/")); - } - echo " || {$version} || " . str_replace("\n", ' ', $explanition) . "\n"; - - } -} - -function export_from_php($phpbb_root_path) -{ - $files = get_file_list($phpbb_root_path); - $events = array(); - foreach ($files as $file) - { - $file_events = check_for_events($phpbb_root_path, $file); - if (!empty($file_events)) - { - $events = array_merge($events, $file_events); - } - } - - ksort($events); - - foreach ($events as $event) - { - echo '|- id="' . $event['event'] . '"' . "\n"; - echo '| [[#' . $event['event'] . '|' . $event['event'] . ']] || ' . $event['file'] . ' || ' . implode(', ', $event['arguments']) . ' || ' . $event['since'] . ' || ' . $event['description'] . "\n"; - } -} - -function check_for_events($phpbb_root_path, $file) -{ - $events = array(); - $content = file_get_contents($phpbb_root_path . $file); - - if (strpos($content, "phpbb_dispatcher->trigger_event('") || strpos($content, "phpbb_dispatcher->dispatch('")) - { - $lines = explode("\n", $content); - for ($i = 0, $num_lines = sizeof($lines); $i < $num_lines; $i++) - { - $event_line = 0; - $found_trigger_event = strpos($lines[$i], "phpbb_dispatcher->trigger_event('"); - if ($found_trigger_event !== false) - { - $event_line = $i; - $event_name = $lines[$event_line]; - $event_name = substr($event_name, $found_trigger_event + strlen("phpbb_dispatcher->trigger_event('")); - $event_name = substr($event_name, 0, strpos($event_name, "'")); - - $current_line = trim($lines[$event_line]); - $arguments = array(); - $found_inline_array = strpos($current_line, "', compact(array('"); - if ($found_inline_array !== false) - { - $varsarray = substr($current_line, $found_inline_array + strlen("', compact(array('"), -6); - $arguments = explode("', '", $varsarray); - } - - if (empty($arguments)) - { - // Find $vars array lines - $find_varsarray_line = 1; - while (strpos($lines[$event_line - $find_varsarray_line], "vars = array('") === false) - { - $find_varsarray_line++; - - if ($find_varsarray_line > min(50, $event_line)) - { - throw new LogicException('Can not find "$vars = array()"-line for event "' . $event_name . '" in file "' . $file . '"'); - } - } - $varsarray = substr(trim($lines[$event_line - $find_varsarray_line]), strlen("\$vars = array('"), -3); - $arguments = explode("', '", $varsarray); - } - - // Validate $vars array with @var - $find_vars_line = 3; - $doc_vars = array(); - while (strpos(trim($lines[$event_line - $find_vars_line]), '*') === 0) - { - $var_line = trim($lines[$event_line - $find_vars_line]); - $var_line = preg_replace('!\s+!', ' ', $var_line); - if (strpos($var_line, '* @var ') === 0) - { - $doc_line = explode(' ', $var_line); - if (isset($doc_line[3])) - { - $doc_vars[] = $doc_line[3]; - } - } - $find_vars_line++; - } - 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 . '"'); - } - } - $found_dispatch = strpos($lines[$i], "phpbb_dispatcher->dispatch('"); - if ($found_dispatch !== false) - { - $event_line = $i; - $event_name = $lines[$event_line]; - $event_name = substr($event_name, $found_dispatch + strlen("phpbb_dispatcher->dispatch('")); - $event_name = substr($event_name, 0, strpos($event_name, "'")); - $arguments = array(); - } - - if ($event_line) - { - // Validate @event name - $find_event_line = 1; - while (strpos($lines[$event_line - $find_event_line], '* @event ') === false) - { - $find_event_line++; - - if ($find_event_line > min(50, $event_line)) - { - throw new LogicException('Can not find @event tag for event "' . $event_name . '" in file "' . $file . '"'); - } - } - $event_name_tag = substr(trim($lines[$event_line - $find_event_line]), strlen('* @event ')); - if ($event_name_tag !== $event_name) - { - throw new LogicException('Event name does not match @event tag for event "' . $event_name . '" in file "' . $file . '"'); - } - - // Find @since - $find_since_line = 1; - while (strpos($lines[$event_line - $find_since_line], '* @since ') === false) - { - $find_since_line++; - - if ($find_since_line > min(50, $event_line)) - { - throw new LogicException('Can not find @since tag for event "' . $event_name . '" in file "' . $file . '"'); - } - } - $since = substr(trim($lines[$event_line - $find_since_line]), strlen('* @since ')); - $since = ($since == '3.1-A1') ? '3.1.0-a1' : $since; - - // Find event description line - $find_description_line = 3; - while (strpos(trim($lines[$event_line - $find_description_line]), '*') === 0) - { - $find_description_line++; - - if ($find_description_line > min(50, $event_line)) - { - throw new LogicException('Can not find description-line for event "' . $event_name . '" in file "' . $file . '"'); - } - } - $description = substr(trim($lines[$event_line - $find_description_line + 1]), strlen('* ')); - - $events[$event_name] = array( - 'event' => $event_name, - 'file' => $file, - 'arguments' => $arguments, - 'since' => $since, - 'description' => $description, - ); - } - } - } - - return $events; -} - -/** -* Returns a list of files in that directory -* -* Works recursive with any depth -* -* @param string $dir Directory to go through -* @return array List of files (including directories from within $dir -*/ -function get_file_list($dir, $path = '') -{ - try - { - $iterator = new \DirectoryIterator($dir); - } - catch (Exception $e) - { - return array(); - } - - $files = array(); - foreach ($iterator as $file_info) - { - if ($file_info->isDot()) - { - continue; - } - - // Do not scan some directories - if ($file_info->isDir() && ( - ($path == '' && in_array($file_info->getFilename(), array('cache', 'develop', 'ext', 'files', 'language', 'store', 'vendor'))) - || ($path == '/includes' && in_array($file_info->getFilename(), array('utf'))) - || ($path == '/phpbb/db/migration' && in_array($file_info->getFilename(), array('data'))) - || ($path == '/phpbb' && in_array($file_info->getFilename(), array('event'))) - )) - { - continue; - } - else if ($file_info->isDir()) - { - $sub_dir = get_file_list($file_info->getPath() . '/' . $file_info->getFilename(), $path . '/' . $file_info->getFilename()); - foreach ($sub_dir as $file) - { - $files[] = $file_info->getFilename() . '/' . $file; - } - } - else if (substr($file_info->getFilename(), -4) == '.php') - { - $files[] = $file_info->getFilename(); - } - } - - return $files; -} - function validate_argument_count($arguments, $count) { if ($arguments <= $count) @@ -312,19 +41,20 @@ function validate_argument_count($arguments, $count) validate_argument_count($argc, 1); $action = $argv[1]; +$exporter = new \event_exporter($phpbb_root_path); switch ($action) { case 'acp': - export_from_eventsmd($phpbb_root_path, 'acp'); + $exporter->export_from_eventsmd('acp'); break; case 'styles': - export_from_eventsmd($phpbb_root_path, 'styles'); + $exporter->export_from_eventsmd('styles'); break; case 'php': - export_from_php($phpbb_root_path); + $exporter->export_from_php(); break; default: From 5387511f89dbb8e7a8edb70b90f5f510aad8779b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Apr 2014 16:55:36 +0200 Subject: [PATCH 03/55] [ticket/12273] Grab name of events with a function PHPBB3-12273 --- phpBB/develop/event_exporter.php | 115 +++++++++++++++++++++---------- 1 file changed, 80 insertions(+), 35 deletions(-) diff --git a/phpBB/develop/event_exporter.php b/phpBB/develop/event_exporter.php index 6277433423..3b4f054ad0 100644 --- a/phpBB/develop/event_exporter.php +++ b/phpBB/develop/event_exporter.php @@ -105,45 +105,26 @@ class event_exporter $events = array(); $content = file_get_contents($this->root_path . $file); - if (strpos($content, "phpbb_dispatcher->trigger_event('") || strpos($content, "phpbb_dispatcher->dispatch('")) + if (strpos($content, "dispatcher->trigger_event('") || strpos($content, "dispatcher->dispatch('")) { $lines = explode("\n", $content); for ($i = 0, $num_lines = sizeof($lines); $i < $num_lines; $i++) { $event_line = 0; - $found_trigger_event = strpos($lines[$i], "phpbb_dispatcher->trigger_event('"); + $found_trigger_event = strpos($lines[$i], "dispatcher->trigger_event('"); if ($found_trigger_event !== false) { $event_line = $i; - $event_name = $lines[$event_line]; - $event_name = substr($event_name, $found_trigger_event + strlen("phpbb_dispatcher->trigger_event('")); - $event_name = substr($event_name, 0, strpos($event_name, "'")); + $event_name = $this->get_trigger_event_name($file, $lines[$event_line]); - $current_line = trim($lines[$event_line]); - $arguments = array(); - $found_inline_array = strpos($current_line, "', compact(array('"); - if ($found_inline_array !== false) + // Find $vars array lines + $vars_line = ltrim($lines[$event_line - 1], "\t"); + if (strpos($vars_line, "\$vars = array('") !== 0) { - $varsarray = substr($current_line, $found_inline_array + strlen("', compact(array('"), -6); - $arguments = explode("', '", $varsarray); - } - - if (empty($arguments)) - { - // Find $vars array lines - $find_varsarray_line = 1; - while (strpos($lines[$event_line - $find_varsarray_line], "\$vars = array('") === false) - { - $find_varsarray_line++; - - if ($find_varsarray_line > min(50, $event_line)) - { - throw new LogicException('Can not find "$vars = array()"-line for event "' . $event_name . '" in file "' . $file . '"'); - } - } - $varsarray = substr(trim($lines[$event_line - $find_varsarray_line]), strlen("\$vars = array('"), -3); - $arguments = explode("', '", $varsarray); + 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 $find_vars_line = 3; @@ -167,14 +148,16 @@ class event_exporter throw new LogicException('$vars array does not match the list of @var tags for event "' . $event_name . '" in file "' . $file . '"'); } } - $found_dispatch = strpos($lines[$i], "phpbb_dispatcher->dispatch('"); - if ($found_dispatch !== false) + + if (!$event_line) { - $event_line = $i; - $event_name = $lines[$event_line]; - $event_name = substr($event_name, $found_dispatch + strlen("phpbb_dispatcher->dispatch('")); - $event_name = substr($event_name, 0, strpos($event_name, "'")); - $arguments = array(); + $found_dispatch = strpos($lines[$i], "dispatcher->dispatch('"); + if ($found_dispatch !== false) + { + $event_line = $i; + $event_name = $this->get_dispatch_name($file, $lines[$event_line]); + $arguments = array(); + } } if ($event_line) @@ -205,6 +188,68 @@ class event_exporter return $events; } + /** + * Find the name of the event inside the dispatch() line + * + * @param string $file + * @param string $event_line + * @return int Absolute line number + */ + public function get_dispatch_name($file, $event_line) + { + $event_line = ltrim($event_line, "\t"); + + $regex = '#\$([a-z](?:[a-z0-9_]|->)*)'; + $regex .= '->dispatch\('; + $regex .= '\'' . $this->preg_match_event_name() . '\''; + $regex .= '\);#'; + + $match = array(); + preg_match($regex, $event_line, $match); + if (!isset($match[2])) + { + throw new LogicException('Can not find event name in line "' . $event_line . '" in file "' . $file . '"', 1); + } + + return $match[2]; + } + + /** + * Find the name of the event inside the trigger_event() line + * + * @param string $file + * @param string $event_line + * @return int Absolute line number + */ + public function get_trigger_event_name($file, $event_line) + { + $event_line = ltrim($event_line, "\t"); + + $regex = '#extract\(\$([a-z](?:[a-z0-9_]|->)*)'; + $regex .= '->trigger_event\('; + $regex .= '\'' . $this->preg_match_event_name() . '\''; + $regex .= ', compact\(\$vars\)\)\);#'; + + $match = array(); + preg_match($regex, $event_line, $match); + if (!isset($match[2])) + { + throw new LogicException('Can not find event name in line "' . $event_line . '" in file "' . $file . '"', 1); + } + + return $match[2]; + } + + /** + * Find the name of the event inside the trigger_event() line + * + * @return string Returns a regex match for the event name + */ + protected function preg_match_event_name() + { + return '([a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+)'; + } + /** * Find the "@since" Information line * From 4a3756741c9d1689430c557166a43d79739e98fe Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Apr 2014 18:21:18 +0200 Subject: [PATCH 04/55] [ticket/12273] Move grabbing the $vars array line to a method PHPBB3-12273 --- phpBB/develop/event_exporter.php | 60 ++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/phpBB/develop/event_exporter.php b/phpBB/develop/event_exporter.php index 3b4f054ad0..644063df2b 100644 --- a/phpBB/develop/event_exporter.php +++ b/phpBB/develop/event_exporter.php @@ -110,21 +110,15 @@ class event_exporter $lines = explode("\n", $content); 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('"); if ($found_trigger_event !== false) { $event_line = $i; $event_name = $this->get_trigger_event_name($file, $lines[$event_line]); - // Find $vars array lines - $vars_line = ltrim($lines[$event_line - 1], "\t"); - 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); + // Find $vars array + $arguments = $this->get_vars_from_array($file, $event_name, $lines, $event_line); // Validate $vars array with @var $find_vars_line = 3; @@ -143,13 +137,13 @@ class event_exporter } $find_vars_line++; } + 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 . '"'); } } - - if (!$event_line) + else { $found_dispatch = strpos($lines[$i], "dispatcher->dispatch('"); if ($found_dispatch !== false) @@ -250,12 +244,48 @@ class event_exporter 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 * * @param string $file * @param string $event_name - * @param string $lines + * @param array $lines * @param int $event_line Index of the event call in $lines * @return int Absolute line number */ @@ -269,7 +299,7 @@ class event_exporter * * @param string $file * @param string $event_name - * @param string $lines + * @param array $lines * @param int $event_line Index of the event call in $lines * @return int Absolute line number */ @@ -283,7 +313,7 @@ class event_exporter * * @param string $file * @param string $event_name - * @param string $lines + * @param array $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 array $disallowed_tags List of tags that must not appear between @@ -332,7 +362,7 @@ class event_exporter * * @param string $file * @param string $event_name - * @param string $lines + * @param array $lines * @param int $event_line Index of the event call in $lines * @return int Absolute line number */ From 91deb4419b3f7c93288e969cf97fb9e1541c2ecf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 18 Apr 2014 00:31:06 +0200 Subject: [PATCH 05/55] [ticket/12273] Add more tests for the event exporter PHPBB3-12273 --- phpBB/develop/event_exporter.php | 112 +++++-- tests/event/exporter_test.php | 301 +++++++++++++++++- .../event/fixtures/legacy_alpha1_version.test | 9 - tests/event/fixtures/missing_var.test | 18 ++ tests/event/fixtures/none.test | 6 + tests/event/fixtures/trigger.test | 18 ++ 6 files changed, 424 insertions(+), 40 deletions(-) delete mode 100644 tests/event/fixtures/legacy_alpha1_version.test create mode 100644 tests/event/fixtures/missing_var.test create mode 100644 tests/event/fixtures/none.test create mode 100644 tests/event/fixtures/trigger.test diff --git a/phpBB/develop/event_exporter.php b/phpBB/develop/event_exporter.php index 644063df2b..c17e714764 100644 --- a/phpBB/develop/event_exporter.php +++ b/phpBB/develop/event_exporter.php @@ -117,31 +117,10 @@ class event_exporter $event_line = $i; $event_name = $this->get_trigger_event_name($file, $lines[$event_line]); - // Find $vars array + // Find variables of the event $arguments = $this->get_vars_from_array($file, $event_name, $lines, $event_line); - - // Validate $vars array with @var - $find_vars_line = 3; - $doc_vars = array(); - while (strpos(trim($lines[$event_line - $find_vars_line]), '*') === 0) - { - $var_line = trim($lines[$event_line - $find_vars_line]); - $var_line = preg_replace('!\s+!', ' ', $var_line); - if (strpos($var_line, '* @var ') === 0) - { - $doc_line = explode(' ', $var_line); - if (isset($doc_line[3])) - { - $doc_vars[] = $doc_line[3]; - } - } - $find_vars_line++; - } - - 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 . '"'); - } + $doc_vars = $this->get_vars_from_docblock($file, $event_name, $lines, $event_line); + $this->validate_vars_docblock_array($file, $event_name, $arguments, $doc_vars); } else { @@ -277,9 +256,73 @@ class event_exporter } } + sort($vars_array); return $vars_array; } + /** + * 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_docblock($file, $event_name, $lines, $event_line) + { + $doc_vars = array(); + $current_doc_line = 1; + $found_comment_end = false; + while (ltrim($lines[$event_line - $current_doc_line], "\t") !== '/**') + { + if (ltrim($lines[$event_line - $current_doc_line], "\t") === '*/') + { + $found_comment_end = true; + } + + if ($found_comment_end) + { + $var_line = trim($lines[$event_line - $current_doc_line]); + $var_line = preg_replace('!\s+!', ' ', $var_line); + if (strpos($var_line, '* @var ') === 0) + { + $doc_line = explode(' ', $var_line, 5); + if (sizeof($doc_line) !== 5) + { + throw new LogicException('Found invalid line "' . $lines[$event_line - $current_doc_line] + . '" for event "' . $event_name . '" in file "' . $file . '"', 1); + } + $doc_vars[] = $doc_line[3]; + } + } + + $current_doc_line++; + if ($current_doc_line > $event_line) + { + // Reached the start of the file + throw new LogicException('Can not find end of docblock for event "' . $event_name . '" in file "' . $file . '"', 2); + } + } + + if (empty($doc_vars)) + { + // Reached the start of the file + throw new LogicException('Can not find @var lines for event "' . $event_name . '" in file "' . $file . '"', 3); + } + + foreach ($doc_vars as $var) + { + if (!preg_match('#^([a-zA-Z_][a-zA-Z0-9_]*)$#', $var)) + { + throw new LogicException('Found invalid @var "' . $var . '" in docblock for event "' . $event_name . '" in file "' . $file . '"', 4); + } + } + + sort($doc_vars); + return $doc_vars; + } + /** * Find the "@since" Information line * @@ -443,6 +486,27 @@ class event_exporter return $event; } + /** + * Validates that two arrays contain the same strings + * + * @param string $file + * @param string $event_name + * @param array $vars_array Variables found in the array line + * @param array $vars_docblock Variables found in the doc block + * @return null + */ + public function validate_vars_docblock_array($file, $event_name, $vars_array, $vars_docblock) + { + $vars_array = array_unique($vars_array); + $vars_docblock = array_unique($vars_docblock); + $sizeof_vars_array = sizeof($vars_array); + + if ($sizeof_vars_array !== sizeof($vars_docblock) || $sizeof_vars_array !== sizeof(array_intersect($vars_array, $vars_docblock))) + { + throw new LogicException('$vars array does not match the list of @var tags for event "' . $event_name . '" in file "' . $file . '"'); + } + } + /** * Returns a list of files in that directory * diff --git a/tests/event/exporter_test.php b/tests/event/exporter_test.php index ee9c9267b2..06a66abb04 100644 --- a/tests/event/exporter_test.php +++ b/tests/event/exporter_test.php @@ -48,17 +48,21 @@ class phpbb_event_exporter_test extends phpbb_test_case ), ), array( - 'legacy_alpha1_version.test', + 'trigger.test', array( - 'legacy_alpha1_version.dispatch' => array( - 'event' => 'legacy_alpha1_version.dispatch', - 'file' => 'legacy_alpha1_version.test', - 'arguments' => array(), - 'since' => '3.1.0-a1', - 'description' => 'Description', + 'core.trigger' => array( + 'event' => 'core.trigger', + 'file' => 'trigger.test', + 'arguments' => array('attachments', 'cp_row', 'current_row_number', 'end', 'post_row', 'row', 'start', 'user_poster_data'), + 'since' => '3.1.0-a3', + 'description' => 'Event after the post data has been assigned to the template', ), ), ), + array( + 'none.test', + array(), + ), ); } @@ -145,6 +149,289 @@ class phpbb_event_exporter_test extends phpbb_test_case $this->exporter->validate_event('', $event_name, $event); } + static public function validate_vars_docblock_array_data() + { + return array( + array(array('abc', 'def'), array('abc', 'def')), + ); + } + + /** + * @dataProvider validate_vars_docblock_array_data + */ + public function test_validate_vars_docblock_array($vars_array, $vars_docblock) + { + $this->assertNull($this->exporter->validate_vars_docblock_array('', '', $vars_array, $vars_docblock)); + } + + static public function validate_vars_docblock_array_throws_data() + { + return array( + array(array('abc', 'def'), array()), + array(array('abc', 'def'), array('abc')), + array(array('abc', 'defg'), array('abc', 'def')), + array(array('abc'), array('abc', 'def')), + array(array(), array('abc', 'def')), + ); + } + + /** + * @dataProvider validate_vars_docblock_array_throws_data + * @expectedException LogicException + */ + public function test_validate_vars_docblock_array_throws($vars_array, $vars_docblock) + { + $this->exporter->validate_vars_docblock_array('', '', $vars_array, $vars_docblock); + } + + static public function get_dispatch_name_data() + { + return array( + array("\$phpbb_dispatcher->dispatch('dispatch.one2');", 'dispatch.one2'), + array("\t\$phpbb_dispatcher->dispatch('dispatch.one2.thr_ee4');", 'dispatch.one2.thr_ee4'), + array("\$this->dispatcher->dispatch('dispatch.one2');", 'dispatch.one2'), + array("\$phpbb_dispatcher->dispatch('dis_patch.one');", 'dis_patch.one'), + ); + } + + /** + * @dataProvider get_dispatch_name_data + */ + public function test_get_dispatch_name($event_line, $expected) + { + $this->assertEquals($expected, $this->exporter->get_dispatch_name('', $event_line)); + } + + static public function get_dispatch_name_throws_data() + { + return array( + array("\$phpbb_dispatcher->dispatch();"), + array("\$phpbb_dispatcher->dispatch('');"), + array("\$phpbb_dispatcher->dispatch('dispatch.2one');"), + array("\$phpbb_dispatcher->dispatch('dispatch');"), + ); + } + + /** + * @dataProvider get_dispatch_name_throws_data + * @expectedException LogicException + */ + public function test_get_dispatch_name_throws($event_line) + { + $this->exporter->get_dispatch_name('', $event_line); + } + + static public function get_trigger_event_name_data() + { + return array( + array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one2', compact(\$vars)));", 'dispatch.one2'), + array("\textract(\$phpbb_dispatcher->trigger_event('dispatch.one2.thr_ee4', compact(\$vars)));", 'dispatch.one2.thr_ee4'), + array("extract(\$this->dispatcher->trigger_event('dispatch.one2', compact(\$vars)));", 'dispatch.one2'), + array("extract(\$phpbb_dispatcher->trigger_event('dis_patch.one', compact(\$vars)));", 'dis_patch.one'), + ); + } + + /** + * @dataProvider get_trigger_event_name_data + */ + public function test_get_trigger_event_name($event_line, $expected) + { + $this->assertEquals($expected, $this->exporter->get_trigger_event_name('', $event_line)); + } + + static public function get_trigger_event_name_throws_data() + { + return array( + array("extract(\$phpbb_dispatcher->trigger_event());"), + array("extract(\$phpbb_dispatcher->trigger_event(''));"), + array("extract(\$phpbb_dispatcher->trigger_event('dispatch.2one'));"), + array("extract(\$phpbb_dispatcher->trigger_event('dispatch'));"), + array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one', \$vars));"), + array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one', compact(\$var)));"), + array("extract(\$phpbb_dispatcher->trigger_event('dispatch.one', compact(\$array)));"), + array("\$phpbb_dispatcher->trigger_event('dis_patch.one', compact(\$vars));", 'dis_patch.one'), + ); + } + + /** + * @dataProvider get_trigger_event_name_throws_data + * @expectedException LogicException + */ + public function test_get_trigger_event_name_throws($event_line) + { + $this->exporter->get_trigger_event_name('', $event_line); + } + + static public function get_vars_from_array_data() + { + return array( + array( + array( + '/**', + '*/', + '$vars = array(\'bertie\');', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 3, + array('bertie'), + ), + array( + array( + "\t/**", + "\t*/", + "\t\$vars = array('_Strange123', 'phpBB3_Test');", + "\t\$this->dispatcher->dispatch('test');", + ), + 3, + array('_Strange123', 'phpBB3_Test'), + ), + ); + } + + /** + * @dataProvider get_vars_from_array_data + */ + public function test_get_vars_from_array($lines, $event_line, $expected) + { + $this->assertEquals($expected, $this->exporter->get_vars_from_array('', '', $lines, $event_line)); + } + + static public function get_vars_from_array_throws_data() + { + return array( + array( + array( + '/**', + '*/', + '$vars = $bertie;', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 3, + 1, + ), + array( + array( + '/**', + '*/', + '$vars = array();', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 3, + 1, + ), + array( + array( + '/**', + '*/', + '$vars = array(\'\');', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 3, + 2, + ), + array( + array( + '/**', + '*/', + '$vars = array(\'$bertie\');', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 3, + 3, + ), + ); + } + + /** + * @dataProvider get_vars_from_array_throws_data + * @expectedException LogicException + */ + public function test_get_vars_from_array_throws($lines, $event_line, $exception_code) + { + $this->setExpectedException('LogicException', '', $exception_code); + $this->exporter->get_vars_from_array('', '', $lines, $event_line); + } + + static public function get_vars_from_docblock_data() + { + return array( + array( + array( + '/**', + '* @var int name1 Description', + '* @var array name2 Description test', + '*/', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 4, + array('name1', 'name2'), + ), + ); + } + + /** + * @dataProvider get_vars_from_docblock_data + */ + public function test_get_vars_from_docblock($lines, $event_line, $expected) + { + $this->assertEquals($expected, $this->exporter->get_vars_from_docblock('', '', $lines, $event_line)); + } + + static public function get_vars_from_docblock_throws_data() + { + return array( + array( + array( + '$vars = array();', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 1, + 2, + ), + array( + array( + '/**', + '* @var int name1', + '* @var array name2 Description test', + '*/', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 4, + 1, + ), + array( + array( + '/**', + '*/', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 2, + 3, + ), + array( + array( + '/**', + '* @var int name1 Description', + '* @var array $name2 Description', + '*/', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 4, + 4, + ), + ); + } + + /** + * @dataProvider get_vars_from_docblock_throws_data + * @expectedException LogicException + */ + public function test_get_vars_from_docblock_throws($lines, $event_line, $exception_code) + { + $this->setExpectedException('LogicException', '', $exception_code); + $this->exporter->get_vars_from_docblock('', '', $lines, $event_line); + } + static public function find_since_data() { return array( diff --git a/tests/event/fixtures/legacy_alpha1_version.test b/tests/event/fixtures/legacy_alpha1_version.test deleted file mode 100644 index 064af4daf8..0000000000 --- a/tests/event/fixtures/legacy_alpha1_version.test +++ /dev/null @@ -1,9 +0,0 @@ -dispatch('legacy_alpha1_version.dispatch'); diff --git a/tests/event/fixtures/missing_var.test b/tests/event/fixtures/missing_var.test new file mode 100644 index 0000000000..9df6e5b386 --- /dev/null +++ b/tests/event/fixtures/missing_var.test @@ -0,0 +1,18 @@ +trigger_event('core.trigger', compact($vars))); diff --git a/tests/event/fixtures/none.test b/tests/event/fixtures/none.test new file mode 100644 index 0000000000..6e2267024b --- /dev/null +++ b/tests/event/fixtures/none.test @@ -0,0 +1,6 @@ +trigger_event('core.trigger', compact($vars))); From b831e96aafc4b8c2bc883dd47c4f2452f329e5b2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 18 Apr 2014 02:08:23 +0200 Subject: [PATCH 06/55] [ticket/12273] Use class properties instead of parameters PHPBB3-12273 --- phpBB/develop/event_exporter.php | 237 ++++++++++++---------- tests/event/exporter_test.php | 76 +++++-- tests/event/fixtures/duplicate_event.test | 26 +++ tests/event/fixtures/missing_var.test | 1 - 4 files changed, 211 insertions(+), 129 deletions(-) create mode 100644 tests/event/fixtures/duplicate_event.test diff --git a/phpBB/develop/event_exporter.php b/phpBB/develop/event_exporter.php index c17e714764..a84b18db26 100644 --- a/phpBB/develop/event_exporter.php +++ b/phpBB/develop/event_exporter.php @@ -12,12 +12,30 @@ class event_exporter /** @var string */ protected $root_path; + /** @var string */ + protected $current_file; + + /** @var string */ + protected $current_event; + + /** @var int */ + protected $current_event_line; + + /** @var array */ + protected $events; + + /** @var array */ + protected $file_lines; + /** * @param string $phpbb_root_path */ public function __construct($phpbb_root_path) { $this->root_path = $phpbb_root_path; + $this->events = $this->file_lines = array(); + $this->current_file = $this->current_event = ''; + $this->current_event_line = 0; } function export_from_eventsmd($filter) @@ -82,53 +100,70 @@ class event_exporter function export_from_php() { $files = $this->get_file_list($this->root_path); - $events = array(); + $this->events = array(); foreach ($files as $file) { - $file_events = $this->check_for_events($file); - if (!empty($file_events)) - { - $events = array_merge($events, $file_events); - } + $this->check_for_events($file); } - ksort($events); + ksort($this->events); - foreach ($events as $event) + foreach ($this->events as $event) { echo '|- id="' . $event['event'] . '"' . "\n"; echo '| [[#' . $event['event'] . '|' . $event['event'] . ']] || ' . $event['file'] . ' || ' . implode(', ', $event['arguments']) . ' || ' . $event['since'] . ' || ' . $event['description'] . "\n"; } } + public function get_events() + { + return $this->events; + } + + public function set_current_event($name, $line) + { + $this->current_event = $name; + $this->current_event_line = $line; + } + + public function set_content($content) + { + $this->file_lines = $content; + } + + /** + * @param $file + * @throws LogicException + */ public function check_for_events($file) { - $events = array(); - $content = file_get_contents($this->root_path . $file); + $this->current_file = $file; + $this->file_lines = array(); + $content = file_get_contents($this->root_path . $this->current_file); if (strpos($content, "dispatcher->trigger_event('") || strpos($content, "dispatcher->dispatch('")) { - $lines = explode("\n", $content); - for ($i = 0, $num_lines = sizeof($lines); $i < $num_lines; $i++) + $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($lines[$i], "dispatcher->trigger_event('"); + $found_trigger_event = strpos($this->file_lines[$i], "dispatcher->trigger_event('"); if ($found_trigger_event !== false) { $event_line = $i; - $event_name = $this->get_trigger_event_name($file, $lines[$event_line]); + $this->set_current_event($this->get_trigger_event_name($this->file_lines[$event_line]), $event_line); // Find variables of the event - $arguments = $this->get_vars_from_array($file, $event_name, $lines, $event_line); - $doc_vars = $this->get_vars_from_docblock($file, $event_name, $lines, $event_line); - $this->validate_vars_docblock_array($file, $event_name, $arguments, $doc_vars); + $arguments = $this->get_vars_from_array(); + $doc_vars = $this->get_vars_from_docblock(); + $this->validate_vars_docblock_array($arguments, $doc_vars); } else { - $found_dispatch = strpos($lines[$i], "dispatcher->dispatch('"); + $found_dispatch = strpos($this->file_lines[$i], "dispatcher->dispatch('"); if ($found_dispatch !== false) { $event_line = $i; - $event_name = $this->get_dispatch_name($file, $lines[$event_line]); + $this->set_current_event($this->get_dispatch_name($this->file_lines[$event_line]), $event_line); $arguments = array(); } } @@ -136,20 +171,26 @@ class event_exporter if ($event_line) { // Validate @event - $event_line_num = $this->find_event($file, $event_name, $lines, $event_line); - $this->validate_event($file, $event_name, $lines[$event_line_num]); + $event_line_num = $this->find_event(); + $this->validate_event($this->current_event, $this->file_lines[$event_line_num]); // Validate @since - $since_line_num = $this->find_since($file, $event_name, $lines, $event_line); - $since = $this->validate_since($file, $event_name, $lines[$since_line_num]); + $since_line_num = $this->find_since(); + $since = $this->validate_since($this->file_lines[$since_line_num]); // Find event description line - $description_line_num = $this->find_description($file, $event_name, $lines, $event_line); - $description = substr(trim($lines[$description_line_num]), strlen('* ')); + $description_line_num = $this->find_description(); + $description = substr(trim($this->file_lines[$description_line_num]), strlen('* ')); - $events[$event_name] = array( - 'event' => $event_name, - 'file' => $file, + if (isset($this->events[$this->current_event])) + { + throw new LogicException('The event "' . $this->current_event . '" from file "' . $this->current_file + . '" already exists in file "'. $this->events[$this->current_event]['file'] . '"', 10); + } + + $this->events[$this->current_event] = array( + 'event' => $this->current_event, + 'file' => $this->current_file, 'arguments' => $arguments, 'since' => $since, 'description' => $description, @@ -157,18 +198,16 @@ class event_exporter } } } - - return $events; } /** * Find the name of the event inside the dispatch() line * - * @param string $file * @param string $event_line * @return int Absolute line number + * @throws LogicException */ - public function get_dispatch_name($file, $event_line) + public function get_dispatch_name($event_line) { $event_line = ltrim($event_line, "\t"); @@ -181,7 +220,7 @@ class event_exporter preg_match($regex, $event_line, $match); if (!isset($match[2])) { - throw new LogicException('Can not find event name in line "' . $event_line . '" in file "' . $file . '"', 1); + throw new LogicException('Can not find event name in line "' . $event_line . '" in file "' . $this->current_file . '"', 1); } return $match[2]; @@ -190,11 +229,11 @@ class event_exporter /** * Find the name of the event inside the trigger_event() line * - * @param string $file * @param string $event_line * @return int Absolute line number + * @throws LogicException */ - public function get_trigger_event_name($file, $event_line) + public function get_trigger_event_name($event_line) { $event_line = ltrim($event_line, "\t"); @@ -207,7 +246,7 @@ class event_exporter preg_match($regex, $event_line, $match); if (!isset($match[2])) { - throw new LogicException('Can not find event name in line "' . $event_line . '" in file "' . $file . '"', 1); + throw new LogicException('Can not find event name in line "' . $event_line . '" in file "' . $this->current_file . '"', 1); } return $match[2]; @@ -226,24 +265,21 @@ class event_exporter /** * 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 + * @throws LogicException */ - public function get_vars_from_array($file, $event_name, $lines, $event_line) + public function get_vars_from_array() { - $vars_line = ltrim($lines[$event_line - 1], "\t"); + $vars_line = ltrim($this->file_lines[$this->current_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); + throw new LogicException('Can not find "$vars = array();"-line for event "' . $this->current_event . '" in file "' . $this->current_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); + throw new LogicException('Found empty $vars array for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); } $vars_array = explode("', '", $vars_array); @@ -252,7 +288,7 @@ class event_exporter { 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); + throw new LogicException('Found invalid var "' . $var . '" in array for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 3); } } @@ -263,59 +299,56 @@ class event_exporter /** * 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 + * @throws LogicException */ - public function get_vars_from_docblock($file, $event_name, $lines, $event_line) + public function get_vars_from_docblock() { $doc_vars = array(); $current_doc_line = 1; $found_comment_end = false; - while (ltrim($lines[$event_line - $current_doc_line], "\t") !== '/**') + while (ltrim($this->file_lines[$this->current_event_line - $current_doc_line], "\t") !== '/**') { - if (ltrim($lines[$event_line - $current_doc_line], "\t") === '*/') + if (ltrim($this->file_lines[$this->current_event_line - $current_doc_line], "\t") === '*/') { $found_comment_end = true; } if ($found_comment_end) { - $var_line = trim($lines[$event_line - $current_doc_line]); + $var_line = trim($this->file_lines[$this->current_event_line - $current_doc_line]); $var_line = preg_replace('!\s+!', ' ', $var_line); if (strpos($var_line, '* @var ') === 0) { $doc_line = explode(' ', $var_line, 5); if (sizeof($doc_line) !== 5) { - throw new LogicException('Found invalid line "' . $lines[$event_line - $current_doc_line] - . '" for event "' . $event_name . '" in file "' . $file . '"', 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 . '"', 1); } $doc_vars[] = $doc_line[3]; } } $current_doc_line++; - if ($current_doc_line > $event_line) + if ($current_doc_line > $this->current_event_line) { // Reached the start of the file - throw new LogicException('Can not find end of docblock for event "' . $event_name . '" in file "' . $file . '"', 2); + throw new LogicException('Can not find end of docblock for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); } } if (empty($doc_vars)) { // Reached the start of the file - throw new LogicException('Can not find @var lines for event "' . $event_name . '" in file "' . $file . '"', 3); + throw new LogicException('Can not find @var lines for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 3); } foreach ($doc_vars as $var) { if (!preg_match('#^([a-zA-Z_][a-zA-Z0-9_]*)$#', $var)) { - throw new LogicException('Found invalid @var "' . $var . '" in docblock for event "' . $event_name . '" in file "' . $file . '"', 4); + throw new LogicException('Found invalid @var "' . $var . '" in docblock for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 4); } } @@ -326,109 +359,96 @@ class event_exporter /** * Find the "@since" Information line * - * @param string $file - * @param string $event_name - * @param array $lines - * @param int $event_line Index of the event call in $lines * @return int Absolute line number + * @throws LogicException */ - public function find_since($file, $event_name, $lines, $event_line) + public function find_since() { - return $this->find_tag($file, $event_name, $lines, $event_line, 'since', array('event', 'var')); + return $this->find_tag('since', array('event', 'var')); } /** * Find the "@event" Information line * - * @param string $file - * @param string $event_name - * @param array $lines - * @param int $event_line Index of the event call in $lines * @return int Absolute line number */ - public function find_event($file, $event_name, $lines, $event_line) + public function find_event() { - return $this->find_tag($file, $event_name, $lines, $event_line, 'event', array()); + return $this->find_tag('event', array()); } /** * Find a "@*" Information line * - * @param string $file - * @param string $event_name - * @param array $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 array $disallowed_tags List of tags that must not appear between * the tag and the actual event * @return int Absolute line number + * @throws LogicException */ - public function find_tag($file, $event_name, $lines, $event_line, $find_tag, $disallowed_tags) + public function find_tag($find_tag, $disallowed_tags) { $find_tag_line = 0; $found_comment_end = false; - while (strpos(ltrim($lines[$event_line - $find_tag_line], "\t"), '* @' . $find_tag . ' ') !== 0) + while (strpos(ltrim($this->file_lines[$this->current_event_line - $find_tag_line], "\t"), '* @' . $find_tag . ' ') !== 0) { - if ($found_comment_end && ltrim($lines[$event_line - $find_tag_line], "\t") === '/**') + if ($found_comment_end && ltrim($this->file_lines[$this->current_event_line - $find_tag_line], "\t") === '/**') { // Reached the start of this doc block - throw new LogicException('Can not find @' . $find_tag . ' information for event "' . $event_name . '" in file "' . $file . '"', 1); + throw new LogicException('Can not find @' . $find_tag . ' information for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 1); } foreach ($disallowed_tags as $disallowed_tag) { - if ($found_comment_end && strpos(ltrim($lines[$event_line - $find_tag_line], "\t"), '* @' . $disallowed_tag) === 0) + if ($found_comment_end && strpos(ltrim($this->file_lines[$this->current_event_line - $find_tag_line], "\t"), '* @' . $disallowed_tag) === 0) { // Found @var after the @since - throw new LogicException('Found @' . $disallowed_tag . ' information after @' . $find_tag . ' for event "' . $event_name . '" in file "' . $file . '"', 3); + throw new LogicException('Found @' . $disallowed_tag . ' information after @' . $find_tag . ' for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 3); } } - if (ltrim($lines[$event_line - $find_tag_line], "\t") === '*/') + if (ltrim($this->file_lines[$this->current_event_line - $find_tag_line], "\t") === '*/') { $found_comment_end = true; } $find_tag_line++; - if ($find_tag_line >= $event_line) + if ($find_tag_line >= $this->current_event_line) { // Reached the start of the file - throw new LogicException('Can not find @' . $find_tag . ' information for event "' . $event_name . '" in file "' . $file . '"', 2); + throw new LogicException('Can not find @' . $find_tag . ' information for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); } } - return $event_line - $find_tag_line; + return $this->current_event_line - $find_tag_line; } /** * Find a "@*" Information line * - * @param string $file - * @param string $event_name - * @param array $lines - * @param int $event_line Index of the event call in $lines * @return int Absolute line number + * @throws LogicException */ - public function find_description($file, $event_name, $lines, $event_line) + public function find_description() { $find_desc_line = 0; - while (ltrim($lines[$event_line - $find_desc_line], "\t") !== '/**') + while (ltrim($this->file_lines[$this->current_event_line - $find_desc_line], "\t") !== '/**') { $find_desc_line++; - if ($find_desc_line > $event_line) + if ($find_desc_line > $this->current_event_line) { // Reached the start of the file - throw new LogicException('Can not find a description for event "' . $event_name . '" in file "' . $file . '"', 1); + throw new LogicException('Can not find a description for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 1); } } - $find_desc_line = $event_line - $find_desc_line + 1; + $find_desc_line = $this->current_event_line - $find_desc_line + 1; - $desc = trim($lines[$find_desc_line]); + $desc = trim($this->file_lines[$find_desc_line]); if (strpos($desc, '* @') === 0 || $desc[0] !== '*' || substr($desc, 1) == '') { // First line of the doc block is a @-line, empty or only contains "*" - throw new LogicException('Can not find a description for event "' . $event_name . '" in file "' . $file . '"', 2); + throw new LogicException('Can not find a description for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); } return $find_desc_line; @@ -437,25 +457,24 @@ class event_exporter /** * Validate "@since" Information * - * @param string $file - * @param string $event_name * @param string $line * @return string + * @throws LogicException */ - public function validate_since($file, $event_name, $line) + public function validate_since($line) { $since = substr(ltrim($line, "\t"), strlen('* @since ')); if ($since !== trim($since)) { - throw new LogicException('Invalid @since information for event "' . $event_name . '" in file "' . $file . '"', 1); + throw new LogicException('Invalid @since information for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 1); } $since = ($since === '3.1-A1') ? '3.1.0-a1' : $since; if (!preg_match('#^\d+\.\d+\.\d+(?:-(?:a|b|rc|pl)\d+)?$#', $since)) { - throw new LogicException('Invalid @since information for event "' . $event_name . '" in file "' . $file . '"', 2); + throw new LogicException('Invalid @since information for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); } return $since; @@ -464,23 +483,23 @@ class event_exporter /** * Validate "@event" Information * - * @param string $file * @param string $event_name * @param string $line * @return string + * @throws LogicException */ - public function validate_event($file, $event_name, $line) + public function validate_event($event_name, $line) { $event = substr(ltrim($line, "\t"), strlen('* @event ')); if ($event !== trim($event)) { - throw new LogicException('Invalid @event information for event "' . $event_name . '" in file "' . $file . '"', 1); + throw new LogicException('Invalid @event information for event "' . $event_name . '" in file "' . $this->current_file . '"', 1); } if ($event !== $event_name) { - throw new LogicException('Event name does not match @event tag for event "' . $event_name . '" in file "' . $file . '"', 2); + throw new LogicException('Event name does not match @event tag for event "' . $event_name . '" in file "' . $this->current_file . '"', 2); } return $event; @@ -489,13 +508,12 @@ class event_exporter /** * Validates that two arrays contain the same strings * - * @param string $file - * @param string $event_name * @param array $vars_array Variables found in the array line * @param array $vars_docblock Variables found in the doc block * @return null + * @throws LogicException */ - public function validate_vars_docblock_array($file, $event_name, $vars_array, $vars_docblock) + public function validate_vars_docblock_array($vars_array, $vars_docblock) { $vars_array = array_unique($vars_array); $vars_docblock = array_unique($vars_docblock); @@ -503,7 +521,7 @@ class event_exporter if ($sizeof_vars_array !== sizeof($vars_docblock) || $sizeof_vars_array !== sizeof(array_intersect($vars_array, $vars_docblock))) { - 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 "' . $this->current_event . '" in file "' . $this->current_file . '"'); } } @@ -513,6 +531,7 @@ class event_exporter * Works recursive with any depth * * @param string $dir Directory to go through + * @param string $path Path from root to $dir * @return array List of files (including directories from within $dir */ function get_file_list($dir, $path = '') diff --git a/tests/event/exporter_test.php b/tests/event/exporter_test.php index 06a66abb04..df5a258bbb 100644 --- a/tests/event/exporter_test.php +++ b/tests/event/exporter_test.php @@ -71,7 +71,25 @@ class phpbb_event_exporter_test extends phpbb_test_case */ public function test_check_for_events($file, $expected) { - $this->assertEquals($expected, $this->exporter->check_for_events($file)); + $this->exporter->check_for_events($file); + $this->assertEquals($expected, $this->exporter->get_events()); + } + + static public function check_for_events_throws_data() + { + return array( + array('missing_var.test', null), + array('duplicate_event.test', 10), + ); + } + + /** + * @dataProvider check_for_events_throws_data + */ + public function test_check_for_events_throws($file, $exception_code) + { + $this->setExpectedException('LogicException', '', $exception_code); + $this->assertNull($this->exporter->check_for_events($file)); } static public function validate_since_data() @@ -89,7 +107,7 @@ class phpbb_event_exporter_test extends phpbb_test_case */ public function test_validate_since($since, $expected) { - $this->assertEquals($expected, $this->exporter->validate_since('', '', $since)); + $this->assertEquals($expected, $this->exporter->validate_since($since)); } static public function validate_since_throws_data() @@ -111,7 +129,7 @@ class phpbb_event_exporter_test extends phpbb_test_case public function test_validate_since_throws($since, $exception_code) { $this->setExpectedException('LogicException', '', $exception_code); - $this->exporter->validate_since('', '', $since); + $this->exporter->validate_since($since); } static public function validate_event_data() @@ -127,7 +145,7 @@ class phpbb_event_exporter_test extends phpbb_test_case */ public function test_validate_event($event_name, $event, $expected) { - $this->assertEquals($expected, $this->exporter->validate_event('', $event_name, $event)); + $this->assertEquals($expected, $this->exporter->validate_event($event_name, $event)); } static public function validate_event_throws_data() @@ -146,7 +164,7 @@ class phpbb_event_exporter_test extends phpbb_test_case public function test_validate_event_throws($event_name, $event, $exception_code) { $this->setExpectedException('LogicException', '', $exception_code); - $this->exporter->validate_event('', $event_name, $event); + $this->exporter->validate_event($event_name, $event); } static public function validate_vars_docblock_array_data() @@ -161,7 +179,7 @@ class phpbb_event_exporter_test extends phpbb_test_case */ public function test_validate_vars_docblock_array($vars_array, $vars_docblock) { - $this->assertNull($this->exporter->validate_vars_docblock_array('', '', $vars_array, $vars_docblock)); + $this->assertNull($this->exporter->validate_vars_docblock_array($vars_array, $vars_docblock)); } static public function validate_vars_docblock_array_throws_data() @@ -181,7 +199,7 @@ class phpbb_event_exporter_test extends phpbb_test_case */ public function test_validate_vars_docblock_array_throws($vars_array, $vars_docblock) { - $this->exporter->validate_vars_docblock_array('', '', $vars_array, $vars_docblock); + $this->exporter->validate_vars_docblock_array($vars_array, $vars_docblock); } static public function get_dispatch_name_data() @@ -199,7 +217,7 @@ class phpbb_event_exporter_test extends phpbb_test_case */ public function test_get_dispatch_name($event_line, $expected) { - $this->assertEquals($expected, $this->exporter->get_dispatch_name('', $event_line)); + $this->assertEquals($expected, $this->exporter->get_dispatch_name($event_line)); } static public function get_dispatch_name_throws_data() @@ -218,7 +236,7 @@ class phpbb_event_exporter_test extends phpbb_test_case */ public function test_get_dispatch_name_throws($event_line) { - $this->exporter->get_dispatch_name('', $event_line); + $this->exporter->get_dispatch_name($event_line); } static public function get_trigger_event_name_data() @@ -236,7 +254,7 @@ class phpbb_event_exporter_test extends phpbb_test_case */ public function test_get_trigger_event_name($event_line, $expected) { - $this->assertEquals($expected, $this->exporter->get_trigger_event_name('', $event_line)); + $this->assertEquals($expected, $this->exporter->get_trigger_event_name($event_line)); } static public function get_trigger_event_name_throws_data() @@ -259,7 +277,7 @@ class phpbb_event_exporter_test extends phpbb_test_case */ public function test_get_trigger_event_name_throws($event_line) { - $this->exporter->get_trigger_event_name('', $event_line); + $this->exporter->get_trigger_event_name($event_line); } static public function get_vars_from_array_data() @@ -293,7 +311,9 @@ class phpbb_event_exporter_test extends phpbb_test_case */ public function test_get_vars_from_array($lines, $event_line, $expected) { - $this->assertEquals($expected, $this->exporter->get_vars_from_array('', '', $lines, $event_line)); + $this->exporter->set_current_event('', $event_line); + $this->exporter->set_content($lines); + $this->assertEquals($expected, $this->exporter->get_vars_from_array()); } static public function get_vars_from_array_throws_data() @@ -349,7 +369,10 @@ class phpbb_event_exporter_test extends phpbb_test_case public function test_get_vars_from_array_throws($lines, $event_line, $exception_code) { $this->setExpectedException('LogicException', '', $exception_code); - $this->exporter->get_vars_from_array('', '', $lines, $event_line); + + $this->exporter->set_current_event('', $event_line); + $this->exporter->set_content($lines); + $this->exporter->get_vars_from_array(); } static public function get_vars_from_docblock_data() @@ -374,7 +397,9 @@ class phpbb_event_exporter_test extends phpbb_test_case */ public function test_get_vars_from_docblock($lines, $event_line, $expected) { - $this->assertEquals($expected, $this->exporter->get_vars_from_docblock('', '', $lines, $event_line)); + $this->exporter->set_current_event('', $event_line); + $this->exporter->set_content($lines); + $this->assertEquals($expected, $this->exporter->get_vars_from_docblock()); } static public function get_vars_from_docblock_throws_data() @@ -429,7 +454,10 @@ class phpbb_event_exporter_test extends phpbb_test_case public function test_get_vars_from_docblock_throws($lines, $event_line, $exception_code) { $this->setExpectedException('LogicException', '', $exception_code); - $this->exporter->get_vars_from_docblock('', '', $lines, $event_line); + + $this->exporter->set_current_event('', $event_line); + $this->exporter->set_content($lines); + $this->exporter->get_vars_from_docblock(); } static public function find_since_data() @@ -465,7 +493,9 @@ class phpbb_event_exporter_test extends phpbb_test_case */ public function test_find_since($lines, $event_line, $expected) { - $this->assertEquals($expected, $this->exporter->find_since('', '', $lines, $event_line)); + $this->exporter->set_current_event('', $event_line); + $this->exporter->set_content($lines); + $this->assertEquals($expected, $this->exporter->find_since()); } static public function find_since_throws_data() @@ -527,7 +557,10 @@ class phpbb_event_exporter_test extends phpbb_test_case public function test_find_since_throws($lines, $event_line, $exception_code) { $this->setExpectedException('LogicException', '', $exception_code); - $this->exporter->find_since('', '', $lines, $event_line); + + $this->exporter->set_current_event('', $event_line); + $this->exporter->set_content($lines); + $this->exporter->find_since(); } static public function find_description_data() @@ -565,7 +598,9 @@ class phpbb_event_exporter_test extends phpbb_test_case */ public function test_find_description($lines, $event_line, $expected) { - $this->assertEquals($expected, $this->exporter->find_description('', '', $lines, $event_line)); + $this->exporter->set_current_event('', $event_line); + $this->exporter->set_content($lines); + $this->assertEquals($expected, $this->exporter->find_description()); } static public function find_description_throws_data() @@ -623,6 +658,9 @@ class phpbb_event_exporter_test extends phpbb_test_case public function test_find_description_throws($lines, $event_line, $exception_code) { $this->setExpectedException('LogicException', '', $exception_code); - $this->exporter->find_description('', '', $lines, $event_line); + + $this->exporter->set_current_event('', $event_line); + $this->exporter->set_content($lines); + $this->exporter->find_description(); } } diff --git a/tests/event/fixtures/duplicate_event.test b/tests/event/fixtures/duplicate_event.test new file mode 100644 index 0000000000..f5fa580c2b --- /dev/null +++ b/tests/event/fixtures/duplicate_event.test @@ -0,0 +1,26 @@ +trigger_event('duplicate.trigger', compact($vars))); + + /** + * Event after the post data has been assigned to the template + * + * @event duplicate.trigger + * @since 3.1.0-b1 + */ + $phpbb_dispatcher->dispatch('duplicate.trigger'); diff --git a/tests/event/fixtures/missing_var.test b/tests/event/fixtures/missing_var.test index 9df6e5b386..7ced5e93dc 100644 --- a/tests/event/fixtures/missing_var.test +++ b/tests/event/fixtures/missing_var.test @@ -11,7 +11,6 @@ * @var array cp_row Custom profile field data of the poster * @var array attachments List of attachments * @var array user_poster_data Poster's data from user cache - * @var array post_row Template block array of the post * @since 3.1.0-a3 */ $vars = array('start', 'current_row_number', 'end', 'row', 'cp_row', 'attachments', 'user_poster_data', 'post_row'); From d213e09a40cb0ee9c94c35b3aecb1814d740184a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 18 Apr 2014 11:06:04 +0200 Subject: [PATCH 07/55] [ticket/12273] Crawl the phpBB directory for events PHPBB3-12273 --- phpBB/develop/event_exporter.php | 178 +++++++++++++---------- phpBB/develop/export_events_for_wiki.php | 3 +- tests/event/exporter_test.php | 27 ++-- 3 files changed, 122 insertions(+), 86 deletions(-) diff --git a/phpBB/develop/event_exporter.php b/phpBB/develop/event_exporter.php index a84b18db26..223f9318ba 100644 --- a/phpBB/develop/event_exporter.php +++ b/phpBB/develop/event_exporter.php @@ -34,6 +34,7 @@ class event_exporter { $this->root_path = $phpbb_root_path; $this->events = $this->file_lines = array(); + $this->events['php'] = array(); $this->current_file = $this->current_event = ''; $this->current_event_line = 0; } @@ -97,23 +98,6 @@ class event_exporter } } - function export_from_php() - { - $files = $this->get_file_list($this->root_path); - $this->events = array(); - foreach ($files as $file) - { - $this->check_for_events($file); - } - ksort($this->events); - - foreach ($this->events as $event) - { - echo '|- id="' . $event['event'] . '"' . "\n"; - echo '| [[#' . $event['event'] . '|' . $event['event'] . ']] || ' . $event['file'] . ' || ' . implode(', ', $event['arguments']) . ' || ' . $event['since'] . ' || ' . $event['description'] . "\n"; - } - } - public function get_events() { return $this->events; @@ -130,11 +114,108 @@ class event_exporter $this->file_lines = $content; } + /** + * Crawl the phpBB/ directory for php events + * @return int The number of events found + */ + public function crawl_phpbb_directory_php() + { + $files = $this->get_recursive_file_list($this->root_path); + $this->events['php'] = array(); + foreach ($files as $file) + { + $this->crawl_php_file($file); + } + ksort($this->events['php']); + + return sizeof($this->events['php']); + } + + /** + * Returns a list of files in $dir + * + * Works recursive with any depth + * + * @param string $dir Directory to go through + * @param string $path Path from root to $dir + * @return array List of files (including directories) + */ + public function get_recursive_file_list($dir, $path = '') + { + try + { + $iterator = new \DirectoryIterator($dir); + } + catch (Exception $e) + { + return array(); + } + + $files = array(); + foreach ($iterator as $file_info) + { + /** @var \DirectoryIterator $file_info */ + if ($file_info->isDot()) + { + continue; + } + + // Do not scan some directories + if ($file_info->isDir() && ( + ($path == '' && in_array($file_info->getFilename(), array( + 'cache', + 'develop', + 'ext', + 'files', + 'language', + 'store', + 'vendor', + ))) + || ($path == '/includes' && in_array($file_info->getFilename(), array('utf'))) + || ($path == '/phpbb/db/migration' && in_array($file_info->getFilename(), array('data'))) + || ($path == '/phpbb' && in_array($file_info->getFilename(), array('event'))) + )) + { + continue; + } + else if ($file_info->isDir()) + { + $sub_dir = $this->get_recursive_file_list($file_info->getPath() . '/' . $file_info->getFilename(), $path . '/' . $file_info->getFilename()); + foreach ($sub_dir as $file) + { + $files[] = $file_info->getFilename() . '/' . $file; + } + } + else if ($file_info->getExtension() == 'php') + { + $files[] = $file_info->getFilename(); + } + } + + return $files; + } + + /** + * Format the php events as a wiki table + * @return string + */ + public function export_php_events_for_wiki() + { + $wiki_page = ''; + foreach ($this->events['php'] as $event) + { + $wiki_page .= '|- id="' . $event['event'] . '"' . "\n"; + $wiki_page .= '| [[#' . $event['event'] . '|' . $event['event'] . ']] || ' . $event['file'] . ' || ' . implode(', ', $event['arguments']) . ' || ' . $event['since'] . ' || ' . $event['description'] . "\n"; + } + + return $wiki_page; + } + /** * @param $file * @throws LogicException */ - public function check_for_events($file) + public function crawl_php_file($file) { $this->current_file = $file; $this->file_lines = array(); @@ -182,13 +263,13 @@ class event_exporter $description_line_num = $this->find_description(); $description = substr(trim($this->file_lines[$description_line_num]), strlen('* ')); - if (isset($this->events[$this->current_event])) + if (isset($this->events['php'][$this->current_event])) { throw new LogicException('The event "' . $this->current_event . '" from file "' . $this->current_file - . '" already exists in file "'. $this->events[$this->current_event]['file'] . '"', 10); + . '" already exists in file "'. $this->events['php'][$this->current_event]['file'] . '"', 10); } - $this->events[$this->current_event] = array( + $this->events['php'][$this->current_event] = array( 'event' => $this->current_event, 'file' => $this->current_file, 'arguments' => $arguments, @@ -524,59 +605,4 @@ class event_exporter throw new LogicException('$vars array does not match the list of @var tags for event "' . $this->current_event . '" in file "' . $this->current_file . '"'); } } - - /** - * Returns a list of files in that directory - * - * Works recursive with any depth - * - * @param string $dir Directory to go through - * @param string $path Path from root to $dir - * @return array List of files (including directories from within $dir - */ - function get_file_list($dir, $path = '') - { - try - { - $iterator = new \DirectoryIterator($dir); - } - catch (Exception $e) - { - return array(); - } - - $files = array(); - foreach ($iterator as $file_info) - { - if ($file_info->isDot()) - { - continue; - } - - // Do not scan some directories - if ($file_info->isDir() && ( - ($path == '' && in_array($file_info->getFilename(), array('cache', 'develop', 'ext', 'files', 'language', 'store', 'vendor'))) - || ($path == '/includes' && in_array($file_info->getFilename(), array('utf'))) - || ($path == '/phpbb/db/migration' && in_array($file_info->getFilename(), array('data'))) - || ($path == '/phpbb' && in_array($file_info->getFilename(), array('event'))) - )) - { - continue; - } - else if ($file_info->isDir()) - { - $sub_dir = $this->get_file_list($file_info->getPath() . '/' . $file_info->getFilename(), $path . '/' . $file_info->getFilename()); - foreach ($sub_dir as $file) - { - $files[] = $file_info->getFilename() . '/' . $file; - } - } - else if (substr($file_info->getFilename(), -4) == '.php') - { - $files[] = $file_info->getFilename(); - } - } - - return $files; - } } diff --git a/phpBB/develop/export_events_for_wiki.php b/phpBB/develop/export_events_for_wiki.php index 0c4f14a4b4..0019fbaa44 100644 --- a/phpBB/develop/export_events_for_wiki.php +++ b/phpBB/develop/export_events_for_wiki.php @@ -54,7 +54,8 @@ switch ($action) break; case 'php': - $exporter->export_from_php(); + $exporter->crawl_phpbb_directory_php(); + echo $exporter->export_php_events_for_wiki(); break; default: diff --git a/tests/event/exporter_test.php b/tests/event/exporter_test.php index df5a258bbb..5736476f45 100644 --- a/tests/event/exporter_test.php +++ b/tests/event/exporter_test.php @@ -20,7 +20,7 @@ class phpbb_event_exporter_test extends phpbb_test_case $this->exporter = new \event_exporter(dirname(__FILE__) . '/fixtures/'); } - static public function check_for_events_data() + static public function crawl_php_file_data() { return array( array( @@ -67,15 +67,17 @@ class phpbb_event_exporter_test extends phpbb_test_case } /** - * @dataProvider check_for_events_data + * @dataProvider crawl_php_file_data */ - public function test_check_for_events($file, $expected) + public function test_crawl_php_file($file, $expected) { - $this->exporter->check_for_events($file); - $this->assertEquals($expected, $this->exporter->get_events()); + $this->exporter->crawl_php_file($file); + $events = $this->exporter->get_events(); + $this->assertArrayHasKey('php', $events); + $this->assertEquals($expected, $events['php']); } - static public function check_for_events_throws_data() + static public function crawl_php_file_throws_data() { return array( array('missing_var.test', null), @@ -84,12 +86,12 @@ class phpbb_event_exporter_test extends phpbb_test_case } /** - * @dataProvider check_for_events_throws_data + * @dataProvider crawl_php_file_throws_data */ - public function test_check_for_events_throws($file, $exception_code) + public function test_crawl_php_file_throws($file, $exception_code) { $this->setExpectedException('LogicException', '', $exception_code); - $this->assertNull($this->exporter->check_for_events($file)); + $this->exporter->crawl_php_file($file); } static public function validate_since_data() @@ -663,4 +665,11 @@ class phpbb_event_exporter_test extends phpbb_test_case $this->exporter->set_content($lines); $this->exporter->find_description(); } + + public function test_crawl_phpbb_directory_php() + { + global $phpbb_root_path; + $exporter = new \event_exporter($phpbb_root_path); + $this->assertGreaterThan(0, $exporter->crawl_phpbb_directory_php()); + } } From 3352d9fd344c14172bd690f20ee50a912032db7f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 18 Apr 2014 11:13:02 +0200 Subject: [PATCH 08/55] [ticket/12273] Move event exporter to namespace PHPBB3-12273 --- phpBB/develop/export_events_for_wiki.php | 4 +- .../event/exporter.php} | 70 ++++++++++--------- tests/event/exporter_test.php | 6 +- 3 files changed, 40 insertions(+), 40 deletions(-) rename phpBB/{develop/event_exporter.php => phpbb/event/exporter.php} (81%) diff --git a/phpBB/develop/export_events_for_wiki.php b/phpBB/develop/export_events_for_wiki.php index 0019fbaa44..ff64dc493e 100644 --- a/phpBB/develop/export_events_for_wiki.php +++ b/phpBB/develop/export_events_for_wiki.php @@ -13,7 +13,7 @@ if (php_sapi_name() != 'cli') $phpEx = substr(strrchr(__FILE__, '.'), 1); $phpbb_root_path = __DIR__ . '/../'; -require __DIR__ . '/event_exporter.' . $phpEx; +require __DIR__ . '/../phpbb/event/exporter.' . $phpEx; function usage() { @@ -41,7 +41,7 @@ function validate_argument_count($arguments, $count) validate_argument_count($argc, 1); $action = $argv[1]; -$exporter = new \event_exporter($phpbb_root_path); +$exporter = new \phpbb\event\exporter($phpbb_root_path); switch ($action) { diff --git a/phpBB/develop/event_exporter.php b/phpBB/phpbb/event/exporter.php similarity index 81% rename from phpBB/develop/event_exporter.php rename to phpBB/phpbb/event/exporter.php index 223f9318ba..e3dd85f5ac 100644 --- a/phpBB/develop/event_exporter.php +++ b/phpBB/phpbb/event/exporter.php @@ -7,7 +7,9 @@ * */ -class event_exporter +namespace phpbb\event; + +class exporter { /** @var string */ protected $root_path; @@ -146,7 +148,7 @@ class event_exporter { $iterator = new \DirectoryIterator($dir); } - catch (Exception $e) + catch (\Exception $e) { return array(); } @@ -213,7 +215,7 @@ class event_exporter /** * @param $file - * @throws LogicException + * @throws \LogicException */ public function crawl_php_file($file) { @@ -228,6 +230,7 @@ class event_exporter { $event_line = false; $found_trigger_event = strpos($this->file_lines[$i], "dispatcher->trigger_event('"); + $arguments = array(); if ($found_trigger_event !== false) { $event_line = $i; @@ -245,7 +248,6 @@ class event_exporter { $event_line = $i; $this->set_current_event($this->get_dispatch_name($this->file_lines[$event_line]), $event_line); - $arguments = array(); } } @@ -265,7 +267,7 @@ class event_exporter if (isset($this->events['php'][$this->current_event])) { - throw new LogicException('The event "' . $this->current_event . '" from file "' . $this->current_file + throw new \LogicException('The event "' . $this->current_event . '" from file "' . $this->current_file . '" already exists in file "'. $this->events['php'][$this->current_event]['file'] . '"', 10); } @@ -286,7 +288,7 @@ class event_exporter * * @param string $event_line * @return int Absolute line number - * @throws LogicException + * @throws \LogicException */ public function get_dispatch_name($event_line) { @@ -301,7 +303,7 @@ class event_exporter preg_match($regex, $event_line, $match); if (!isset($match[2])) { - throw new LogicException('Can not find event name in line "' . $event_line . '" in file "' . $this->current_file . '"', 1); + throw new \LogicException('Can not find event name in line "' . $event_line . '" in file "' . $this->current_file . '"', 1); } return $match[2]; @@ -312,7 +314,7 @@ class event_exporter * * @param string $event_line * @return int Absolute line number - * @throws LogicException + * @throws \LogicException */ public function get_trigger_event_name($event_line) { @@ -327,7 +329,7 @@ class event_exporter preg_match($regex, $event_line, $match); if (!isset($match[2])) { - throw new LogicException('Can not find event name in line "' . $event_line . '" in file "' . $this->current_file . '"', 1); + throw new \LogicException('Can not find event name in line "' . $event_line . '" in file "' . $this->current_file . '"', 1); } return $match[2]; @@ -347,20 +349,20 @@ class event_exporter * Find the $vars array * * @return array List of variables - * @throws LogicException + * @throws \LogicException */ public function get_vars_from_array() { $vars_line = ltrim($this->file_lines[$this->current_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 "' . $this->current_event . '" in file "' . $this->current_file . '"', 1); + throw new \LogicException('Can not find "$vars = array();"-line for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 1); } $vars_array = substr($vars_line, strlen("\$vars = array('"), 0 - strlen('\');')); if ($vars_array === '') { - throw new LogicException('Found empty $vars array for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); + throw new \LogicException('Found empty $vars array for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); } $vars_array = explode("', '", $vars_array); @@ -369,7 +371,7 @@ class event_exporter { if (!preg_match('#^([a-zA-Z_][a-zA-Z0-9_]*)$#', $var)) { - throw new LogicException('Found invalid var "' . $var . '" in array for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 3); + throw new \LogicException('Found invalid var "' . $var . '" in array for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 3); } } @@ -381,7 +383,7 @@ class event_exporter * Find the $vars array * * @return array List of variables - * @throws LogicException + * @throws \LogicException */ public function get_vars_from_docblock() { @@ -404,7 +406,7 @@ class event_exporter $doc_line = explode(' ', $var_line, 5); if (sizeof($doc_line) !== 5) { - throw new LogicException('Found invalid line "' . $this->file_lines[$this->current_event_line - $current_doc_line] + 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 . '"', 1); } $doc_vars[] = $doc_line[3]; @@ -415,21 +417,21 @@ class event_exporter if ($current_doc_line > $this->current_event_line) { // Reached the start of the file - throw new LogicException('Can not find end of docblock for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); + throw new \LogicException('Can not find end of docblock for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); } } if (empty($doc_vars)) { // Reached the start of the file - throw new LogicException('Can not find @var lines for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 3); + throw new \LogicException('Can not find @var lines for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 3); } foreach ($doc_vars as $var) { if (!preg_match('#^([a-zA-Z_][a-zA-Z0-9_]*)$#', $var)) { - throw new LogicException('Found invalid @var "' . $var . '" in docblock for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 4); + throw new \LogicException('Found invalid @var "' . $var . '" in docblock for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 4); } } @@ -441,7 +443,7 @@ class event_exporter * Find the "@since" Information line * * @return int Absolute line number - * @throws LogicException + * @throws \LogicException */ public function find_since() { @@ -465,7 +467,7 @@ class event_exporter * @param array $disallowed_tags List of tags that must not appear between * the tag and the actual event * @return int Absolute line number - * @throws LogicException + * @throws \LogicException */ public function find_tag($find_tag, $disallowed_tags) { @@ -476,7 +478,7 @@ class event_exporter if ($found_comment_end && ltrim($this->file_lines[$this->current_event_line - $find_tag_line], "\t") === '/**') { // Reached the start of this doc block - throw new LogicException('Can not find @' . $find_tag . ' information for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 1); + throw new \LogicException('Can not find @' . $find_tag . ' information for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 1); } foreach ($disallowed_tags as $disallowed_tag) @@ -484,7 +486,7 @@ class event_exporter if ($found_comment_end && strpos(ltrim($this->file_lines[$this->current_event_line - $find_tag_line], "\t"), '* @' . $disallowed_tag) === 0) { // Found @var after the @since - throw new LogicException('Found @' . $disallowed_tag . ' information after @' . $find_tag . ' for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 3); + throw new \LogicException('Found @' . $disallowed_tag . ' information after @' . $find_tag . ' for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 3); } } @@ -497,7 +499,7 @@ class event_exporter if ($find_tag_line >= $this->current_event_line) { // Reached the start of the file - throw new LogicException('Can not find @' . $find_tag . ' information for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); + throw new \LogicException('Can not find @' . $find_tag . ' information for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); } } @@ -508,7 +510,7 @@ class event_exporter * Find a "@*" Information line * * @return int Absolute line number - * @throws LogicException + * @throws \LogicException */ public function find_description() { @@ -519,7 +521,7 @@ class event_exporter if ($find_desc_line > $this->current_event_line) { // Reached the start of the file - throw new LogicException('Can not find a description for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 1); + throw new \LogicException('Can not find a description for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 1); } } @@ -529,7 +531,7 @@ class event_exporter if (strpos($desc, '* @') === 0 || $desc[0] !== '*' || substr($desc, 1) == '') { // First line of the doc block is a @-line, empty or only contains "*" - throw new LogicException('Can not find a description for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); + throw new \LogicException('Can not find a description for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); } return $find_desc_line; @@ -540,7 +542,7 @@ class event_exporter * * @param string $line * @return string - * @throws LogicException + * @throws \LogicException */ public function validate_since($line) { @@ -548,14 +550,14 @@ class event_exporter if ($since !== trim($since)) { - throw new LogicException('Invalid @since information for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 1); + throw new \LogicException('Invalid @since information for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 1); } $since = ($since === '3.1-A1') ? '3.1.0-a1' : $since; if (!preg_match('#^\d+\.\d+\.\d+(?:-(?:a|b|rc|pl)\d+)?$#', $since)) { - throw new LogicException('Invalid @since information for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); + throw new \LogicException('Invalid @since information for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); } return $since; @@ -567,7 +569,7 @@ class event_exporter * @param string $event_name * @param string $line * @return string - * @throws LogicException + * @throws \LogicException */ public function validate_event($event_name, $line) { @@ -575,12 +577,12 @@ class event_exporter if ($event !== trim($event)) { - throw new LogicException('Invalid @event information for event "' . $event_name . '" in file "' . $this->current_file . '"', 1); + throw new \LogicException('Invalid @event information for event "' . $event_name . '" in file "' . $this->current_file . '"', 1); } if ($event !== $event_name) { - throw new LogicException('Event name does not match @event tag for event "' . $event_name . '" in file "' . $this->current_file . '"', 2); + throw new \LogicException('Event name does not match @event tag for event "' . $event_name . '" in file "' . $this->current_file . '"', 2); } return $event; @@ -592,7 +594,7 @@ class event_exporter * @param array $vars_array Variables found in the array line * @param array $vars_docblock Variables found in the doc block * @return null - * @throws LogicException + * @throws \LogicException */ public function validate_vars_docblock_array($vars_array, $vars_docblock) { @@ -602,7 +604,7 @@ class event_exporter if ($sizeof_vars_array !== sizeof($vars_docblock) || $sizeof_vars_array !== sizeof(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 . '"'); + throw new \LogicException('$vars array does not match the list of @var tags for event "' . $this->current_event . '" in file "' . $this->current_file . '"'); } } } diff --git a/tests/event/exporter_test.php b/tests/event/exporter_test.php index 5736476f45..1608964b42 100644 --- a/tests/event/exporter_test.php +++ b/tests/event/exporter_test.php @@ -7,8 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/develop/event_exporter.php'; - class phpbb_event_exporter_test extends phpbb_test_case { /** @var \event_exporter */ @@ -17,7 +15,7 @@ class phpbb_event_exporter_test extends phpbb_test_case public function setUp() { parent::setUp(); - $this->exporter = new \event_exporter(dirname(__FILE__) . '/fixtures/'); + $this->exporter = new \phpbb\event\exporter(dirname(__FILE__) . '/fixtures/'); } static public function crawl_php_file_data() @@ -669,7 +667,7 @@ class phpbb_event_exporter_test extends phpbb_test_case public function test_crawl_phpbb_directory_php() { global $phpbb_root_path; - $exporter = new \event_exporter($phpbb_root_path); + $exporter = new \phpbb\event\exporter($phpbb_root_path); $this->assertGreaterThan(0, $exporter->crawl_phpbb_directory_php()); } } From 6da52acb3ce849b25adbf0ef9533a0acb7286ddf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 18 Apr 2014 12:50:23 +0200 Subject: [PATCH 09/55] [ticket/12273] Rename exporter to php_exporter PHPBB3-12273 --- .../event/{exporter.php => php_exporter.php} | 93 +++++-------------- ...xporter_test.php => php_exporter_test.php} | 12 +-- 2 files changed, 26 insertions(+), 79 deletions(-) rename phpBB/phpbb/event/{exporter.php => php_exporter.php} (86%) rename tests/event/{exporter_test.php => php_exporter_test.php} (97%) diff --git a/phpBB/phpbb/event/exporter.php b/phpBB/phpbb/event/php_exporter.php similarity index 86% rename from phpBB/phpbb/event/exporter.php rename to phpBB/phpbb/event/php_exporter.php index e3dd85f5ac..51fe878d41 100644 --- a/phpBB/phpbb/event/exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -9,7 +9,13 @@ namespace phpbb\event; -class exporter +/** +* Class php_exporter +* Crawls through a list of files and grabs all php-events +* +* @package phpbb\event +*/ +class php_exporter { /** @var string */ protected $root_path; @@ -36,70 +42,10 @@ class exporter { $this->root_path = $phpbb_root_path; $this->events = $this->file_lines = array(); - $this->events['php'] = array(); $this->current_file = $this->current_event = ''; $this->current_event_line = 0; } - function export_from_eventsmd($filter) - { - $file_content = file_get_contents($this->root_path . 'docs/events.md'); - - $events = explode("\n\n", $file_content); - foreach ($events as $event) - { - // Last row of the file - if (strpos($event, "\n===\n") === false) continue; - - list($event_name, $details) = explode("\n===\n", $event); - - if ($filter == 'acp' && strpos($event_name, 'acp_') !== 0) continue; - if ($filter == 'styles' && strpos($event_name, 'acp_') === 0) continue; - - list($file_details, $details) = explode("\n* Since: ", $details); - list($version, $explanition) = explode("\n* Purpose: ", $details); - - echo "|- id=\"{$event_name}\"\n"; - echo "| [[#{$event_name}|{$event_name}]] || "; - - if (strpos($file_details, "* Locations:\n + ") === 0) - { - $file_details = substr($file_details, strlen("* Locations:\n + ")); - $files = explode("\n + ", $file_details); - $prosilver = $subsilver2 = $adm = array(); - foreach ($files as $file) - { - if (strpos($file, 'styles/prosilver/template/') === 0) - { - $prosilver[] = substr($file, strlen('styles/prosilver/template/')); - } - if (strpos($file, 'styles/subsilver2/template/') === 0) - { - $subsilver2[] = substr($file, strlen('styles/subsilver2/template/')); - } - if (strpos($file, 'adm/style/') === 0) - { - $adm[] = substr($file, strlen('adm/style/')); - } - } - if ($filter == 'acp') - { - echo implode(', ', $adm); - } - else - { - echo implode(', ', $prosilver) . ' || ' . implode(', ', $subsilver2); - } - } - else if ($filter == 'acp') - { - echo substr($file_details, strlen("* Location: adm/style/")); - } - echo " || {$version} || " . str_replace("\n", ' ', $explanition) . "\n"; - - } - } - public function get_events() { return $this->events; @@ -123,14 +69,14 @@ class exporter public function crawl_phpbb_directory_php() { $files = $this->get_recursive_file_list($this->root_path); - $this->events['php'] = array(); + $this->events = array(); foreach ($files as $file) { $this->crawl_php_file($file); } - ksort($this->events['php']); + ksort($this->events); - return sizeof($this->events['php']); + return sizeof($this->events); } /** @@ -201,14 +147,17 @@ class exporter * Format the php events as a wiki table * @return string */ - public function export_php_events_for_wiki() + public function export_events_for_wiki() { - $wiki_page = ''; - foreach ($this->events['php'] as $event) + $wiki_page = '= PHP Events (Hook Locations) =' . "\n"; + $wiki_page .= '{| class="sortable zebra" cellspacing="0" cellpadding="5"' . "\n"; + $wiki_page .= '! Identifier !! Placement !! Arguments !! Added in Release !! Explanation' . "\n"; + foreach ($this->events as $event) { $wiki_page .= '|- id="' . $event['event'] . '"' . "\n"; $wiki_page .= '| [[#' . $event['event'] . '|' . $event['event'] . ']] || ' . $event['file'] . ' || ' . implode(', ', $event['arguments']) . ' || ' . $event['since'] . ' || ' . $event['description'] . "\n"; } + $wiki_page .= '|}' . "\n"; return $wiki_page; } @@ -265,13 +214,13 @@ class exporter $description_line_num = $this->find_description(); $description = substr(trim($this->file_lines[$description_line_num]), strlen('* ')); - if (isset($this->events['php'][$this->current_event])) + if (isset($this->events[$this->current_event])) { throw new \LogicException('The event "' . $this->current_event . '" from file "' . $this->current_file - . '" already exists in file "'. $this->events['php'][$this->current_event]['file'] . '"', 10); + . '" already exists in file "'. $this->events[$this->current_event]['file'] . '"', 10); } - $this->events['php'][$this->current_event] = array( + $this->events[$this->current_event] = array( 'event' => $this->current_event, 'file' => $this->current_file, 'arguments' => $arguments, @@ -336,9 +285,9 @@ class exporter } /** - * Find the name of the event inside the trigger_event() line + * Returns a regex match for the event name * - * @return string Returns a regex match for the event name + * @return string */ protected function preg_match_event_name() { diff --git a/tests/event/exporter_test.php b/tests/event/php_exporter_test.php similarity index 97% rename from tests/event/exporter_test.php rename to tests/event/php_exporter_test.php index 1608964b42..2a23d1a6c1 100644 --- a/tests/event/exporter_test.php +++ b/tests/event/php_exporter_test.php @@ -7,15 +7,15 @@ * */ -class phpbb_event_exporter_test extends phpbb_test_case +class phpbb_event_php_exporter_test extends phpbb_test_case { - /** @var \event_exporter */ + /** @var \phpbb\event\php_exporter */ protected $exporter; public function setUp() { parent::setUp(); - $this->exporter = new \phpbb\event\exporter(dirname(__FILE__) . '/fixtures/'); + $this->exporter = new \phpbb\event\php_exporter(dirname(__FILE__) . '/fixtures/'); } static public function crawl_php_file_data() @@ -70,9 +70,7 @@ class phpbb_event_exporter_test extends phpbb_test_case public function test_crawl_php_file($file, $expected) { $this->exporter->crawl_php_file($file); - $events = $this->exporter->get_events(); - $this->assertArrayHasKey('php', $events); - $this->assertEquals($expected, $events['php']); + $this->assertEquals($expected, $this->exporter->get_events()); } static public function crawl_php_file_throws_data() @@ -667,7 +665,7 @@ class phpbb_event_exporter_test extends phpbb_test_case public function test_crawl_phpbb_directory_php() { global $phpbb_root_path; - $exporter = new \phpbb\event\exporter($phpbb_root_path); + $exporter = new \phpbb\event\php_exporter($phpbb_root_path); $this->assertGreaterThan(0, $exporter->crawl_phpbb_directory_php()); } } From 17a1ed6fb59e36dcefa43d9755a69ab146e11576 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 18 Apr 2014 12:51:13 +0200 Subject: [PATCH 10/55] [ticket/12273] Move MD Exporter to separate file PHPBB3-12273 --- phpBB/phpbb/event/md_exporter.php | 223 ++++++++++++++++++++++++++++++ tests/event/md_exporter_test.php | 30 ++++ 2 files changed, 253 insertions(+) create mode 100644 phpBB/phpbb/event/md_exporter.php create mode 100644 tests/event/md_exporter_test.php diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php new file mode 100644 index 0000000000..6a8a9b1adb --- /dev/null +++ b/phpBB/phpbb/event/md_exporter.php @@ -0,0 +1,223 @@ +root_path = $phpbb_root_path; + $this->events = array(); + $this->filter = $this->current_event = ''; + } + + public function get_events() + { + return $this->events; + } + + /** + * @param string $md_file + * @param string $filter + * @return int Number of events found + * @throws \LogicException + */ + public function crawl_eventsmd($md_file, $filter) + { + $file_content = file_get_contents($this->root_path . $md_file); + $this->filter = $filter; + + $events = explode("\n\n", $file_content); + foreach ($events as $event) + { + // Last row of the file + if (strpos($event, "\n===\n") === false) continue; + + list($event_name, $details) = explode("\n===\n", $event, 2); + $this->validate_event_name($event_name); + $this->current_event = $event_name; + + if (isset($this->events[$this->current_event])) + { + throw new \LogicException('The event "' . $this->current_event . '" is defined multiple times'); + } + + if ($this->filter == 'adm' && strpos($this->current_event, 'acp_') !== 0) continue; + if ($this->filter == 'styles' && strpos($this->current_event, 'acp_') === 0) continue; + + list($file_details, $details) = explode("\n* Since: ", $details, 2); + list($since, $description) = explode("\n* Purpose: ", $details, 2); + + $files = $this->validate_file_list($file_details); + $since = $this->validate_since($since); + + $this->events[$event_name] = array( + 'event' => $this->current_event, + 'files' => $files, + 'since' => $since, + 'description' => $description, + ); + } + + return sizeof($this->events); + } + + /** + * Format the php events as a wiki table + * @return string Number of events found + */ + public function export_events_for_wiki() + { + if ($this->filter === 'acp') + { + $wiki_page = '= ACP Template Events =' . "\n"; + $wiki_page .= '{| class="zebra sortable" cellspacing="0" cellpadding="5"' . "\n"; + $wiki_page .= '! Identifier !! Placement !! Added in Release !! Explanation' . "\n"; + } + else + { + $wiki_page = '= Template Events =' . "\n"; + $wiki_page .= '{| class="zebra sortable" cellspacing="0" cellpadding="5"' . "\n"; + $wiki_page .= '! Identifier !! Prosilver Placement (If applicable) !! Subsilver Placement (If applicable) !! Added in Release !! Explanation' . "\n"; + } + + foreach ($this->events as $event_name => $event) + { + $wiki_page .= "|- id=\"{$event_name}\"\n"; + $wiki_page .= "| [[#{$event_name}|{$event_name}]] || "; + + if ($this->filter === 'adm') + { + $wiki_page .= implode(', ', $event['files']['adm']); + } + else + { + $wiki_page .= implode(', ', $event['files']['prosilver']) . ' || ' . implode(', ', $event['files']['subsilver2']); + } + + $wiki_page .= " || {$event['since']} || " . str_replace("\n", ' ', $event['description']) . "\n"; + } + $wiki_page .= '|}' . "\n"; + + return $wiki_page; + } + + /** + * Validates a template event name + * + * @param $event_name + * @return null + * @throws \LogicException + */ + public function validate_event_name($event_name) + { + if (!preg_match('#^([a-z][a-z0-9]*(?:_[a-z][a-z0-9]*)+)$#', $event_name)) + { + throw new \LogicException('Found invalid event name "' . $event_name . '"'); + } + } + + /** + * Validate "Since" Information + * + * @param string $since + * @return string + * @throws \LogicException + */ + public function validate_since($since) + { + $since = ($since === '3.1-A1') ? '3.1.0-a1' : $since; + + if (!preg_match('#^\d+\.\d+\.\d+(?:-(?:a|b|rc|pl)\d+)?$#', $since)) + { + throw new \LogicException('Invalid since information for event "' . $this->current_event . '"'); + } + + return $since; + } + + /** + * Validate the files list + * + * @param string $file_details + * @return array + * @throws \LogicException + */ + public function validate_file_list($file_details) + { + $files_list = array( + 'prosilver' => array(), + 'subsilver2' => array(), + 'adm' => array(), + ); + + // Multi file list + if (strpos($file_details, "* Locations:\n + ") === 0) + { + $file_details = substr($file_details, strlen("* Locations:\n + ")); + $files = explode("\n + ", $file_details); + foreach ($files as $file) + { + if (!file_exists($this->root_path . $file)) + { + throw new \LogicException('File "' . $file . '" not found for event "' . $this->current_event . '"', 2); + } + + if (($this->filter !== 'adm') && strpos($file, 'styles/prosilver/template/') === 0) + { + $files_list['prosilver'][] = substr($file, strlen('styles/prosilver/template/')); + } + else if (($this->filter !== 'adm') && strpos($file, 'styles/subsilver2/template/') === 0) + { + $files_list['subsilver2'][] = substr($file, strlen('styles/subsilver2/template/')); + } + else if (($this->filter === 'adm') && strpos($file, 'adm/style/') === 0) + { + $files_list['adm'][] = substr($file, strlen('adm/style/')); + } + else + { + throw new \LogicException('Invalid file "' . $file . '" found for event "' . $this->current_event . '"', 2); + } + } + } + else if ($this->filter == 'adm') + { + $files_list['adm'][] = substr($file_details, strlen("* Location: adm/style/")); + } + else + { + throw new \LogicException('Invalid file list found for event "' . $this->current_event . '"', 2); + } + + return $files_list; + } +} diff --git a/tests/event/md_exporter_test.php b/tests/event/md_exporter_test.php new file mode 100644 index 0000000000..52d10bd3e3 --- /dev/null +++ b/tests/event/md_exporter_test.php @@ -0,0 +1,30 @@ +assertGreaterThan(0, $exporter->crawl_eventsmd('docs/events.md', $filter)); + } +} From 3566325874a7d6da00ec7cd0e95543db34e1e811 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 18 Apr 2014 12:51:45 +0200 Subject: [PATCH 11/55] [ticket/12273] Fix export script PHPBB3-12273 --- phpBB/develop/export_events_for_wiki.php | 63 +++++++++++++++++------- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/phpBB/develop/export_events_for_wiki.php b/phpBB/develop/export_events_for_wiki.php index ff64dc493e..69b09ff136 100644 --- a/phpBB/develop/export_events_for_wiki.php +++ b/phpBB/develop/export_events_for_wiki.php @@ -13,20 +13,23 @@ if (php_sapi_name() != 'cli') $phpEx = substr(strrchr(__FILE__, '.'), 1); $phpbb_root_path = __DIR__ . '/../'; -require __DIR__ . '/../phpbb/event/exporter.' . $phpEx; function usage() { echo "Usage: export_events_for_wiki.php COMMAND\n"; echo "\n"; - echo "acp:\n"; - echo " Export all events for files in the acp style.\n"; - echo "\n"; - echo "styles:\n"; - echo " Export all events for files in the prosilver and subsilver2 styles.\n"; + echo "all:\n"; + echo " Generate the complete wikipage for https://wiki.phpbb.com/Event_List\n"; echo "\n"; echo "php:\n"; - echo " Export all events for php-files.\n"; + echo " Generate the PHP event section of Event_List\n"; + echo "\n"; + echo "acp:\n"; + echo " Generate the ACP Template event section of Event_List\n"; + echo "\n"; + echo "styles:\n"; + echo " Generate the Styles Template event section of Event_List\n"; + echo "\n"; exit(2); } @@ -41,22 +44,48 @@ function validate_argument_count($arguments, $count) validate_argument_count($argc, 1); $action = $argv[1]; -$exporter = new \phpbb\event\exporter($phpbb_root_path); +require __DIR__ . '/../phpbb/event/php_exporter.' . $phpEx; +require __DIR__ . '/../phpbb/event/md_exporter.' . $phpEx; switch ($action) { - case 'acp': - $exporter->export_from_eventsmd('acp'); - break; - - case 'styles': - $exporter->export_from_eventsmd('styles'); - break; + case 'all': + echo '__FORCETOC__' . "\n"; case 'php': + $exporter = new \phpbb\event\php_exporter($phpbb_root_path); $exporter->crawl_phpbb_directory_php(); - echo $exporter->export_php_events_for_wiki(); - break; + echo $exporter->export_events_for_wiki(); + + if ($action === 'php') + { + break; + } + echo "\n"; + // no break; + + case 'styles': + $exporter = new \phpbb\event\md_exporter($phpbb_root_path); + $exporter->crawl_eventsmd('docs/events.md', 'styles'); + echo $exporter->export_events_for_wiki(); + + if ($action === 'styles') + { + break; + } + echo "\n"; + // no break; + + case 'adm': + $exporter = new \phpbb\event\md_exporter($phpbb_root_path); + $exporter->crawl_eventsmd('docs/events.md', 'adm'); + echo $exporter->export_events_for_wiki(); + + if ($action === 'all') + { + echo "\n" . '[[Category:Events and Listeners]]' . "\n"; + } + break; default: usage(); From 9ba9a024d6a72eb81d77347eb866e73556b81051 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 18 Apr 2014 13:06:13 +0200 Subject: [PATCH 12/55] [ticket/12273] Make event exporter compatible with php 5.3.3 PHPBB3-12273 --- phpBB/phpbb/event/php_exporter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 51fe878d41..eb9e8f72b3 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -134,7 +134,7 @@ class php_exporter $files[] = $file_info->getFilename() . '/' . $file; } } - else if ($file_info->getExtension() == 'php') + else if (substr($file_info->getFilename(), -4) == '.php') { $files[] = $file_info->getFilename(); } From 7b5321092639b0f508fe160f5a58b834247982dd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Apr 2014 15:06:24 +0200 Subject: [PATCH 13/55] [ticket/12273] Fix invalid @event and @since tags PHPBB3-12273 --- phpBB/includes/functions_module.php | 2 +- phpBB/includes/functions_posting.php | 2 +- phpBB/includes/functions_privmsgs.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index be066de0f0..7531883ed9 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -409,7 +409,7 @@ class p_master * @var string module_auth The module_auth of the current * module * @var int forum_id The current forum_id - * @since 3.1-A3 + * @since 3.1.0-a3 */ $vars = array('valid_tokens', 'module_auth', 'forum_id'); extract($phpbb_dispatcher->trigger_event('core.module_auth', compact($vars))); diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 51bbcb8bae..638b94c220 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2345,7 +2345,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u * @var string url The "Return to topic" URL * @var array data Array of post data about the * submitted post - * @since 3.1-A3 + * @since 3.1.0-a3 */ $vars = array('url', 'data'); extract($phpbb_dispatcher->trigger_event('core.submit_post_end', compact($vars))); diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 9b44984dfa..7b075fc4a1 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -1588,7 +1588,7 @@ function submit_pm($mode, $subject, &$data, $put_in_outbox = true) /** * Get all parts of the PM that are to be submited to the DB. * - * @event core.submit_pm_before + * @event core.submit_pm_before * @var string mode PM Post mode - post|reply|quote|quotepost|forward|edit * @var string subject Subject of the private message * @var array data The whole row data of the PM. From 8f57880edb9fac353754976eeec0c1e0f1f2f502 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Apr 2014 16:33:12 +0200 Subject: [PATCH 14/55] [ticket/12273] Fix missing $vars line PHPBB3-12273 --- phpBB/includes/functions_posting.php | 3 ++- phpBB/mcp.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 638b94c220..df55c4540c 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1497,7 +1497,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u * @var bool update_search_index Flag indicating if the search index will be updated * @since 3.1.0-a4 */ - extract($phpbb_dispatcher->trigger_event('core.modify_submit_post_data', compact(array('mode', 'subject', 'username', 'topic_type', 'poll', 'data', 'update_message', 'update_search_index')))); + $vars = array('mode', 'subject', 'username', 'topic_type', 'poll', 'data', 'update_message', 'update_search_index'); + extract($phpbb_dispatcher->trigger_event('core.modify_submit_post_data', compact($vars))); // We do not handle erasing posts here if ($mode == 'delete') diff --git a/phpBB/mcp.php b/phpBB/mcp.php index 1449346deb..5676c399af 100644 --- a/phpBB/mcp.php +++ b/phpBB/mcp.php @@ -197,7 +197,8 @@ if ($quickmod) * @var bool is_valid_action Flag indicating if the action was handled properly * @since 3.1.0-a4 */ - extract($phpbb_dispatcher->trigger_event('core.modify_quickmod_options', compact(array('module', 'action', 'is_valid_action')))); + $vars = array('module', 'action', 'is_valid_action'); + extract($phpbb_dispatcher->trigger_event('core.modify_quickmod_options', compact($vars))); if (!$is_valid_action) { From be48d1258354b83f64b3ae70e6b26e638221be58 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 18 Apr 2014 12:52:02 +0200 Subject: [PATCH 15/55] [ticket/12273] Fix Markdown layout PHPBB3-12273 --- phpBB/docs/events.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/docs/events.md b/phpBB/docs/events.md index 6897c3f22e..514b39fee2 100644 --- a/phpBB/docs/events.md +++ b/phpBB/docs/events.md @@ -549,16 +549,16 @@ Display Options screen ucp_friend_list_before === * Locations: - + styles/prosilver/template/ucp_zebra_friends.html - + styles/subsilver2/template/ucp_zebra_friends.html + + styles/prosilver/template/ucp_zebra_friends.html + + styles/subsilver2/template/ucp_zebra_friends.html * Since: 3.1.0-a4 * Purpose: Add optional elements before list of friends in UCP ucp_friend_list_after === * Locations: - + styles/prosilver/template/ucp_zebra_friends.html - + styles/subsilver2/template/ucp_zebra_friends.html + + styles/prosilver/template/ucp_zebra_friends.html + + styles/subsilver2/template/ucp_zebra_friends.html * Since: 3.1.0-a4 * Purpose: Add optional elements after list of friends in UCP From 1a913d6e0f9f1e0f5df2acbfdc5a5f43a0c83be0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 18 Apr 2014 14:05:38 +0200 Subject: [PATCH 16/55] [ticket/12273] Do not use Inline control structures PHPBB3-12273 --- phpBB/phpbb/event/md_exporter.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index 6a8a9b1adb..44b990c5ed 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -59,7 +59,10 @@ class md_exporter foreach ($events as $event) { // Last row of the file - if (strpos($event, "\n===\n") === false) continue; + if (strpos($event, "\n===\n") === false) + { + continue; + } list($event_name, $details) = explode("\n===\n", $event, 2); $this->validate_event_name($event_name); @@ -70,8 +73,11 @@ class md_exporter throw new \LogicException('The event "' . $this->current_event . '" is defined multiple times'); } - if ($this->filter == 'adm' && strpos($this->current_event, 'acp_') !== 0) continue; - if ($this->filter == 'styles' && strpos($this->current_event, 'acp_') === 0) continue; + if (($this->filter == 'adm' && strpos($this->current_event, 'acp_') !== 0) + || ($this->filter == 'styles' && strpos($this->current_event, 'acp_') === 0)) + { + continue; + } list($file_details, $details) = explode("\n* Since: ", $details, 2); list($since, $description) = explode("\n* Purpose: ", $details, 2); From 8ddc9ff185527128d74b618107edde2f57637dde Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 20 Apr 2014 14:15:54 +0200 Subject: [PATCH 17/55] [ticket/12273] Allow multiple $vars lines PHPBB3-12273 --- phpBB/phpbb/event/php_exporter.php | 36 ++++++++++++----- tests/event/fixtures/duplicate_event.test | 9 +---- tests/event/fixtures/trigger.test | 5 +-- tests/event/fixtures/trigger_many_vars.test | 45 +++++++++++++++++++++ tests/event/php_exporter_test.php | 37 ++++++++++++++--- 5 files changed, 106 insertions(+), 26 deletions(-) create mode 100644 tests/event/fixtures/trigger_many_vars.test diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index eb9e8f72b3..9044168980 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -302,25 +302,43 @@ class php_exporter */ public function get_vars_from_array() { - $vars_line = ltrim($this->file_lines[$this->current_event_line - 1], "\t"); - if (strpos($vars_line, "\$vars = array('") !== 0 || substr($vars_line, -3) !== '\');') + $vars_array_line = 1; + $found_vars_array = false; + $vars_array = array(); + while (ltrim($this->file_lines[$this->current_event_line - $vars_array_line], "\t") !== '*/') { - throw new \LogicException('Can not find "$vars = array();"-line for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 1); + $line = ltrim($this->file_lines[$this->current_event_line - $vars_array_line], "\t"); + $match = array(); + preg_match('#^\$vars (?:\+)?= array\(\'([a-zA-Z0-9_\' ,]+)\'\);$#', $line, $match); + + if (isset($match[1])) + { + $found_vars_array = true; + if (strlen($match[1]) > 90) + { + throw new \LogicException('Should use multiple lines for $vars definition' + . ' for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 1); + } + $vars_array = array_merge($vars_array, explode("', '", $match[1])); + } + + $vars_array_line++; + if ($this->current_event_line - $vars_array_line === 0) + { + throw new \LogicException('Can not find "$vars = array();"-line for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); + } } - $vars_array = substr($vars_line, strlen("\$vars = array('"), 0 - strlen('\');')); - if ($vars_array === '') + if (!$found_vars_array) { - throw new \LogicException('Found empty $vars array for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); + throw new \LogicException('Can not find "$vars = array();"-line for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 3); } - $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 "' . $this->current_event . '" in file "' . $this->current_file . '"', 3); + throw new \LogicException('Found invalid var "' . $var . '" in array for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 4); } } diff --git a/tests/event/fixtures/duplicate_event.test b/tests/event/fixtures/duplicate_event.test index f5fa580c2b..b042ca0377 100644 --- a/tests/event/fixtures/duplicate_event.test +++ b/tests/event/fixtures/duplicate_event.test @@ -5,16 +5,9 @@ * * @event duplicate.trigger * @var int start Start item of this page - * @var int current_row_number Number of the post on this page - * @var int end Number of posts on this page - * @var array row Array with original post and user data - * @var array cp_row Custom profile field data of the poster - * @var array attachments List of attachments - * @var array user_poster_data Poster's data from user cache - * @var array post_row Template block array of the post * @since 3.1.0-a3 */ - $vars = array('start', 'current_row_number', 'end', 'row', 'cp_row', 'attachments', 'user_poster_data', 'post_row'); + $vars = array('start'); extract($phpbb_dispatcher->trigger_event('duplicate.trigger', compact($vars))); /** diff --git a/tests/event/fixtures/trigger.test b/tests/event/fixtures/trigger.test index 9df6e5b386..7cd6a7b956 100644 --- a/tests/event/fixtures/trigger.test +++ b/tests/event/fixtures/trigger.test @@ -9,10 +9,7 @@ * @var int end Number of posts on this page * @var array row Array with original post and user data * @var array cp_row Custom profile field data of the poster - * @var array attachments List of attachments - * @var array user_poster_data Poster's data from user cache - * @var array post_row Template block array of the post * @since 3.1.0-a3 */ - $vars = array('start', 'current_row_number', 'end', 'row', 'cp_row', 'attachments', 'user_poster_data', 'post_row'); + $vars = array('start', 'current_row_number', 'end', 'row', 'cp_row'); extract($phpbb_dispatcher->trigger_event('core.trigger', compact($vars))); diff --git a/tests/event/fixtures/trigger_many_vars.test b/tests/event/fixtures/trigger_many_vars.test new file mode 100644 index 0000000000..79f121cd7b --- /dev/null +++ b/tests/event/fixtures/trigger_many_vars.test @@ -0,0 +1,45 @@ +assign_vars() + * @var object message_parser The message parser object + * @since 3.1-A1 + * @change 3.1.0-b3 Added vars post_data, moderators, mode, page_title, + * s_topic_icons, form_enctype, s_action, s_hidden_fields, + * post_id, topic_id, forum_id, submit, preview, save, load, + * delete, cancel, refresh, error, page_data, message_parser + */ + $vars = array('post_data', 'moderators', 'mode', 'page_title', 's_topic_icons', 'form_enctype'); + $vars += array('s_action', 's_hidden_fields', 'post_id', 'topic_id', 'forum_id', 'submit', 'preview'); + $vars += array('save', 'load', 'delete', 'cancel', 'refresh', 'error', 'page_data', 'message_parser'); + extract($phpbb_dispatcher->trigger_event('core.posting_modify_template_vars', compact($vars))); diff --git a/tests/event/php_exporter_test.php b/tests/event/php_exporter_test.php index 2a23d1a6c1..fca7698c71 100644 --- a/tests/event/php_exporter_test.php +++ b/tests/event/php_exporter_test.php @@ -51,12 +51,30 @@ class phpbb_event_php_exporter_test extends phpbb_test_case 'core.trigger' => array( 'event' => 'core.trigger', 'file' => 'trigger.test', - 'arguments' => array('attachments', 'cp_row', 'current_row_number', 'end', 'post_row', 'row', 'start', 'user_poster_data'), + 'arguments' => array('cp_row', 'current_row_number', 'end', 'row', 'start'), 'since' => '3.1.0-a3', 'description' => 'Event after the post data has been assigned to the template', ), ), ), + array( + 'trigger_many_vars.test', + array( + 'core.posting_modify_template_vars' => array( + 'event' => 'core.posting_modify_template_vars', + 'file' => 'trigger_many_vars.test', + 'arguments' => array( + 'cancel', 'delete', 'error', 'form_enctype', 'forum_id', + 'load', 'message_parser', 'mode', 'moderators', 'page_data', + 'page_title', 'post_data', 'post_id', 'preview', 'refresh', + 's_action', 's_hidden_fields', 's_topic_icons', 'save', + 'submit', 'topic_id', + ), + 'since' => '3.1.0-a1', + 'description' => 'This event allows you to modify template variables for the posting screen', + ), + ), + ), array( 'none.test', array(), @@ -317,6 +335,15 @@ class phpbb_event_php_exporter_test extends phpbb_test_case static public function get_vars_from_array_throws_data() { return array( + array( + array( + '/**', + '*/', + '$phpbb_dispatcher->dispatch(\'test\');', + ), + 2, + 3, + ), array( array( '/**', @@ -325,7 +352,7 @@ class phpbb_event_php_exporter_test extends phpbb_test_case '$phpbb_dispatcher->dispatch(\'test\');', ), 3, - 1, + 3, ), array( array( @@ -335,17 +362,17 @@ class phpbb_event_php_exporter_test extends phpbb_test_case '$phpbb_dispatcher->dispatch(\'test\');', ), 3, - 1, + 3, ), array( array( '/**', '*/', - '$vars = array(\'\');', + '$vars = array(\'test2\', \'\');', '$phpbb_dispatcher->dispatch(\'test\');', ), 3, - 2, + 4, ), array( array( From b83a555da5df5b6916e4ae15aee10815bdac65d5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 20 Apr 2014 14:28:09 +0200 Subject: [PATCH 18/55] [ticket/12273] Move phpBB test to new file and use a data provider PHPBB3-12273 --- phpBB/phpbb/event/php_exporter.php | 7 ++++- tests/event/export_php_test.php | 45 ++++++++++++++++++++++++++++++ tests/event/php_exporter_test.php | 7 ----- 3 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 tests/event/export_php_test.php diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 9044168980..1e680ec896 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -163,7 +163,8 @@ class php_exporter } /** - * @param $file + * @param string $file + * @return int Number of events found in this file * @throws \LogicException */ public function crawl_php_file($file) @@ -171,6 +172,7 @@ class php_exporter $this->current_file = $file; $this->file_lines = array(); $content = file_get_contents($this->root_path . $this->current_file); + $num_events_found = 0; if (strpos($content, "dispatcher->trigger_event('") || strpos($content, "dispatcher->dispatch('")) { @@ -227,9 +229,12 @@ class php_exporter 'since' => $since, 'description' => $description, ); + $num_events_found++; } } } + + return $num_events_found; } /** diff --git a/tests/event/export_php_test.php b/tests/event/export_php_test.php new file mode 100644 index 0000000000..f38b524ffe --- /dev/null +++ b/tests/event/export_php_test.php @@ -0,0 +1,45 @@ +exporter = new \phpbb\event\php_exporter($phpbb_root_path); + } + + static public function crawl_php_file_data() + { + global $phpbb_root_path; + $exporter = new \phpbb\event\php_exporter($phpbb_root_path); + $files = $exporter->get_recursive_file_list($phpbb_root_path); + + $data_provider = array(); + foreach ($files as $file) + { + $data_provider[] = array($file); + } + + return $data_provider; + } + + /** + * @dataProvider crawl_php_file_data + */ + public function test_crawl_php_file($file) + { + $this->assertGreaterThanOrEqual(0, $this->exporter->crawl_php_file($file)); + } +} diff --git a/tests/event/php_exporter_test.php b/tests/event/php_exporter_test.php index fca7698c71..a289f5f6e4 100644 --- a/tests/event/php_exporter_test.php +++ b/tests/event/php_exporter_test.php @@ -688,11 +688,4 @@ class phpbb_event_php_exporter_test extends phpbb_test_case $this->exporter->set_content($lines); $this->exporter->find_description(); } - - public function test_crawl_phpbb_directory_php() - { - global $phpbb_root_path; - $exporter = new \phpbb\event\php_exporter($phpbb_root_path); - $this->assertGreaterThan(0, $exporter->crawl_phpbb_directory_php()); - } } From 6849e8b36f5d097a413c87a1321a09b9209a9d71 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 20 Apr 2014 14:57:18 +0200 Subject: [PATCH 19/55] [ticket/12273] Add file line to exception message PHPBB3-12273 --- phpBB/phpbb/event/php_exporter.php | 73 ++++++++++++++++++------------ 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 1e680ec896..88301f86f6 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -185,7 +185,7 @@ class php_exporter if ($found_trigger_event !== false) { $event_line = $i; - $this->set_current_event($this->get_trigger_event_name($this->file_lines[$event_line]), $event_line); + $this->set_current_event($this->get_trigger_event_name($event_line), $event_line); // Find variables of the event $arguments = $this->get_vars_from_array(); @@ -198,7 +198,7 @@ class php_exporter if ($found_dispatch !== false) { $event_line = $i; - $this->set_current_event($this->get_dispatch_name($this->file_lines[$event_line]), $event_line); + $this->set_current_event($this->get_dispatch_name($event_line), $event_line); } } @@ -240,13 +240,14 @@ class php_exporter /** * Find the name of the event inside the dispatch() line * - * @param string $event_line + * @param int $event_line * @return int Absolute line number * @throws \LogicException */ public function get_dispatch_name($event_line) { - $event_line = ltrim($event_line, "\t"); + $event_text_line = $this->file_lines[$event_line]; + $event_text_line = ltrim($event_text_line, "\t"); $regex = '#\$([a-z](?:[a-z0-9_]|->)*)'; $regex .= '->dispatch\('; @@ -254,10 +255,11 @@ class php_exporter $regex .= '\);#'; $match = array(); - preg_match($regex, $event_line, $match); + preg_match($regex, $event_text_line, $match); if (!isset($match[2])) { - throw new \LogicException('Can not find event name in line "' . $event_line . '" in file "' . $this->current_file . '"', 1); + throw new \LogicException("Can not find event name in line '{$event_text_line}' " + . "in file '{$this->current_file}:{$event_line}'", 1); } return $match[2]; @@ -266,13 +268,14 @@ class php_exporter /** * Find the name of the event inside the trigger_event() line * - * @param string $event_line + * @param int $event_line * @return int Absolute line number * @throws \LogicException */ public function get_trigger_event_name($event_line) { - $event_line = ltrim($event_line, "\t"); + $event_text_line = $this->file_lines[$event_line]; + $event_text_line = ltrim($event_text_line, "\t"); $regex = '#extract\(\$([a-z](?:[a-z0-9_]|->)*)'; $regex .= '->trigger_event\('; @@ -280,10 +283,11 @@ class php_exporter $regex .= ', compact\(\$vars\)\)\);#'; $match = array(); - preg_match($regex, $event_line, $match); + preg_match($regex, $event_text_line, $match); if (!isset($match[2])) { - throw new \LogicException('Can not find event name in line "' . $event_line . '" in file "' . $this->current_file . '"', 1); + throw new \LogicException("Can not find event name in line '{$event_text_line}' " + . "in file '{$this->current_file}:{$event_line}'", 1); } return $match[2]; @@ -322,7 +326,7 @@ class php_exporter if (strlen($match[1]) > 90) { throw new \LogicException('Should use multiple lines for $vars definition' - . ' for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 1); + . "for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 3); } $vars_array = array_merge($vars_array, explode("', '", $match[1])); } @@ -330,20 +334,20 @@ class php_exporter $vars_array_line++; if ($this->current_event_line - $vars_array_line === 0) { - throw new \LogicException('Can not find "$vars = array();"-line for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); + throw new \LogicException("Can not find '\$vars = array();'-line for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 2); } } if (!$found_vars_array) { - throw new \LogicException('Can not find "$vars = array();"-line for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 3); + throw new \LogicException("Can not find '\$vars = array();'-line for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 3); } 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 "' . $this->current_event . '" in file "' . $this->current_file . '"', 4); + throw new \LogicException("Found invalid var '{$var}' in array for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 4); } } @@ -378,8 +382,8 @@ class php_exporter $doc_line = explode(' ', $var_line, 5); if (sizeof($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 . '"', 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); } $doc_vars[] = $doc_line[3]; } @@ -389,21 +393,22 @@ class php_exporter if ($current_doc_line > $this->current_event_line) { // Reached the start of the file - throw new \LogicException('Can not find end of docblock for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); + throw new \LogicException("Can not find end of docblock for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 2); } } if (empty($doc_vars)) { // Reached the start of the file - throw new \LogicException('Can not find @var lines for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 3); + throw new \LogicException("Can not find @var lines for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 3); } foreach ($doc_vars as $var) { if (!preg_match('#^([a-zA-Z_][a-zA-Z0-9_]*)$#', $var)) { - throw new \LogicException('Found invalid @var "' . $var . '" in docblock for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 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); } } @@ -450,7 +455,8 @@ class php_exporter if ($found_comment_end && ltrim($this->file_lines[$this->current_event_line - $find_tag_line], "\t") === '/**') { // Reached the start of this doc block - throw new \LogicException('Can not find @' . $find_tag . ' information for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 1); + throw new \LogicException("Can not find '@{$find_tag}' information for event " + . "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 1); } foreach ($disallowed_tags as $disallowed_tag) @@ -458,7 +464,8 @@ class php_exporter if ($found_comment_end && strpos(ltrim($this->file_lines[$this->current_event_line - $find_tag_line], "\t"), '* @' . $disallowed_tag) === 0) { // Found @var after the @since - throw new \LogicException('Found @' . $disallowed_tag . ' information after @' . $find_tag . ' for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 3); + throw new \LogicException("Found '@{$disallowed_tag}' information after '@{$find_tag}' for event " + . "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 3); } } @@ -471,7 +478,8 @@ class php_exporter if ($find_tag_line >= $this->current_event_line) { // Reached the start of the file - throw new \LogicException('Can not find @' . $find_tag . ' information for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); + throw new \LogicException("Can not find '@{$find_tag}' information for event " + . "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 2); } } @@ -493,7 +501,8 @@ class php_exporter if ($find_desc_line > $this->current_event_line) { // Reached the start of the file - throw new \LogicException('Can not find a description for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 1); + throw new \LogicException("Can not find a description for event " + . "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 1); } } @@ -503,7 +512,8 @@ class php_exporter if (strpos($desc, '* @') === 0 || $desc[0] !== '*' || substr($desc, 1) == '') { // First line of the doc block is a @-line, empty or only contains "*" - throw new \LogicException('Can not find a description for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); + throw new \LogicException("Can not find a description for event " + . "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 2); } return $find_desc_line; @@ -522,14 +532,16 @@ class php_exporter if ($since !== trim($since)) { - throw new \LogicException('Invalid @since information for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 1); + throw new \LogicException("Invalid '@since' information for event " + . "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 1); } $since = ($since === '3.1-A1') ? '3.1.0-a1' : $since; if (!preg_match('#^\d+\.\d+\.\d+(?:-(?:a|b|rc|pl)\d+)?$#', $since)) { - throw new \LogicException('Invalid @since information for event "' . $this->current_event . '" in file "' . $this->current_file . '"', 2); + throw new \LogicException("Invalid '@since' information for event " + . "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 2); } return $since; @@ -549,12 +561,14 @@ class php_exporter if ($event !== trim($event)) { - throw new \LogicException('Invalid @event information for event "' . $event_name . '" in file "' . $this->current_file . '"', 1); + throw new \LogicException("Invalid '@event' information for event " + . "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 1); } if ($event !== $event_name) { - throw new \LogicException('Event name does not match @event tag for event "' . $event_name . '" in file "' . $this->current_file . '"', 2); + throw new \LogicException("Event name does not match '@event' tag for event" + . "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 2); } return $event; @@ -576,7 +590,8 @@ class php_exporter if ($sizeof_vars_array !== sizeof($vars_docblock) || $sizeof_vars_array !== sizeof(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 . '"'); + 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}'"); } } } From 08cce5fba548374c8c067ee8bed8aa6d388367e5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 20 Apr 2014 14:58:24 +0200 Subject: [PATCH 20/55] [ticket/12273] Remove duplicated code PHPBB3-12273 --- phpBB/phpbb/event/php_exporter.php | 49 ++++++++++-------------------- tests/event/php_exporter_test.php | 12 +++++--- 2 files changed, 24 insertions(+), 37 deletions(-) diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 88301f86f6..c076d7567d 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -185,7 +185,7 @@ class php_exporter if ($found_trigger_event !== false) { $event_line = $i; - $this->set_current_event($this->get_trigger_event_name($event_line), $event_line); + $this->set_current_event($this->get_event_name($event_line, false), $event_line); // Find variables of the event $arguments = $this->get_vars_from_array(); @@ -198,7 +198,7 @@ class php_exporter if ($found_dispatch !== false) { $event_line = $i; - $this->set_current_event($this->get_dispatch_name($event_line), $event_line); + $this->set_current_event($this->get_event_name($event_line, true), $event_line); } } @@ -241,46 +241,29 @@ class php_exporter * Find the name of the event inside the dispatch() line * * @param int $event_line + * @param bool $is_dispatch Do we look for dispatch() or trigger_event() ? * @return int Absolute line number * @throws \LogicException */ - public function get_dispatch_name($event_line) + public function get_event_name($event_line, $is_dispatch) { $event_text_line = $this->file_lines[$event_line]; $event_text_line = ltrim($event_text_line, "\t"); - $regex = '#\$([a-z](?:[a-z0-9_]|->)*)'; - $regex .= '->dispatch\('; - $regex .= '\'' . $this->preg_match_event_name() . '\''; - $regex .= '\);#'; - - $match = array(); - preg_match($regex, $event_text_line, $match); - if (!isset($match[2])) + if ($is_dispatch) { - throw new \LogicException("Can not find event name in line '{$event_text_line}' " - . "in file '{$this->current_file}:{$event_line}'", 1); + $regex = '#\$([a-z](?:[a-z0-9_]|->)*)'; + $regex .= '->dispatch\('; + $regex .= '\'' . $this->preg_match_event_name() . '\''; + $regex .= '\);#'; + } + else + { + $regex = '#extract\(\$([a-z](?:[a-z0-9_]|->)*)'; + $regex .= '->trigger_event\('; + $regex .= '\'' . $this->preg_match_event_name() . '\''; + $regex .= ', compact\(\$vars\)\)\);#'; } - - return $match[2]; - } - - /** - * Find the name of the event inside the trigger_event() line - * - * @param int $event_line - * @return int Absolute line number - * @throws \LogicException - */ - public function get_trigger_event_name($event_line) - { - $event_text_line = $this->file_lines[$event_line]; - $event_text_line = ltrim($event_text_line, "\t"); - - $regex = '#extract\(\$([a-z](?:[a-z0-9_]|->)*)'; - $regex .= '->trigger_event\('; - $regex .= '\'' . $this->preg_match_event_name() . '\''; - $regex .= ', compact\(\$vars\)\)\);#'; $match = array(); preg_match($regex, $event_text_line, $match); diff --git a/tests/event/php_exporter_test.php b/tests/event/php_exporter_test.php index a289f5f6e4..5df7713bdf 100644 --- a/tests/event/php_exporter_test.php +++ b/tests/event/php_exporter_test.php @@ -233,7 +233,8 @@ class phpbb_event_php_exporter_test extends phpbb_test_case */ public function test_get_dispatch_name($event_line, $expected) { - $this->assertEquals($expected, $this->exporter->get_dispatch_name($event_line)); + $this->exporter->set_content(array($event_line)); + $this->assertEquals($expected, $this->exporter->get_event_name(0, true)); } static public function get_dispatch_name_throws_data() @@ -252,7 +253,8 @@ class phpbb_event_php_exporter_test extends phpbb_test_case */ public function test_get_dispatch_name_throws($event_line) { - $this->exporter->get_dispatch_name($event_line); + $this->exporter->set_content(array($event_line)); + $this->exporter->get_event_name(0, true); } static public function get_trigger_event_name_data() @@ -270,7 +272,8 @@ class phpbb_event_php_exporter_test extends phpbb_test_case */ public function test_get_trigger_event_name($event_line, $expected) { - $this->assertEquals($expected, $this->exporter->get_trigger_event_name($event_line)); + $this->exporter->set_content(array($event_line)); + $this->assertEquals($expected, $this->exporter->get_event_name(0, false)); } static public function get_trigger_event_name_throws_data() @@ -293,7 +296,8 @@ class phpbb_event_php_exporter_test extends phpbb_test_case */ public function test_get_trigger_event_name_throws($event_line) { - $this->exporter->get_trigger_event_name($event_line); + $this->exporter->set_content(array($event_line)); + $this->exporter->get_event_name(0, false); } static public function get_vars_from_array_data() From bc1ab3dc79b63091c82a29f5c5175558423ac8cd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 20 Apr 2014 15:11:23 +0200 Subject: [PATCH 21/55] [ticket/12273] Fix missing space in some Exceptions PHPBB3-12273 --- phpBB/phpbb/event/php_exporter.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index c076d7567d..3956be600b 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -218,8 +218,9 @@ class php_exporter if (isset($this->events[$this->current_event])) { - throw new \LogicException('The event "' . $this->current_event . '" from file "' . $this->current_file - . '" already exists in file "'. $this->events[$this->current_event]['file'] . '"', 10); + throw new \LogicException("The event '{$this->current_event}' from file " + . "'{$this->current_file}:{$event_line_num}' already exists in file " + . "'{$this->events[$this->current_event]['file']}'", 10); } $this->events[$this->current_event] = array( @@ -308,7 +309,7 @@ class php_exporter $found_vars_array = true; if (strlen($match[1]) > 90) { - throw new \LogicException('Should use multiple lines for $vars definition' + 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[1])); @@ -365,7 +366,7 @@ class php_exporter $doc_line = explode(' ', $var_line, 5); if (sizeof($doc_line) !== 5) { - throw new \LogicException("Found invalid line '{$this->file_lines[$this->current_event_line - $current_doc_line]}'" + 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); } $doc_vars[] = $doc_line[3]; @@ -550,7 +551,7 @@ class php_exporter if ($event !== $event_name) { - throw new \LogicException("Event name does not match '@event' tag for event" + throw new \LogicException("Event name does not match '@event' tag for event " . "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 2); } @@ -573,7 +574,7 @@ class php_exporter if ($sizeof_vars_array !== sizeof($vars_docblock) || $sizeof_vars_array !== sizeof(array_intersect($vars_array, $vars_docblock))) { - throw new \LogicException("\$vars array does not match the list of '@var' tags for event" + 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}'"); } } From c7dcc6d7007d1500fc5007b2b33916e9f20f137b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 20 Apr 2014 15:48:04 +0200 Subject: [PATCH 22/55] [ticket/12273] Verify that the events are still in the named files PHPBB3-12273 --- phpBB/phpbb/event/md_exporter.php | 53 +++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index 44b990c5ed..8714bdb2f7 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -36,6 +36,7 @@ class md_exporter { $this->root_path = $phpbb_root_path; $this->events = array(); + $this->events_by_file = array(); $this->filter = $this->current_event = ''; } @@ -70,7 +71,7 @@ class md_exporter if (isset($this->events[$this->current_event])) { - throw new \LogicException('The event "' . $this->current_event . '" is defined multiple times'); + throw new \LogicException("The event '{$this->current_event}' is defined multiple times"); } if (($this->filter == 'adm' && strpos($this->current_event, 'acp_') !== 0) @@ -93,6 +94,11 @@ class md_exporter ); } + foreach ($this->events_by_file as $file => $events) + { + $this->validate_events_for_file($file, $events); + } + return sizeof($this->events); } @@ -147,7 +153,7 @@ class md_exporter { if (!preg_match('#^([a-z][a-z0-9]*(?:_[a-z][a-z0-9]*)+)$#', $event_name)) { - throw new \LogicException('Found invalid event name "' . $event_name . '"'); + throw new \LogicException("Invalid event name '{$event_name}'"); } } @@ -164,7 +170,7 @@ class md_exporter if (!preg_match('#^\d+\.\d+\.\d+(?:-(?:a|b|rc|pl)\d+)?$#', $since)) { - throw new \LogicException('Invalid since information for event "' . $this->current_event . '"'); + throw new \LogicException("Invalid since information found for event '{$this->current_event}'"); } return $since; @@ -192,10 +198,6 @@ class md_exporter $files = explode("\n + ", $file_details); foreach ($files as $file) { - if (!file_exists($this->root_path . $file)) - { - throw new \LogicException('File "' . $file . '" not found for event "' . $this->current_event . '"', 2); - } if (($this->filter !== 'adm') && strpos($file, 'styles/prosilver/template/') === 0) { @@ -211,19 +213,50 @@ class md_exporter } else { - throw new \LogicException('Invalid file "' . $file . '" found for event "' . $this->current_event . '"', 2); + throw new \LogicException("Invalid file '{$file}' not found for event '{$this->current_event}'", 2); } + + $this->events_by_file[$file][] = $this->current_event; } } else if ($this->filter == 'adm') { - $files_list['adm'][] = substr($file_details, strlen("* Location: adm/style/")); + $file = substr($file_details, strlen('* Location: ')); + $files_list['adm'][] = substr($file, strlen('adm/style/')); + + $this->events_by_file[$file][] = $this->current_event; } else { - throw new \LogicException('Invalid file list found for event "' . $this->current_event . '"', 2); + throw new \LogicException("Invalid file list found for event '{$this->current_event}'", 2); } return $files_list; } + + /** + * Validates whether a list of events is named in $file + * + * @param string $file + * @param array $events + * @return null + * @throws \LogicException + */ + public function validate_events_for_file($file, array $events) + { + if (!file_exists($this->root_path . $file)) + { + $event_list = implode("', '", $events); + throw new \LogicException("File '{$file}' not found for event '{$event_list}'", 1); + } + + $file_content = file_get_contents($this->root_path . $file); + foreach ($events as $event) + { + if (strpos($file_content, '') === false) + { + throw new \LogicException("Event '{$event}' not found in file '{$file}'", 2); + } + } + } } From 23dbddc59d864a71d99b1fd024533cb24ffff626 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 20 Apr 2014 15:51:08 +0200 Subject: [PATCH 23/55] [ticket/12273] Fix some locations of existing events PHPBB3-12273 --- phpBB/docs/events.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/docs/events.md b/phpBB/docs/events.md index 514b39fee2..db73989616 100644 --- a/phpBB/docs/events.md +++ b/phpBB/docs/events.md @@ -66,13 +66,13 @@ acp_simple_header_body_before acp_simple_header_head_append === -* Location: adm/style/overall_header.html +* Location: adm/style/simple_header.html * Since: 3.1.0-a1 * Purpose: Add assets within the `` tags in the simple header of the ACP acp_users_overview_options_append === -* Location: adm/style/acp_users.html +* Location: adm/style/acp_users_overview.html * Since: 3.1.0-a1 * Purpose: Add options and settings on user overview page From f676f50c22a2e8d4a6c5671c5cf2f9f7372ed40d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 20 Apr 2014 15:55:24 +0200 Subject: [PATCH 24/55] [ticket/12273] Only check selected files PHPBB3-12273 --- phpBB/phpbb/event/md_exporter.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index 8714bdb2f7..089115b91f 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -198,7 +198,6 @@ class md_exporter $files = explode("\n + ", $file_details); foreach ($files as $file) { - if (($this->filter !== 'adm') && strpos($file, 'styles/prosilver/template/') === 0) { $files_list['prosilver'][] = substr($file, strlen('styles/prosilver/template/')); @@ -253,9 +252,13 @@ class md_exporter $file_content = file_get_contents($this->root_path . $file); foreach ($events as $event) { - if (strpos($file_content, '') === false) + if (($this->filter !== 'adm') && strpos($file, 'adm/style/') !== 0 + || ($this->filter === 'adm') && strpos($file, 'adm/style/') === 0) { - throw new \LogicException("Event '{$event}' not found in file '{$file}'", 2); + if (strpos($file_content, '') === false) + { + throw new \LogicException("Event '{$event}' not found in file '{$file}'", 2); + } } } } From 7dc32a45e5c43f29b19b8a8138b515c9e09d23de Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 20 Apr 2014 17:00:18 +0200 Subject: [PATCH 25/55] [ticket/12273] Verify the result of the .md file to the source PHPBB3-12273 --- phpBB/phpbb/event/md_exporter.php | 172 ++++++++++++++++++++++++++---- 1 file changed, 154 insertions(+), 18 deletions(-) diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index 089115b91f..8dba963f11 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -45,6 +45,54 @@ class md_exporter return $this->events; } + /** + * @param string $md_file + * @param string $filter + * @return int Number of events found + * @throws \LogicException + */ + public function crawl_phpbb_directory_adm($md_file) + { + $this->crawl_eventsmd($md_file, 'adm'); + + $file_list = $this->get_recursive_file_list($this->root_path . 'adm/style/', 'adm/style/'); + foreach ($file_list as $file) + { + $file_name = 'adm/style/' . $file; + $this->validate_events_from_file($file_name, $this->crawl_file_for_events($file_name)); + } + + return sizeof($this->events); + } + + /** + * @param string $md_file + * @param string $filter + * @return int Number of events found + * @throws \LogicException + */ + public function crawl_phpbb_directory_styles($md_file) + { + $this->crawl_eventsmd($md_file, 'styles'); + + $styles = array('prosilver', 'subsilver2'); + foreach ($styles as $style) + { + $file_list = $this->get_recursive_file_list( + $this->root_path . 'styles/' . $style . '/template/', + 'styles/' . $style . '/template/' + ); + + foreach ($file_list as $file) + { + $file_name = 'styles/' . $style . '/template/' . $file; + $this->validate_events_from_file($file_name, $this->crawl_file_for_events($file_name)); + } + } + + return sizeof($this->events); + } + /** * @param string $md_file * @param string $filter @@ -94,11 +142,6 @@ class md_exporter ); } - foreach ($this->events_by_file as $file => $events) - { - $this->validate_events_for_file($file, $events); - } - return sizeof($this->events); } @@ -233,33 +276,126 @@ class md_exporter return $files_list; } + public function crawl_file_for_events($file) + { + if (!file_exists($this->root_path . $file)) + { + throw new \LogicException("File '{$file}' does not exist", 1); + } + + $event_list = array(); + $file_content = file_get_contents($this->root_path . $file); + + $events = explode('', $event, 2); + $event_list[] = $event_name; + } + + return $event_list; + } + /** - * Validates whether a list of events is named in $file + * Validates whether all events from $file are in the md file and vice-versa * * @param string $file * @param array $events * @return null * @throws \LogicException */ - public function validate_events_for_file($file, array $events) + public function validate_events_from_file($file, array $events) { - if (!file_exists($this->root_path . $file)) + if (empty($this->events_by_file[$file]) && empty($events)) { - $event_list = implode("', '", $events); - throw new \LogicException("File '{$file}' not found for event '{$event_list}'", 1); + return true; + } + else if (empty($events)) + { + $event_list = implode("', '", $this->events_by_file[$file]); + throw new \LogicException("File '{$file}' contains no events, but should contain: " + . "'{$event_list}'", 1); } - $file_content = file_get_contents($this->root_path . $file); - foreach ($events as $event) + $missing_events_from_file = array(); + foreach ($this->events_by_file[$file] as $event) { - if (($this->filter !== 'adm') && strpos($file, 'adm/style/') !== 0 - || ($this->filter === 'adm') && strpos($file, 'adm/style/') === 0) + if (!in_array($event, $events)) { - if (strpos($file_content, '') === false) - { - throw new \LogicException("Event '{$event}' not found in file '{$file}'", 2); - } + $missing_events_from_file[] = $event; } } + + if (!empty($missing_events_from_file)) + { + $event_list = implode("', '", $missing_events_from_file); + throw new \LogicException("File '{$file}' does not contain events: '{$event_list}'", 2); + } + + $missing_events_from_md = array(); + foreach ($events as $event) + { + if (!in_array($event, $this->events_by_file[$file])) + { + $missing_events_from_md[] = $event; + } + } + + if (!empty($missing_events_from_md)) + { + $event_list = implode("', '", $missing_events_from_md); + throw new \LogicException("File '{$file}' contains additional events: '{$event_list}'", 3); + } + + return true; + } + + /** + * Returns a list of files in $dir + * + * Works recursive with any depth + * + * @param string $dir Directory to go through + * @param string $path Path from root to $dir + * @return array List of files (including directories) + */ + public function get_recursive_file_list($dir, $path = '') + { + try + { + $iterator = new \DirectoryIterator($dir); + } + catch (\Exception $e) + { + return array(); + } + + $files = array(); + foreach ($iterator as $file_info) + { + /** @var \DirectoryIterator $file_info */ + if ($file_info->isDot()) + { + continue; + } + + // Do not scan some directories + if ($file_info->isDir()) + { + $sub_dir = $this->get_recursive_file_list($file_info->getPath() . '/' . $file_info->getFilename(), $path . '/' . $file_info->getFilename()); + foreach ($sub_dir as $file) + { + $files[] = $file_info->getFilename() . '/' . $file; + } + } + else if (substr($file_info->getFilename(), -5) == '.html') + { + $files[] = $file_info->getFilename(); + } + } + + return $files; } } From 58892555299ad9df5bdd2c5401a854068860e68d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 20 Apr 2014 17:01:00 +0200 Subject: [PATCH 26/55] [ticket/12273] Test source files and compare with events.md PHPBB3-12273 --- phpBB/develop/export_events_for_wiki.php | 6 ++-- tests/event/md_exporter_test.php | 37 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/phpBB/develop/export_events_for_wiki.php b/phpBB/develop/export_events_for_wiki.php index 69b09ff136..cc4aa4444f 100644 --- a/phpBB/develop/export_events_for_wiki.php +++ b/phpBB/develop/export_events_for_wiki.php @@ -24,7 +24,7 @@ function usage() echo "php:\n"; echo " Generate the PHP event section of Event_List\n"; echo "\n"; - echo "acp:\n"; + echo "adm:\n"; echo " Generate the ACP Template event section of Event_List\n"; echo "\n"; echo "styles:\n"; @@ -66,7 +66,7 @@ switch ($action) case 'styles': $exporter = new \phpbb\event\md_exporter($phpbb_root_path); - $exporter->crawl_eventsmd('docs/events.md', 'styles'); + $exporter->crawl_phpbb_directory_styles('docs/events.md'); echo $exporter->export_events_for_wiki(); if ($action === 'styles') @@ -78,7 +78,7 @@ switch ($action) case 'adm': $exporter = new \phpbb\event\md_exporter($phpbb_root_path); - $exporter->crawl_eventsmd('docs/events.md', 'adm'); + $exporter->crawl_phpbb_directory_adm('docs/events.md'); echo $exporter->export_events_for_wiki(); if ($action === 'all') diff --git a/tests/event/md_exporter_test.php b/tests/event/md_exporter_test.php index 52d10bd3e3..5fb3a99254 100644 --- a/tests/event/md_exporter_test.php +++ b/tests/event/md_exporter_test.php @@ -27,4 +27,41 @@ class phpbb_event_md_exporter_test extends phpbb_test_case $exporter = new \phpbb\event\md_exporter($phpbb_root_path); $this->assertGreaterThan(0, $exporter->crawl_eventsmd('docs/events.md', $filter)); } + + static public function crawl_adm_files_data() + { + global $phpbb_root_path; + $exporter = new \phpbb\event\md_exporter($phpbb_root_path); + $data_provider = array(); + + $styles = array( + 'adm/style/' => 'adm', + 'styles/prosilver/template/' => 'styles', + 'styles/subsilver2/template/' => 'styles', + ); + foreach ($styles as $path => $filter) + { + $files = $exporter->get_recursive_file_list($phpbb_root_path . $path, $path); + foreach ($files as $file) + { + $data_provider[] = array($filter, $path . $file); + } + } + + return $data_provider; + } + + /** + * @dataProvider crawl_adm_files_data + */ + public function test_crawl_adm_files($filter, $file) + { + global $phpbb_root_path; + $exporter = new \phpbb\event\md_exporter($phpbb_root_path); + $exporter->crawl_eventsmd('docs/events.md', $filter); + $events = $exporter->crawl_file_for_events($file); + + $this->assertGreaterThanOrEqual(0, sizeof($events)); + $this->assertTrue($exporter->validate_events_from_file($file, $events)); + } } From a2c3b2534a3a187a7ccc3e4b86ba69735c4b8b1a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 20 Apr 2014 17:08:06 +0200 Subject: [PATCH 27/55] [ticket/12273] Fix method name of test and fix undefined index PHPBB3-12273 --- phpBB/phpbb/event/md_exporter.php | 11 +++++++++++ tests/event/md_exporter_test.php | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index 8dba963f11..708900c693 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -241,6 +241,11 @@ class md_exporter $files = explode("\n + ", $file_details); foreach ($files as $file) { + if (!file_exists($this->root_path . $file)) + { + throw new \LogicException("Invalid file '{$file}' not found for event '{$this->current_event}'", 1); + } + if (($this->filter !== 'adm') && strpos($file, 'styles/prosilver/template/') === 0) { $files_list['prosilver'][] = substr($file, strlen('styles/prosilver/template/')); @@ -312,6 +317,12 @@ class md_exporter { return true; } + else if (empty($this->events_by_file[$file])) + { + $event_list = implode("', '", $events); + throw new \LogicException("File '{$file}' should not contain events, but contains: " + . "'{$event_list}'", 1); + } else if (empty($events)) { $event_list = implode("', '", $this->events_by_file[$file]); diff --git a/tests/event/md_exporter_test.php b/tests/event/md_exporter_test.php index 5fb3a99254..b62b55accd 100644 --- a/tests/event/md_exporter_test.php +++ b/tests/event/md_exporter_test.php @@ -28,7 +28,7 @@ class phpbb_event_md_exporter_test extends phpbb_test_case $this->assertGreaterThan(0, $exporter->crawl_eventsmd('docs/events.md', $filter)); } - static public function crawl_adm_files_data() + static public function crawl_template_file_data() { global $phpbb_root_path; $exporter = new \phpbb\event\md_exporter($phpbb_root_path); @@ -52,9 +52,9 @@ class phpbb_event_md_exporter_test extends phpbb_test_case } /** - * @dataProvider crawl_adm_files_data + * @dataProvider crawl_template_file_data */ - public function test_crawl_adm_files($filter, $file) + public function test_crawl_template_file($filter, $file) { global $phpbb_root_path; $exporter = new \phpbb\event\md_exporter($phpbb_root_path); From 8e4b4bc72e201d5511e5dc45fc19fae88b182a22 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 20 Apr 2014 17:13:22 +0200 Subject: [PATCH 28/55] [ticket/12273] Fix subsilver2 missing from simple_footer_after docs PHPBB3-12273 --- phpBB/docs/events.md | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/docs/events.md b/phpBB/docs/events.md index db73989616..578bad3187 100644 --- a/phpBB/docs/events.md +++ b/phpBB/docs/events.md @@ -423,6 +423,7 @@ simple_footer_after === * Locations: + styles/prosilver/template/simple_footer.html + + styles/subsilver2/template/simple_footer.html * Since: 3.1.0-a1 * Purpose: Add content directly prior to the `` tag of the simple footer From 320a2f75789bf124a3300f91c8275aa650fd3271 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 20 Apr 2014 17:23:32 +0200 Subject: [PATCH 29/55] [ticket/12273] Fix number of = in events.md PHPBB3-12273 --- phpBB/docs/events.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/phpBB/docs/events.md b/phpBB/docs/events.md index 578bad3187..2a6adcb94f 100644 --- a/phpBB/docs/events.md +++ b/phpBB/docs/events.md @@ -91,7 +91,7 @@ acp_users_signature_editor_buttons_before * Purpose: Add content before BBCode posting buttons in the ACP user signature forumlist_body_category_header_after -==== +=== * Locations: + styles/prosilver/template/forumlist_body.html + styles/subsilver2/template/forumlist_body.html @@ -99,7 +99,7 @@ forumlist_body_category_header_after * Purpose: Add content after the header of the category on the forum list. forumlist_body_category_header_before -==== +=== * Locations: + styles/prosilver/template/forumlist_body.html + styles/subsilver2/template/forumlist_body.html @@ -107,7 +107,7 @@ forumlist_body_category_header_before * Purpose: Add content before the header of the category on the forum list. forumlist_body_last_post_title_prepend -==== +=== * Locations: + styles/prosilver/template/forumlist_body.html + styles/subsilver2/template/forumlist_body.html @@ -115,7 +115,7 @@ forumlist_body_last_post_title_prepend * Purpose: Add content before the post title of the latest post in a forum on the forum list. forumlist_body_subforums_after -==== +=== * Locations: + styles/prosilver/template/forumlist_body.html + styles/subsilver2/template/forumlist_body.html @@ -123,7 +123,7 @@ forumlist_body_subforums_after * Purpose: Add content after the list of subforums (if any) for each forum on the forum list. forumlist_body_subforums_before -==== +=== * Locations: + styles/prosilver/template/forumlist_body.html + styles/subsilver2/template/forumlist_body.html @@ -131,7 +131,7 @@ forumlist_body_subforums_before * Purpose: Add content before the list of subforums (if any) for each forum on the forum list. forumlist_body_last_row_after -==== +=== * Locations: + styles/prosilver/template/forumlist_body.html + styles/subsilver2/template/forumlist_body.html From d2ab30590988511778e9448ac68ad4db379e6f8a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 20 Apr 2014 17:35:48 +0200 Subject: [PATCH 30/55] [ticket/12273] Add missing event documentation PHPBB3-12273 --- phpBB/docs/events.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/phpBB/docs/events.md b/phpBB/docs/events.md index 2a6adcb94f..686f5e6203 100644 --- a/phpBB/docs/events.md +++ b/phpBB/docs/events.md @@ -455,6 +455,22 @@ topiclist_row_append * Since: 3.1.0-a1 * Purpose: Add content into topic rows (inside the elements containing topic titles) +ucp_pm_viewmessage_contact_fields_after +=== +* Locations: + + styles/prosilver/template/ucp_pm_viewmessage.html +* Since: 3.1.0-b1 +* Purpose: Add data after the contact fields on the user profile when viewing +a private message + +ucp_pm_viewmessage_contact_fields_before +=== +* Locations: + + styles/prosilver/template/ucp_pm_viewmessage.html +* Since: 3.1.0-b1 +* Purpose: Add data before the contact fields on the user profile when viewing +a private message + ucp_pm_viewmessage_custom_fields_after === * Locations: From b0a9acd8ff953736d6aeb39095aca278c0869563 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 24 Apr 2014 17:14:12 +0200 Subject: [PATCH 31/55] [ticket/12273] Use array_merge instead of += PHPBB3-12273 --- phpBB/phpbb/event/php_exporter.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 3956be600b..8de3051d9b 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -302,17 +302,17 @@ class php_exporter { $line = ltrim($this->file_lines[$this->current_event_line - $vars_array_line], "\t"); $match = array(); - preg_match('#^\$vars (?:\+)?= array\(\'([a-zA-Z0-9_\' ,]+)\'\);$#', $line, $match); + preg_match('#^\$vars = (array_merge\(\$vars, )?array\(\'([a-zA-Z0-9_\' ,]+)\'\)(?(1)\));$#', $line, $match); - if (isset($match[1])) + if (isset($match[2])) { $found_vars_array = true; - if (strlen($match[1]) > 90) + 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[1])); + $vars_array = array_merge($vars_array, explode("', '", $match[2])); } $vars_array_line++; From 8599554443deee1d655ffc4ae0ad97c60ba0a123 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 24 Apr 2014 17:14:45 +0200 Subject: [PATCH 32/55] [ticket/12273] Fix unit test for multi line $vars PHPBB3-12273 --- tests/event/fixtures/trigger_many_vars.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/event/fixtures/trigger_many_vars.test b/tests/event/fixtures/trigger_many_vars.test index 79f121cd7b..fadfcffefc 100644 --- a/tests/event/fixtures/trigger_many_vars.test +++ b/tests/event/fixtures/trigger_many_vars.test @@ -40,6 +40,6 @@ * delete, cancel, refresh, error, page_data, message_parser */ $vars = array('post_data', 'moderators', 'mode', 'page_title', 's_topic_icons', 'form_enctype'); - $vars += array('s_action', 's_hidden_fields', 'post_id', 'topic_id', 'forum_id', 'submit', 'preview'); - $vars += array('save', 'load', 'delete', 'cancel', 'refresh', 'error', 'page_data', 'message_parser'); + $vars = array_merge($vars, array('s_action', 's_hidden_fields', 'post_id', 'topic_id', 'forum_id', 'submit', 'preview')); + $vars = array_merge($vars, array('save', 'load', 'delete', 'cancel', 'refresh', 'error', 'page_data', 'message_parser')); extract($phpbb_dispatcher->trigger_event('core.posting_modify_template_vars', compact($vars))); From c2dace762ec295c7a2d67758006b1fff56f1f573 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 20 Apr 2014 15:13:13 +0200 Subject: [PATCH 33/55] [ticket/12273] Fix long $vars lines for existing events PHPBB3-12273 --- phpBB/includes/acp/acp_bbcodes.php | 4 +++- phpBB/includes/acp/acp_forums.php | 3 ++- phpBB/includes/functions_admin.php | 9 ++++++--- phpBB/includes/functions_content.php | 3 ++- phpBB/includes/functions_posting.php | 3 ++- phpBB/memberlist.php | 3 ++- phpBB/phpbb/log/log.php | 4 +++- phpBB/phpbb/user.php | 3 ++- phpBB/posting.php | 7 +++++-- phpBB/viewtopic.php | 12 +++++++++--- 10 files changed, 36 insertions(+), 15 deletions(-) diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index 84382b6276..a05b1df760 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -159,7 +159,9 @@ class acp_bbcodes * submitting form when $warn_text is true * @since 3.1.0-a3 */ - $vars = array('action', 'sql_ary', 'bbcode_id', 'display_on_posting', 'bbcode_match', 'bbcode_tpl', 'bbcode_helpline', 'hidden_fields'); + $vars = array('action', 'sql_ary', 'bbcode_id', 'display_on_posting'); + $vars = array_merge($vars, array('bbcode_match', 'bbcode_tpl')); + $vars = array_merge($vars, array('bbcode_helpline', 'hidden_fields')); extract($phpbb_dispatcher->trigger_event('core.acp_bbcodes_modify_create', compact($vars))); $warn_text = preg_match('%<[^>]*\{text[\d]*\}[^>]*>%i', $bbcode_tpl); diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index c47d9bc185..0163d12ed0 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -707,7 +707,8 @@ class acp_forums * @var array template_data Array with new forum data * @since 3.1-A1 */ - $vars = array('action', 'update', 'forum_id', 'row', 'forum_data', 'parents_list', 'errors', 'template_data'); + $vars = array('action', 'update', 'forum_id', 'row', 'forum_data'); + $vars = array_merge($vars, array('parents_list', 'errors', 'template_data')); extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_display_form', compact($vars))); $template->assign_vars($template_data); diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index d72f89b6ac..28cb2c2f63 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -755,7 +755,8 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = * @var array delete_notifications_types Array with notifications types to delete * @since 3.1.0-a4 */ - $vars = array('where_type', 'where_ids', 'auto_sync', 'posted_sync', 'post_count_sync', 'call_delete_topics', 'delete_notifications_types'); + $vars = array('where_type', 'where_ids', 'auto_sync', 'posted_sync', 'post_count_sync'); + $vars = array_merge($vars, array('call_delete_topics', 'delete_notifications_types')); extract($phpbb_dispatcher->trigger_event('core.delete_posts_before', compact($vars))); if ($where_type === 'range') @@ -912,7 +913,8 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = * @var array delete_notifications_types Array with notifications types to delete * @since 3.1.0-a4 */ - $vars = array('post_ids', 'poster_ids', 'topic_ids', 'forum_ids', 'where_type', 'where_ids', 'delete_notifications_types'); + $vars = array('post_ids', 'poster_ids', 'topic_ids', 'forum_ids', 'where_type'); + $vars = array_merge($vars, array('where_ids', 'delete_notifications_types')); extract($phpbb_dispatcher->trigger_event('core.delete_posts_in_transaction', compact($vars))); $db->sql_transaction('commit'); @@ -930,7 +932,8 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = * @var array delete_notifications_types Array with notifications types to delete * @since 3.1.0-a4 */ - $vars = array('post_ids', 'poster_ids', 'topic_ids', 'forum_ids', 'where_type', 'where_ids', 'delete_notifications_types'); + $vars = array('post_ids', 'poster_ids', 'topic_ids', 'forum_ids', 'where_type'); + $vars = array_merge($vars, array('where_ids', 'delete_notifications_types')); extract($phpbb_dispatcher->trigger_event('core.delete_posts_after', compact($vars))); // Resync topics_posted table diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index b1f69c5756..bd711541c2 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -1410,7 +1410,8 @@ function get_username_string($mode, $user_id, $username, $username_colour = '', * @var array _profile_cache Array of original return templates * @since 3.1-A1 */ - $vars = array('mode', 'user_id', 'username', 'username_colour', 'guest_username', 'custom_profile_url', 'username_string', '_profile_cache'); + $vars = array('mode', 'user_id', 'username', 'username_colour', 'guest_username'); + $vars = array_merge($vars, array('custom_profile_url', 'username_string', '_profile_cache')); extract($phpbb_dispatcher->trigger_event('core.modify_username_string', compact($vars))); return $username_string; diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index df55c4540c..b3d8ccdb39 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1497,7 +1497,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u * @var bool update_search_index Flag indicating if the search index will be updated * @since 3.1.0-a4 */ - $vars = array('mode', 'subject', 'username', 'topic_type', 'poll', 'data', 'update_message', 'update_search_index'); + $vars = array('mode', 'subject', 'username', 'topic_type', 'poll', 'data'); + $vars = array_merge($vars, array('update_message', 'update_search_index')); extract($phpbb_dispatcher->trigger_event('core.modify_submit_post_data', compact($vars))); // We do not handle erasing posts here diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 8fceb4ac5b..0a96f6c418 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -604,7 +604,8 @@ switch ($mode) * @since 3.1-A1 * @changed 3.1.0-b2 Added friend and foe status */ - $vars = array('member', 'user_notes_enabled', 'warn_user_enabled', 'zebra_enabled', 'friends_enabled', 'foes_enabled', 'friend', 'foe'); + $vars = array('member', 'user_notes_enabled', 'warn_user_enabled', 'zebra_enabled'); + $vars = array_merge($vars, array('friends_enabled', 'foes_enabled', 'friend', 'foe')); extract($phpbb_dispatcher->trigger_event('core.memberlist_view_profile', compact($vars))); $template->assign_vars(show_profile($member, $user_notes_enabled, $warn_user_enabled)); diff --git a/phpBB/phpbb/log/log.php b/phpBB/phpbb/log/log.php index 44fba06d9d..b0aa637002 100644 --- a/phpBB/phpbb/log/log.php +++ b/phpBB/phpbb/log/log.php @@ -405,7 +405,9 @@ class log implements \phpbb\log\log_interface * e.g.: 'AND l.forum_id = 1' * @since 3.1-A1 */ - $vars = array('mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id', 'user_id', 'log_time', 'sort_by', 'keywords', 'profile_url', 'log_type', 'sql_additional'); + $vars = array('mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id'); + $vars = array_merge($vars, array('user_id', 'log_time', 'sort_by', 'keywords')); + $vars = array_merge($vars, array('profile_url', 'log_type', 'sql_additional')); extract($this->dispatcher->trigger_event('core.get_logs_modify_type', compact($vars))); if ($log_type === false) diff --git a/phpBB/phpbb/user.php b/phpBB/phpbb/user.php index b9b3896606..1f65b63522 100644 --- a/phpBB/phpbb/user.php +++ b/phpBB/phpbb/user.php @@ -145,7 +145,8 @@ class user extends \phpbb\session * @var mixed style_id Style we are going to display * @since 3.1-A1 */ - $vars = array('user_data', 'user_lang_name', 'user_date_format', 'user_timezone', 'lang_set', 'lang_set_ext', 'style_id'); + $vars = array('user_data', 'user_lang_name', 'user_date_format', 'lang_set'); + $vars = array_merge($vars, array('user_timezone', 'lang_set_ext', 'style_id')); extract($phpbb_dispatcher->trigger_event('core.user_setup', compact($vars))); $this->data = $user_data; diff --git a/phpBB/posting.php b/phpBB/posting.php index ed1268e84b..3d48a67e60 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -82,7 +82,9 @@ $current_time = time(); * language keys. * @since 3.1-A1 */ -$vars = array('post_id', 'topic_id', 'forum_id', 'draft_id', 'lastclick', 'submit', 'preview', 'save', 'load', 'delete', 'cancel', 'refresh', 'mode', 'error'); +$vars = array('post_id', 'topic_id', 'forum_id', 'draft_id', 'lastclick'); +$vars = array_merge($vars, array('submit', 'preview', 'save', 'load', 'delete')); +$vars = array_merge($vars, array('cancel', 'refresh', 'mode', 'error')); extract($phpbb_dispatcher->trigger_event('core.modify_posting_parameters', compact($vars))); // Was cancel pressed? If so then redirect to the appropriate page @@ -1561,7 +1563,8 @@ $template->assign_vars(array( * @since 3.1-A1 * @change 3.1.0-b3 Added vars post_data, moderators, mode, page_title, s_topic_icons, form_enctype, s_action, s_hidden_fields */ -$vars = array('post_data', 'moderators', 'mode', 'page_title', 's_topic_icons', 'form_enctype', 's_action', 's_hidden_fields'); +$vars = array('post_data', 'moderators', 'mode', 'page_title', 's_topic_icons'); +$vars = array_merge($vars, array('form_enctype', 's_action', 's_hidden_fields')); extract($phpbb_dispatcher->trigger_event('core.posting_modify_template_vars', compact($vars))); // Build custom bbcodes array diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index ad7e8c29bc..5be578423f 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1000,7 +1000,8 @@ $sql_ary = array( * @since 3.1-A1 * @change 3.1.0-a2 Added vars forum_id, topic_id, topic_data, post_list, sort_days, sort_key, sort_dir, start */ -$vars = array('forum_id', 'topic_id', 'topic_data', 'post_list', 'sort_days', 'sort_key', 'sort_dir', 'start', 'sql_ary'); +$vars = array('forum_id', 'topic_id', 'topic_data', 'post_list', 'sort_days'); +$vars = array_merge($vars, array('sort_key', 'sort_dir', 'start', 'sql_ary')); extract($phpbb_dispatcher->trigger_event('core.viewtopic_get_post_data', compact($vars))); $sql = $db->sql_build_query('SELECT', $sql_ary); @@ -1679,7 +1680,8 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) * @change 3.1.0-a3 Added vars start, current_row_number, end, attachments * @change 3.1.0-b3 Added topic_data array, total_posts */ - $vars = array('start', 'current_row_number', 'end', 'total_posts', 'row', 'cp_row', 'attachments', 'user_poster_data', 'post_row', 'topic_data'); + $vars = array('start', 'current_row_number', 'end', 'total_posts', 'row', 'cp_row'); + $vars = array_merge($vars, array('attachments', 'user_poster_data', 'post_row', 'topic_data')); extract($phpbb_dispatcher->trigger_event('core.viewtopic_modify_post_row', compact($vars))); $i = $current_row_number; @@ -1726,14 +1728,18 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) * @var int start Start item of this page * @var int current_row_number Number of the post on this page * @var int end Number of posts on this page + * @var int total_posts Total posts count * @var array row Array with original post and user data * @var array cp_row Custom profile field data of the poster * @var array attachments List of attachments * @var array user_poster_data Poster's data from user cache * @var array post_row Template block array of the post + * @var array topic_data Array with topic data * @since 3.1.0-a3 + * @change 3.1.0-b3 Added topic_data array, total_posts */ - $vars = array('start', 'current_row_number', 'end', 'row', 'cp_row', 'attachments', 'user_poster_data', 'post_row'); + $vars = array('start', 'current_row_number', 'end', 'total_posts', 'row', 'cp_row'); + $vars = array_merge($vars, array('attachments', 'user_poster_data', 'post_row', 'topic_data')); extract($phpbb_dispatcher->trigger_event('core.viewtopic_post_row_after', compact($vars))); $i = $current_row_number; From 142fe1a0e57797aa77059edda42ebedd91b11397 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 25 Apr 2014 11:45:54 +0200 Subject: [PATCH 34/55] [ticket/12273] Use multiline arrays instead of array_merge() PHPBB3-12273 --- phpBB/phpbb/event/php_exporter.php | 88 ++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 28 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,43 +295,21 @@ 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); - - if (isset($match[2])) - { - $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])); - } - - $vars_array_line++; - if ($this->current_event_line - $vars_array_line === 0) - { - throw new \LogicException("Can not find '\$vars = array();'-line for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 2); - } + $vars_array = $this->get_vars_from_multi_line_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); + $vars_array = $this->get_vars_from_single_line_array($line); } 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 '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 4); + throw new \LogicException("Found invalid var '{$var}' in array for event '{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 3); } } @@ -339,6 +317,60 @@ class php_exporter 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); + + if (isset($match[1])) + { + $vars_array = explode("', '", $match[1]); + if ($throw_multiline && sizeof($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); + } + return $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}'", 1); + } + } + + /** + * 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(') + { + $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) + { + // 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); + } + } + + return $this->get_vars_from_single_line_array('$vars = array(' . implode(", ", $var_lines) . ');', false); + } + /** * Find the $vars array * From 01e2d7c26c9974405c073d43ecd12614aca6faa5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 25 Apr 2014 11:46:24 +0200 Subject: [PATCH 35/55] [ticket/12273] Fix unit tests for multi line arrays PHPBB3-12273 --- tests/event/fixtures/trigger_many_vars.test | 26 ++++++- tests/event/php_exporter_test.php | 80 ++++++++++++++------- 2 files changed, 78 insertions(+), 28 deletions(-) diff --git a/tests/event/fixtures/trigger_many_vars.test b/tests/event/fixtures/trigger_many_vars.test index fadfcffefc..da72f4c57f 100644 --- a/tests/event/fixtures/trigger_many_vars.test +++ b/tests/event/fixtures/trigger_many_vars.test @@ -39,7 +39,27 @@ * post_id, topic_id, forum_id, submit, preview, save, load, * delete, cancel, refresh, error, page_data, message_parser */ - $vars = array('post_data', 'moderators', 'mode', 'page_title', 's_topic_icons', 'form_enctype'); - $vars = array_merge($vars, array('s_action', 's_hidden_fields', 'post_id', 'topic_id', 'forum_id', 'submit', 'preview')); - $vars = array_merge($vars, array('save', 'load', 'delete', 'cancel', 'refresh', 'error', 'page_data', 'message_parser')); + $vars = array( + 'post_data', + 'moderators', + 'mode', + 'page_title', + 's_topic_icons', + 'form_enctype', + 's_action', + 's_hidden_fields', + 'post_id', + 'topic_id', + 'forum_id', + 'submit', + 'preview', + 'save', + 'load', + 'delete', + 'cancel', + 'refresh', + 'error', + 'page_data', + 'message_parser', + ); extract($phpbb_dispatcher->trigger_event('core.posting_modify_template_vars', compact($vars))); diff --git a/tests/event/php_exporter_test.php b/tests/event/php_exporter_test.php index 5df7713bdf..03f6974af1 100644 --- a/tests/event/php_exporter_test.php +++ b/tests/event/php_exporter_test.php @@ -343,47 +343,77 @@ class phpbb_event_php_exporter_test extends phpbb_test_case array( '/**', '*/', - '$phpbb_dispatcher->dispatch(\'test\');', + '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));', ), 2, - 3, + 1, ), array( array( '/**', '*/', '$vars = $bertie;', - '$phpbb_dispatcher->dispatch(\'test\');', + '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));', ), 3, - 3, - ), - array( - array( - '/**', - '*/', - '$vars = array();', - '$phpbb_dispatcher->dispatch(\'test\');', - ), - 3, - 3, - ), - array( - array( - '/**', - '*/', - '$vars = array(\'test2\', \'\');', - '$phpbb_dispatcher->dispatch(\'test\');', - ), - 3, - 4, + 1, ), array( array( '/**', '*/', '$vars = array(\'$bertie\');', - '$phpbb_dispatcher->dispatch(\'test\');', + '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));', + ), + 3, + 1, + ), + array( + array( + '/**', + '*/', + '$vars = array();', + '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));', + ), + 3, + 1, + ), + array( + array( + '/**', + '*/', + '$vars = array(\'t1\', \'t2\', \'t3\', \'t4\', \'t5\', \'t6\', \'t7\');', + '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));', + ), + 3, + 2, + ), + array( + array( + '/**', + '*/', + '$vars = array(\'test2\', \'\');', + '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));', + ), + 3, + 3, + ), + array( + array( + '/**', + '*/', + '$vars = array(\'bertie\'\');', + '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));', + ), + 3, + 3, + ), + array( + array( + '/**', + '*/', + '$vars = array(\'bertie\',\'basically_valid\');', + '$phpbb_dispatcher->trigger_event(\'test\', compact($vars));', ), 3, 3, From 87899b0e140400e23341ea1286d50e330132be90 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 25 Apr 2014 11:46:44 +0200 Subject: [PATCH 36/55] [ticket/12273] Update existing events PHPBB3-12273 --- phpBB/includes/acp/acp_bbcodes.php | 13 +++++-- phpBB/includes/acp/acp_forums.php | 12 +++++-- phpBB/includes/functions_admin.php | 33 ++++++++++++++---- phpBB/includes/functions_content.php | 22 ++++++++++-- phpBB/includes/functions_posting.php | 12 +++++-- phpBB/includes/ucp/ucp_pm_viewmessage.php | 11 +++++- phpBB/mcp.php | 11 +++++- phpBB/memberlist.php | 12 +++++-- phpBB/phpbb/log/log.php | 28 +++++++++++++--- phpBB/phpbb/user.php | 11 ++++-- phpBB/posting.php | 31 ++++++++++++++--- phpBB/viewtopic.php | 41 +++++++++++++++++++---- 12 files changed, 200 insertions(+), 37 deletions(-) diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index a05b1df760..7cc52024cf 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -159,9 +159,16 @@ class acp_bbcodes * submitting form when $warn_text is true * @since 3.1.0-a3 */ - $vars = array('action', 'sql_ary', 'bbcode_id', 'display_on_posting'); - $vars = array_merge($vars, array('bbcode_match', 'bbcode_tpl')); - $vars = array_merge($vars, array('bbcode_helpline', 'hidden_fields')); + $vars = array( + 'action', + 'sql_ary', + 'bbcode_id', + 'display_on_posting', + 'bbcode_match', + 'bbcode_tpl', + 'bbcode_helpline', + 'hidden_fields', + ); extract($phpbb_dispatcher->trigger_event('core.acp_bbcodes_modify_create', compact($vars))); $warn_text = preg_match('%<[^>]*\{text[\d]*\}[^>]*>%i', $bbcode_tpl); diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 0163d12ed0..4d100d32c2 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -707,8 +707,16 @@ class acp_forums * @var array template_data Array with new forum data * @since 3.1-A1 */ - $vars = array('action', 'update', 'forum_id', 'row', 'forum_data'); - $vars = array_merge($vars, array('parents_list', 'errors', 'template_data')); + $vars = array( + 'action', + 'update', + 'forum_id', + 'row', + 'forum_data', + 'parents_list', + 'errors', + 'template_data', + ); extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_display_form', compact($vars))); $template->assign_vars($template_data); diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 28cb2c2f63..9342582346 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -755,8 +755,15 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = * @var array delete_notifications_types Array with notifications types to delete * @since 3.1.0-a4 */ - $vars = array('where_type', 'where_ids', 'auto_sync', 'posted_sync', 'post_count_sync'); - $vars = array_merge($vars, array('call_delete_topics', 'delete_notifications_types')); + $vars = array( + 'where_type', + 'where_ids', + 'auto_sync', + 'posted_sync', + 'post_count_sync', + 'call_delete_topics', + 'delete_notifications_types', + ); extract($phpbb_dispatcher->trigger_event('core.delete_posts_before', compact($vars))); if ($where_type === 'range') @@ -913,8 +920,15 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = * @var array delete_notifications_types Array with notifications types to delete * @since 3.1.0-a4 */ - $vars = array('post_ids', 'poster_ids', 'topic_ids', 'forum_ids', 'where_type'); - $vars = array_merge($vars, array('where_ids', 'delete_notifications_types')); + $vars = array( + 'post_ids', + 'poster_ids', + 'topic_ids', + 'forum_ids', + 'where_type', + 'where_ids', + 'delete_notifications_types', + ); extract($phpbb_dispatcher->trigger_event('core.delete_posts_in_transaction', compact($vars))); $db->sql_transaction('commit'); @@ -932,8 +946,15 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = * @var array delete_notifications_types Array with notifications types to delete * @since 3.1.0-a4 */ - $vars = array('post_ids', 'poster_ids', 'topic_ids', 'forum_ids', 'where_type'); - $vars = array_merge($vars, array('where_ids', 'delete_notifications_types')); + $vars = array( + 'post_ids', + 'poster_ids', + 'topic_ids', + 'forum_ids', + 'where_type', + 'where_ids', + 'delete_notifications_types', + ); extract($phpbb_dispatcher->trigger_event('core.delete_posts_after', compact($vars))); // Resync topics_posted table diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index bd711541c2..89a0c2823e 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -527,7 +527,15 @@ function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bb * @var bool allow_smilies Whether or not to parse Smilies * @since 3.1-A1 */ - $vars = array('text', 'uid', 'bitfield', 'flags', 'allow_bbcode', 'allow_urls', 'allow_smilies'); + $vars = array( + 'text', + 'uid', + 'bitfield', + 'flags', + 'allow_bbcode', + 'allow_urls', + 'allow_smilies', + ); extract($phpbb_dispatcher->trigger_event('core.modify_text_for_storage_before', compact($vars))); $uid = $bitfield = ''; @@ -1410,8 +1418,16 @@ function get_username_string($mode, $user_id, $username, $username_colour = '', * @var array _profile_cache Array of original return templates * @since 3.1-A1 */ - $vars = array('mode', 'user_id', 'username', 'username_colour', 'guest_username'); - $vars = array_merge($vars, array('custom_profile_url', 'username_string', '_profile_cache')); + $vars = array( + 'mode', + 'user_id', + 'username', + 'username_colour', + 'guest_username', + 'custom_profile_url', + 'username_string', + '_profile_cache', + ); extract($phpbb_dispatcher->trigger_event('core.modify_username_string', compact($vars))); return $username_string; diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index b3d8ccdb39..7dbcae7f6e 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1497,8 +1497,16 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u * @var bool update_search_index Flag indicating if the search index will be updated * @since 3.1.0-a4 */ - $vars = array('mode', 'subject', 'username', 'topic_type', 'poll', 'data'); - $vars = array_merge($vars, array('update_message', 'update_search_index')); + $vars = array( + 'mode', + 'subject', + 'username', + 'topic_type', + 'poll', + 'data', + 'update_message', + 'update_search_index', + ); extract($phpbb_dispatcher->trigger_event('core.modify_submit_post_data', compact($vars))); // We do not handle erasing posts here diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index 03064a31d3..44a6982a8e 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -250,7 +250,16 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) * @var array msg_data Template array with message data * @since 3.1-A1 */ - $vars = array('id', 'mode', 'folder_id', 'msg_id', 'folder', 'message_row', 'cp_row', 'msg_data'); + $vars = array( + 'id', + 'mode', + 'folder_id', + 'msg_id', + 'folder', + 'message_row', + 'cp_row', + 'msg_data', + ); extract($phpbb_dispatcher->trigger_event('core.ucp_pm_view_messsage', compact($vars))); $template->assign_vars($msg_data); diff --git a/phpBB/mcp.php b/phpBB/mcp.php index 5676c399af..8e124bf526 100644 --- a/phpBB/mcp.php +++ b/phpBB/mcp.php @@ -267,7 +267,16 @@ if (!$user_id && $username == '') * @var int id Parent module id * @since 3.1.0-b2 */ -$vars = array('module', 'mode', 'user_id', 'forum_id', 'topic_id', 'post_id', 'username', 'id'); +$vars = array( + 'module', + 'mode', + 'user_id', + 'forum_id', + 'topic_id', + 'post_id', + 'username', + 'id', +); extract($phpbb_dispatcher->trigger_event('core.modify_mcp_modules_display_option', compact($vars))); // Load and execute the relevant module diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 0a96f6c418..7f78e694b9 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -604,8 +604,16 @@ switch ($mode) * @since 3.1-A1 * @changed 3.1.0-b2 Added friend and foe status */ - $vars = array('member', 'user_notes_enabled', 'warn_user_enabled', 'zebra_enabled'); - $vars = array_merge($vars, array('friends_enabled', 'foes_enabled', 'friend', 'foe')); + $vars = array( + 'member', + 'user_notes_enabled', + 'warn_user_enabled', + 'zebra_enabled', + 'friends_enabled', + 'foes_enabled', + 'friend', + 'foe', + ); extract($phpbb_dispatcher->trigger_event('core.memberlist_view_profile', compact($vars))); $template->assign_vars(show_profile($member, $user_notes_enabled, $warn_user_enabled)); diff --git a/phpBB/phpbb/log/log.php b/phpBB/phpbb/log/log.php index b0aa637002..ea04344c59 100644 --- a/phpBB/phpbb/log/log.php +++ b/phpBB/phpbb/log/log.php @@ -307,7 +307,15 @@ class log implements \phpbb\log\log_interface * we won't add the entry to the database. * @since 3.1-A1 */ - $vars = array('mode', 'user_id', 'log_ip', 'log_operation', 'log_time', 'additional_data', 'sql_ary'); + $vars = array( + 'mode', + 'user_id', + 'log_ip', + 'log_operation', + 'log_time', + 'additional_data', + 'sql_ary', + ); extract($this->dispatcher->trigger_event('core.add_log', compact($vars))); // We didn't find a log_type, so we don't save it in the database. @@ -405,9 +413,21 @@ class log implements \phpbb\log\log_interface * e.g.: 'AND l.forum_id = 1' * @since 3.1-A1 */ - $vars = array('mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id'); - $vars = array_merge($vars, array('user_id', 'log_time', 'sort_by', 'keywords')); - $vars = array_merge($vars, array('profile_url', 'log_type', 'sql_additional')); + $vars = array( + 'mode', + 'count_logs', + 'limit', + 'offset', + 'forum_id', + 'topic_id', + 'user_id', + 'log_time', + 'sort_by', + 'keywords', + 'profile_url', + 'log_type', + 'sql_additional', + ); extract($this->dispatcher->trigger_event('core.get_logs_modify_type', compact($vars))); if ($log_type === false) diff --git a/phpBB/phpbb/user.php b/phpBB/phpbb/user.php index 1f65b63522..417cc71fd3 100644 --- a/phpBB/phpbb/user.php +++ b/phpBB/phpbb/user.php @@ -145,8 +145,15 @@ class user extends \phpbb\session * @var mixed style_id Style we are going to display * @since 3.1-A1 */ - $vars = array('user_data', 'user_lang_name', 'user_date_format', 'lang_set'); - $vars = array_merge($vars, array('user_timezone', 'lang_set_ext', 'style_id')); + $vars = array( + 'user_data', + 'user_lang_name', + 'user_date_format', + 'user_timezone', + 'lang_set', + 'lang_set_ext', + 'style_id', + ); extract($phpbb_dispatcher->trigger_event('core.user_setup', compact($vars))); $this->data = $user_data; diff --git a/phpBB/posting.php b/phpBB/posting.php index 3d48a67e60..11f0898440 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -82,9 +82,22 @@ $current_time = time(); * language keys. * @since 3.1-A1 */ -$vars = array('post_id', 'topic_id', 'forum_id', 'draft_id', 'lastclick'); -$vars = array_merge($vars, array('submit', 'preview', 'save', 'load', 'delete')); -$vars = array_merge($vars, array('cancel', 'refresh', 'mode', 'error')); +$vars = array( + 'post_id', + 'topic_id', + 'forum_id', + 'draft_id', + 'lastclick', + 'submit', + 'preview', + 'save', + 'load', + 'delete', + 'cancel', + 'refresh', + 'mode', + 'error', +); extract($phpbb_dispatcher->trigger_event('core.modify_posting_parameters', compact($vars))); // Was cancel pressed? If so then redirect to the appropriate page @@ -1563,8 +1576,16 @@ $template->assign_vars(array( * @since 3.1-A1 * @change 3.1.0-b3 Added vars post_data, moderators, mode, page_title, s_topic_icons, form_enctype, s_action, s_hidden_fields */ -$vars = array('post_data', 'moderators', 'mode', 'page_title', 's_topic_icons'); -$vars = array_merge($vars, array('form_enctype', 's_action', 's_hidden_fields')); +$vars = array( + 'post_data', + 'moderators', + 'mode', + 'page_title', + 's_topic_icons', + 'form_enctype', + 's_action', + 's_hidden_fields', +); extract($phpbb_dispatcher->trigger_event('core.posting_modify_template_vars', compact($vars))); // Build custom bbcodes array diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 5be578423f..0dbda7564f 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1000,8 +1000,17 @@ $sql_ary = array( * @since 3.1-A1 * @change 3.1.0-a2 Added vars forum_id, topic_id, topic_data, post_list, sort_days, sort_key, sort_dir, start */ -$vars = array('forum_id', 'topic_id', 'topic_data', 'post_list', 'sort_days'); -$vars = array_merge($vars, array('sort_key', 'sort_dir', 'start', 'sql_ary')); +$vars = array( + 'forum_id', + 'topic_id', + 'topic_data', + 'post_list', + 'sort_days', + 'sort_key', + 'sort_dir', + 'start', + 'sql_ary', +); extract($phpbb_dispatcher->trigger_event('core.viewtopic_get_post_data', compact($vars))); $sql = $db->sql_build_query('SELECT', $sql_ary); @@ -1680,8 +1689,18 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) * @change 3.1.0-a3 Added vars start, current_row_number, end, attachments * @change 3.1.0-b3 Added topic_data array, total_posts */ - $vars = array('start', 'current_row_number', 'end', 'total_posts', 'row', 'cp_row'); - $vars = array_merge($vars, array('attachments', 'user_poster_data', 'post_row', 'topic_data')); + $vars = array( + 'start', + 'current_row_number', + 'end', + 'total_posts', + 'row', + 'cp_row', + 'attachments', + 'user_poster_data', + 'post_row', + 'topic_data', + ); extract($phpbb_dispatcher->trigger_event('core.viewtopic_modify_post_row', compact($vars))); $i = $current_row_number; @@ -1738,8 +1757,18 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) * @since 3.1.0-a3 * @change 3.1.0-b3 Added topic_data array, total_posts */ - $vars = array('start', 'current_row_number', 'end', 'total_posts', 'row', 'cp_row'); - $vars = array_merge($vars, array('attachments', 'user_poster_data', 'post_row', 'topic_data')); + $vars = array( + 'start', + 'current_row_number', + 'end', + 'total_posts', + 'row', + 'cp_row', + 'attachments', + 'user_poster_data', + 'post_row', + 'topic_data', + ); extract($phpbb_dispatcher->trigger_event('core.viewtopic_post_row_after', compact($vars))); $i = $current_row_number; From b32895308d13d5d9b0cd954fd8ce871a1fa073da Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 25 Apr 2014 12:15:44 +0200 Subject: [PATCH 37/55] [ticket/12273] Update since version to 3.1.0-a* style PHPBB3-12273 --- phpBB/common.php | 2 +- phpBB/includes/acp/acp_forums.php | 16 ++++++++-------- phpBB/includes/acp/acp_users.php | 6 +++--- phpBB/includes/functions.php | 8 ++++---- phpBB/includes/functions_acp.php | 8 ++++---- phpBB/includes/functions_content.php | 14 +++++++------- phpBB/includes/functions_display.php | 12 ++++++------ phpBB/includes/functions_posting.php | 2 +- phpBB/includes/functions_user.php | 14 +++++++------- phpBB/includes/mcp/mcp_forum.php | 2 +- phpBB/includes/ucp/ucp_pm_viewmessage.php | 2 +- phpBB/includes/ucp/ucp_prefs.php | 12 ++++++------ phpBB/includes/ucp/ucp_zebra.php | 4 ++-- phpBB/index.php | 2 +- phpBB/memberlist.php | 4 ++-- phpBB/phpbb/log/log.php | 8 ++++---- phpBB/phpbb/permissions.php | 2 +- phpBB/phpbb/user.php | 2 +- phpBB/posting.php | 4 ++-- phpBB/search.php | 4 ++-- phpBB/ucp.php | 2 +- phpBB/viewforum.php | 6 +++--- phpBB/viewonline.php | 4 ++-- phpBB/viewtopic.php | 12 ++++++------ 24 files changed, 76 insertions(+), 76 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index b1da2215fb..12dbe5a62c 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -151,6 +151,6 @@ if (!$config['use_system_cron']) * please use the core.user_setup event instead! * * @event core.common -* @since 3.1-A1 +* @since 3.1.0-a1 */ $phpbb_dispatcher->dispatch('core.common'); diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 4d100d32c2..160bfc05de 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -158,7 +158,7 @@ class acp_forums * @event core.acp_manage_forums_request_data * @var string action Type of the action: add|edit * @var array forum_data Array with new forum data - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('action', 'forum_data'); extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_request_data', compact($vars))); @@ -484,7 +484,7 @@ class acp_forums * empty when creating new forum * @var array forum_data Array with new forum data * @var string parents_list List of parent options - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('action', 'update', 'forum_id', 'row', 'forum_data', 'parents_list'); extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_initialise_data', compact($vars))); @@ -705,7 +705,7 @@ class acp_forums * ensure to update the template variables * S_ERROR and ERROR_MSG to display it * @var array template_data Array with new forum data - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array( 'action', @@ -955,7 +955,7 @@ class acp_forums * @var array forum_data Array with new forum data * @var array errors Array of errors, should be strings and not * language key. - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('forum_data', 'errors'); extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_validate_data', compact($vars))); @@ -1063,7 +1063,7 @@ class acp_forums * @var array forum_data_sql Array with data we are going to update * If forum_data_sql[forum_id] is set, we update * that forum, otherwise a new one is created. - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('forum_data', 'forum_data_sql'); extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_update_data_before', compact($vars))); @@ -1356,7 +1356,7 @@ class acp_forums * ensure to set forum_data_sql[forum_id] * @var array errors Array of errors, should be strings and not * language key. - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('forum_data', 'forum_data_sql', 'is_new_forum', 'errors'); extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_update_data_after', compact($vars))); @@ -1394,7 +1394,7 @@ class acp_forums * @var int to_id If of the new parent forum * @var array errors Array of errors, should be strings and not * language key. - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('from_id', 'to_id', 'errors'); extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_move_children', compact($vars))); @@ -1498,7 +1498,7 @@ class acp_forums * @var array errors Array of errors, should be strings and not * language key. If this array is not empty, * The content will not be moved. - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('from_id', 'to_id', 'sync', 'errors'); extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_move_content', compact($vars))); diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index a720334ed2..f6d46188b8 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -772,7 +772,7 @@ class acp_users * @event core.acp_users_overview_run_quicktool * @var array user_row Current user data * @var string action Quick tool that should be run - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('action', 'user_row'); extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_run_quicktool', compact($vars))); @@ -893,7 +893,7 @@ class acp_users * @var array user_row Current user data * @var array data Submitted user data * @var array sql_ary User data we udpate - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('user_row', 'data', 'sql_ary'); extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_modify_data', compact($vars))); @@ -1008,7 +1008,7 @@ class acp_users * @event core.acp_users_display_overview * @var array user_row Array with user data * @var array quick_tool_ary Ouick tool options - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('user_row', 'quick_tool_ary'); extract($phpbb_dispatcher->trigger_event('core.acp_users_display_overview', compact($vars))); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 69f7c3f162..685784190a 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2022,7 +2022,7 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) * the global one (false) * @var bool|string append_sid_overwrite Overwrite function (string * URL) or not (false) - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('url', 'params', 'is_amp', 'session_id', 'append_sid_overwrite'); extract($phpbb_dispatcher->trigger_event('core.append_sid', compact($vars))); @@ -4735,7 +4735,7 @@ function page_header($page_title = '', $display_online_list = false, $item_id = * @var int item_id Restrict online users to item id * @var bool page_header_override Shall we return instead of running * the rest of page_header() - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('page_title', 'display_online_list', 'item_id', 'item', 'page_header_override'); extract($phpbb_dispatcher->trigger_event('core.page_header', compact($vars))); @@ -5100,7 +5100,7 @@ function page_footer($run_cron = true, $display_template = true, $exit_handler = * @var bool run_cron Shall we run cron tasks * @var bool page_footer_override Shall we return instead of running * the rest of page_footer() - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('run_cron', 'page_footer_override'); extract($phpbb_dispatcher->trigger_event('core.page_footer', compact($vars))); @@ -5208,7 +5208,7 @@ function garbage_collection() * Unload some objects, to free some memory, before we finish our task * * @event core.garbage_collection - * @since 3.1-A1 + * @since 3.1.0-a1 */ $phpbb_dispatcher->dispatch('core.garbage_collection'); } diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index cb44ed2794..2c66f6009c 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -41,7 +41,7 @@ function adm_page_header($page_title) * @var string page_title Page title * @var bool adm_page_header_override Shall we return instead of * running the rest of adm_page_header() - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('page_title', 'adm_page_header_override'); extract($phpbb_dispatcher->trigger_event('core.adm_page_header', compact($vars))); @@ -132,7 +132,7 @@ function adm_page_footer($copyright_html = true) * @var bool copyright_html Shall we display the copyright? * @var bool adm_page_footer_override Shall we return instead of * running the rest of adm_page_footer() - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('copyright_html', 'adm_page_footer_override'); extract($phpbb_dispatcher->trigger_event('core.adm_page_footer', compact($vars))); @@ -396,7 +396,7 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars) * @var string name Should be used for the name attribute * @var array vars Array with the options for the config * @var string tpl The resulting html code we display - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('tpl_type', 'key', 'new', 'name', 'vars', 'tpl'); extract($phpbb_dispatcher->trigger_event('core.build_config_template', compact($vars))); @@ -606,7 +606,7 @@ function validate_config_vars($config_vars, &$cfg_array, &$error) * @var array error Array of errors, the errors should * be strings only, language keys are * not replaced afterwards - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('cfg_array', 'config_name', 'config_definition', 'error'); extract($phpbb_dispatcher->trigger_event('core.validate_config_variable', compact($vars))); diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 89a0c2823e..6ea1b378e8 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -445,7 +445,7 @@ function generate_text_for_display($text, $uid, $bitfield, $flags, $censor_text * @var string bitfield The BBCode Bitfield * @var int flags The BBCode Flags * @var bool censor_text Whether or not to apply word censors - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('text', 'uid', 'bitfield', 'flags', 'censor_text'); extract($phpbb_dispatcher->trigger_event('core.modify_text_for_display_before', compact($vars))); @@ -487,7 +487,7 @@ function generate_text_for_display($text, $uid, $bitfield, $flags, $censor_text * @var string uid The BBCode UID * @var string bitfield The BBCode Bitfield * @var int flags The BBCode Flags - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('text', 'uid', 'bitfield', 'flags'); extract($phpbb_dispatcher->trigger_event('core.modify_text_for_display_after', compact($vars))); @@ -525,7 +525,7 @@ function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bb * @var bool allow_bbcode Whether or not to parse BBCode * @var bool allow_urls Whether or not to parse URLs * @var bool allow_smilies Whether or not to parse Smilies - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array( 'text', @@ -573,7 +573,7 @@ function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bb * @var string uid The BBCode UID * @var string bitfield The BBCode Bitfield * @var int flags The BBCode Flags - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('text', 'uid', 'bitfield', 'flags'); extract($phpbb_dispatcher->trigger_event('core.modify_text_for_storage_after', compact($vars))); @@ -596,7 +596,7 @@ function generate_text_for_edit($text, $uid, $flags) * @var string text The text to parse * @var string uid The BBCode UID * @var int flags The BBCode Flags - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('text', 'uid', 'flags'); extract($phpbb_dispatcher->trigger_event('core.modify_text_for_edit_before', compact($vars))); @@ -609,7 +609,7 @@ function generate_text_for_edit($text, $uid, $flags) * @event core.modify_text_for_edit_after * @var string text The text to parse * @var int flags The BBCode Flags - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('text', 'flags'); extract($phpbb_dispatcher->trigger_event('core.modify_text_for_edit_after', compact($vars))); @@ -1416,7 +1416,7 @@ function get_username_string($mode, $user_id, $username, $username_colour = '', * profile url. * @var string username_string The string that has been generated * @var array _profile_cache Array of original return templates - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array( 'mode', diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 2b11d00f1e..acbcb57c36 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -138,7 +138,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod * * @event core.display_forums_modify_sql * @var array sql_ary The SQL array to get the data of the forums - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('sql_ary'); extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_sql', compact($vars))); @@ -161,7 +161,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod * @event core.display_forums_modify_row * @var int branch_root_id Last top-level forum * @var array row The data of the forum - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('branch_root_id', 'row'); extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_row', compact($vars))); @@ -318,7 +318,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod * @var int branch_root_id Current top-level forum * @var int parent_id Current parent forum * @var array row The data of the forum - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('forum_rows', 'subforums', 'branch_root_id', 'parent_id', 'row'); extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_forum_rows', compact($vars))); @@ -568,7 +568,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod * @event core.display_forums_modify_template_vars * @var array forum_row Template data of the forum * @var array row The data of the forum - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('forum_row', 'row'); extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_template_vars', compact($vars))); @@ -975,7 +975,7 @@ function display_custom_bbcodes() * @event core.display_custom_bbcodes_modify_row * @var array custom_tags Template data of the bbcode * @var array row The data of the bbcode - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('custom_tags', 'row'); extract($phpbb_dispatcher->trigger_event('core.display_custom_bbcodes_modify_row', compact($vars))); @@ -990,7 +990,7 @@ function display_custom_bbcodes() * Display custom bbcodes * * @event core.display_custom_bbcodes - * @since 3.1-A1 + * @since 3.1.0-a1 */ $phpbb_dispatcher->dispatch('core.display_custom_bbcodes'); } diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 7dbcae7f6e..09b9434a2d 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -133,7 +133,7 @@ function generate_smilies($mode, $forum_id) * @var string mode Mode of the smilies: window|inline * @var int forum_id The forum ID we are currently in * @var bool display_link Shall we display the "more smilies" link? - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('mode', 'forum_id', 'display_link'); extract($phpbb_dispatcher->trigger_event('core.generate_smilies_after', compact($vars))); diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 6682622d94..e44aa4dacd 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -143,7 +143,7 @@ function user_update_name($old_name, $new_name) * @event core.update_username * @var string old_name The old username that is replaced * @var string new_name The new username - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('old_name', 'new_name'); extract($phpbb_dispatcher->trigger_event('core.update_username', compact($vars))); @@ -259,7 +259,7 @@ function user_add($user_row, $cp_data = false) * * @event core.user_add_modify_data * @var array sql_ary Array of data to be inserted when a user is added - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('sql_ary'); extract($phpbb_dispatcher->trigger_event('core.user_add_modify_data', compact($vars))); @@ -386,7 +386,7 @@ function user_delete($mode, $user_ids, $retain_username = true) * @var array user_ids IDs of the deleted user * @var mixed retain_username True if username should be retained * or false if not - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('mode', 'user_ids', 'retain_username'); extract($phpbb_dispatcher->trigger_event('core.delete_user_before', compact($vars))); @@ -615,7 +615,7 @@ function user_delete($mode, $user_ids, $retain_username = true) * @var array user_ids IDs of the deleted user * @var mixed retain_username True if username should be retained * or false if not - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('mode', 'user_ids', 'retain_username'); extract($phpbb_dispatcher->trigger_event('core.delete_user_after', compact($vars))); @@ -2504,7 +2504,7 @@ function group_delete($group_id, $group_name = false) * @event core.delete_group_after * @var int group_id ID of the deleted group * @var string group_name Name of the deleted group - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('group_id', 'group_name'); extract($phpbb_dispatcher->trigger_event('core.delete_group_after', compact($vars))); @@ -2752,7 +2752,7 @@ function group_user_del($group_id, $user_id_ary = false, $username_ary = false, * @var string group_name Name of the group * @var array user_id_ary IDs of the users which are removed * @var array username_ary names of the users which are removed - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('group_id', 'group_name', 'user_id_ary', 'username_ary'); extract($phpbb_dispatcher->trigger_event('core.group_delete_user_before', compact($vars))); @@ -3198,7 +3198,7 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal * @var array group_attributes Group attributes which were changed * @var array update_listing Update the list of moderators and foes * @var array sql_ary User attributes which were changed - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('group_id', 'user_id_ary', 'group_attributes', 'update_listing', 'sql_ary'); extract($phpbb_dispatcher->trigger_event('core.user_set_default_group', compact($vars))); diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index 7c1c61dae7..e4603ad0ce 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -302,7 +302,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) * @event core.mcp_view_forum_modify_topicrow * @var array row Array with topic data * @var array topic_row Template array with topic data - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('row', 'topic_row'); extract($phpbb_dispatcher->trigger_event('core.mcp_view_forum_modify_topicrow', compact($vars))); diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index 44a6982a8e..2911eb57bc 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -248,7 +248,7 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) * @var array message_row Array with message data * @var array cp_row Array with senders custom profile field data * @var array msg_data Template array with message data - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array( 'id', diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index e80cc2dce3..e3339c4c0b 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -64,7 +64,7 @@ class ucp_prefs * @var bool submit Do we display the form only * or did the user press submit * @var array data Array with current ucp options data - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('submit', 'data'); extract($phpbb_dispatcher->trigger_event('core.ucp_prefs_personal_data', compact($vars))); @@ -113,7 +113,7 @@ class ucp_prefs * @event core.ucp_prefs_personal_update_data * @var array data Submitted display options data * @var array sql_ary Display options data we udpate - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('data', 'sql_ary'); extract($phpbb_dispatcher->trigger_event('core.ucp_prefs_personal_update_data', compact($vars))); @@ -243,7 +243,7 @@ class ucp_prefs * @var bool submit Do we display the form only * or did the user press submit * @var array data Array with current ucp options data - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('submit', 'data'); extract($phpbb_dispatcher->trigger_event('core.ucp_prefs_view_data', compact($vars))); @@ -292,7 +292,7 @@ class ucp_prefs * @event core.ucp_prefs_view_update_data * @var array data Submitted display options data * @var array sql_ary Display options data we udpate - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('data', 'sql_ary'); extract($phpbb_dispatcher->trigger_event('core.ucp_prefs_view_update_data', compact($vars))); @@ -394,7 +394,7 @@ class ucp_prefs * @var bool submit Do we display the form only * or did the user press submit * @var array data Array with current ucp options data - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('submit', 'data'); extract($phpbb_dispatcher->trigger_event('core.ucp_prefs_post_data', compact($vars))); @@ -418,7 +418,7 @@ class ucp_prefs * @event core.ucp_prefs_post_update_data * @var array data Submitted display options data * @var array sql_ary Display options data we udpate - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('data', 'sql_ary'); extract($phpbb_dispatcher->trigger_event('core.ucp_prefs_post_update_data', compact($vars))); diff --git a/phpBB/includes/ucp/ucp_zebra.php b/phpBB/includes/ucp/ucp_zebra.php index 090f9bf34c..3bbbdb6726 100644 --- a/phpBB/includes/ucp/ucp_zebra.php +++ b/phpBB/includes/ucp/ucp_zebra.php @@ -62,7 +62,7 @@ class ucp_zebra * @event core.ucp_remove_zebra * @var string mode Zebra type: friends|foes * @var array user_ids User ids we remove - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('mode', 'user_ids'); extract($phpbb_dispatcher->trigger_event('core.ucp_remove_zebra', compact($vars))); @@ -207,7 +207,7 @@ class ucp_zebra * friends|foes * @var array sql_ary Array of * entries we add - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('mode', 'sql_ary'); extract($phpbb_dispatcher->trigger_event('core.ucp_add_zebra', compact($vars))); diff --git a/phpBB/index.php b/phpBB/index.php index 32bc118e8c..716b6c99a0 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -188,7 +188,7 @@ $page_title = $user->lang['INDEX']; * * @event core.index_modify_page_title * @var string page_title Title of the index page -* @since 3.1-A1 +* @since 3.1.0-a1 */ $vars = array('page_title'); extract($phpbb_dispatcher->trigger_event('core.index_modify_page_title', compact($vars))); diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 7f78e694b9..dd886a4014 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -601,7 +601,7 @@ switch ($mode) * enabled? * @var bool friend Is the user friend? * @var bool foe Is the user foe? - * @since 3.1-A1 + * @since 3.1.0-a1 * @changed 3.1.0-b2 Added friend and foe status */ $vars = array( @@ -1764,7 +1764,7 @@ function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = f * @event core.memberlist_prepare_profile_data * @var array data Array with user's data * @var array template_data Template array with user's data - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('data', 'template_data'); extract($phpbb_dispatcher->trigger_event('core.memberlist_prepare_profile_data', compact($vars))); diff --git a/phpBB/phpbb/log/log.php b/phpBB/phpbb/log/log.php index ea04344c59..d1a09f9a2b 100644 --- a/phpBB/phpbb/log/log.php +++ b/phpBB/phpbb/log/log.php @@ -305,7 +305,7 @@ class log implements \phpbb\log\log_interface * @var array sql_ary Array with log data we insert into the * database. If sql_ary[log_type] is not set, * we won't add the entry to the database. - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array( 'mode', @@ -411,7 +411,7 @@ class log implements \phpbb\log\log_interface * is false, no entries will be returned. * @var string sql_additional Additional conditions for the entries, * e.g.: 'AND l.forum_id = 1' - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array( 'mode', @@ -521,7 +521,7 @@ class log implements \phpbb\log\log_interface * @event core.get_logs_modify_entry_data * @var array row Entry data from the database * @var array log_entry_data Entry's data which is returned - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('row', 'log_entry_data'); extract($this->dispatcher->trigger_event('core.get_logs_modify_entry_data', compact($vars))); @@ -598,7 +598,7 @@ class log implements \phpbb\log\log_interface * get the permission data * @var array reportee_id_list Array of additional user IDs we * get the username strings for - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('log', 'topic_id_list', 'reportee_id_list'); extract($this->dispatcher->trigger_event('core.get_logs_get_additional_data', compact($vars))); diff --git a/phpBB/phpbb/permissions.php b/phpBB/phpbb/permissions.php index a3fddb0b9e..3cf39b5126 100644 --- a/phpBB/phpbb/permissions.php +++ b/phpBB/phpbb/permissions.php @@ -57,7 +57,7 @@ class permissions * 'lang' => 'ACL_U_VIEWPROFILE', * 'cat' => 'profile', * ), - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('types', 'categories', 'permissions'); extract($phpbb_dispatcher->trigger_event('core.permissions', compact($vars))); diff --git a/phpBB/phpbb/user.php b/phpBB/phpbb/user.php index 417cc71fd3..18b7a3d096 100644 --- a/phpBB/phpbb/user.php +++ b/phpBB/phpbb/user.php @@ -143,7 +143,7 @@ class user extends \phpbb\session * that are absolutely needed globally using this * event. Use local events otherwise. * @var mixed style_id Style we are going to display - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array( 'user_data', diff --git a/phpBB/posting.php b/phpBB/posting.php index 11f0898440..cfd6524e62 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -80,7 +80,7 @@ $current_time = time(); * form submission. * NOTE: Should be actual language strings, NOT * language keys. -* @since 3.1-A1 +* @since 3.1.0-a1 */ $vars = array( 'post_id', @@ -1573,7 +1573,7 @@ $template->assign_vars(array( * this is "multipart/form-data" else it is the empty string * @var string s_action The URL to submit the POST data to * @var string s_hidden_fields The concatenated input tags of the form's hidden fields -* @since 3.1-A1 +* @since 3.1.0-a1 * @change 3.1.0-b3 Added vars post_data, moderators, mode, page_title, s_topic_icons, form_enctype, s_action, s_hidden_fields */ $vars = array( diff --git a/phpBB/search.php b/phpBB/search.php index fbb4e93089..6364539ab3 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -681,7 +681,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) * @var string sql_select The SQL SELECT string used by search to get topic data * @var string sql_from The SQL FROM string used by search to get topic data * @var string sql_where The SQL WHERE string used by search to get topic data - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('sql_select', 'sql_from', 'sql_where'); extract($phpbb_dispatcher->trigger_event('core.search_get_topic_data', compact($vars))); @@ -1004,7 +1004,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) * @event core.search_modify_tpl_ary * @var array row Array with topic data * @var array tpl_ary Template block array with topic data - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('row', 'tpl_ary'); extract($phpbb_dispatcher->trigger_event('core.search_modify_tpl_ary', compact($vars))); diff --git a/phpBB/ucp.php b/phpBB/ucp.php index eaa40a07a2..73eaeaa127 100644 --- a/phpBB/ucp.php +++ b/phpBB/ucp.php @@ -337,7 +337,7 @@ if (!$config['allow_topic_notify'] && !$config['allow_forum_notify']) * @var p_master module Object holding all modules and their status * @var mixed id Active module category (can be the int or string) * @var string mode Active module -* @since 3.1-A1 +* @since 3.1.0-a1 */ $vars = array('module', 'id', 'mode'); extract($phpbb_dispatcher->trigger_event('core.ucp_display_module_before', compact($vars))); diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index a7396f9c72..552f8dfa8b 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -387,7 +387,7 @@ $sql_array = array( * * @event core.viewforum_get_topic_data * @var array sql_array The SQL array to get the data of all topics -* @since 3.1-A1 +* @since 3.1.0-a1 */ $vars = array('sql_array'); extract($phpbb_dispatcher->trigger_event('core.viewforum_get_topic_data', compact($vars))); @@ -582,7 +582,7 @@ if (sizeof($shadow_topic_list)) * * @event core.viewforum_get_shadowtopic_data * @var array sql_array SQL array to get the data of any shadowtopics - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('sql_array'); extract($phpbb_dispatcher->trigger_event('core.viewforum_get_shadowtopic_data', compact($vars))); @@ -819,7 +819,7 @@ if (sizeof($topic_list)) * @event core.viewforum_modify_topicrow * @var array row Array with topic data * @var array topic_row Template array with topic data - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('row', 'topic_row'); extract($phpbb_dispatcher->trigger_event('core.viewforum_modify_topicrow', compact($vars))); diff --git a/phpBB/viewonline.php b/phpBB/viewonline.php index 1738005786..9b462b2656 100644 --- a/phpBB/viewonline.php +++ b/phpBB/viewonline.php @@ -143,7 +143,7 @@ $sql_ary = array( * @var bool show_guests Do we display guests in the list * @var int guest_counter Number of guests displayed * @var array forum_data Array with forum data -* @since 3.1-A1 +* @since 3.1.0-a1 * @change 3.1.0-a2 Added vars guest_counter and forum_data */ $vars = array('sql_ary', 'show_guests', 'guest_counter', 'forum_data'); @@ -351,7 +351,7 @@ while ($row = $db->sql_fetchrow($result)) * @var string location Page name to displayed in the list * @var string location_url Page url to displayed in the list * @var array forum_data Array with forum data - * @since 3.1-A1 + * @since 3.1.0-a1 * @change 3.1.0-a2 Added var forum_data */ $vars = array('on_page', 'row', 'location', 'location_url', 'forum_data'); diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 0dbda7564f..76e20b8492 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -997,7 +997,7 @@ $sql_ary = array( * @var string sort_dir Direction the posts are sorted by * @var int start Pagination information * @var array sql_ary The SQL array to get the data of posts and posters -* @since 3.1-A1 +* @since 3.1.0-a1 * @change 3.1.0-a2 Added vars forum_id, topic_id, topic_data, post_list, sort_days, sort_key, sort_dir, start */ $vars = array( @@ -1083,7 +1083,7 @@ while ($row = $db->sql_fetchrow($result)) * @event core.viewtopic_post_rowset_data * @var array rowset_data Array with the rowset data for this post * @var array row Array with original user and post data - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('rowset_data', 'row'); extract($phpbb_dispatcher->trigger_event('core.viewtopic_post_rowset_data', compact($vars))); @@ -1139,7 +1139,7 @@ while ($row = $db->sql_fetchrow($result)) * @var array user_cache_data Array with the user's data * @var int poster_id Poster's user id * @var array row Array with original user and post data - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('user_cache_data', 'poster_id', 'row'); extract($phpbb_dispatcher->trigger_event('core.viewtopic_cache_guest_data', compact($vars))); @@ -1199,7 +1199,7 @@ while ($row = $db->sql_fetchrow($result)) * @var array user_cache_data Array with the user's data * @var int poster_id Poster's user id * @var array row Array with original user and post data - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('user_cache_data', 'poster_id', 'row'); extract($phpbb_dispatcher->trigger_event('core.viewtopic_cache_user_data', compact($vars))); @@ -1685,7 +1685,7 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) * @var array user_poster_data Poster's data from user cache * @var array post_row Template block array of the post * @var array topic_data Array with topic data - * @since 3.1-A1 + * @since 3.1.0-a1 * @change 3.1.0-a3 Added vars start, current_row_number, end, attachments * @change 3.1.0-b3 Added topic_data array, total_posts */ @@ -1916,7 +1916,7 @@ $page_title = $topic_data['topic_title'] . ($start ? ' - ' . sprintf($user->lang * @var array topic_data Array with topic data * @var int forum_id Forum ID of the topic * @var int start Start offset used to calculate the page -* @since 3.1-A1 +* @since 3.1.0-a1 */ $vars = array('page_title', 'topic_data', 'forum_id', 'start'); extract($phpbb_dispatcher->trigger_event('core.viewtopic_modify_page_title', compact($vars))); From 48278f122cf9a2b23c39eccdd998b0c9b0552b2a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 25 Apr 2014 12:31:57 +0200 Subject: [PATCH 38/55] [ticket/12273] Do not allow 3.1-A1 version PHPBB3-12273 --- phpBB/phpbb/event/php_exporter.php | 18 +++++------------- tests/event/fixtures/trigger_many_vars.test | 2 +- tests/event/php_exporter_test.php | 15 ++++++--------- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 2a69f15802..ac88ffa8b5 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -544,23 +544,15 @@ class php_exporter */ public function validate_since($line) { - $since = substr(ltrim($line, "\t"), strlen('* @since ')); - - if ($since !== trim($since)) + $match = array(); + preg_match('#^\* @since (\d+\.\d+\.\d+(?:-(?:a|b|rc|pl)\d+)?)$#', ltrim($line, "\t"), $match); + if (!isset($match[1])) { throw new \LogicException("Invalid '@since' information for event " - . "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 1); + . "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'"); } - $since = ($since === '3.1-A1') ? '3.1.0-a1' : $since; - - if (!preg_match('#^\d+\.\d+\.\d+(?:-(?:a|b|rc|pl)\d+)?$#', $since)) - { - throw new \LogicException("Invalid '@since' information for event " - . "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 2); - } - - return $since; + return $match[1]; } /** diff --git a/tests/event/fixtures/trigger_many_vars.test b/tests/event/fixtures/trigger_many_vars.test index da72f4c57f..a624138588 100644 --- a/tests/event/fixtures/trigger_many_vars.test +++ b/tests/event/fixtures/trigger_many_vars.test @@ -33,7 +33,7 @@ * @var array page_data Posting page data that should be passed to the * posting page via $template->assign_vars() * @var object message_parser The message parser object - * @since 3.1-A1 + * @since 3.1.0-a1 * @change 3.1.0-b3 Added vars post_data, moderators, mode, page_title, * s_topic_icons, form_enctype, s_action, s_hidden_fields, * post_id, topic_id, forum_id, submit, preview, save, load, diff --git a/tests/event/php_exporter_test.php b/tests/event/php_exporter_test.php index 03f6974af1..9917f8309b 100644 --- a/tests/event/php_exporter_test.php +++ b/tests/event/php_exporter_test.php @@ -114,7 +114,6 @@ class phpbb_event_php_exporter_test extends phpbb_test_case array('* @since 3.1.0-a1', '3.1.0-a1'), array('* @since 3.1.0-b3', '3.1.0-b3'), array(' * @since 3.1.0-b3', '3.1.0-b3'), - array('* @since 3.1-A1', '3.1.0-a1'), ); } @@ -129,12 +128,11 @@ class phpbb_event_php_exporter_test extends phpbb_test_case static public function validate_since_throws_data() { return array( - array(' * @since 3.1.0-a1', 1), - array('* @since 3.1.0-a1 ', 1), - array('* @since 3.1.0-a1 bertie is cool', 2), - array('bertie* @since 3.1.0-a1', 2), - array('* @since 3.1-A2', 2), - array('* @since 3.1-B3', 2), + array(' * @since 3.1.0-a1'), + array('* @since 3.1.0-a1 '), + array('* @since 3.1.0-a1 bertie is cool'), + array('bertie* @since 3.1.0-a1'), + array('* @since 3.1-A2'), ); } @@ -142,9 +140,8 @@ class phpbb_event_php_exporter_test extends phpbb_test_case * @dataProvider validate_since_throws_data * @expectedException LogicException */ - public function test_validate_since_throws($since, $exception_code) + public function test_validate_since_throws($since) { - $this->setExpectedException('LogicException', '', $exception_code); $this->exporter->validate_since($since); } From 3bcda97e28f096558baa46be63e8bb40f43c59c8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 25 Apr 2014 12:37:39 +0200 Subject: [PATCH 39/55] [ticket/12273] Sort arguments alphabetically before exporting PHPBB3-12273 --- phpBB/phpbb/event/php_exporter.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index ac88ffa8b5..a92bd2671d 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -223,6 +223,7 @@ class php_exporter . "'{$this->events[$this->current_event]['file']}'", 10); } + sort($arguments); $this->events[$this->current_event] = array( 'event' => $this->current_event, 'file' => $this->current_file, From 18be18e9989dcd48b662c5bb2bd128ca947f68d3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 25 Apr 2014 20:26:47 +0200 Subject: [PATCH 40/55] [ticket/12273] Do not allow 3.1-A1 for template events PHPBB3-12273 --- phpBB/phpbb/event/md_exporter.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index 708900c693..4940094e77 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -209,8 +209,6 @@ class md_exporter */ public function validate_since($since) { - $since = ($since === '3.1-A1') ? '3.1.0-a1' : $since; - if (!preg_match('#^\d+\.\d+\.\d+(?:-(?:a|b|rc|pl)\d+)?$#', $since)) { throw new \LogicException("Invalid since information found for event '{$this->current_event}'"); From 6aa8596d4dc206797e4740465e3035c65bcdba3f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 26 Apr 2014 16:30:19 +0200 Subject: [PATCH 41/55] [ticket/12273] Fix doc blocks PHPBB3-12273 --- phpBB/phpbb/event/md_exporter.php | 20 +++++++++++++++----- phpBB/phpbb/event/php_exporter.php | 21 ++++++++++++++++++++- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index 4940094e77..540ec9a0d7 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -40,6 +40,11 @@ class md_exporter $this->filter = $this->current_event = ''; } + /** + * Get the list of all events + * + * @return array Array with events: name => details + */ public function get_events() { return $this->events; @@ -47,7 +52,6 @@ class md_exporter /** * @param string $md_file - * @param string $filter * @return int Number of events found * @throws \LogicException */ @@ -67,7 +71,6 @@ class md_exporter /** * @param string $md_file - * @param string $filter * @return int Number of events found * @throws \LogicException */ @@ -279,6 +282,13 @@ class md_exporter return $files_list; } + /** + * Get all template events in a template file + * + * @param string $file + * @return array + * @throws \LogicException + */ public function crawl_file_for_events($file) { if (!file_exists($this->root_path . $file)) @@ -294,8 +304,8 @@ class md_exporter array_shift($events); foreach ($events as $event) { - list($event_name, $null) = explode(' -->', $event, 2); - $event_list[] = $event_name; + $event = explode(' -->', $event, 2); + $event_list[] = array_shift($event); } return $event_list; @@ -306,7 +316,7 @@ class md_exporter * * @param string $file * @param array $events - * @return null + * @return true * @throws \LogicException */ public function validate_events_from_file($file, array $events) diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index a92bd2671d..41058216e8 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -46,17 +46,35 @@ class php_exporter $this->current_event_line = 0; } + /** + * Get the list of all events + * + * @return array Array with events: name => details + */ public function get_events() { return $this->events; } + /** + * Set current event data + * + * @param string $name Name of the current event (used for error messages) + * @param int $line Line where the current event is placed in + * @return null + */ public function set_current_event($name, $line) { $this->current_event = $name; $this->current_event_line = $line; } + /** + * Set the content of this file + * + * @param array $content Array with the lines of the file + * @return null + */ public function set_content($content) { $this->file_lines = $content; @@ -322,6 +340,8 @@ class php_exporter * Find the variables in single line array * * @param string $line + * @param bool $throw_multiline Throw an exception when there are too + * many arguments in one line. * @return array List of variables * @throws \LogicException */ @@ -349,7 +369,6 @@ class php_exporter /** * Find the variables in single line array * - * @param string $line * @return array List of variables * @throws \LogicException */ From 7a44f66448fcdc53ed3c371c25317e553217eec8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 26 Apr 2014 16:59:18 +0200 Subject: [PATCH 42/55] [ticket/12273] Use RecursiveDirectoryIterator in md_exporter PHPBB3-12273 --- phpBB/phpbb/event/md_exporter.php | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index 540ec9a0d7..cb14ff5778 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -377,14 +377,21 @@ class md_exporter * Works recursive with any depth * * @param string $dir Directory to go through - * @param string $path Path from root to $dir * @return array List of files (including directories) */ - public function get_recursive_file_list($dir, $path = '') + public function get_recursive_file_list($dir) { try { - $iterator = new \DirectoryIterator($dir); + $iterator = new \RecursiveIteratorIterator( + new \phpbb\recursive_dot_prefix_filter_iterator( + new \RecursiveDirectoryIterator( + $dir, + \FilesystemIterator::SKIP_DOTS + ) + ), + \RecursiveIteratorIterator::SELF_FIRST + ); } catch (\Exception $e) { @@ -394,24 +401,17 @@ class md_exporter $files = array(); foreach ($iterator as $file_info) { - /** @var \DirectoryIterator $file_info */ - if ($file_info->isDot()) + /** @var \RecursiveDirectoryIterator $file_info */ + if ($file_info->isDir()) { continue; } - // Do not scan some directories - if ($file_info->isDir()) + $relative_path = $iterator->getInnerIterator()->getSubPathname(); + + if (substr($relative_path, -5) == '.html') { - $sub_dir = $this->get_recursive_file_list($file_info->getPath() . '/' . $file_info->getFilename(), $path . '/' . $file_info->getFilename()); - foreach ($sub_dir as $file) - { - $files[] = $file_info->getFilename() . '/' . $file; - } - } - else if (substr($file_info->getFilename(), -5) == '.html') - { - $files[] = $file_info->getFilename(); + $files[] = str_replace(DIRECTORY_SEPARATOR, '/', $relative_path); } } From 927c219b1fc1cc69f724827771d567384b2cda8c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 26 Apr 2014 18:04:47 +0200 Subject: [PATCH 43/55] [ticket/12273] Use RecursiveDirectoryIterator with filter in php_exporter PHPBB3-12273 --- phpBB/phpbb/event/php_exporter.php | 56 +++++-------------- .../event/recursive_event_filter_iterator.php | 45 +++++++++++++++ 2 files changed, 59 insertions(+), 42 deletions(-) create mode 100644 phpBB/phpbb/event/recursive_event_filter_iterator.php diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 41058216e8..8e4a9d399d 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -100,17 +100,22 @@ class php_exporter /** * Returns a list of files in $dir * - * Works recursive with any depth - * * @param string $dir Directory to go through - * @param string $path Path from root to $dir - * @return array List of files (including directories) + * @return array List of files (including the path) */ - public function get_recursive_file_list($dir, $path = '') + public function get_recursive_file_list($dir) { try { - $iterator = new \DirectoryIterator($dir); + $iterator = new \RecursiveIteratorIterator( + new \phpbb\event\recursive_event_filter_iterator( + new \RecursiveDirectoryIterator( + $dir, + \FilesystemIterator::SKIP_DOTS + ) + ), + \RecursiveIteratorIterator::LEAVES_ONLY + ); } catch (\Exception $e) { @@ -120,42 +125,9 @@ class php_exporter $files = array(); foreach ($iterator as $file_info) { - /** @var \DirectoryIterator $file_info */ - if ($file_info->isDot()) - { - continue; - } - - // Do not scan some directories - if ($file_info->isDir() && ( - ($path == '' && in_array($file_info->getFilename(), array( - 'cache', - 'develop', - 'ext', - 'files', - 'language', - 'store', - 'vendor', - ))) - || ($path == '/includes' && in_array($file_info->getFilename(), array('utf'))) - || ($path == '/phpbb/db/migration' && in_array($file_info->getFilename(), array('data'))) - || ($path == '/phpbb' && in_array($file_info->getFilename(), array('event'))) - )) - { - continue; - } - else if ($file_info->isDir()) - { - $sub_dir = $this->get_recursive_file_list($file_info->getPath() . '/' . $file_info->getFilename(), $path . '/' . $file_info->getFilename()); - foreach ($sub_dir as $file) - { - $files[] = $file_info->getFilename() . '/' . $file; - } - } - else if (substr($file_info->getFilename(), -4) == '.php') - { - $files[] = $file_info->getFilename(); - } + /** @var \RecursiveDirectoryIterator $file_info */ + $relative_path = $iterator->getInnerIterator()->getSubPathname(); + $files[] = str_replace(DIRECTORY_SEPARATOR, '/', $relative_path); } return $files; diff --git a/phpBB/phpbb/event/recursive_event_filter_iterator.php b/phpBB/phpbb/event/recursive_event_filter_iterator.php new file mode 100644 index 0000000000..c520bdae4a --- /dev/null +++ b/phpBB/phpbb/event/recursive_event_filter_iterator.php @@ -0,0 +1,45 @@ +current()); + $filename = $this->current()->getFilename(); + + return (substr($relative_path, -4) === '.php' || $this->current()->isDir()) + && $filename[0] !== '.' + && strpos($relative_path, 'phpBB/cache/') !== 0 + && strpos($relative_path, 'phpBB/develop/') !== 0 + && strpos($relative_path, 'phpBB/ext/') !== 0 + && strpos($relative_path, 'phpBB/files/') !== 0 + && strpos($relative_path, 'phpBB/includes/utf/') !== 0 + && strpos($relative_path, 'phpBB/language/') !== 0 + && strpos($relative_path, 'phpBB/phpbb/db/migration/data/') !== 0 + && strpos($relative_path, 'phpBB/phpbb/event/') !== 0 + && strpos($relative_path, 'phpBB/store/') !== 0 + && strpos($relative_path, 'phpBB/vendor/') !== 0 + ; + } +} From e934cefe809b91b80db509916a0be4b64a3ad2a5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 27 Apr 2014 23:50:02 +0200 Subject: [PATCH 44/55] [ticket/12273] Fix missing classes in export_events_for_wiki.php PHPBB3-12273 --- phpBB/develop/export_events_for_wiki.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpBB/develop/export_events_for_wiki.php b/phpBB/develop/export_events_for_wiki.php index cc4aa4444f..2a8e4533e5 100644 --- a/phpBB/develop/export_events_for_wiki.php +++ b/phpBB/develop/export_events_for_wiki.php @@ -46,6 +46,8 @@ validate_argument_count($argc, 1); $action = $argv[1]; require __DIR__ . '/../phpbb/event/php_exporter.' . $phpEx; require __DIR__ . '/../phpbb/event/md_exporter.' . $phpEx; +require __DIR__ . '/../phpbb/event/recursive_event_filter_iterator.' . $phpEx; +require __DIR__ . '/../phpbb/recursive_dot_prefix_filter_iterator.' . $phpEx; switch ($action) { From dbac4bb5c07973a14469169a6bcc2feeb024306b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 27 Apr 2014 23:51:06 +0200 Subject: [PATCH 45/55] [ticket/12273] Add root path to recursive_event_filter_iterator PHPBB3-12273 --- phpBB/phpbb/event/php_exporter.php | 3 +- .../event/recursive_event_filter_iterator.php | 43 ++++++++++++++----- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 8e4a9d399d..e95426244b 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -112,7 +112,8 @@ class php_exporter new \RecursiveDirectoryIterator( $dir, \FilesystemIterator::SKIP_DOTS - ) + ), + $dir ), \RecursiveIteratorIterator::LEAVES_ONLY ); diff --git a/phpBB/phpbb/event/recursive_event_filter_iterator.php b/phpBB/phpbb/event/recursive_event_filter_iterator.php index c520bdae4a..970c4bbd04 100644 --- a/phpBB/phpbb/event/recursive_event_filter_iterator.php +++ b/phpBB/phpbb/event/recursive_event_filter_iterator.php @@ -20,6 +20,29 @@ namespace phpbb\event; */ class recursive_event_filter_iterator extends \RecursiveFilterIterator { + protected $root_path; + + /** + * Construct + * + * @param \RecursiveIterator $iterator + * @param string $root_path + */ + public function __construct(\RecursiveIterator $iterator, $root_path) + { + $this->root_path = str_replace(DIRECTORY_SEPARATOR, '/', $root_path); + parent::__construct($iterator); + } + + /** + * Return the inner iterator's children contained in a recursive_event_filter_iterator + * + * @return recursive_event_filter_iterator + */ + public function getChildren() { + return new self($this->getInnerIterator()->getChildren(), $this->root_path); + } + /** * {@inheritDoc} */ @@ -30,16 +53,16 @@ class recursive_event_filter_iterator extends \RecursiveFilterIterator return (substr($relative_path, -4) === '.php' || $this->current()->isDir()) && $filename[0] !== '.' - && strpos($relative_path, 'phpBB/cache/') !== 0 - && strpos($relative_path, 'phpBB/develop/') !== 0 - && strpos($relative_path, 'phpBB/ext/') !== 0 - && strpos($relative_path, 'phpBB/files/') !== 0 - && strpos($relative_path, 'phpBB/includes/utf/') !== 0 - && strpos($relative_path, 'phpBB/language/') !== 0 - && strpos($relative_path, 'phpBB/phpbb/db/migration/data/') !== 0 - && strpos($relative_path, 'phpBB/phpbb/event/') !== 0 - && strpos($relative_path, 'phpBB/store/') !== 0 - && strpos($relative_path, 'phpBB/vendor/') !== 0 + && strpos($relative_path, $this->root_path . 'cache/') !== 0 + && strpos($relative_path, $this->root_path . 'develop/') !== 0 + && strpos($relative_path, $this->root_path . 'ext/') !== 0 + && strpos($relative_path, $this->root_path . 'files/') !== 0 + && strpos($relative_path, $this->root_path . 'includes/utf/') !== 0 + && strpos($relative_path, $this->root_path . 'language/') !== 0 + && strpos($relative_path, $this->root_path . 'phpbb/db/migration/data/') !== 0 + && strpos($relative_path, $this->root_path . 'phpbb/event/') !== 0 + && strpos($relative_path, $this->root_path . 'store/') !== 0 + && strpos($relative_path, $this->root_path . 'vendor/') !== 0 ; } } From 35f8b7f5ea606fd59ccfa4600e806b37e170c63a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 27 Apr 2014 23:54:12 +0200 Subject: [PATCH 46/55] [ticket/12273] Fix table header for adm events PHPBB3-12273 --- phpBB/phpbb/event/md_exporter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index cb14ff5778..068207d08a 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -154,7 +154,7 @@ class md_exporter */ public function export_events_for_wiki() { - if ($this->filter === 'acp') + if ($this->filter === 'adm') { $wiki_page = '= ACP Template Events =' . "\n"; $wiki_page .= '{| class="zebra sortable" cellspacing="0" cellpadding="5"' . "\n"; From bf8b9f01437b4b6bff3e27291eafcd73dbcbdb0c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 28 Apr 2014 00:06:14 +0200 Subject: [PATCH 47/55] [ticket/12273] Remove old parameter from function call PHPBB3-12273 --- phpBB/phpbb/event/md_exporter.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index 068207d08a..415f001ac1 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -59,7 +59,7 @@ class md_exporter { $this->crawl_eventsmd($md_file, 'adm'); - $file_list = $this->get_recursive_file_list($this->root_path . 'adm/style/', 'adm/style/'); + $file_list = $this->get_recursive_file_list($this->root_path . 'adm/style/'); foreach ($file_list as $file) { $file_name = 'adm/style/' . $file; @@ -82,8 +82,7 @@ class md_exporter foreach ($styles as $style) { $file_list = $this->get_recursive_file_list( - $this->root_path . 'styles/' . $style . '/template/', - 'styles/' . $style . '/template/' + $this->root_path . 'styles/' . $style . '/template/' ); foreach ($file_list as $file) From ed669982c2a8225e262d57b60f5654658799becd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 28 Apr 2014 21:03:59 +0200 Subject: [PATCH 48/55] [ticket/12273] Allow to filter events for extensions PHPBB3-12273 --- phpBB/phpbb/event/md_exporter.php | 48 ++++++++++++++++++++---------- phpBB/phpbb/event/php_exporter.php | 26 +++++++++++----- 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index 415f001ac1..574827ac44 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -17,7 +17,10 @@ namespace phpbb\event; */ class md_exporter { - /** @var string */ + /** @var string Path where we look for files*/ + protected $path; + + /** @var string phpBB Root Path */ protected $root_path; /** @var string */ @@ -51,15 +54,22 @@ class md_exporter } /** - * @param string $md_file + * @param string $md_file Relative from phpBB root + * @param mixed $extension String 'vendor/ext' to filter, null for phpBB core * @return int Number of events found * @throws \LogicException */ - public function crawl_phpbb_directory_adm($md_file) + public function crawl_phpbb_directory_adm($md_file, $extension = null) { - $this->crawl_eventsmd($md_file, 'adm'); + $this->path = $this->root_path; + if ($extension) + { + $this->path .= 'ext/' . $extension . '/'; + } - $file_list = $this->get_recursive_file_list($this->root_path . 'adm/style/'); + $this->crawl_eventsmd($md_file, 'adm', $extension); + + $file_list = $this->get_recursive_file_list($this->path . 'adm/style/'); foreach ($file_list as $file) { $file_name = 'adm/style/' . $file; @@ -70,19 +80,26 @@ class md_exporter } /** - * @param string $md_file + * @param string $md_file Relative from phpBB root + * @param mixed $extension String 'vendor/ext' to filter, null for phpBB core * @return int Number of events found * @throws \LogicException */ - public function crawl_phpbb_directory_styles($md_file) + public function crawl_phpbb_directory_styles($md_file, $extension = null) { - $this->crawl_eventsmd($md_file, 'styles'); + $this->path = $this->root_path; + if ($extension) + { + $this->path .= 'ext/' . $extension . '/'; + } + + $this->crawl_eventsmd($md_file, 'styles', $extension); $styles = array('prosilver', 'subsilver2'); foreach ($styles as $style) { $file_list = $this->get_recursive_file_list( - $this->root_path . 'styles/' . $style . '/template/' + $this->path . 'styles/' . $style . '/template/' ); foreach ($file_list as $file) @@ -96,12 +113,13 @@ class md_exporter } /** - * @param string $md_file - * @param string $filter + * @param string $md_file Relative from phpBB root + * @param string $filter Should be 'styles' or 'adm' + * @param mixed $extension String 'vendor/ext' to filter, null for phpBB core * @return int Number of events found * @throws \LogicException */ - public function crawl_eventsmd($md_file, $filter) + public function crawl_eventsmd($md_file, $filter, $extension = null) { $file_content = file_get_contents($this->root_path . $md_file); $this->filter = $filter; @@ -241,7 +259,7 @@ class md_exporter $files = explode("\n + ", $file_details); foreach ($files as $file) { - if (!file_exists($this->root_path . $file)) + if (!file_exists($this->path . $file)) { throw new \LogicException("Invalid file '{$file}' not found for event '{$this->current_event}'", 1); } @@ -290,13 +308,13 @@ class md_exporter */ public function crawl_file_for_events($file) { - if (!file_exists($this->root_path . $file)) + if (!file_exists($this->path . $file)) { throw new \LogicException("File '{$file}' does not exist", 1); } $event_list = array(); - $file_content = file_get_contents($this->root_path . $file); + $file_content = file_get_contents($this->path . $file); $events = explode('