FileSystemBundle is a file system component supporting different file storage adapters.
This adapter was made to be used when you want to interact with your local file system.
Config example:
partnermarketing_file_system.default_file_system: local_storage
partnermarketing_file_system.config:
local_storage:
path: /path/to/test/directory
url: 'http://your-project-url.dev/test'
This adapter was made to be used when you want to interactive with Amazon S3 file system.
Config example:
partnermarketing_file_system.default_file_system: amazon_s3
partnermarketing_file_system.config:
amazon_s3:
key: your-amazon-key
secret: your-amazon-secret
bucket: your-bucket-name
region: eu-west-1
acl: public-read # Optional parameter.
First step is to pass the factory into where you need to use it.
# In your services.yml
YourServiceName:
class: Your\Namespace\Path\ServiceName
arguments:
fileSystemFactory: @partnermarketing_file_system.factory
Then in your ServiceName.php file you can use the factory as you need.
namespace Your\Namespace\Path;
use Partnermarketing\FileSystemBundle\Factory\FileSystemFactory;
class ServiceName
{
private $fileSystem;
public function __construct(FileSystemFactory $fileSystemFactory)
{
// This will build a fileSystem based on configs specified.
$this->filesystem = $fileSystemFactory->build();
}
}
$this->filesystem->read($varWithFilePath);
// Writes the content of the $source into the $path returns the URL.
$url = $this->filesystem->write($path, $source);
// Writes the $content into the $path returns the URL:
$url = $this->filesystem->writeContent($path, $content);
// Deletes the file $path:
$isDeleted = $this->filesystem->delete($path);
$isRenamed = $this->filesystem->rename($sourcePath, $targetPath);
// Returns an array of files under given directory.
$filesArray = $this->filesystem->getFiles($directory = '');
// Copies all files under given source directory to given target directory.
$filesArray = $this->filesystem->copyFiles($sourceDir, $targetDir);
$fileExists = $this->filesystem->exists($varWithFilePath);
$isDirectory = $this->filesystem->isDirectory($varWithFilePath);
$absoluteFileUrl = $this->filesystem->getURL($path);
// Copy a file to the local temporary directory, and return the full path.
$temporaryFilePath = $this->filesystem->copyToLocalTemporaryFile($path);
You can add more adapters or improve the existing ones.
Create a pull request and please add tests if you fix a bug or added new functionality.
Report founded issues here:
https://github.com/partnermarketing/PartnermarketingFileSystemBundle/issues