partnermarketing / file-system-bundle
支持不同文件存储适配器的文件系统组件。
3.0.3
2017-02-24 14:01 UTC
Requires
- php: >=5.4.0
- aws/aws-sdk-php: ~3.0
- symfony/filesystem: >2.3.0
Requires (Dev)
- johnkary/phpunit-speedtrap: ~1.0.0
- partnermarketing/pm-git-hooks-php: ^1.0
- phpunit/phpunit: ~4.0 | ~5.0
README
FileSystemBundle 是一个支持不同文件存储适配器的文件系统组件。
适配器
本地存储
此适配器用于与本地文件系统交互。
配置示例
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
此适配器用于与 Amazon S3 文件系统交互。
配置示例
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.
如何使用
配置
第一步是将工厂传递到需要使用它的位置。
# In your services.yml YourServiceName: class: Your\Namespace\Path\ServiceName arguments: fileSystemFactory: @partnermarketing_file_system.factory
然后在您的 ServiceName.php 文件中,您可以按需使用工厂。
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);
获取文件的绝对URL
$absoluteFileUrl = $this->filesystem->getURL($path);
将文件复制到临时目录
// Copy a file to the local temporary directory, and return the full path. $temporaryFilePath = $this->filesystem->copyToLocalTemporaryFile($path);
如何贡献
您可以为添加更多适配器或改进现有的适配器。
创建一个 pull request,如果您修复了一个错误或添加了新功能,请添加测试。
在此处报告发现的问题
https://github.com/partnermarketing/PartnermarketingFileSystemBundle/issues