承接 bnine/filesbundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

bnine/filesbundle

Composer 安装命令:

composer require bnine/filesbundle

包简介

Symfony bundle for entity-based file browser and management.

README 文档

README

Bundle Symfony pour la gestion de fichiers : upload, navigateur, galerie, crop, thumbnail, téléchargement.

Installation

composer require bnine/filesbundle

Dans config/bundles.php :

Bnine\FilesBundle\BnineFilesBundle::class => ['all' => true],

Routes

Route Méthode Description
bninefiles_files GET Navigateur de fichiers
bninefiles_files_uploadmodal GET Page d'upload (iframe)
bninefiles_files_uploadfile POST Upload de fichier
bninefiles_files_delete POST Suppression de fichier/dossier
bninefiles_files_mkdir POST Création de dossier
bninefiles_files_download GET Téléchargement de fichier
bninefiles_files_image GET Affichage d'image inline
bninefiles_files_thumbnail GET Thumbnail auto-généré (300px)
bninefiles_files_gallery GET Galerie d'images
bninefiles_files_crop_page GET Page de crop (sélection imgAreaSelect)
bninefiles_files_crop POST Application du crop (génère thumbnail 150x150)

Form Type

IconUploadType

Champ de formulaire pour upload d'image avec preview et crop optionnel.

use Bnine\FilesBundle\Form\Type\IconUploadType;

$builder->add('avatar', IconType::class, [
    'label' => false,
    'required' => false,
    'icon_endpoint' => 'avatar',
    'icon_label' => 'Avatar',
    'icon_upload_url' => '/bninefiles/uploadmodal/avatar/0?path=&crop',
]);

Options :

  • icon_endpoint : domaine pour les routes (défaut: icon)
  • icon_label : label du bouton (défaut: Icon)
  • icon_empty_preview : image par défaut quand vide
  • icon_upload_url : URL de la modale d'upload. Ajouter &crop pour activer le crop.

Système de modal custom

Le bundle fournit un système de modal léger (pas de dépendance Bootstrap) via bninefiles.js :

// Ouvrir une modale
BnineModalOpen({
    id: 'ma-modale',           // ID unique
    title: 'Titre',            // Titre affiché
    url: '/path/to/iframe',    // URL chargée dans l'iframe
    height: '600px',           // Hauteur de l'iframe
    onClose: function () {}    // Callback appelé à la fermeture
});

// Fermer la modale (depuis l'iframe)
window.parent.BnineModalClose();

Twig Function

bninefile()

Génère une URL valide pour un fichier stocké (upload ou statique) :

<img src="{{ bninefile(user.avatar) }}" alt="Avatar">
<img src="{{ bninefile(group.logo) }}" alt="Logo">

La fonction ajoute / si nécessaire. Compatible avec les anciens paths (uploads/...) et les nouvelles URLs bNineFilesBundle.

CSS

Le fichier bninefiles.css fournit le style du système de modal custom (.bnine-overlay, .bnine-dialog). À inclure dans le template de base :

<link rel="stylesheet" href="{{ asset('bundles/bninefilesbundle/css/bninefiles.css') }}">
<script src="{{ asset('bundles/bninefilesbundle/js/bninefiles.js') }}"></script>

Stockage

Le bundle supporte le stockage local et S3 via Flysystem. Le FileService détecte automatiquement le mode via un paramètre bool $s3.

# config/services.yaml
Bnine\FilesBundle\Service\FileService:
    arguments:
        $storage: '@app_storage'
        $s3: '%env(bool:STORAGE_S3)%'

Mode local

STORAGE_DSN="local://uploads"
STORAGE_S3=0

Mode S3

STORAGE_DSN="s3://bucket"
STORAGE_S3=1
S3_ENDPOINT="http://rustfs:9000"
S3_BUCKET="ninegate-uploads"
S3_ACCESS_KEY="rustfs"
S3_SECRET_KEY="changeme"
S3_REGION="us-east-1"

Voter

Le bundle fournit AbstractFileVoter abstrait. Dans l'app hôte, implémentez un voter concret :

class FileVoter extends AbstractFileVoter
{
    private const PUBLIC_DOMAINS = ['avatar', 'logo', 'icon'];

    protected function canView(string $domain, $id, TokenInterface $token): bool
    {
        if (in_array($domain, self::PUBLIC_DOMAINS)) {
            return true;
        }
        return $this->canManage($domain, $id, $token);
    }

    // canEdit, canDelete...
}

Structure des fichiers

uploads/                          # Racine du stockage
  {domain}/                       # ex: blog, pagewidgetfile
    {id}/                         # ID de l'entité
      {fichier.jpg}               # Fichiers uploadés
      _thumbs/300xN/              # Thumbnails auto-générés
      _thumbs/{size}x{size}/      # Thumbnails de crop

bnine/filesbundle 适用场景与选型建议

bnine/filesbundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 161 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 bnine/filesbundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 161
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-02