]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - extensions/LocalisationUpdate/fetcher/FileSystemFetcher.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / extensions / LocalisationUpdate / fetcher / FileSystemFetcher.php
1 <?php
2 /**
3  * @file
4  * @author Niklas Laxström
5  * @license GPL-2.0+
6  */
7
8 namespace LocalisationUpdate;
9
10 /**
11  * Accesses file system directly.
12  */
13 class FileSystemFetcher implements Fetcher {
14         public function fetchFile( $url ) {
15                 // Remove the protocol prefix
16                 $url = preg_replace( '~^file://~', '', $url );
17
18                 if ( !is_readable( $url ) ) {
19                         return false;
20                 }
21
22                 return file_get_contents( $url );
23         }
24
25         public function fetchDirectory( $pattern ) {
26                 // Remove the protocol prefix
27                 $pattern = preg_replace( '~^file://~', '', $pattern );
28
29                 $data = [];
30                 foreach ( glob( $pattern ) as $file ) {
31                         if ( is_readable( $file ) ) {
32                                 $data["file://$file"] = file_get_contents( $file );
33                         }
34                 }
35                 return $data;
36         }
37 }