1 | <?php |
||
26 | class HttpLoader implements LoaderInterface |
||
27 | { |
||
28 | /** |
||
29 | * @var ValidatorInterface |
||
30 | */ |
||
31 | private $validator; |
||
32 | |||
33 | /** |
||
34 | * @var Client |
||
35 | */ |
||
36 | private $client; |
||
37 | |||
38 | /** |
||
39 | * @var LoggerInterface |
||
40 | */ |
||
41 | private $logger; |
||
42 | |||
43 | /** |
||
44 | * @var DispersalStrategyInterface |
||
45 | */ |
||
46 | private $strategy; |
||
47 | |||
48 | /** |
||
49 | * doctrine cache |
||
50 | * |
||
51 | * @var CacheProvider |
||
52 | */ |
||
53 | private $cache; |
||
54 | |||
55 | /** |
||
56 | * doctrine cache lifetime |
||
57 | * |
||
58 | * @var int |
||
59 | */ |
||
60 | private $cacheLifetime; |
||
61 | |||
62 | /** |
||
63 | * @var array |
||
64 | */ |
||
65 | private $options = [ |
||
66 | 'storeKey' => 'httpLoader', |
||
67 | ]; |
||
68 | |||
69 | /** |
||
70 | * constructor |
||
71 | * |
||
72 | * @param ValidatorInterface $validator validator |
||
73 | * @param Client $client http client |
||
74 | * @param LoggerInterface $logger Logger |
||
75 | */ |
||
76 | 8 | public function __construct(ValidatorInterface $validator, Client $client, LoggerInterface $logger) |
|
82 | |||
83 | /** |
||
84 | * @inheritDoc |
||
85 | * |
||
86 | * @param DispersalStrategyInterface $strategy dispersal strategy |
||
87 | * |
||
88 | * @return void |
||
89 | */ |
||
90 | 6 | public function setDispersalStrategy(DispersalStrategyInterface $strategy) |
|
94 | |||
95 | /** |
||
96 | * @inheritDoc |
||
97 | * |
||
98 | * @param CacheProvider $cache doctrine cache provider |
||
99 | * @param string $cacheNamespace cache namespace |
||
100 | * @param int $cacheLifetime cache lifetime |
||
101 | * |
||
102 | * @return void |
||
103 | */ |
||
104 | 2 | public function setCache(CacheProvider $cache, $cacheNamespace, $cacheLifetime) |
|
110 | |||
111 | /** |
||
112 | * @inheritDoc |
||
113 | * |
||
114 | * @param array $options cache strategy |
||
115 | * |
||
116 | * @return void |
||
117 | */ |
||
118 | 2 | public function setOptions($options) |
|
119 | { |
||
120 | 2 | if (!empty($options['prefix'])) { |
|
121 | 2 | $options['storeKey'] = $options['prefix']; |
|
122 | 2 | unset($options['prefix']); |
|
123 | } |
||
124 | |||
125 | 2 | $this->options = array_merge($this->options, $options); |
|
126 | 2 | } |
|
127 | |||
128 | /** |
||
129 | * check if the url is valid |
||
130 | * |
||
131 | * @param string $url url |
||
132 | * |
||
133 | * @return boolean |
||
134 | */ |
||
135 | 2 | public function supports($url) |
|
141 | |||
142 | /** |
||
143 | * @inheritDoc |
||
144 | * |
||
145 | * @param string $input url |
||
146 | * |
||
147 | * @return ApiDefinition |
||
148 | */ |
||
149 | 6 | public function load($input) |
|
185 | |||
186 | /** |
||
187 | * fetch file from remote destination |
||
188 | * |
||
189 | * @param RequestInterface $request request |
||
190 | * |
||
191 | * @return string |
||
192 | */ |
||
193 | 4 | private function fetchFile(RequestInterface $request) |
|
215 | } |
||
216 |