1 | <?php |
||
25 | class HttpLoader implements LoaderInterface |
||
26 | { |
||
27 | /** |
||
28 | * @var ValidatorInterface |
||
29 | */ |
||
30 | private $validator; |
||
31 | |||
32 | /** |
||
33 | * @var Client |
||
34 | */ |
||
35 | private $client; |
||
36 | |||
37 | /** |
||
38 | * @var DispersalStrategyInterface |
||
39 | */ |
||
40 | private $strategy; |
||
41 | |||
42 | /** |
||
43 | * doctrine cache |
||
44 | * |
||
45 | * @var CacheProvider |
||
46 | */ |
||
47 | private $cache; |
||
48 | |||
49 | /** |
||
50 | * doctrine cache lifetime |
||
51 | * |
||
52 | * @var int |
||
53 | */ |
||
54 | private $cacheLifetime; |
||
55 | |||
56 | /** |
||
57 | * @var array curl options to apply on each request |
||
58 | */ |
||
59 | private $curlOptions = []; |
||
60 | |||
61 | /** |
||
62 | * @var array |
||
63 | */ |
||
64 | private $options = [ |
||
65 | 'storeKey' => 'httpLoader', |
||
66 | ]; |
||
67 | |||
68 | /** |
||
69 | * constructor |
||
70 | * |
||
71 | * @param ValidatorInterface $validator validator |
||
72 | * @param Client $client http client |
||
73 | */ |
||
74 | 4 | public function __construct(ValidatorInterface $validator, Client $client) |
|
79 | |||
80 | /** |
||
81 | * @inheritDoc |
||
82 | * |
||
83 | * @param DispersalStrategyInterface $strategy dispersal strategy |
||
84 | * |
||
85 | * @return void |
||
86 | */ |
||
87 | 3 | public function setDispersalStrategy($strategy) |
|
91 | |||
92 | /** |
||
93 | * @inheritDoc |
||
94 | * |
||
95 | * @param CacheProvider $cache doctrine cache provider |
||
96 | * @param string $cacheNamespace cache namespace |
||
97 | * @param int $cacheLifetime cache lifetime |
||
98 | * |
||
99 | * @return void |
||
100 | */ |
||
101 | 1 | public function setCache(CacheProvider $cache, $cacheNamespace, $cacheLifetime) |
|
102 | { |
||
103 | 1 | $this->cache = $cache; |
|
104 | 1 | $this->cache->setNamespace($cacheNamespace); |
|
105 | 1 | $this->cacheLifetime = $cacheLifetime; |
|
106 | 1 | } |
|
107 | |||
108 | /** |
||
109 | * set curl options |
||
110 | * |
||
111 | * @param array $curlOptions the curl options |
||
112 | * |
||
113 | * @return void |
||
114 | */ |
||
115 | public function setCurlOptions(array $curlOptions) |
||
119 | |||
120 | /** |
||
121 | * @inheritDoc |
||
122 | * |
||
123 | * @param array $options cache strategy |
||
124 | * |
||
125 | * @return void |
||
126 | */ |
||
127 | 1 | public function setOptions($options) |
|
128 | { |
||
129 | 1 | if (!empty($options['prefix'])) { |
|
130 | 1 | $options['storeKey'] = $options['prefix']; |
|
131 | 1 | unset($options['prefix']); |
|
132 | 1 | } |
|
133 | |||
134 | 1 | $this->options = array_merge($this->options, $options); |
|
135 | 1 | } |
|
136 | |||
137 | /** |
||
138 | * check if the url is valid |
||
139 | * |
||
140 | * @param string $url url |
||
141 | * |
||
142 | * @return boolean |
||
143 | */ |
||
144 | 1 | public function supports($url) |
|
150 | |||
151 | /** |
||
152 | * Applies the specified curl option on a request |
||
153 | * |
||
154 | * @param RequestInterface $request request |
||
155 | * |
||
156 | * @return void |
||
157 | */ |
||
158 | 3 | protected function applyCurlOptions($request) |
|
167 | |||
168 | /** |
||
169 | * @inheritDoc |
||
170 | * |
||
171 | * @param string $input url |
||
172 | * |
||
173 | * @return ApiDefinition |
||
174 | */ |
||
175 | 3 | public function load($input) |
|
208 | |||
209 | /** |
||
210 | * fetch file from remote destination |
||
211 | * |
||
212 | * @param RequestInterface $request request |
||
213 | * |
||
214 | * @return string |
||
215 | */ |
||
216 | 2 | private function fetchFile($request) |
|
236 | } |
||
237 |