1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @copyright 2011 - 2016, Stephan Gambke, mwjames |
5
|
|
|
* |
6
|
|
|
* @license GNU General Public License, version 2 (or any later version) |
7
|
|
|
* |
8
|
|
|
* This file is part of the MediaWiki extension Lingo. |
9
|
|
|
* The Lingo extension is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU General Public License as published by the Free |
11
|
|
|
* Software Foundation; either version 2 of the License, or (at your option) any |
12
|
|
|
* later version. |
13
|
|
|
* |
14
|
|
|
* The Lingo extension is distributed in the hope that it will be useful, but |
15
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
16
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
17
|
|
|
* details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License along |
20
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
* @since 2.0.1 |
23
|
|
|
* @file |
24
|
|
|
* @ingroup Lingo |
25
|
|
|
* @ingroup Test |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
namespace Lingo\Tests\Util; |
29
|
|
|
|
30
|
|
|
use RuntimeException; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @group extensions-lingo |
34
|
|
|
* @group mediawiki-databaseless |
35
|
|
|
* |
36
|
|
|
* @since 2.0.1 |
37
|
|
|
* @author mwjames, Stephan Gambke |
38
|
|
|
* @ingroup Lingo |
39
|
|
|
* @ingroup Test |
40
|
|
|
*/ |
41
|
|
|
class XmlFileProvider { |
42
|
|
|
|
43
|
|
|
protected $path = null; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $path |
47
|
|
|
*/ |
48
|
|
|
public function __construct( $path ) { |
49
|
|
|
$this->path = $path; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return string[] |
54
|
|
|
*/ |
55
|
|
|
public function getFiles() { |
56
|
|
|
return $this->loadXmlFiles( $this->readDirectory( $this->path ) ); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param String $path |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
protected function readDirectory( $path ) { |
64
|
|
|
|
65
|
|
|
$path = str_replace( array( '\\', '/' ), DIRECTORY_SEPARATOR, $path ); |
66
|
|
|
|
67
|
|
|
if ( is_readable( $path ) ) { |
68
|
|
|
return $path; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
throw new RuntimeException( "Expected an accessible {$path} path" ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param String $path |
76
|
|
|
* @return string[] |
77
|
|
|
*/ |
78
|
|
|
protected function loadXmlFiles( $path ) { |
79
|
|
|
|
80
|
|
|
$directoryIterator = new \RecursiveDirectoryIterator( $path ); |
81
|
|
|
$iteratorIterator = new \RecursiveIteratorIterator($directoryIterator); |
82
|
|
|
$regexIterator = new \RegexIterator($iteratorIterator, '/^.+\.xml$/i', \RecursiveRegexIterator::GET_MATCH); |
83
|
|
|
|
84
|
|
|
$files = call_user_func_array('array_merge', iterator_to_array( $regexIterator ) ); |
85
|
|
|
|
86
|
|
|
return $files; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|