定制 symfony-helper/media-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

symfony-helper/media-bundle

Composer 安装命令:

composer require symfony-helper/media-bundle

包简介

This Bundle provides tools to rapidly process image with Symfony

关键字:

README 文档

README

This Bundle provides tools to rapidly process image with Symfony

Instalation

add package to composer

    "symfony-helper/media-bundle": "@dev",

Register bundle in AppKernel

    public function registerBundles()
        {
            $bundles = [
                ...
                new SHelper\MediaBundle\SHelperMediaBundle(),
                ...
            ];
    
            ...
            
            return $bundles;
        }

Configuration

Add configuration config to config.yml

s_helper_media:
    original_resolution:
        width: 1920
        height: 1080
    previews:
        small:
            width: 32
            height: 32
        thumbnail:
            width: 640
            height: 480
        ... other resolutions

Preview section is not required. Parameters small and thumbnail are only example. You can define custom subsections in preview section.

Configure Doctrine ORM mapping

doctrine:
    orm:
        mappings:
            AppBundle:      # this is only example section 
                type: annotation
                prefix: App\Entity
            SHelperMediaBundle:     # Media bundle mapping
                type: annotation
                dir: "Model/Entity"
                prefix: SHelper\MediaBundle\Model\Entity

Usage

Steps:

  • Upload an image and get image ID in response. (Not multipart)
  • Attach this image to you custom entity
  • Enjoy and be happy

Media bundle will create entity Image. You must make a unidirectional relation to this Image entity.

Add an unidirectional relation

/**
 * User
 *
 * @ORM\Table(name="`user`")
 * @ORM\Entity
 */
class User implements UserInterface
{
    ...
    /**
     * @var Image
     *
     * @ORM\OneToOne(targetEntity="SHelper\MediaBundle\Model\Entity\Image")
     * @ORM\JoinColumn(name="avatar_id", referencedColumnName="id", nullable=true)
     */
    private $avatar;
    ...
}

Create image manually

Inject image service to your service.

    class YourService
    {
        /** @var IImageService */
        private $imageService;
        
        public function __construct(IImageService $imageService)
        {
            $this->imageService = $imageService;
        }
        ...
        
        public function doSomething()
        {
            $imageBlob = file_get_contents('filename.jpg');
            $image = $this->imageService->createImageFromBlob($imageBlob);
            
            ...
            
            $user->setAvatar($image);
            //OR
            $article->setAvatar($image);
            //OR
            $someThingElse->setAvatar($image);
        }
    }

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3
  • 更新时间: 2016-05-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固