diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2014-04-28 21:03:59 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2014-04-28 21:03:59 +0200 |
commit | ed669982c2a8225e262d57b60f5654658799becd (patch) | |
tree | 0bbb501850f5554c5dd14b7813e6dc6396e31558 /phpBB/phpbb/event | |
parent | bf8b9f01437b4b6bff3e27291eafcd73dbcbdb0c (diff) | |
download | forums-ed669982c2a8225e262d57b60f5654658799becd.tar forums-ed669982c2a8225e262d57b60f5654658799becd.tar.gz forums-ed669982c2a8225e262d57b60f5654658799becd.tar.bz2 forums-ed669982c2a8225e262d57b60f5654658799becd.tar.xz forums-ed669982c2a8225e262d57b60f5654658799becd.zip |
[ticket/12273] Allow to filter events for extensions
PHPBB3-12273
Diffstat (limited to 'phpBB/phpbb/event')
-rw-r--r-- | phpBB/phpbb/event/md_exporter.php | 48 | ||||
-rw-r--r-- | phpBB/phpbb/event/php_exporter.php | 26 |
2 files changed, 51 insertions, 23 deletions
diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index 415f001ac1..574827ac44 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -17,7 +17,10 @@ namespace phpbb\event; */ class md_exporter { - /** @var string */ + /** @var string Path where we look for files*/ + protected $path; + + /** @var string phpBB Root Path */ protected $root_path; /** @var string */ @@ -51,15 +54,22 @@ class md_exporter } /** - * @param string $md_file + * @param string $md_file Relative from phpBB root + * @param mixed $extension String 'vendor/ext' to filter, null for phpBB core * @return int Number of events found * @throws \LogicException */ - public function crawl_phpbb_directory_adm($md_file) + public function crawl_phpbb_directory_adm($md_file, $extension = null) { - $this->crawl_eventsmd($md_file, 'adm'); + $this->path = $this->root_path; + if ($extension) + { + $this->path .= 'ext/' . $extension . '/'; + } - $file_list = $this->get_recursive_file_list($this->root_path . 'adm/style/'); + $this->crawl_eventsmd($md_file, 'adm', $extension); + + $file_list = $this->get_recursive_file_list($this->path . 'adm/style/'); foreach ($file_list as $file) { $file_name = 'adm/style/' . $file; @@ -70,19 +80,26 @@ class md_exporter } /** - * @param string $md_file + * @param string $md_file Relative from phpBB root + * @param mixed $extension String 'vendor/ext' to filter, null for phpBB core * @return int Number of events found * @throws \LogicException */ - public function crawl_phpbb_directory_styles($md_file) + public function crawl_phpbb_directory_styles($md_file, $extension = null) { - $this->crawl_eventsmd($md_file, 'styles'); + $this->path = $this->root_path; + if ($extension) + { + $this->path .= 'ext/' . $extension . '/'; + } + + $this->crawl_eventsmd($md_file, 'styles', $extension); $styles = array('prosilver', 'subsilver2'); foreach ($styles as $style) { $file_list = $this->get_recursive_file_list( - $this->root_path . 'styles/' . $style . '/template/' + $this->path . 'styles/' . $style . '/template/' ); foreach ($file_list as $file) @@ -96,12 +113,13 @@ class md_exporter } /** - * @param string $md_file - * @param string $filter + * @param string $md_file Relative from phpBB root + * @param string $filter Should be 'styles' or 'adm' + * @param mixed $extension String 'vendor/ext' to filter, null for phpBB core * @return int Number of events found * @throws \LogicException */ - public function crawl_eventsmd($md_file, $filter) + public function crawl_eventsmd($md_file, $filter, $extension = null) { $file_content = file_get_contents($this->root_path . $md_file); $this->filter = $filter; @@ -241,7 +259,7 @@ class md_exporter $files = explode("\n + ", $file_details); foreach ($files as $file) { - if (!file_exists($this->root_path . $file)) + if (!file_exists($this->path . $file)) { throw new \LogicException("Invalid file '{$file}' not found for event '{$this->current_event}'", 1); } @@ -290,13 +308,13 @@ class md_exporter */ public function crawl_file_for_events($file) { - if (!file_exists($this->root_path . $file)) + if (!file_exists($this->path . $file)) { throw new \LogicException("File '{$file}' does not exist", 1); } $event_list = array(); - $file_content = file_get_contents($this->root_path . $file); + $file_content = file_get_contents($this->path . $file); $events = explode('<!-- EVENT ', $file_content); // Remove the code before the first event diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index e95426244b..4e77d336b1 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -17,7 +17,10 @@ namespace phpbb\event; */ class php_exporter { - /** @var string */ + /** @var string Path where we look for files*/ + protected $path; + + /** @var string phpBB Root Path */ protected $root_path; /** @var string */ @@ -41,6 +44,7 @@ class php_exporter public function __construct($phpbb_root_path) { $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; @@ -82,11 +86,18 @@ class php_exporter /** * Crawl the phpBB/ directory for php events + * @param mixed $extension String 'vendor/ext' to filter, null for phpBB core * @return int The number of events found */ - public function crawl_phpbb_directory_php() + public function crawl_phpbb_directory_php($extension = null) { - $files = $this->get_recursive_file_list($this->root_path); + $this->path = $this->root_path; + if ($extension) + { + $this->path .= 'ext/' . $extension . '/'; + } + + $files = $this->get_recursive_file_list(); $this->events = array(); foreach ($files as $file) { @@ -100,20 +111,19 @@ class php_exporter /** * Returns a list of files in $dir * - * @param string $dir Directory to go through * @return array List of files (including the path) */ - public function get_recursive_file_list($dir) + public function get_recursive_file_list() { try { $iterator = new \RecursiveIteratorIterator( new \phpbb\event\recursive_event_filter_iterator( new \RecursiveDirectoryIterator( - $dir, + $this->path, \FilesystemIterator::SKIP_DOTS ), - $dir + $this->path ), \RecursiveIteratorIterator::LEAVES_ONLY ); @@ -162,7 +172,7 @@ class php_exporter { $this->current_file = $file; $this->file_lines = array(); - $content = file_get_contents($this->root_path . $this->current_file); + $content = file_get_contents($this->path . $this->current_file); $num_events_found = 0; if (strpos($content, "dispatcher->trigger_event('") || strpos($content, "dispatcher->dispatch('")) |