集成 / 存储包
集成存储包
Requires
- php: >=5.4
- doctrine/collections: ~1.3
- fzaninotto/faker: ~1.6
- integrated/asset-bundle: ~0.7
- integrated/content-bundle: ~0.7
- integrated/image-bundle: ~0.7
- integrated/library: ~0.7
- knplabs/knp-gaufrette-bundle: ~0.1.7
- symfony/symfony: ~2.8 || ~3.0
Requires (Dev)
- phpunit/phpunit: ^5.7
- squizlabs/php_codesniffer: ^2.8
Suggests
- ext-imagick: Allows more image formats to be uploaded
This package is auto-updated.
Last update: 2024-08-28 06:03:52 UTC
README
此包增强了任何集成(0.4+)项目中的存储。
要求
- 请参阅 composer.json 中的 require 部分
文档
安装
按照以下步骤安装此包
使用 composer 安装
$ php composer.phar require integrated/storage-bundle:~0.4
启用包
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new Knp\Bundle\GaufretteBundle\KnpGaufretteBundle(),
new Integrated\Bundle\StorageBundle\IntegratedStorageBundle()
// ...
);
}
配置
此包利用 knplabs/knp-gaufrette-bundle 进行配置和文件系统映射。启用包后,以下配置对于默认集成安装是必需的。
# 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
当没有决策映射存在时,存储包将文件放置在所有已知的文件系统中。配置中定义的顺序将用于确定其主路径。当一个文件系统没有解析器存储(用于受保护文件)时,开发者必须编写自己的实现以提供文件访问(请参阅 保护文件 部分)。在 knp_gaufrette 配置中的文件系统(如上面的 foo)与 integrated_storage 配置链接。根据键(s),解析器或决策映射条目链接到文件系统。
配置资源
IntegratedStorageBundle 使用 SpBowerBundle 来处理外部资源。
# app/config/config.yml
sp_bower:
bundles:
IntegratedStorageBundle: ~
路由
需要将路由导入应用程序以支持在各个集成组件中使用。
# app/routing.yml
integrated_storage:
resource: "@IntegratedStorageBundle/Resources/config/routing/storage.xml"
prefix: "/"
决策映射
除了将受保护的实体存储在公共可访问的资源中,开发者还可以为实体配置文件系统。
可以强制实体存储在特定的存储(从而防止公共存储)中。
# app/config.yml
integrated_storage:
// ...
decision_map:
"Integrated\Bundle\ContentBundle\Document\File": [foo]
重新分发命令不使用决策映射,并复制给定存储中的所有文件。
标识符
文件需要一个唯一的标识符。默认情况下,标识符基于文件的 内容。您可以编写自己的 Integrated\Common\Storage\Identifier\IdentifierInterface
实现。以下配置是默认配置,不需要设置。
# app/config.yml
integrated_storage:
// ...
identifier_class: Integrated\Bundle\StorageBundle\Storage\Identifier\FileIdentifier
解析器
解析器返回存储文件的地址,为浏览器提供一个位置。文件系统没有链接到公共可访问的位置,对于每个文件系统,必须编写一个解析器。在某些情况下,您可能需要在解析器中添加特定于文件系统的逻辑。您可以编写自己的 Integrated\Common\Storage\Resolver\ResolverInterface
实现。
以下配置是默认配置,不需要设置。
# app/config.yml
integrated_storage:
// ..
resolver:
foo:
public: /uploads/documents
resolver_class: Integrated\Bundle\StorageBundle\Storage\Resolver\LocalResolver
传递给解析器的参数在构造函数的 options 变量中。您可以通过配置将服务或参数添加到解析器中。
保护文件
在某些情况下,文件可能不会存储在公共可用的目录中。在大多数情况下,用户的主目录上的目录足以存储在本地。您可以通过添加额外的私有本地存储来实现这一点。但是,也可以通过不定义解析器将文件存储在任何远程位置。
控制器可能如下所示
// File is a Integrated\Common\Content\Document\FileInterface object
$response = new Response();
$response->setContent($file->getContent());
$response->setHeaders($file->getMetadata()->getHeaders());
数据固定
为了在 fixtures 中使用 StorageBundle,文件必须在磁盘上存在,并且必须由 StorageManager 创建。管理器将在应用程序配置的磁盘上创建文件。文件存在,并且放置在具有所需属性的正确的文件系统中。要使用助手,您必须将 trait 添加到您的 LoadFixtureData 类中,并且 LoadFixtureData 类必须是 ContainerAware 以访问容器。
// 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;
现在您可以在您的 alice/Fixtures.yml 文件中使用以下内容
# 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()>
根据您的实现,您可以删除类型和扩展要求,或者将其作为参数整体删除。
许可协议
此软件包采用 MIT 许可协议。请参阅软件包中的完整许可协议。
LICENSE
贡献
欢迎提交拉取请求。请参阅我们的 CONTRIBUTING 指南。
关于
此软件包是 Integrated 项目的一部分。您可以在 Integrated for Developers 网站上了解更多关于此项目的信息。