partnermarketing/file-system-bundle
最新稳定版本:3.0.3
Composer 安装命令:
composer require partnermarketing/file-system-bundle
包简介
A file system component supporting different file storage adapters.
README 文档
README
FileSystemBundle is a file system component supporting different file storage adapters.
Adapters:
Local storage
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'
Amazon S3
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.
How to use
Configuration
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(); } }
Read a file content
$this->filesystem->read($varWithFilePath);
Write content from a file to other
// Writes the content of the $source into the $path returns the URL. $url = $this->filesystem->write($path, $source);
Write content into a file
// Writes the $content into the $path returns the URL: $url = $this->filesystem->writeContent($path, $content);
Delete a file
// Deletes the file $path: $isDeleted = $this->filesystem->delete($path);
Rename a file
$isRenamed = $this->filesystem->rename($sourcePath, $targetPath);
Get files from directory
// Returns an array of files under given directory. $filesArray = $this->filesystem->getFiles($directory = '');
Copy files from one directory to another
// Copies all files under given source directory to given target directory. $filesArray = $this->filesystem->copyFiles($sourceDir, $targetDir);
Check if a file exist
$fileExists = $this->filesystem->exists($varWithFilePath);
Check if path is a directory
$isDirectory = $this->filesystem->isDirectory($varWithFilePath);
Gets the Absolute URL to a file
$absoluteFileUrl = $this->filesystem->getURL($path);
Copy file to temporary directory
// Copy a file to the local temporary directory, and return the full path. $temporaryFilePath = $this->filesystem->copyToLocalTemporaryFile($path);
How to contribute
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
统计信息
- 总下载量: 9.03k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2014-12-01