integrated/storage-bundle
Composer 安装命令:
composer require integrated/storage-bundle
包简介
Integrated Storage Bundle
关键字:
README 文档
README
This bundle enhances storage in any Integrated (0.4+) project.
Requirements
- See the require section in the composer.json
Documentation
Installation
This bundle can be installed following these steps:
Install using composer
$ php composer.phar require integrated/storage-bundle:~0.4
Enable the bundle
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new Knp\Bundle\GaufretteBundle\KnpGaufretteBundle(),
new Integrated\Bundle\StorageBundle\IntegratedStorageBundle()
// ...
);
}
Configuration
The bundle makes use of knplabs/knp-gaufrette-bundle for configuration and a filesystem map. When you've enabled the bundle this config below is required for a default Integrated installation.
# app/config.yml
knp_gaufrette:
adapters:
foo:
local:
directory: %kernel.root_dir%/../web/uploads/documents
filesystems:
foo:
adapter: foo
integrated_storage:
resolver:
foo:
public: /uploads/documents
The StorageBundle places the files on all known filesystems when no decision mapping exists. The order defined in the configuration will be used to determine its primary path. When a filesystem has no resolver storage (for protected files) the developer must write an own implementation to give access to file (see Protecting files section). The filesystems (foo above) in the knp_gaufrette configuration are linked to the integrated_storage configuration. Based on the key(s) a resolver or decision map entry is linked to a filesystem.
Configuring the assets
The IntegratedStorageBundle uses the SpBowerBundle for handling the external resources.
# app/config/config.yml
sp_bower:
bundles:
IntegratedStorageBundle: ~
Routing
The routing needs to be to imported into the application to support usage in various Integrated components.
# app/routing.yml
integrated_storage:
resource: "@IntegratedStorageBundle/Resources/config/routing/storage.xml"
prefix: "/"
Decision map
Additionally to protected entities from being stored in a public accessible resource a developer can configure filesystems for entities.
You can enforce entities to be stored in specific storage(s) (thus preventing a public storage).
# app/config.yml
integrated_storage:
// ...
decision_map:
"Integrated\Bundle\ContentBundle\Document\File": [foo]
The redistribution command does not make use of the decision map and copies all files in the given storage.
Identifier
A file requires an unique identifier. By default the identifier is based on the contents of the file. You can write your own implementation of Integrated\Common\Storage\Identifier\IdentifierInterface. The config below is default and does not have to be set.
# app/config.yml
integrated_storage:
// ...
identifier_class: Integrated\Bundle\StorageBundle\Storage\Identifier\FileIdentifier
Resolver
A resolver returns the location of the stored file, providing a location for a browser. The filesystem does is not linked to public accessible location, for each filesystem a resolver must be written. In some cases you will need to add filesystem specific logic to the resolver. You can write your own implementation of Integrated\Common\Storage\Resolver\ResolverInterface.
The config below is default and does not have to be set.
# app/config.yml
integrated_storage:
// ..
resolver:
foo:
public: /uploads/documents
resolver_class: Integrated\Bundle\StorageBundle\Storage\Resolver\LocalResolver
The arguments given to the resolver are passed in the options variable of the constructor. You can add a service or a parameter to your resolver trough the configuration.
Protecting files
In some cases the files may not be stored in a public available directory. Most cases a directory on the home of the user is enough which can be stored local. You can do this by adding an additional private local storage. However files can also be stored on any remote by not defining an resolver.
A controller might look like the following:
// File is a Integrated\Common\Content\Document\FileInterface object
$response = new Response();
$response->setContent($file->getContent());
$response->setHeaders($file->getMetadata()->getHeaders());
Data fixtures
In order to make use of the StorageBundle in fixtures the file must exist on disk and must be created by an StorageManager. The manager creates the file on the disk as configured in the application. The file exists and is placed on the correct filesystem with the required properties. To use the helper you must add a trait to your LoadFixtureData class and the LoadFixtureData class must be ContainerAware to have access to the container.
// Required class and trait
use Integrated\Bundle\StorageBundle\DataFixtures\MongoDB\Extension\FileExtensionTrait;
use Integrated\Bundle\StorageBundle\DataFixtures\MongoDB\Extension\ImageExtensionTrait;
use Integrated\Bundle\StorageBundle\DataFixtures\MongoDB\Extension\VideoExtensionTrait;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
...
class LoadFixtureData implements FixtureInterface, ContainerAwareInterface {
// The trait to include the public helper
use FileExtensionTrait;
use ImageExtensionTrait;
use VideoExtensionTrait;
use ContainerAwareTrait;
Now you can use the following in your alice/Fixtures.yml file:
# Create an image (storage object)
<createImage(300, 400, 'nature')>
# Create a file type (might be slower because it uses lorempixel)
<createFile($this->fake('image', '', '/tmp', 300, 400, 'business'), 'name')>
# Create a storage object (file) (might be slower because it uses lorempixel)
<createStorage($this->fake('image', '', '/tmp', 300, 400, 'city'))>
# Create a random video (storage object) (from wosvideo.e-activesites.nl)
<createVideo()>
Depending on your implementation you can remove the type and extension requirements or as a parameter in whole.
License
This bundle is under the MIT license. See the complete license in the bundle:
LICENSE
Contributing
Pull requests are welcome. Please see our CONTRIBUTING guide.
About
This bundle is part of the Integrated project. You can read more about this project on the Integrated for Developers website.
integrated/storage-bundle 适用场景与选型建议
integrated/storage-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.05k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 07 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「storage」 「Integrated」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 integrated/storage-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 integrated/storage-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 integrated/storage-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SDK for working with B2 cloud storage.
Small library to access Microsoft Windows Azure Blob Storage with a Service or a StreamWrapper.
Integrated Content Bundle
Integrated Library
Integrated User Bundle
Integrated FormType Bundle
统计信息
- 总下载量: 3.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-07-31