bprs/asset-bundle
Composer 安装命令:
composer require bprs/asset-bundle
包简介
Simple assets for your application. Upload Pictures, videos and more and link it with your entities
README 文档
README
Simple assets for your application. Upload Pictures, videos and more and link it with your entities
Installation
in your composer.json file, add to "require"
composer require bprs/asset-bundle
OR
"require": { "bprs/asset-bundle": "^2.0"
Activate the bundle in the AppKernel
$bundles = array( ... new Bprs\AssetBundle\BprsAssetBundle() ... );
And your Filesystem manager of choice
$bundles = array( ... new Knp\Bundle\GaufretteBundle\KnpGaufretteBundle() ... );
OR
$bundles = array( ... new Oneup\FlysystemBundle\OneupFlysystemBundle() ... );
Configuration
The BPRSAssetBundle is on top of the OneupUploaderBundle. This allows for maximum flexibility.
Gaufrette
# Example config
bprs_asset:
class: "AppBundle\Entity\Asset"
adapters:
gallery:
url: "http://localhost/MyProject/web/uploads"
path: "/opt/local/apache2/htdocs/MyProject/web/uploads"
knp_gaufrette:
adapters:
gallery:
local:
directory: %kernel.root_dir%/../web/uploads
create: true
filesystems:
gallery:
adapter: gallery
oneup_uploader:
mappings:
gallery:
frontend: blueimp
storage:
type: gaufrette
filesystem: gaufrette.gallery_filesystem
sync_buffer_size: 100M
Flysystem
Usage
Relations
Assets can be standalone, or be in OneToOne, OneToMany or in a ManyToMany Relationship. To be that flexible, the Asset Entity is now a MappedSuperclass. Your Asset can now include any needed properties and your database remains clean.
The BaseAsset already defines several useful informations:
- createdAt (automatically set)
- updatedAt (automatically set and updated)
- filekey (the unique filename)
- adapter (the name of the filesystem adapter it is saved under)
- mimetype (for example image/jpeg, quicktime/video)
- filesize (in bytes)
- md5 (hash)
- name (original filename)
<?php // Example asset childclass namespace Your\Name\Space; use Doctrine\ORM\Mapping as ORM; use Bprs\AssetBundle\Entity\Asset as BaseAsset; /** * Extends the MappedSupperclass from the BprsAssetBundle * * @ORM\Entity * @ORM\Table() */ class Asset extends BaseAsset { // Whatever your Asset needs //... //... } ?>
Forms
The BPRSAssetBundle includes a custom Formtype, a Datatransformer and even the needed JavaScript. Lets say, you have an entity that is linked to many assets:
// form builder public function buidlForm(FormBuilderInterface $builder, array $options) { $builder->add('assets', 'assets'); }
Or just one asset
// form builder public function buidlForm(FormBuilderInterface $builder, array $options) { $builder->add('asset', 'asset'); }
Next, the View:
{{ form_start(form) }}
{% include "BprsAssetBundle::upload.html.twig" with {'form': form, 'adapter': 'gallery', 'hidePrevious': true} %}
{{ form_end(form) }}
{% block stylesheets %}
{{ parent() }}
<link href="{{ asset('bundles/bprsasset/css/jquery.fileupload.css') }}" rel="stylesheet" />
{% endblock %}
{% block javascripts %}
{{ parent() }}
{# if you don't use the BprsStylBundle, you'll need to include jquery yourself! #}
{% include "BprsAssetBundle::upload.js.twig" %}
{% endblock %}
Thumbnails
The Bundle comes with an handy thumbnail filter for twig. All tou need to do is
# asset|thumb(height,width) <img src="{{ asset|thumb(720,1280) }}" />
To create and display thumbnails on the fly.
Filesize and Relative Paths
<a href="{{ asset|link }}">{{ asset.name|filesize(false) }}</a>
Download and List
Activate the routing with
#routing.yml bprs_asset: resource: . type: bprs_asset prefix: /{_locale} requirements: _locale: de|en defaults: { _locale: de }
You can secure downloading with security settings.
path "bprs_asset_list (page: page)" Lists all known Assets.
path "bprs_asset_download (filekey: filekey)" allows downloads. (you'll probably need xsendfile for large files)
bprs/asset-bundle 适用场景与选型建议
bprs/asset-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 234 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 02 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 bprs/asset-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bprs/asset-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 234
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: 未知许可证
- 更新时间: 2015-02-26