Total Complexity | 5 |
Total Lines | 49 |
Duplicated Lines | 0 % |
Coverage | 94.74% |
Changes | 0 |
1 | <?php |
||
17 | class Web extends AbstractAdapter |
||
18 | { |
||
19 | private $path; |
||
20 | private $http; |
||
21 | |||
22 | 5 | public function __construct($path, HttpInterface $http) |
|
23 | { |
||
24 | 5 | $this->path = realpath($path); |
|
25 | 5 | $this->http = $http; |
|
26 | 5 | } |
|
27 | |||
28 | /** |
||
29 | * {@inheritdoc} |
||
30 | */ |
||
31 | 1 | protected function doRun(Code $code) |
|
32 | { |
||
33 | 1 | $filename = $this->createFilename(); |
|
34 | 1 | $file = $this->createWebFile($filename); |
|
35 | 1 | $code->writeTo($file); |
|
36 | |||
37 | 1 | $content = $this->http->fetch($filename); |
|
38 | |||
39 | 1 | if (!@unlink($file)) { |
|
40 | $this->logger->debug(sprintf('Web: Could not delete file: %s', $file)); |
||
41 | } |
||
42 | |||
43 | 1 | return $content; |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param string $filename |
||
48 | * @return string |
||
49 | */ |
||
50 | 1 | protected function createWebFile($filename) |
|
51 | { |
||
52 | 1 | $file = sprintf("%s/%s", $this->path, $filename); |
|
53 | |||
54 | 1 | touch($file); |
|
55 | 1 | chmod($file, 0664); |
|
56 | |||
57 | 1 | return $file; |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * @return string |
||
62 | */ |
||
63 | 1 | protected function createFilename() |
|
66 | } |
||
67 | } |
||
68 |