StreamWrapper, write called twice
JoniJnm opened this issue · comments
Jónatan Núñez commented
I was testing with google cloud storage and seems that content is uploaded twice using StreamWrapper.
The test:
<?php
use Gaufrette\Adapter\GoogleCloudStorage;
use Gaufrette\Filesystem;
use Gaufrette\StreamWrapper;
require_once(__DIR__ . '/../vendor/autoload.php');
const AUTH_FILE = './google-cloud.json';
const BUCKET_NAME = 'testing';
const LOCAL_FILE = __DIR__.'/test.txt';
// Create filesystem
$googleClient = new \Google_Client();
$googleClient->setAuthConfig(AUTH_FILE);
$googleClient->addScope(\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL);
$service = new \Google_Service_Storage($googleClient);
$adapter = new class($service, BUCKET_NAME) extends GoogleCloudStorage
{
public function write($key, $content)
{
echo 'write strlen ' . strlen($content) . PHP_EOL;
return parent::write($key, $content);
}
};
$filesystem = new Filesystem($adapter);
// Register wrapper
$map = StreamWrapper::getFilesystemMap();
$map->set(BUCKET_NAME, $filesystem);
StreamWrapper::register();
// Upload file
copy(LOCAL_FILE, 'gaufrette://' . BUCKET_NAME . '/test.txt');
The output is:
jnunez@xxx:~$ php ./test.php
write strlen 0
write strlen 5
write strlen 5
Changing
copy(LOCAL_FILE, 'gaufrette://' . BUCKET_NAME . '/test.txt');
by
$filesystem->write('/test.txt', file_get_contents(LOCAL_FILE));
The output is:
jnunez@xxx:~$ php ./test.php
write strlen 5
Is there a bug?