elazar / flystream Goto Github PK
View Code? Open in Web Editor NEWPHP stream wrapper for Flysystem v2/3
License: MIT License
PHP stream wrapper for Flysystem v2/3
License: MIT License
Hi,
I have a question. I'm not familiar with streams.
I'm wondering whether it is possible to store a value in memory from one script and access the value from another script and vice versa. Since the example code in readme appears to deal with memories, is it perhaps possible somehow with this library without installing extra PHP extensions?
Is there any intention to get a new major version here to support newer versions of the PSR Log interfaces?
Hello,
I tried the example in readme and got the following error.
Fatal error: Uncaught TypeError: fclose(): supplied resource is not a valid stream resource in .../vendor/elazar/flystream/src/MemoryBuffer.php on line 40
TypeError: fclose(): supplied resource is not a valid stream resource in .../vendor/elazar/flystream/src/MemoryBuffer.php on line 40
Call Stack:
0.0013 401440 1. {main}() .../scratch/flysystem-01.php:0
0.2299 1156832 2. file_put_contents($filename = 'mem://foo/bar', $data = 'bay') .../scratch/flysystem-01.php:32
0.2875 1161632 3. Elazar/Flystream/StreamWrapper->stream_close() .../scratch/flysystem-01.php:32
0.2875 1161632 4. Elazar/Flystream/MemoryBuffer->close() .../vendor/elazar/flystream/src/StreamWrapper.php:162
0.2875 1161632 5. fclose($stream = resource(50) of type (Unknown)) .../vendor/elazar/flystream/src/MemoryBuffer.php:40
<?php
include( dirname( __DIR__ ) . '/vendor/autoload.php' );
use League\Flysystem\Filesystem;
use League\Flysystem\InMemory\InMemoryFilesystemAdapter;
$adapter = new InMemoryFilesystemAdapter();
$filesystem = new Filesystem($adapter);
/**
* 2. Register the filesystem with Flystream and associate it with a
* custom protocol (e.g. 'mem').
*/
use Elazar\Flystream\FilesystemRegistry;
use Elazar\Flystream\ServiceLocator;
$registry = ServiceLocator::get(FilesystemRegistry::class);
$registry->register('mem', $filesystem);
/**
* 3. Interact with the filesystem instance using the custom protocol.
*/
mkdir('mem://foo');
$file = fopen('mem://foo/bar', 'w');
fwrite($file, 'baz');
fclose($file);
file_put_contents('mem://foo/bar', 'bay');
$contents = file_get_contents('mem://foo/bar');
// or
$contents = stream_get_contents('mem://foo/bar');
if (file_exists('mem://foo/bar')) {
rename('mem://foo/bar', 'mem://foo/baz');
touch('mem://foo/bar');
}
$file = fopen('mem://foo/baz', 'r');
fseek($file, 2);
$position = ftell($file);
ftruncate($file, 0);
fclose($file);
$dir = opendir('mem://foo');
while (($entry = readdir($dir)) !== false) {
echo $entry, PHP_EOL;
}
closedir($dir);
unlink('mem://foo/bar');
unlink('mem://foo/baz');
rmdir('mem://foo');
// These won't have any effect because Flysystem doesn't support them.
chmod('mem://foo', 0755);
chown('mem://foo', 'root');
chgrp('mem://foo', 'root');
/**
* 4. Optionally, unregister the filesystem with Flystream.
*/
$registry->unregister('mem');
touch('vol-public://foo.txt');
copy('vol-public://foo.txt', 'vol-private://bar.txt');
This creates an empty file in my public volume, but does not copy to private.
If I add content to one on public, then copy, it seems to work.
By contrast, doing this without stream wrappers works as expected.
touch('foo.txt');
copy('foo.txt', 'bar.txt');
Hello,
I just tried the example in readme and it seems
use League\Flysystem\InMemory\InMemoryFilesystemAdapter;
$adapter = new InMemoryFilesystemAdapter();
causes the error Fatal error: Uncaught Error: Class 'League\Flysystem\InMemory\InMemoryFilesystemAdapter' not found
.
I could not find the declaration for InMemoryFilesystemAdapter
in the vendor
directory downloaded with Composer.
I'm I missing something?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.