承接 pfcode/symfony-attachment-storage 相关项目开发

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

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

pfcode/symfony-attachment-storage

Composer 安装命令:

composer require pfcode/symfony-attachment-storage

包简介

Attachment storage abstraction layer for Doctrine ORM

README 文档

README

This library provides abstraction layer for storage of attachments (images, videos and any files) that are indexed in database accessed by Doctrine ORM. Created with extensibility in mind, allows developer to quickly integrate their own storage platforms, slug generation methods and attachment download methods.

Installation

Add it to your project by:

composer require pfcode/symfony-attachment-storage

Sample configuration

First of all, you need to create a Doctrine entity that implements Pfcode\AttachmentStorage\Entity\AttachmentInterface and implement its getters and setters. Here is an example:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Pfcode\AttachmentStorage\Entity\AttachmentInterface;

/**
 * @ORM\Entity()
 */
class MyAttachment implements AttachmentInterface
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer", nullable=false)
     * @var int|null
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255, nullable=false)
     * @var string|null
     */
    private $storageIdentifier;

    /**
     * @ORM\Column(type="string", length=8, nullable=false)
     * @var string|null
     */
    private $slug;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @var string|null
     */
    private $mimeType;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @var string|null
     */
    private $extension;

    /**
     * @ORM\Column(type="integer", nullable=false)
     * @var int
     */
    private $fileSize = 0;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @var string|null
     */
    private $originalName;

    public function setStorageIdentifier(?string $storageIdentifier): void {
        $this->storageIdentifier = $storageIdentifier;
    }

    public function getStorageIdentifier(): ?string {
        return $this->storageIdentifier;
    }

    public function setSlug(?string $slug): void {
        $this->slug = $slug;
    }

    public function getSlug(): ?string {
        return $this->slug;
    }

    public function setMimeType(?string $mimeType): void {
        $this->mimeType = $mimeType;
    }

    public function getMimeType(): ?string {
        return $this->mimeType;
    }

    public function setExtension(?string $extension): void {
        $this->extension = $extension;
    }

    public function getExtension(): ?string {
        return $this->extension;
    }

    public function setFileSize(int $bytes): void {
        $this->fileSize = $bytes;
    }

    public function getFileSize(): int {
        return $this->fileSize;
    }

    public function setOriginalName(?string $originalName): void {
        $this->originalName = $originalName;
    }

    public function getOriginalName(): ?string {
        return $this->originalName;
    }
    
    public function setId(?int $id): void {
        $this->id = $id;    
    }   

    public function getId(): ?int {
        return $this->id;
    }
}

Then, you should register a few services in your config/services.yml file:

# Implementation of a simple storage service that uses directory on a local machine that is accessible publicly by URL
Pfcode\AttachmentStorage\Storage\LocalStorage:
    public: true
    bind:
      # Absolute path to directory used to store all files by this service 
      $absolutePath: '/var/www/public/images'
      # Relative path from directory accessible publicly by URL address in browser
      $baseUrl: '/images'

# Registry for all storage services that should be available in your project
Pfcode\AttachmentStorage\StorageRegistry\StorageRegistry:
    public: true
    calls: 
      # Register all storage services that you need. At least one is required
      - [registerStorage, ['@Pfcode\AttachmentStorage\Storage\LocalStorage']]
      # You should set default storage that will be used as a default method for uploading
      - [setDefaultStorage, ['@Pfcode\AttachmentStorage\Storage\LocalStorage']]

# Sample class used by AttachmentUploader to store files accessible on remote servers by URL
Pfcode\AttachmentStorage\Utils\Downloader\CurlDownloader:
    public: true
    
# Utility service used to recognize if file is an image, video or other type
Pfcode\AttachmentStorage\Utils\AttachmentDescriber:
    public: true

# Utility service used to suggest a file extension, when a file being uploaded doesn't have one
Pfcode\AttachmentStorage\Utils\ExtensionSuggester:
    public: true
    
# Sample service used to generate a slug for new uploaded attachments
  Pfcode\AttachmentStorage\Utils\SlugGenerator\SampleSlugGenerator:
    public: true
    arguments: ['@doctrine.orm.default_entity_manager']
    bind:
      $entityClass: 'App\Entity\MyAttachment'

# Service used to upload new attachments
Pfcode\AttachmentStorage\Uploader\AttachmentUploader:
    public: true
    arguments: [
      '@Pfcode\AttachmentStorage\StorageRegistry\StorageRegistry', 
      '@Pfcode\AttachmentStorage\Utils\ExtensionSuggester',
      '@Pfcode\AttachmentStorage\Utils\SlugGenerator\SampleSlugGenerator',
      '@Pfcode\AttachmentStorage\Utils\Downloader\CurlDownloader']
    bind:
      # Specify class of entity that implements AttachmentInterface.
      # Warning! This is not a service! Just a string with Fully Qualified Class Name
      $entityClass: 'App\Entity\MyAttachment'

Extending components

All components of this library are created with extensibility in mind, so you can implement available interfaces or create new classes of existing services, register them in your services.yml file and reference them in other services' configuration.

License

This library is released under MIT license.

pfcode/symfony-attachment-storage 适用场景与选型建议

pfcode/symfony-attachment-storage 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 105 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 03 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 pfcode/symfony-attachment-storage 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-23