Merge branch 'develop-ascraeus' into develop

* develop-ascraeus: (55 commits)
  [ticket/12273] Move $extension to constructor so the path is always set
  [ticket/12273] Find events.md relative from the path not the phpbb root
  [ticket/12273] Do not look in extensions docs/ and tests/ directory
  [ticket/12273] Also check file for adm "Location:" events
  [ticket/12273] Do not allow template events in non-html files
  [ticket/12273] Fix return description
  [ticket/12273] Update exporter to allow specifying an extension
  [ticket/12273] Allow to filter events for extensions
  [ticket/12273] Remove old parameter from function call
  [ticket/12273] Fix table header for adm events
  [ticket/12273] Add root path to recursive_event_filter_iterator
  [ticket/12273] Fix missing classes in export_events_for_wiki.php
  [ticket/12273] Use RecursiveDirectoryIterator with filter in php_exporter
  [ticket/12273] Use RecursiveDirectoryIterator in md_exporter
  [ticket/12273] Fix doc blocks
  [ticket/12273] Do not allow 3.1-A1 for template events
  [ticket/12273] Sort arguments alphabetically before exporting
  [ticket/12273] Do not allow 3.1-A1 version
  [ticket/12273] Update since version to 3.1.0-a* style
  [ticket/12273] Update existing events
  ...
This commit is contained in:
Nils Adermann 2014-05-02 12:25:04 +02:00
commit 5f76c8be07
44 changed files with 2463 additions and 399 deletions

View file

@ -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');

View file

@ -16,291 +16,28 @@ $phpbb_root_path = __DIR__ . '/../';
function usage()
{
echo "Usage: export_events_for_wiki.php COMMAND\n";
echo "Usage: export_events_for_wiki.php COMMAND [EXTENSION]\n";
echo "\n";
echo "acp:\n";
echo " Export all events for files in the acp style.\n";
echo "COMMAND:\n";
echo " all:\n";
echo " Generate the complete wikipage for https://wiki.phpbb.com/Event_List\n";
echo "\n";
echo "styles:\n";
echo " Export all events for files in the prosilver and subsilver2 styles.\n";
echo " php:\n";
echo " Generate the PHP event section of Event_List\n";
echo "\n";
echo " adm:\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";
echo "EXTENSION (Optional):\n";
echo " If not given, only core events will be exported.\n";
echo " Otherwise only events from the extension will be exported.\n";
echo "\n";
echo "php:\n";
echo " Export all events for php-files.\n";
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,20 +49,51 @@ function validate_argument_count($arguments, $count)
validate_argument_count($argc, 1);
$action = $argv[1];
$extension = isset($argv[2]) ? $argv[2] : null;
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)
{
case 'acp':
export_from_eventsmd($phpbb_root_path, 'acp');
break;
case 'styles':
export_from_eventsmd($phpbb_root_path, 'styles');
break;
case 'all':
echo '__FORCETOC__' . "\n";
case 'php':
export_from_php($phpbb_root_path);
break;
$exporter = new \phpbb\event\php_exporter($phpbb_root_path, $extension);
$exporter->crawl_phpbb_directory_php();
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, $extension);
$exporter->crawl_phpbb_directory_styles('docs/events.md');
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, $extension);
$exporter->crawl_phpbb_directory_adm('docs/events.md');
echo $exporter->export_events_for_wiki();
if ($action === 'all')
{
echo "\n" . '[[Category:Events and Listeners]]' . "\n";
}
break;
default:
usage();

View file

@ -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 `<head>` 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
@ -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
@ -455,6 +455,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 `</body>` tag of the simple footer
@ -486,6 +487,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:
@ -581,16 +598,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

View file

@ -159,7 +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', 'bbcode_match', 'bbcode_tpl', '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);

View file

@ -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,9 +705,18 @@ 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', 'update', 'forum_id', 'row', 'forum_data', '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);
@ -946,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)));
@ -1054,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)));
@ -1347,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)));
@ -1385,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)));
@ -1489,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)));

View file

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

View file

@ -2004,7 +2004,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)));
@ -4726,7 +4726,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)));
@ -5091,7 +5091,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)));
@ -5199,7 +5199,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');
}

View file

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

View file

@ -753,7 +753,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', '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')
@ -910,7 +918,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', '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');
@ -928,7 +944,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', '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

View file

@ -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,9 +525,17 @@ 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', '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 = '';
@ -565,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)));
@ -588,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)));
@ -601,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)));
@ -1408,9 +1416,18 @@ 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', 'user_id', 'username', 'username_colour', 'guest_username', '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;

View file

@ -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)));
@ -974,7 +974,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)));
@ -989,7 +989,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');
}

View file

@ -410,7 +410,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)));

View file

@ -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)));
@ -1496,7 +1496,17 @@ 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')
@ -2362,7 +2372,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)));

View file

@ -1587,7 +1587,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.

View file

@ -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)));
@ -2512,7 +2512,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)));
@ -2760,7 +2760,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)));
@ -3206,7 +3206,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)));

View file

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

View file

@ -248,9 +248,18 @@ 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', '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);

View file

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

View file

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

View file

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

View file

@ -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)
{
@ -266,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

View file

@ -601,10 +601,19 @@ 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('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',
'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));
@ -1755,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)));

View file

@ -0,0 +1,439 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\event;
/**
* Class md_exporter
* Crawls through a markdown file and grabs all events
*
* @package phpbb\event
*/
class md_exporter
{
/** @var string Path where we look for files*/
protected $path;
/** @var string phpBB Root Path */
protected $root_path;
/** @var string */
protected $filter;
/** @var string */
protected $current_event;
/** @var array */
protected $events;
/**
* @param string $phpbb_root_path
* @param mixed $extension String 'vendor/ext' to filter, null for phpBB core
*/
public function __construct($phpbb_root_path, $extension = null)
{
$this->root_path = $phpbb_root_path;
$this->path = $this->root_path;
if ($extension)
{
$this->path .= 'ext/' . $extension . '/';
}
$this->events = array();
$this->events_by_file = array();
$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;
}
/**
* @param string $md_file Relative from phpBB root
* @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->path . '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 Relative from phpBB root
* @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->path . '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 Relative from phpBB root
* @param string $filter Should be 'styles' or 'adm'
* @return int Number of events found
* @throws \LogicException
*/
public function crawl_eventsmd($md_file, $filter)
{
if (!file_exists($this->path . $md_file))
{
throw new \LogicException("The event docs file '{$md_file}' could not be found");
}
$file_content = file_get_contents($this->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)
|| ($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 === 'adm')
{
$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("Invalid event name '{$event_name}'");
}
}
/**
* Validate "Since" Information
*
* @param string $since
* @return string
* @throws \LogicException
*/
public function validate_since($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}'");
}
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->path . $file) || substr($file, -5) !== '.html')
{
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/'));
}
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}' not found for event '{$this->current_event}'", 2);
}
$this->events_by_file[$file][] = $this->current_event;
}
}
else if ($this->filter == 'adm')
{
$file = substr($file_details, strlen('* Location: '));
if (!file_exists($this->path . $file) || substr($file, -5) !== '.html')
{
throw new \LogicException("Invalid file '{$file}' not found for event '{$this->current_event}'", 1);
}
$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);
}
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->path . $file))
{
throw new \LogicException("File '{$file}' does not exist", 1);
}
$event_list = array();
$file_content = file_get_contents($this->path . $file);
$events = explode('<!-- EVENT ', $file_content);
// Remove the code before the first event
array_shift($events);
foreach ($events as $event)
{
$event = explode(' -->', $event, 2);
$event_list[] = array_shift($event);
}
return $event_list;
}
/**
* Validates whether all events from $file are in the md file and vice-versa
*
* @param string $file
* @param array $events
* @return true
* @throws \LogicException
*/
public function validate_events_from_file($file, array $events)
{
if (empty($this->events_by_file[$file]) && empty($events))
{
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]);
throw new \LogicException("File '{$file}' contains no events, but should contain: "
. "'{$event_list}'", 1);
}
$missing_events_from_file = array();
foreach ($this->events_by_file[$file] as $event)
{
if (!in_array($event, $events))
{
$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
* @return array List of files (including directories)
*/
public function get_recursive_file_list($dir)
{
try
{
$iterator = new \RecursiveIteratorIterator(
new \phpbb\recursive_dot_prefix_filter_iterator(
new \RecursiveDirectoryIterator(
$dir,
\FilesystemIterator::SKIP_DOTS
)
),
\RecursiveIteratorIterator::SELF_FIRST
);
}
catch (\Exception $e)
{
return array();
}
$files = array();
foreach ($iterator as $file_info)
{
/** @var \RecursiveDirectoryIterator $file_info */
if ($file_info->isDir())
{
continue;
}
$relative_path = $iterator->getInnerIterator()->getSubPathname();
if (substr($relative_path, -5) == '.html')
{
$files[] = str_replace(DIRECTORY_SEPARATOR, '/', $relative_path);
}
}
return $files;
}
}

View file

@ -0,0 +1,608 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\event;
/**
* Class php_exporter
* Crawls through a list of files and grabs all php-events
*
* @package phpbb\event
*/
class php_exporter
{
/** @var string Path where we look for files*/
protected $path;
/** @var string phpBB Root Path */
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
* @param mixed $extension String 'vendor/ext' to filter, null for phpBB core
*/
public function __construct($phpbb_root_path, $extension = null)
{
$this->root_path = $phpbb_root_path;
$this->path = $phpbb_root_path;
$this->events = $this->file_lines = array();
$this->current_file = $this->current_event = '';
$this->current_event_line = 0;
$this->path = $this->root_path;
if ($extension)
{
$this->path .= 'ext/' . $extension . '/';
}
}
/**
* 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;
}
/**
* 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->events = array();
foreach ($files as $file)
{
$this->crawl_php_file($file);
}
ksort($this->events);
return sizeof($this->events);
}
/**
* Returns a list of files in $dir
*
* @return array List of files (including the path)
*/
public function get_recursive_file_list()
{
try
{
$iterator = new \RecursiveIteratorIterator(
new \phpbb\event\recursive_event_filter_iterator(
new \RecursiveDirectoryIterator(
$this->path,
\FilesystemIterator::SKIP_DOTS
),
$this->path
),
\RecursiveIteratorIterator::LEAVES_ONLY
);
}
catch (\Exception $e)
{
return array();
}
$files = array();
foreach ($iterator as $file_info)
{
/** @var \RecursiveDirectoryIterator $file_info */
$relative_path = $iterator->getInnerIterator()->getSubPathname();
$files[] = str_replace(DIRECTORY_SEPARATOR, '/', $relative_path);
}
return $files;
}
/**
* Format the php events as a wiki table
* @return string
*/
public function export_events_for_wiki()
{
$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;
}
/**
* @param string $file
* @return int Number of events found in this file
* @throws \LogicException
*/
public function crawl_php_file($file)
{
$this->current_file = $file;
$this->file_lines = array();
$content = file_get_contents($this->path . $this->current_file);
$num_events_found = 0;
if (strpos($content, "dispatcher->trigger_event('") || strpos($content, "dispatcher->dispatch('"))
{
$this->set_content(explode("\n", $content));
for ($i = 0, $num_lines = sizeof($this->file_lines); $i < $num_lines; $i++)
{
$event_line = false;
$found_trigger_event = strpos($this->file_lines[$i], "dispatcher->trigger_event('");
$arguments = array();
if ($found_trigger_event !== false)
{
$event_line = $i;
$this->set_current_event($this->get_event_name($event_line, false), $event_line);
// Find variables of the event
$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($this->file_lines[$i], "dispatcher->dispatch('");
if ($found_dispatch !== false)
{
$event_line = $i;
$this->set_current_event($this->get_event_name($event_line, true), $event_line);
}
}
if ($event_line)
{
// Validate @event
$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();
$since = $this->validate_since($this->file_lines[$since_line_num]);
// Find event description line
$description_line_num = $this->find_description();
$description = substr(trim($this->file_lines[$description_line_num]), strlen('* '));
if (isset($this->events[$this->current_event]))
{
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);
}
sort($arguments);
$this->events[$this->current_event] = array(
'event' => $this->current_event,
'file' => $this->current_file,
'arguments' => $arguments,
'since' => $since,
'description' => $description,
);
$num_events_found++;
}
}
}
return $num_events_found;
}
/**
* 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 string Name of the event
* @throws \LogicException
*/
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");
if ($is_dispatch)
{
$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\)\)\);#';
}
$match = array();
preg_match($regex, $event_text_line, $match);
if (!isset($match[2]))
{
throw new \LogicException("Can not find event name in line '{$event_text_line}' "
. "in file '{$this->current_file}:{$event_line}'", 1);
}
return $match[2];
}
/**
* Returns a regex match for the event name
*
* @return string
*/
protected function preg_match_event_name()
{
return '([a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+)';
}
/**
* Find the $vars array
*
* @return array List of variables
* @throws \LogicException
*/
public function get_vars_from_array()
{
$line = ltrim($this->file_lines[$this->current_event_line - 1], "\t");
if ($line === ');')
{
$vars_array = $this->get_vars_from_multi_line_array();
}
else
{
$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}'", 3);
}
}
sort($vars_array);
return $vars_array;
}
/**
* 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
*/
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
*
* @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
*
* @return array List of variables
* @throws \LogicException
*/
public function get_vars_from_docblock()
{
$doc_vars = array();
$current_doc_line = 1;
$found_comment_end = false;
while (ltrim($this->file_lines[$this->current_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($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 '{$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];
}
}
$current_doc_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 '{$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}:{$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}:{$this->current_event_line}'", 4);
}
}
sort($doc_vars);
return $doc_vars;
}
/**
* Find the "@since" Information line
*
* @return int Absolute line number
* @throws \LogicException
*/
public function find_since()
{
return $this->find_tag('since', array('event', 'var'));
}
/**
* Find the "@event" Information line
*
* @return int Absolute line number
*/
public function find_event()
{
return $this->find_tag('event', array());
}
/**
* Find a "@*" Information line
*
* @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($find_tag, $disallowed_tags)
{
$find_tag_line = 0;
$found_comment_end = false;
while (strpos(ltrim($this->file_lines[$this->current_event_line - $find_tag_line], "\t"), '* @' . $find_tag . ' ') !== 0)
{
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}:{$this->current_event_line}'", 1);
}
foreach ($disallowed_tags as $disallowed_tag)
{
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}:{$this->current_event_line}'", 3);
}
}
if (ltrim($this->file_lines[$this->current_event_line - $find_tag_line], "\t") === '*/')
{
$found_comment_end = true;
}
$find_tag_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 "
. "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 2);
}
}
return $this->current_event_line - $find_tag_line;
}
/**
* Find a "@*" Information line
*
* @return int Absolute line number
* @throws \LogicException
*/
public function find_description()
{
$find_desc_line = 0;
while (ltrim($this->file_lines[$this->current_event_line - $find_desc_line], "\t") !== '/**')
{
$find_desc_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 "
. "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 1);
}
}
$find_desc_line = $this->current_event_line - $find_desc_line + 1;
$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 "
. "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 2);
}
return $find_desc_line;
}
/**
* Validate "@since" Information
*
* @param string $line
* @return string
* @throws \LogicException
*/
public function validate_since($line)
{
$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}'");
}
return $match[1];
}
/**
* Validate "@event" Information
*
* @param string $event_name
* @param string $line
* @return string
* @throws \LogicException
*/
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 "
. "'{$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 "
. "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'", 2);
}
return $event;
}
/**
* Validates that two arrays contain the same strings
*
* @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($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 "
. "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'");
}
}
}

View file

@ -0,0 +1,70 @@
<?php
/**
*
* @package event
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbb\event;
/**
* Class recursive_event_filter_iterator
*
* This filter ignores directories and files starting with a dot.
* It also skips some directories that do not contain events anyway,
* such as e.g. files/, store/ and vendor/
*
* @package 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}
*/
public function accept()
{
$relative_path = str_replace(DIRECTORY_SEPARATOR, '/', $this->current());
$filename = $this->current()->getFilename();
return (substr($relative_path, -4) === '.php' || $this->current()->isDir())
&& $filename[0] !== '.'
&& strpos($relative_path, $this->root_path . 'cache/') !== 0
&& strpos($relative_path, $this->root_path . 'develop/') !== 0
&& strpos($relative_path, $this->root_path . 'docs/') !== 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 . 'tests/') !== 0
&& strpos($relative_path, $this->root_path . 'vendor/') !== 0
;
}
}

View file

@ -305,9 +305,17 @@ 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', '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.
@ -403,9 +411,23 @@ 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', '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',
'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)
@ -499,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)));
@ -576,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)));

View file

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

View file

@ -143,9 +143,17 @@ 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', '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',
'user_timezone',
'lang_set',
'lang_set_ext',
'style_id',
);
extract($phpbb_dispatcher->trigger_event('core.user_setup', compact($vars)));
$this->data = $user_data;

View file

@ -80,9 +80,24 @@ $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', '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',
'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
@ -1558,10 +1573,19 @@ $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('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',
);
extract($phpbb_dispatcher->trigger_event('core.posting_modify_template_vars', compact($vars)));
// Build custom bbcodes array

View file

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

View file

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

View file

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

View file

@ -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');

View file

@ -999,10 +999,20 @@ $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('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',
'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);
@ -1075,7 +1085,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)));
@ -1131,7 +1141,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)));
@ -1191,7 +1201,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)));
@ -1677,11 +1687,22 @@ 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
*/
$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',
'attachments',
'user_poster_data',
'post_row',
'topic_data',
);
extract($phpbb_dispatcher->trigger_event('core.viewtopic_modify_post_row', compact($vars)));
$i = $current_row_number;
@ -1728,14 +1749,28 @@ 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',
'attachments',
'user_poster_data',
'post_row',
'topic_data',
);
extract($phpbb_dispatcher->trigger_event('core.viewtopic_post_row_after', compact($vars)));
$i = $current_row_number;
@ -1883,7 +1918,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)));

View file

@ -0,0 +1,45 @@
<?php
/**
*
* @package testing
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
class phpbb_event_export_php_test extends phpbb_test_case
{
/** @var \phpbb\event\php_exporter */
protected $exporter;
public function setUp()
{
parent::setUp();
global $phpbb_root_path;
$this->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));
}
}

View file

@ -0,0 +1,9 @@
<?php
/**
* Description
*
* @event default.dispatch
* @since 3.1.0-b2
*/
$phpbb_dispatcher->dispatch('default.dispatch');

View file

@ -0,0 +1,19 @@
<?php
/**
* Event after the post data has been assigned to the template
*
* @event duplicate.trigger
* @var int start Start item of this page
* @since 3.1.0-a3
*/
$vars = array('start');
extract($phpbb_dispatcher->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');

View file

@ -0,0 +1,11 @@
<?php
/**
* Description
*
* NOTE: This will not be exported
*
* @event extra_description.dispatch
* @since 3.1.0-b2
*/
$phpbb_dispatcher->dispatch('extra_description.dispatch');

View file

@ -0,0 +1,17 @@
<?php
/**
* Event after the post data has been assigned to the template
*
* @event core.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
* @since 3.1.0-a3
*/
$vars = array('start', 'current_row_number', 'end', 'row', 'cp_row', 'attachments', 'user_poster_data', 'post_row');
extract($phpbb_dispatcher->trigger_event('core.trigger', compact($vars)));

View file

@ -0,0 +1,6 @@
<?php
/**
* Hi there :)
*/
echo 1 + 2;

View file

@ -0,0 +1,15 @@
<?php
/**
* Event after the post data has been assigned to the template
*
* @event core.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
* @since 3.1.0-a3
*/
$vars = array('start', 'current_row_number', 'end', 'row', 'cp_row');
extract($phpbb_dispatcher->trigger_event('core.trigger', compact($vars)));

View file

@ -0,0 +1,65 @@
<?php
/**
* This event allows you to modify template variables for the posting screen
*
* @event core.posting_modify_template_vars
* @var array post_data Array with post data
* @var array moderators Array with forum moderators
* @var string mode What action to take if the form is submitted
* post|reply|quote|edit|delete|bump|smilies|popup
* @var string page_title Title of the mode page
* @var bool s_topic_icons Whether or not to show the topic icons
* @var string form_enctype If attachments are allowed for this form
* "multipart/form-data" or empty string
* @var string s_action The URL to submit the POST data to
* @var string s_hidden_fields Concatenated hidden input tags of posting form
* @var int post_id ID of the post
* @var int topic_id ID of the topic
* @var int forum_id ID of the forum
* @var bool submit Whether or not the form has been submitted
* @var bool preview Whether or not the post is being previewed
* @var bool save Whether or not a draft is being saved
* @var bool load Whether or not a draft is being loaded
* @var bool delete Whether or not the post is being deleted
* @var bool cancel Whether or not to cancel the form (returns to
* viewtopic or viewforum depending on if the user
* is posting a new topic or editing a post)
* @var array error Any error strings; a non-empty array aborts
* form submission.
* NOTE: Should be actual language strings, NOT
* language keys.
* @var bool refresh Whether or not to retain previously submitted data
* @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.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,
* 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)));

View file

@ -0,0 +1,67 @@
<?php
/**
*
* @package testing
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
class phpbb_event_md_exporter_test extends phpbb_test_case
{
static public function crawl_eventsmd_data()
{
return array(
array('styles'),
array('adm'),
);
}
/**
* @dataProvider crawl_eventsmd_data
*/
public function test_crawl_eventsmd($filter)
{
global $phpbb_root_path;
$exporter = new \phpbb\event\md_exporter($phpbb_root_path);
$this->assertGreaterThan(0, $exporter->crawl_eventsmd('docs/events.md', $filter));
}
static public function crawl_template_file_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_template_file_data
*/
public function test_crawl_template_file($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));
}
}

View file

@ -0,0 +1,722 @@
<?php
/**
*
* @package testing
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
class phpbb_event_php_exporter_test extends phpbb_test_case
{
/** @var \phpbb\event\php_exporter */
protected $exporter;
public function setUp()
{
parent::setUp();
$this->exporter = new \phpbb\event\php_exporter(dirname(__FILE__) . '/fixtures/');
}
static public function crawl_php_file_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(
'trigger.test',
array(
'core.trigger' => array(
'event' => 'core.trigger',
'file' => 'trigger.test',
'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(),
),
);
}
/**
* @dataProvider crawl_php_file_data
*/
public function test_crawl_php_file($file, $expected)
{
$this->exporter->crawl_php_file($file);
$this->assertEquals($expected, $this->exporter->get_events());
}
static public function crawl_php_file_throws_data()
{
return array(
array('missing_var.test', null),
array('duplicate_event.test', 10),
);
}
/**
* @dataProvider crawl_php_file_throws_data
*/
public function test_crawl_php_file_throws($file, $exception_code)
{
$this->setExpectedException('LogicException', '', $exception_code);
$this->exporter->crawl_php_file($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'),
);
}
/**
* @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'),
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'),
);
}
/**
* @dataProvider validate_since_throws_data
* @expectedException LogicException
*/
public function test_validate_since_throws($since)
{
$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 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->exporter->set_content(array($event_line));
$this->assertEquals($expected, $this->exporter->get_event_name(0, true));
}
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->set_content(array($event_line));
$this->exporter->get_event_name(0, true);
}
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->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()
{
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->set_content(array($event_line));
$this->exporter->get_event_name(0, false);
}
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->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()
{
return array(
array(
array(
'/**',
'*/',
'$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
),
2,
1,
),
array(
array(
'/**',
'*/',
'$vars = $bertie;',
'$phpbb_dispatcher->trigger_event(\'test\', compact($vars));',
),
3,
1,
),
array(
array(
'/**',
'*/',
'$vars = array(\'$bertie\');',
'$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,
),
);
}
/**
* @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->set_current_event('', $event_line);
$this->exporter->set_content($lines);
$this->exporter->get_vars_from_array();
}
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->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()
{
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->set_current_event('', $event_line);
$this->exporter->set_content($lines);
$this->exporter->get_vars_from_docblock();
}
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->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()
{
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->set_current_event('', $event_line);
$this->exporter->set_content($lines);
$this->exporter->find_since();
}
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->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()
{
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->set_current_event('', $event_line);
$this->exporter->set_content($lines);
$this->exporter->find_description();
}
}