forked from phpbb/phpbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursive_event_filter_iterator.php
More file actions
73 lines (67 loc) · 2.29 KB
/
recursive_event_filter_iterator.php
File metadata and controls
73 lines (67 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\event;
/**
* 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/
*/
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(): ?\RecursiveFilterIterator
{
$inner_iterator = $this->getInnerIterator();
assert($inner_iterator instanceof \RecursiveIterator);
return new self($inner_iterator->getChildren(), $this->root_path);
}
/**
* {@inheritDoc}
*/
public function accept(): bool
{
$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
;
}
}