GitHub PullRequestReviewCommentEvent at 2014-04-27 21:48:10
Repository: phpbb
Actor: Nicofuma
Payload: {"comment":{"url":"https://api.github.com/repos/phpbb/phpbb/pulls/comments/12031560","id":12031560,"diff_hunk":"@@ -0,0 +1,420 @@\n+<?php\n+/**\n+*\n+* @package phpBB3\n+* @copyright (c) 2014 phpBB Group\n+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2\n+*\n+*/\n+\n+namespace phpbb\\event;\n+\n+/**\n+* Class md_exporter\n+* Crawls through a markdown file and grabs all events\n+*\n+* @package phpbb\\event\n+*/\n+class md_exporter\n+{\n+\t/** @var string */\n+\tprotected $root_path;\n+\n+\t/** @var string */\n+\tprotected $filter;\n+\n+\t/** @var string */\n+\tprotected $current_event;\n+\n+\t/** @var array */\n+\tprotected $events;\n+\n+\t/**\n+\t* @param string $phpbb_root_path\n+\t*/\n+\tpublic function __construct($phpbb_root_path)\n+\t{\n+\t\t$this->root_path = $phpbb_root_path;\n+\t\t$this->events = array();\n+\t\t$this->events_by_file = array();\n+\t\t$this->filter = $this->current_event = '';\n+\t}\n+\n+\t/**\n+\t* Get the list of all events\n+\t*\n+\t* @return array\t\tArray with events: name => details\n+\t*/\n+\tpublic function get_events()\n+\t{\n+\t\treturn $this->events;\n+\t}\n+\n+\t/**\n+\t* @param string $md_file\n+\t* @return int\t\tNumber of events found\n+\t* @throws \\LogicException\n+\t*/\n+\tpublic function crawl_phpbb_directory_adm($md_file)\n+\t{\n+\t\t$this->crawl_eventsmd($md_file, 'adm');\n+\n+\t\t$file_list = $this->get_recursive_file_list($this->root_path . 'adm/style/', 'adm/style/');\n+\t\tforeach ($file_list as $file)\n+\t\t{\n+\t\t\t$file_name = 'adm/style/' . $file;\n+\t\t\t$this->validate_events_from_file($file_name, $this->crawl_file_for_events($file_name));\n+\t\t}\n+\n+\t\treturn sizeof($this->events);\n+\t}\n+\n+\t/**\n+\t* @param string $md_file\n+\t* @return int\t\tNumber of events found\n+\t* @throws \\LogicException\n+\t*/\n+\tpublic function crawl_phpbb_directory_styles($md_file)\n+\t{\n+\t\t$this->crawl_eventsmd($md_file, 'styles');\n+\n+\t\t$styles = array('prosilver', 'subsilver2');\n+\t\tforeach ($styles as $style)\n+\t\t{\n+\t\t\t$file_list = $this->get_recursive_file_list(\n+\t\t\t\t$this->root_path . 'styles/' . $style . '/template/',\n+\t\t\t\t'styles/' . $style . '/template/'\n+\t\t\t);\n+\n+\t\t\tforeach ($file_list as $file)\n+\t\t\t{\n+\t\t\t\t$file_name = 'styles/' . $style . '/template/' . $file;\n+\t\t\t\t$this->validate_events_from_file($file_name, $this->crawl_file_for_events($file_name));\n+\t\t\t}\n+\t\t}\n+\n+\t\treturn sizeof($this->events);\n+\t}\n+\n+\t/**\n+\t* @param string $md_file\n+\t* @param string $filter\n+\t* @return int\t\tNumber of events found\n+\t* @throws \\LogicException\n+\t*/\n+\tpublic function crawl_eventsmd($md_file, $filter)\n+\t{\n+\t\t$file_content = file_get_contents($this->root_path . $md_file);\n+\t\t$this->filter = $filter;\n+\n+\t\t$events = explode(\"\\n\\n\", $file_content);\n+\t\tforeach ($events as $event)\n+\t\t{\n+\t\t\t// Last row of the file\n+\t\t\tif (strpos($event, \"\\n===\\n\") === false)\n+\t\t\t{\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\tlist($event_name, $details) = explode(\"\\n===\\n\", $event, 2);\n+\t\t\t$this->validate_event_name($event_name);\n+\t\t\t$this->current_event = $event_name;\n+\n+\t\t\tif (isset($this->events[$this->current_event]))\n+\t\t\t{\n+\t\t\t\tthrow new \\LogicException(\"The event '{$this->current_event}' is defined multiple times\");\n+\t\t\t}\n+\n+\t\t\tif (($this->filter == 'adm' && strpos($this->current_event, 'acp_') !== 0)\n+\t\t\t\t|| ($this->filter == 'styles' && strpos($this->current_event, 'acp_') === 0))\n+\t\t\t{\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\tlist($file_details, $details) = explode(\"\\n* Since: \", $details, 2);\n+\t\t\tlist($since, $description) = explode(\"\\n* Purpose: \", $details, 2);\n+\n+\t\t\t$files = $this->validate_file_list($file_details);\n+\t\t\t$since = $this->validate_since($since);\n+\n+\t\t\t$this->events[$event_name] = array(\n+\t\t\t\t'event'\t\t\t=> $this->current_event,\n+\t\t\t\t'files'\t\t\t=> $files,\n+\t\t\t\t'since'\t\t\t=> $since,\n+\t\t\t\t'description'\t=> $description,\n+\t\t\t);\n+\t\t}\n+\n+\t\treturn sizeof($this->events);\n+\t}\n+\n+\t/**\n+\t* Format the php events as a wiki table\n+\t* @return string\t\tNumber of events found\n+\t*/\n+\tpublic function export_events_for_wiki()\n+\t{\n+\t\tif ($this->filter === 'acp')\n+\t\t{\n+\t\t\t$wiki_page = '= ACP Template Events =' . \"\\n\";\n+\t\t\t$wiki_page .= '{| class=\"zebra sortable\" cellspacing=\"0\" cellpadding=\"5\"' . \"\\n\";\n+\t\t\t$wiki_page .= '! Identifier !! Placement !! Added in Release !! Explanation' . \"\\n\";\n+\t\t}\n+\t\telse\n+\t\t{\n+\t\t\t$wiki_page = '= Template Events =' . \"\\n\";\n+\t\t\t$wiki_page .= '{| class=\"zebra sortable\" cellspacing=\"0\" cellpadding=\"5\"' . \"\\n\";\n+\t\t\t$wiki_page .= '! Identifier !! Prosilver Placement (If applicable) !! Subsilver Placement (If applicable) !! Added in Release !! Explanation' . \"\\n\";\n+\t\t}\n+\n+\t\tforeach ($this->events as $event_name => $event)\n+\t\t{\n+\t\t\t$wiki_page .= \"|- id=\\\"{$event_name}\\\"\\n\";\n+\t\t\t$wiki_page .= \"| [[#{$event_name}|{$event_name}]] || \";\n+\n+\t\t\tif ($this->filter === 'adm')\n+\t\t\t{\n+\t\t\t\t$wiki_page .= implode(', ', $event['files']['adm']);\n+\t\t\t}\n+\t\t\telse\n+\t\t\t{\n+\t\t\t\t$wiki_page .= implode(', ', $event['files']['prosilver']) . ' || ' . implode(', ', $event['files']['subsilver2']);\n+\t\t\t}\n+\n+\t\t\t$wiki_page .= \" || {$event['since']} || \" . str_replace(\"\\n\", ' ', $event['description']) . \"\\n\";\n+\t\t}\n+\t\t$wiki_page .= '|}' . \"\\n\";\n+\n+\t\treturn $wiki_page;\n+\t}\n+\n+\t/**\n+\t* Validates a template event name\n+\t*\n+\t* @param $event_name\n+\t* @return null\n+\t* @throws \\LogicException\n+\t*/\n+\tpublic function validate_event_name($event_name)\n+\t{\n+\t\tif (!preg_match('#^([a-z][a-z0-9]*(?:_[a-z][a-z0-9]*)+)$#', $event_name))\n+\t\t{\n+\t\t\tthrow new \\LogicException(\"Invalid event name '{$event_name}'\");\n+\t\t}\n+\t}\n+\n+\t/**\n+\t* Validate \"Since\" Information\n+\t*\n+\t* @param string $since\n+\t* @return string\n+\t* @throws \\LogicException\n+\t*/\n+\tpublic function validate_since($since)\n+\t{\n+\t\tif (!preg_match('#^\\d+\\.\\d+\\.\\d+(?:-(?:a|b|rc|pl)\\d+)?$#', $since))\n+\t\t{\n+\t\t\tthrow new \\LogicException(\"Invalid since information found for event '{$this->current_event}'\");\n+\t\t}\n+\n+\t\treturn $since;\n+\t}\n+\n+\t/**\n+\t* Validate the files list\n+\t*\n+\t* @param string $file_details\n+\t* @return array\n+\t* @throws \\LogicException\n+\t*/\n+\tpublic function validate_file_list($file_details)\n+\t{\n+\t\t$files_list = array(\n+\t\t\t'prosilver'\t\t=> array(),\n+\t\t\t'subsilver2'\t=> array(),\n+\t\t\t'adm'\t\t\t=> array(),\n+\t\t);\n+\n+\t\t// Multi file list\n+\t\tif (strpos($file_details, \"* Locations:\\n    + \") === 0)\n+\t\t{\n+\t\t\t$file_details = substr($file_details, strlen(\"* Locations:\\n    + \"));\n+\t\t\t$files = explode(\"\\n    + \", $file_details);\n+\t\t\tforeach ($files as $file)\n+\t\t\t{\n+\t\t\t\tif (!file_exists($this->root_path . $file))\n+\t\t\t\t{\n+\t\t\t\t\tthrow new \\LogicException(\"Invalid file '{$file}' not found for event '{$this->current_event}'\", 1);\n+\t\t\t\t}\n+\n+\t\t\t\tif (($this->filter !== 'adm') && strpos($file, 'styles/prosilver/template/') === 0)\n+\t\t\t\t{\n+\t\t\t\t\t$files_list['prosilver'][] = substr($file, strlen('styles/prosilver/template/'));\n+\t\t\t\t}\n+\t\t\t\telse if (($this->filter !== 'adm') && strpos($file, 'styles/subsilver2/template/') === 0)\n+\t\t\t\t{\n+\t\t\t\t\t$files_list['subsilver2'][] = substr($file, strlen('styles/subsilver2/template/'));\n+\t\t\t\t}\n+\t\t\t\telse if (($this->filter === 'adm') && strpos($file, 'adm/style/') === 0)\n+\t\t\t\t{\n+\t\t\t\t\t$files_list['adm'][] = substr($file, strlen('adm/style/'));\n+\t\t\t\t}\n+\t\t\t\telse\n+\t\t\t\t{\n+\t\t\t\t\tthrow new \\LogicException(\"Invalid file '{$file}' not found for event '{$this->current_event}'\", 2);\n+\t\t\t\t}\n+\n+\t\t\t\t$this->events_by_file[$file][] = $this->current_event;\n+\t\t\t}\n+\t\t}\n+\t\telse if ($this->filter == 'adm')\n+\t\t{\n+\t\t\t$file = substr($file_details, strlen('* Location: '));\n+\t\t\t$files_list['adm'][] =  substr($file, strlen('adm/style/'));\n+\n+\t\t\t$this->events_by_file[$file][] = $this->current_event;\n+\t\t}","path":"phpBB/phpbb/event/md_exporter.php","position":276,"original_position":276,"commit_id":"927c219b1fc1cc69f724827771d567384b2cda8c","original_commit_id":"927c219b1fc1cc69f724827771d567384b2cda8c","user":{"login":"Nicofuma","id":591456,"avatar_url":"https://avatars.githubusercontent.com/u/591456?","gravatar_id":"4ca6947ea7c6c2303b6a4109cb931dd7","url":"https://api.github.com/users/Nicofuma","html_url":"https://github.com/Nicofuma","followers_url":"https://api.github.com/users/Nicofuma/followers","following_url":"https://api.github.com/users/Nicofuma/following{/other_user}","gists_url":"https://api.github.com/users/Nicofuma/gists{/gist_id}","starred_url":"https://api.github.com/users/Nicofuma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nicofuma/subscriptions","organizations_url":"https://api.github.com/users/Nicofuma/orgs","repos_url":"https://api.github.com/users/Nicofuma/repos","events_url":"https://api.github.com/users/Nicofuma/events{/privacy}","received_events_url":"https://api.github.com/users/Nicofuma/received_events","type":"User","site_admin":false},"body":"So the condition ~12 lines before is an exception for 2 events ? I think that one of them is of excess ","created_at":"2014-04-27T21:48:10Z","updated_at":"2014-04-27T21:48:10Z","html_url":"https://github.com/phpbb/phpbb/pull/2327#discussion_r12031560","pull_request_url":"https://api.github.com/repos/phpbb/phpbb/pulls/2327","_links":{"self":{"href":"https://api.github.com/repos/phpbb/phpbb/pulls/comments/12031560"},"html":{"href":"https://github.com/phpbb/phpbb/pull/2327#discussion_r12031560"},"pull_request":{"href":"https://api.github.com/repos/phpbb/phpbb/pulls/2327"}}}}