1
+ <?php
2
+ namespace Netresearch \Composer \Patches \Downloader ;
3
+
4
+ /* *
5
+ * This script belongs to the Composer-TYPO3-Installer package *
6
+ * (c) 2014 Netresearch GmbH & Co. KG *
7
+ * This copyright notice MUST APPEAR in all copies of the script! *
8
+ * *
9
+ * It is free software; you can redistribute it and/or modify it under *
10
+ * the terms of the GNU Lesser General Public License, either version 3 *
11
+ * of the License, or (at your option) any later version. *
12
+ * *
13
+ * The TYPO3 project - inspiring people to share! *
14
+ * */
15
+
16
+ use Composer \Util \RemoteFilesystem ;
17
+
18
+ /**
19
+ * Downloader, which uses the composer RemoteFilesystem
20
+ */
21
+ class Composer implements DownloaderInterface {
22
+ /**
23
+ * @var RemoteFilesystem
24
+ */
25
+ protected $ remoteFileSystem ;
26
+
27
+ /**
28
+ * Very simple cache system
29
+ * @var array
30
+ */
31
+ protected $ cache = array ();
32
+
33
+ /**
34
+ * Construct the RFS
35
+ *
36
+ * @param \Composer\IO\IOInterface $io
37
+ */
38
+ public function __construct (\Composer \IO \IOInterface $ io ) {
39
+ $ this ->remoteFileSystem = new RemoteFilesystem ($ io );
40
+ }
41
+
42
+ /**
43
+ * Get the origin URL required by composer rfs
44
+ *
45
+ * @param string $url
46
+ * @return string
47
+ */
48
+ protected function getOriginUrl ($ url ) {
49
+ return parse_url ($ url , PHP_URL_HOST );
50
+ }
51
+
52
+ /**
53
+ * Download the file and return its contents
54
+ *
55
+ * @param string $url The URL from where to download
56
+ * @return string Contents of the URL
57
+ */
58
+ public function getContents ($ url ) {
59
+ if (array_key_exists ($ url , $ this ->cache )) {
60
+ return $ this ->cache [$ url ];
61
+ }
62
+ return $ this ->cache [$ url ] = $ this ->remoteFileSystem ->getContents ($ this ->getOriginUrl ($ url ), $ url );
63
+ }
64
+
65
+ /**
66
+ * Download file and decode the JSON string to PHP object
67
+ *
68
+ * @param string $json
69
+ * @return stdClass
70
+ */
71
+ public function getJson ($ url ) {
72
+ $ key = 'json:// ' . $ url ;
73
+ if (array_key_exists ($ key , $ this ->cache )) {
74
+ return $ this ->cache [$ key ];
75
+ }
76
+ $ json = new \Composer \Json \JsonFile ($ url , $ this ->remoteFileSystem );
77
+ return $ this ->cache [$ key ] = $ json ->read ();
78
+ }
79
+ }
80
+ ?>
0 commit comments