1. Go to this page and download the library: Download wshafer/psr11-flysystem library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wshafer / psr11-flysystem example snippets
// Get the FlySystem FileSystem
$fileSystem = $container->get('myFileSystemService');
// Write to file
$fileSystem->put('test.txt', 'this is test');
// Create Container
$container = new \Xtreamwayz\Pimple\Container([
// FlySystem using the default keys.
'fileSystem' => new \WShafer\PSR11FlySystem\FlySystemFactory(),
// FlySystem using a different filesystem configuration
'other' => function($c) {
return \WShafer\PSR11FlySystem\FlySystemFactory::other($c);
},
// Config
'config' => [
'flysystem' => [
'adaptors' => [
// At the bare minimum you must ],
],
'fileSystems' => [
'other' => [
'adaptor' => 'someOtherAdaptor'
],
],
],
]
]);
/** @var \League\Flysystem\FilesystemInterface $fileSystem */
$fileSystem = $container->get('other');
$fileSystem->put('test1.txt', 'this is a test');
print $fileSystem->get('test1.txt')->read();
// Create the container and define the services you'd like to use
$container = new \Zend\ServiceManager\ServiceManager([
'factories' => [
// FlySystem using the default keys.
'fileSystem' => \WShafer\PSR11FlySystem\FlySystemFactory::class,
// FlySystem using a different filesystem configuration
'other' => [\WShafer\PSR11FlySystem\FlySystemFactory::class, 'other'],
],
]);
// Config
$container->setService('config', [
'flysystem' => [
'adaptors' => [
// At the bare minimum you must ],
],
],
]);
/** @var \League\Flysystem\FilesystemInterface $fileSystem */
$fileSystem = $container->get('other');
$fileSystem->put('test1.txt', 'this is a test');
print $fileSystem->get('test1.txt')->read();
return [
'dependencies' => [
'factories' => [
// FlySystem using the default keys.
'fileSystem' => \WShafer\PSR11FlySystem\FlySystemFactory::class,
// FlySystem using a different filesystem configuration
'other' => [\WShafer\PSR11FlySystem\FlySystemFactory::class, 'other'],
],
],
'flysystem' => [
'adaptors' => [
// At the bare minimum you must leSystems' => [
'other' => [
'adaptor' => 'someOtherAdaptor'
],
],
],
];
return [
'service_manager' => [
'factories' => [
// FlySystem using the default keys.
'fileSystem' => \WShafer\PSR11FlySystem\FlySystemFactory::class,
// FlySystem using a different filesystem configuration
'other' => [\WShafer\PSR11FlySystem\FlySystemFactory::class, 'other'],
],
],
'flysystem' => [
'adaptors' => [
// At the bare minimum you must ystems' => [
'other' => [
'adaptor' => 'someOtherAdaptor'
],
],
],
];
return [
// ... Previously registered modules here
'WShafer\\PSR11FlySystem',
];
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class DefaultController extends Controller
{
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
$fileSystem = $this->container->get('fileSystem');
$fileSystem->write('default.txt', 'Hi there');
$fileSystem = $this->container->get('other');
$fileSystem->write('other.txt', 'Hi there');
}
}
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
// At the bare minimum you must ],
],
// Some other Adaptor. Keys are the names for each adaptor
'someOtherAdaptor' => [
'type' => 'local',
'options' => [
'root' => '/tmp/slim'
],
],
],
'fileSystems' => [
'other' => [
'adaptor' => 'someOtherAdaptor'
],
],
],
],
];
$app = new \Slim\App($config);
// Wire up the factory
$container = $app->getContainer();
// FlySystem using the default keys.
$container['fileSystem'] = new \WShafer\PSR11FlySystem\FlySystemFactory();
// FlySystem using a different filesystem configuration
$container['other'] = function ($c) {
return \WShafer\PSR11FlySystem\FlySystemFactory::other($c);
};
// Example usage
$app->get('/example', function (Request $request, Response $response) {
/** @var \League\Flysystem\FilesystemInterface $fileSystem */
$fileSystem = $this->get('fileSystem');
$fileSystem->put('default.txt', 'Hi there');
/** @var \League\Flysystem\FilesystemInterface $fileSystem */
$fileSystem = $this->get('other');
$fileSystem->put('other.txt', 'Hi there');
});
$app->run();
return [
'dependencies' => [
'factories' => [
// FlySystem using the default keys.
'MyServiceName' => \WShafer\PSR11FlySystem\FlySystemFactory::class,
],
],
'flysystem' => [
'adaptors' => [
// Array Keys are the names used for the adaptor
'default' => [
'type' => 'local', # Adaptor name or pre-configured service from the container
// Adaptor specific options. See adaptors below
'options' => [
'root' => '/path/to/root', // Path on local filesystem
],
],
],
],
];
return [
'flysystem' => [
'adaptors' => [
// Array Keys are the names used for the adaptor. Default entry
// Adaptor specific options. See adaptors below
'options' => [
'root' => '/path/to/root', // Path on local filesystem
],
],
'adaptorTwo' => [
'type' => 'null', // Adaptor name or pre-configured service from the container
'options' => [], // Adaptor specific options. See adaptors below
],
],
'caches' => [
// Array Keys are the names used for the cache
//
// Note: You can specify "default" here to overwrite the default settings for the
// default cache. Memory is used if not specified
'default' => [
'type' => 'psr6',
// Cache specific options. See caches below
'options' => [
'service' => 'my_psr6_service_from_container',
'key' => 'my_key_',
'ttl' => 3000
],
],
'cacheTwo' => [
'type' => 'psr6',
// Cache specific options. See caches below
'options' => [
'service' => 'my_psr6_service_from_container',
'key' => 'my_key_',
'ttl' => 3000
],
],
],
'fileSystems' => [
// Array Keys are the file systems identifiers.
//
// Note: You can specify "default" here to overwrite the default settings for the
// default file system
'default' => [
'adaptor' => 'default', // Adaptor name from adaptor configuration
'cache' => 'default', // Cache name from adaptor configuration
'plugins' => [] // User defined plugins to be injected into the file system
],
// Mount Manager Config
'manager' => [
'adaptor' => 'manager',
'fileSystems' => [
'local' => [
'adaptor' => 'default', // Adaptor name from adaptor configuration
'cache' => 'default', // PSR-6 pre-configured service
'plugins' => [] // User defined plugins to be injected into the file system
],
'anotherFileSystem' => [
'adaptor' => 'adaptorTwo', // Adaptor name from adaptor configuration
'cache' => 'cacheTwo', // PSR-6 pre-configured service
'plugins' => [] // User defined plugins to be injected into the file system
],
],
],
],
],
];
return [
'flysystem' => [
'fileSystems' => [
// Array Keys are the file systems identifiers
'myFileSystemName' => [
'adaptor' => 'default', // Required : Adaptor name from adaptor configuration
'cache' => 'default', // Optional : Cache name from adaptor configuration
'plugins' => [] // Optional : User defined plugins to be injected into the file system
],
],
],
];