1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-16 13:52:03 +02:00

[ticket/12273] Rename exporter to php_exporter

PHPBB3-12273
This commit is contained in:
Joas Schilling 2014-04-18 12:50:23 +02:00
parent 3352d9fd34
commit 6da52acb3c
2 changed files with 26 additions and 79 deletions

View File

@ -9,7 +9,13 @@
namespace phpbb\event;
class exporter
/**
* Class php_exporter
* Crawls through a list of files and grabs all php-events
*
* @package phpbb\event
*/
class php_exporter
{
/** @var string */
protected $root_path;
@ -36,70 +42,10 @@ class exporter
{
$this->root_path = $phpbb_root_path;
$this->events = $this->file_lines = array();
$this->events['php'] = array();
$this->current_file = $this->current_event = '';
$this->current_event_line = 0;
}
function export_from_eventsmd($filter)
{
$file_content = file_get_contents($this->root_path . 'docs/events.md');
$events = explode("\n\n", $file_content);
foreach ($events as $event)
{
// Last row of the file
if (strpos($event, "\n===\n") === false) continue;
list($event_name, $details) = explode("\n===\n", $event);
if ($filter == 'acp' && strpos($event_name, 'acp_') !== 0) continue;
if ($filter == 'styles' && strpos($event_name, 'acp_') === 0) continue;
list($file_details, $details) = explode("\n* Since: ", $details);
list($version, $explanition) = explode("\n* Purpose: ", $details);
echo "|- id=\"{$event_name}\"\n";
echo "| [[#{$event_name}|{$event_name}]] || ";
if (strpos($file_details, "* Locations:\n + ") === 0)
{
$file_details = substr($file_details, strlen("* Locations:\n + "));
$files = explode("\n + ", $file_details);
$prosilver = $subsilver2 = $adm = array();
foreach ($files as $file)
{
if (strpos($file, 'styles/prosilver/template/') === 0)
{
$prosilver[] = substr($file, strlen('styles/prosilver/template/'));
}
if (strpos($file, 'styles/subsilver2/template/') === 0)
{
$subsilver2[] = substr($file, strlen('styles/subsilver2/template/'));
}
if (strpos($file, 'adm/style/') === 0)
{
$adm[] = substr($file, strlen('adm/style/'));
}
}
if ($filter == 'acp')
{
echo implode(', ', $adm);
}
else
{
echo implode(', ', $prosilver) . ' || ' . implode(', ', $subsilver2);
}
}
else if ($filter == 'acp')
{
echo substr($file_details, strlen("* Location: adm/style/"));
}
echo " || {$version} || " . str_replace("\n", ' ', $explanition) . "\n";
}
}
public function get_events()
{
return $this->events;
@ -123,14 +69,14 @@ class exporter
public function crawl_phpbb_directory_php()
{
$files = $this->get_recursive_file_list($this->root_path);
$this->events['php'] = array();
$this->events = array();
foreach ($files as $file)
{
$this->crawl_php_file($file);
}
ksort($this->events['php']);
ksort($this->events);
return sizeof($this->events['php']);
return sizeof($this->events);
}
/**
@ -201,14 +147,17 @@ class exporter
* Format the php events as a wiki table
* @return string
*/
public function export_php_events_for_wiki()
public function export_events_for_wiki()
{
$wiki_page = '';
foreach ($this->events['php'] as $event)
$wiki_page = '= PHP Events (Hook Locations) =' . "\n";
$wiki_page .= '{| class="sortable zebra" cellspacing="0" cellpadding="5"' . "\n";
$wiki_page .= '! Identifier !! Placement !! Arguments !! Added in Release !! Explanation' . "\n";
foreach ($this->events as $event)
{
$wiki_page .= '|- id="' . $event['event'] . '"' . "\n";
$wiki_page .= '| [[#' . $event['event'] . '|' . $event['event'] . ']] || ' . $event['file'] . ' || ' . implode(', ', $event['arguments']) . ' || ' . $event['since'] . ' || ' . $event['description'] . "\n";
}
$wiki_page .= '|}' . "\n";
return $wiki_page;
}
@ -265,13 +214,13 @@ class exporter
$description_line_num = $this->find_description();
$description = substr(trim($this->file_lines[$description_line_num]), strlen('* '));
if (isset($this->events['php'][$this->current_event]))
if (isset($this->events[$this->current_event]))
{
throw new \LogicException('The event "' . $this->current_event . '" from file "' . $this->current_file
. '" already exists in file "'. $this->events['php'][$this->current_event]['file'] . '"', 10);
. '" already exists in file "'. $this->events[$this->current_event]['file'] . '"', 10);
}
$this->events['php'][$this->current_event] = array(
$this->events[$this->current_event] = array(
'event' => $this->current_event,
'file' => $this->current_file,
'arguments' => $arguments,
@ -336,9 +285,9 @@ class exporter
}
/**
* Find the name of the event inside the trigger_event() line
* Returns a regex match for the event name
*
* @return string Returns a regex match for the event name
* @return string
*/
protected function preg_match_event_name()
{

View File

@ -7,15 +7,15 @@
*
*/
class phpbb_event_exporter_test extends phpbb_test_case
class phpbb_event_php_exporter_test extends phpbb_test_case
{
/** @var \event_exporter */
/** @var \phpbb\event\php_exporter */
protected $exporter;
public function setUp()
{
parent::setUp();
$this->exporter = new \phpbb\event\exporter(dirname(__FILE__) . '/fixtures/');
$this->exporter = new \phpbb\event\php_exporter(dirname(__FILE__) . '/fixtures/');
}
static public function crawl_php_file_data()
@ -70,9 +70,7 @@ class phpbb_event_exporter_test extends phpbb_test_case
public function test_crawl_php_file($file, $expected)
{
$this->exporter->crawl_php_file($file);
$events = $this->exporter->get_events();
$this->assertArrayHasKey('php', $events);
$this->assertEquals($expected, $events['php']);
$this->assertEquals($expected, $this->exporter->get_events());
}
static public function crawl_php_file_throws_data()
@ -667,7 +665,7 @@ class phpbb_event_exporter_test extends phpbb_test_case
public function test_crawl_phpbb_directory_php()
{
global $phpbb_root_path;
$exporter = new \phpbb\event\exporter($phpbb_root_path);
$exporter = new \phpbb\event\php_exporter($phpbb_root_path);
$this->assertGreaterThan(0, $exporter->crawl_phpbb_directory_php());
}
}