2lenet/attachment-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

2lenet/attachment-bundle

Composer 安装命令:

composer require 2lenet/attachment-bundle

包简介

Attachment

关键字:

README 文档

README

Installation

composer req 2lenet/attachment-bundle

Add to your config/routes.yaml ( no flex reciepe for the moment ).

lle_attachment:
    resource: "@LleAttachmentBundle/Resources/config/routing/routes.yaml"

Embed controller in a template

{{ render(controller('lle.attachment', {'item': item})) }}

Or with field if you want only an group of attachment

{{ render(controller('lle.attachment', {'item': item, options: {'field': 'pdf'}})) }}

Like that you can use "lle.attachment" action with EasyAdminPlusBundle:

show:
    title: title.examen.show
    fields:
        - { type: 'tab', id: 'documents', label: 'tab.documents', action: 'lle.attachment'}

Or with field if you want only an group of attachment

show:
    title: title.examen.show
    fields:
        - { type: 'tab', id: 'documents', label: 'tab.documents', action: 'lle.attachment', options: {'field': 'pdf'}}

Information: the lle.attachment is a alias of lle.attachment.show.action

Easy use

render the widget for upload:

{{ render_attachment(entity) }}

render the list (ul) for download:

{{ list_attachment(entity) }}

You can use several attachment on the same template

{{ render_attachment(item) }}

{%  for examen in item.examens  %}
    <h3>{{ examen }}</h3>
    {{ render_attachment(examen) }}
{%  endfor %}

Configurations

with default value

framework:
    translator:
        fallbacks: ['fr']
  
lle_attachment:
    directory: data/attachment #directory of files is registred
    show_list: false #show or not show the list of files (table) with uploader widget
    need_confirm_remove: true #modal for confirm delete or no

Thanks to use

pre load for list of entities:

If you list 20 entities with 20 call of {{ list_attachment(entity) }} you want 1 request not 20:

call

<?php
$this->attachmentManager->load(MyEntityClass::class, $ids);

exemple with EasyAdmin

<?php

namespace App\EventListener;

use App\Entity\Rapport;
use Lle\AttachmentBundle\Service\AttachmentManager;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
use Symfony\Component\EventDispatcher\GenericEvent;

class RapportSubscriber implements EventSubscriberInterface
{
    private $attachmentManager;

    public function __construct(AttachmentManager $attachmentManager)
    {
        $this->attachmentManager = $attachmentManager;
    }


    public static function getSubscribedEvents()
    {
        return [
            EasyAdminEvents::POST_LIST => 'onPostList',
        ];
    }


    public function onPostList(GenericEvent $event)
    {
        if($event->getArgument('entity')['class'] === Rapport::class){
            $ids = [];
            foreach($event->getSubject()->getCurrentPageResults() as $item){
                $ids[] = $item->getId();
            }
            $this->attachmentManager->load(Rapport::class, $ids);
        }
    }



}

add uploaded file in form

  • Add UploadedFileAttachmentInterface with UploadedFileAttachmentTrait at your entity
use Lle\AttachmentBundle\UploadedFileAttachmentInterface;
use Lle\AttachmentBundle\UploadedFileAttachmentTrait;
  • In your entity form add
$builder->add('uploadedFilesAttachment', FileType::class, ['multiple'=> true]);
// or (and) $builder->add('uploadedFileAttachment', FileType::class, ['multiple'=> false]);
$builder->add('uploadedFilesAttachmentField'); //optional (default is null)
  • Now you have to call addFileByEntity after persist (entity identification have to be create)
$this->attachmentManager->addFileByEntity($entity);
  • here an simple exemple with EasyAdmin:
<?php

namespace App\EventListener;


use Doctrine\ORM\EntityManagerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
use Lle\AttachmentBundle\Service\AttachmentManager;
use Lle\AttachmentBundle\UploadedFileAttachmentInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

class AttachmentSubscriber implements EventSubscriberInterface
{

    private $attachmentManager;

    public function __construct(AttachmentManager $attachmentManager){
        $this->attachmentManager = $attachmentManager;
    }

    public function addFile(GenericEvent $event){
        if($event->getSubject() instanceof UploadedFileAttachmentInterface){
            $this->attachmentManager->addFileByEntity($event->getSubject());
        }
    }


    public static function getSubscribedEvents()
    {
        return [
            EasyAdminEvents::POST_PERSIST => 'addFile',
            EasyAdminEvents::POST_UPDATE => 'addFile'
        ];
    }
}
  • if you want you can defin the default filed in entity
public function getUploadedFilesAtachmentField(): ?string{
    return 'uploaded';
}
  • For validation use Symfony validator annotations or validator in form (Advice: if you use validator annotation create your own Trait)

2lenet/attachment-bundle 适用场景与选型建议

2lenet/attachment-bundle 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 6.68k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 06 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「attachment」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 2lenet/attachment-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 2lenet/attachment-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 2lenet/attachment-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6.68k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 6
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-06-06