### Install Gaufrette FTP Adapter Source: https://knplabs.github.io/Gaufrette/adapters/ftp Installs the Gaufrette FTP adapter using Composer. This command requires Composer to be installed on your system. The 'ftp' PHP extension must also be enabled. ```bash composer require gaufrette/ftp-adapter ``` -------------------------------- ### Install Flysystem Dropbox Adapter Source: https://knplabs.github.io/Gaufrette/adapters/flysystem This command installs the Flysystem Dropbox adapter using Composer. This is a prerequisite for using the Flysystem adapter with Dropbox. ```bash $ composer require league/flysystem-dropbox ``` -------------------------------- ### Install Azure Blob Storage Adapter for Gaufrette Source: https://knplabs.github.io/Gaufrette/adapters/azure-blob-storage This command installs the Azure Blob Storage adapter for Gaufrette using Composer. It requires the Azure SDK for PHP to be installed in your project. ```bash composer require gaufrette/azure-blob-storage-adapter ``` -------------------------------- ### Install PHP-SSH and SSH2 Extension Source: https://knplabs.github.io/Gaufrette/adapters/sftp Instructions for installing the necessary PHP extensions for SFTP functionality using Composer and PECL. Ensure these are installed before attempting to use the SFTP adapter. ```bash composer require herzult/php-ssh:^1.1 pecl install ssh2-beta ``` -------------------------------- ### Install Flysystem Adapter for Gaufrette Source: https://knplabs.github.io/Gaufrette/adapters/flysystem This command installs the Gaufrette Flysystem adapter using Composer. This adapter enables Gaufrette to work with any Flysystem-compatible adapter. ```bash composer require gaufrette/flysystem-adapter ``` -------------------------------- ### Initialize Gaufrette SFTP Adapter with Filesystem Source: https://knplabs.github.io/Gaufrette/adapters/sftp Example of initializing the Gaufrette SFTP adapter and creating a Filesystem instance. This requires an existing SftpClient object, a base directory path, and a boolean to enable automatic directory creation. ```php beConstructedWith($storage); } function it_is_adapter() { $this->shouldImplement('Gaufrette\Adapter'); } } ``` -------------------------------- ### Install Gaufrette Extras with Composer Source: https://knplabs.github.io/Gaufrette/extras This command installs the Gaufrette Extras package using Composer, making its additional features available for your project. ```bash composer require gaufrette/extras ``` -------------------------------- ### Install phpseclib SFTP Adapter via Composer Source: https://knplabs.github.io/Gaufrette/adapters/phpseclib-sftp This command installs the necessary phpseclib SFTP adapter package using Composer. It's a prerequisite for using the adapter. ```bash composer require gaufrette/phpseclib-sftp-adapter ``` -------------------------------- ### Install Doctrine DBAL Adapter for Gaufrette Source: https://knplabs.github.io/Gaufrette/adapters/doctrine-dbal This command installs the Doctrine DBAL adapter for Gaufrette using Composer. It's a prerequisite for using the adapter. ```bash composer require gaufrette/doctrine-dbal-adapter ``` -------------------------------- ### Install AWS S3 Adapter with Composer Source: https://knplabs.github.io/Gaufrette/adapters/aws-s3 Installs the Gaufrette AWS S3 adapter using Composer. You can also optionally install a specific version of the AWS SDK for PHP (v2 or v3). ```bash composer require gaufrette/aws-s3-adapter composer require aws/aws-sdk-php ``` -------------------------------- ### Install Gaufrette GridFS Adapter Source: https://knplabs.github.io/Gaufrette/adapters/grid-fs Installs the Gaufrette GridFS adapter using Composer. This library provides the necessary components to integrate Gaufrette with MongoDB's GridFS. ```bash composer require gaufrette/gridfs-adapter ``` -------------------------------- ### Configure Pure Ftpd to Display Hidden Files Source: https://knplabs.github.io/Gaufrette/adapters/ftp Configures Pure Ftpd to display hidden files (those starting with a dot). This involves creating a configuration file on the FTP server. This is specific to Pure Ftpd installations. ```bash echo "yes" > /etc/pure-ftpd/conf/DisplayDotFiles ``` -------------------------------- ### Install MongoDB PHP Driver Source: https://knplabs.github.io/Gaufrette/adapters/grid-fs Installs the MongoDB PHP driver using the PECL package manager. This is a prerequisite for using the GridFS adapter. ```bash pecl install mongodb ``` -------------------------------- ### Register and Use StreamWrapper for Gaufrette Filesystems (PHP) Source: https://knplabs.github.io/Gaufrette/streaming This example shows how to register a Gaufrette filesystem with the StreamWrapper, making it accessible via traditional file paths (e.g., 'gaufrette://'). It demonstrates registering a filesystem, performing copy and unlink operations, and reading file content using standard PHP functions. ```php $adapter = new InMemoryAdapter(array('hello.txt' => 'Hello World!')); $filesystem = new Filesystem($adapter); $map = StreamWrapper::getFilesystemMap(); $map->set('foo', $filesystem); StreamWrapper::register(); copy('gaufrette://foo/hello.txt', 'gaufrette://foo/world.txt'); unlink('gaufrette://foo/hello.txt'); echo file_get_contents('gaufrette://foo/world.txt'); // Says "Hello World!" ``` -------------------------------- ### Use Gaufrette FTP Adapter in PHP Source: https://knplabs.github.io/Gaufrette/adapters/ftp Demonstrates how to create and use the Gaufrette FTP adapter in a PHP application. This example shows how to pass connection details and configuration options such as port, username, password, passive mode, directory creation, transfer mode (binary/text), and SSL. ```php 21, 'username' => 'my_username', 'password' => 'my_password', 'passive' => true, 'create' => true, // Whether to create the remote directory if it does not exist 'mode' => FTP_BINARY, // Or FTP_TEXT 'ssl' => true, )); $filesystem = new Filesystem($adapter); ``` -------------------------------- ### PHP: Connect to Rackspace Storage with Gaufrette Source: https://knplabs.github.io/Gaufrette/adapters/open-cloud Demonstrates how to connect to Rackspace cloud storage using its specific SDK and integrate with Gaufrette. This example differs from standard OpenCloud by using the OpenCloud\Rackspace connection class. It requires the OpenCloud SDK and gaufrette/opencloud-adapter. Input includes Rackspace credentials and container name, outputting a Filesystem object. ```php 'rackspace-user', 'apiKey' => '0900af093093788912388fc09dde090ffee09' ) ); $objectStore = $connection->objectStoreService('cloudFiles', 'LON', 'publicURL'); $adapter = new OpenCloudAdapter( $objectStore, 'container-name' ); $filesystem = new Filesystem($adapter); ``` -------------------------------- ### AWS IAM Policy for S3 Bucket Access Source: https://knplabs.github.io/Gaufrette/adapters/aws-s3 A recommended IAM policy for granting specific permissions to an S3 bucket. It includes actions for creating, listing, putting, getting, and deleting objects. Replace 'bucket_name' with your actual bucket name. ```json { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:CreateBucket", "s3:ListBucket" ], "Resource": [ "arn:aws:s3:::bucket_name" ] }, { "Effect": "Allow", "Action": [ "s3:PutObject", "s3:GetObject", "s3:DeleteObject" ], "Resource": [ "arn:aws:s3:::bucket_name/*" ] } ] } ``` -------------------------------- ### Gaufrette Basic Usage with Local Filesystem Adapter (PHP) Source: https://knplabs.github.io/Gaufrette/basic-usage This snippet illustrates how to initialize and use the Gaufrette filesystem with the local adapter. It demonstrates reading, writing, and renaming files, as well as accessing file metadata such as modification time. Requires the Gaufrette library and a local directory for storage. ```php read('myFile')); // bool(false) $filesystem->write('myFile', 'Hello world!'); // Or use File objects $file = $filesystem->get('myFile'); echo sprintf('%s (modified %s): %s', $file->getKey(), date('d/m/Y, H:i:s', $file->getMtime()), $file->getContent()); // Will print something like: "myFile (modified 17/01/2016 18:40:36): Hello world!" // You can also rename your file like this: $file->rename('my/new/file'); ``` -------------------------------- ### Initialize Gaufrette GridFS Adapter Source: https://knplabs.github.io/Gaufrette/adapters/grid-fs Demonstrates how to initialize the Gaufrette GridFS adapter. It requires a MongoDB client connection and a selected database to interact with GridFS. ```php $client = new \MongoDB\Client('mongodb://localhost:27017'); $db = $client->selectDatabase('dbname'); $adapter = new \Gaufrette\Adapter\GridFS($db->selectGridFSBucket()); ``` -------------------------------- ### Wrap Flysystem Dropbox Adapter with Gaufrette Source: https://knplabs.github.io/Gaufrette/adapters/flysystem This PHP code demonstrates how to wrap a Flysystem Dropbox adapter with the Gaufrette Flysystem adapter. It initializes a Dropbox client and then creates a Gaufrette Filesystem instance. ```php ', '') ) ); $filesystem = new Gaufrette\Filesystem($adapter); ``` -------------------------------- ### PHP: Initialize AWS S3 Client and Gaufrette Filesystem Source: https://knplabs.github.io/Gaufrette/adapters/aws-s3 Demonstrates how to initialize an S3 client using the AWS SDK for PHP (v2 and v3) and create a Gaufrette Filesystem instance with the AwsS3Adapter. Requires AWS credentials and a bucket name. ```php [ 'key' => 'your_key_here', 'secret' => 'your_secret', ], 'version' => 'latest', 'region' => 'eu-west-1', ]); // For aws-sdk-php v2 $s3client = S3Client::factory([ 'credentials' => [ 'key' => 'your_key_here', 'secret' => 'your_secret', ], 'version' => '2006-03-01', 'region' => 'eu-west-1', ]); $adapter = new AwsS3Adapter($s3client,'your-bucket-name'); $filesystem = new Filesystem($adapter); ``` -------------------------------- ### Instantiate and Use Azure Blob Storage Adapter with Gaufrette Source: https://knplabs.github.io/Gaufrette/adapters/azure-blob-storage Demonstrates how to instantiate and use the Gaufrette Azure Blob Storage adapter in both single-container and multi-container modes. It shows how to configure the adapter with a BlobProxyFactory and connection string, and how to perform write operations. ```php write('my/stuff.txt', 'This is my stuff'); // multi-container mode $adapter = new Gaufrette\Adapter\AzureBlobStorage($factory); // make auto-created containers public by default $containerOptions = new MicrosoftAzure\Storage\Blob\Models\CreateContainerOptions; $containerOptions->setPublicAccess(true); $adapter->setCreateContainerOptions($containerOptions); $filesystem = new Gaufrette\Filesystem($adapter); // container=my (auto-created), path=stuff.txt $filesystem->write('my/stuff.txt', 'This is my stuff'); ``` -------------------------------- ### Initialize Gaufrette Filesystem with Doctrine DBAL Adapter (PHP) Source: https://knplabs.github.io/Gaufrette/adapters/doctrine-dbal This PHP code demonstrates how to initialize the Gaufrette filesystem using the Doctrine DBAL adapter. It requires a prepared DBAL connection and a table name. The adapter stores files in a specified database table. ```php getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock(); } $adapter = new DbalAdapter($connection, 'files'); $filesystem = new Filesystem($adapter); ``` -------------------------------- ### Initialize GoogleCloudStorage Adapter in PHP Source: https://knplabs.github.io/Gaufrette/adapters/google-cloud-storage This snippet demonstrates how to initialize the GoogleCloudStorage adapter for Gaufrette. It requires the Google APIs Client Library for PHP and a pre-configured Google Cloud Storage bucket. The output is a Gaufrette Filesystem instance ready for use. ```php setClientId('xxxxxxxxxxxxxxx.apps.googleusercontent.com'); $client->setApplicationName('Gaufrette'); $cred = new \Google_Auth_AssertionCredentials( 'xxxxxxxxxxxxxxx@developer.gserviceaccount.com', array(\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL), file_get_contents('key.p12') ); $client->setAssertionCredentials($cred); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion($cred); } $service = new \Google_Service_Storage($client); $adapter = new Gaufrette\Adapter\GoogleCloudStorage($service, $config['gcsBucket'], array( 'acl' => 'public', ), true); $filesystem = new Gaufrette\Filesystem($adapter); ``` -------------------------------- ### Configure Gaufrette with phpseclib SFTP Adapter Source: https://knplabs.github.io/Gaufrette/adapters/phpseclib-sftp This code snippet demonstrates how to configure Gaufrette to use the phpseclib SFTP adapter. It involves creating an SFTP connection, logging in, and then instantiating the Gaufrette adapter with the SFTP connection and optional parameters. ```php $sftp = new phpseclib\Net\SFTP($host = 'localhost', $port = 22); //now you need to login manually with the lib $sftp->login('foo', 'bar'); $adapter = new Gaufrette\Adapter\PhpseclibSftp($sftp, $distantDirectory = null, $createDirectoryIfDoesntExist = false); $filesystem = new Gaufrette\Filesystem($adapter); ``` -------------------------------- ### Instantiate Gaufrette APC Adapter (PHP) Source: https://knplabs.github.io/Gaufrette/adapters/apc This snippet shows how to create an instance of the Gaufrette APC adapter. It requires the 'apc' PHP extension. The adapter takes a mandatory prefix and an optional Time-To-Live (TTL) value for cached files. ```php 'root/dir'])); $filesystem = new ResolvableFilesystem( $decorated, new AwsS3PresignedUrlResolver($client, 'my_bucket', 'root/dir') ); // should return something like "https://eu-west-1.blabla.aws.com/my_bucket/root/dir/foo/bar.png?token" var_dump($filesystem->resolve('foo/bar.png')); ``` -------------------------------- ### PHP: Connect to OpenCloud Storage with Gaufrette Source: https://knplabs.github.io/Gaufrette/adapters/open-cloud Establishes a connection to OpenCloud ObjectStore using the OpenCloud SDK and configures a Gaufrette adapter for filesystem operations. Requires the OpenCloud SDK and gaufrette/opencloud-adapter. Input is connection credentials and container name; output is a configured Filesystem object. ```php 'your username', 'password' => 'your Keystone password', 'tenantName' => 'your tenant (project) name' ) ); $objectStore = $connection->objectStoreService('cloudFiles', 'LON', 'publicURL'); $adapter = new OpenCloudAdapter( $objectStore, 'container-name' ); $filesystem = new Filesystem($adapter); ``` -------------------------------- ### PHP: Use LazyOpenCloud Adapter for Gaufrette Source: https://knplabs.github.io/Gaufrette/adapters/open-cloud Implements a lazy-loading Gaufrette adapter for OpenCloud storage to improve performance by deferring authentication until the filesystem is actually used. This is recommended for scenarios where the connection might not always be necessary. It requires an existing OpenCloud connection object and the container name. Output is a Filesystem object initialized with the lazy adapter. ```php