@@ 36-66 (lines=31) @@ | ||
33 | /** |
|
34 | * @inheritdoc |
|
35 | */ |
|
36 | public function transform(ResourceInterface $resource, ResourceCollection $collection) |
|
37 | { |
|
38 | $file = $resource->getFile()->getPathname(); |
|
39 | ||
40 | // the file could be big, so just read the |
|
41 | $tmpFile = tempnam(sys_get_temp_dir(), $file); |
|
42 | $old = fopen($file, 'r'); |
|
43 | $new = fopen($tmpFile, 'w'); |
|
44 | ||
45 | // write the beginning with the xml declaration replaced |
|
46 | fwrite($new, preg_replace($this->xmlDeclarationRegEx, $this->xmlDeclaration, fread($old, 96))); |
|
47 | ||
48 | // now copy the rest of the file |
|
49 | while (!feof($old)) { |
|
50 | fwrite($new, fread($old, 8192)); |
|
51 | } |
|
52 | ||
53 | fclose($old); |
|
54 | fclose($new); |
|
55 | ||
56 | // atomic write |
|
57 | $this->rename($tmpFile, $file); |
|
58 | ||
59 | $transport = FileTransport::create($file); |
|
60 | ||
61 | if ($resource->getTransport()) { |
|
62 | $transport->setDestinationDir($resource->getTransport()->getDestinationDir()); |
|
63 | } |
|
64 | ||
65 | return new FileResource($transport); |
|
66 | } |
|
67 | ||
68 | /** |
|
69 | * @inheritdoc |
@@ 37-67 (lines=31) @@ | ||
34 | /** |
|
35 | * @inheritdoc |
|
36 | */ |
|
37 | public function transform(ResourceInterface $resource, ResourceCollection $collection) |
|
38 | { |
|
39 | $file = $resource->getFile()->getPathname(); |
|
40 | ||
41 | // the file could be big, so just read the |
|
42 | $tmpFile = tempnam(sys_get_temp_dir(), $file); |
|
43 | $old = fopen($file, 'r'); |
|
44 | $new = fopen($tmpFile, 'w'); |
|
45 | ||
46 | // write the beginning with the BOM stripped |
|
47 | fwrite($new, preg_replace($this->getBomRegex(), '', fread($old, 16))); |
|
48 | ||
49 | // now copy the rest of the file |
|
50 | while (!feof($old)) { |
|
51 | fwrite($new, fread($old, 8192)); |
|
52 | } |
|
53 | ||
54 | fclose($old); |
|
55 | fclose($new); |
|
56 | ||
57 | // atomic write |
|
58 | $this->rename($tmpFile, $file); |
|
59 | ||
60 | $transport = FileTransport::create($file); |
|
61 | ||
62 | if ($resource->getTransport()) { |
|
63 | $transport->setDestinationDir($resource->getTransport()->getDestinationDir()); |
|
64 | } |
|
65 | ||
66 | return new FileResource($transport); |
|
67 | } |
|
68 | ||
69 | /** |
|
70 | * @inheritdoc |