@@ 5-29 (lines=25) @@ | ||
2 | ||
3 | namespace Sludio\HelperBundle\Sitemap\Dumper; |
|
4 | ||
5 | class FileDumper implements DumperFileInterface |
|
6 | { |
|
7 | use FileDumperTrait; |
|
8 | ||
9 | /** |
|
10 | * {@inheritdoc} |
|
11 | */ |
|
12 | public function dump($string) |
|
13 | { |
|
14 | if ($this->handle == null) { |
|
15 | $this->openFile(); |
|
16 | } |
|
17 | ||
18 | fwrite($this->handle, $string); |
|
19 | } |
|
20 | ||
21 | protected function openFile() |
|
22 | { |
|
23 | $this->handle = fopen($this->filename, 'w'); |
|
24 | ||
25 | if ($this->handle === false) { |
|
26 | throw new \RuntimeException(sprintf('Impossible to open the file %s in write mode', $this->filename)); |
|
27 | } |
|
28 | } |
|
29 | } |
@@ 5-29 (lines=25) @@ | ||
2 | ||
3 | namespace Sludio\HelperBundle\Sitemap\Dumper; |
|
4 | ||
5 | class GzFileDumper implements DumperFileInterface |
|
6 | { |
|
7 | use FileDumperTrait; |
|
8 | ||
9 | /** |
|
10 | * {@inheritdoc} |
|
11 | */ |
|
12 | public function dump($string) |
|
13 | { |
|
14 | if ($this->handle == null) { |
|
15 | $this->openFile(); |
|
16 | } |
|
17 | ||
18 | gzwrite($this->handle, $string); |
|
19 | } |
|
20 | ||
21 | protected function openFile() |
|
22 | { |
|
23 | $this->handle = gzopen($this->filename, 'w9'); |
|
24 | ||
25 | if ($this->handle === false) { |
|
26 | throw new \RuntimeException(sprintf('Impossible to open the file %s in write mode', $this->filename)); |
|
27 | } |
|
28 | } |
|
29 | } |