2017 © Pedro Peláez
 

library uploader-bundle

Symfony GlavwebUploaderBundle

image

glavweb/uploader-bundle

Symfony GlavwebUploaderBundle

  • Thursday, May 3, 2018
  • by nilov
  • Repository
  • 3 Watchers
  • 3 Stars
  • 680 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 32 Versions
  • 6 % Grown

The README.md

Installation

Get the bundle using composer

Add GlavwebUploaderBundle by running this command from the terminal at the root of your Symfony project:, (*1)

php composer.phar require glavweb/uploader-bundle

Enable the bundle

To start using the bundle, register the bundle in your application's kernel class:, (*2)

// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Glavweb\UploaderBundle\GlavwebUploaderBundle(),
        // ...
    );
}

Configure the bundle

This bundle was designed to just work out of the box. The only thing you have to configure in order to get this bundle up and running is a mapping., (*3)

# app/config/config.yml

glavweb_uploader:
    mappings:
        entity_images:
            providers :
                - glavweb_uploader.provider.image
            use_orphanage: true
            upload_directory:     %kernel.root_dir%/../web/uploads/entity_images
            upload_directory_url: uploads/entity_images
            max_size: 4194304 # 4Mb
            allowed_mimetypes: [image/jpeg, image/gif, image/png]

    orphanage:
        lifetime: 86400
        directory: %kernel.cache_dir%/uploader/orphanage

To enable the dynamic routes, add the following to your routing configuration file., (*4)

#  app/config/routing.yml

glavweb_uploader:
    resource: "@GlavwebUploaderBundle/Resources/config/routing.yml"
    prefix:   /

Basic Usage

  1. Added annotations for the entity which needs to support "GlavwebUploadable". "@Glavweb\Uploadable" before you can define an entity class:
use Glavweb\UploaderBundle\Mapping\Annotation as Glavweb;

/**
 * Entity
 * 
 * @Glavweb\Uploadable
 */
class Entity
{
}

And another annotation "@Glavweb\UploadableField" before defining the properties of a many-to-many:, (*5)

/**
 * @var \Doctrine\Common\Collections\Collection
 * 
 * @ORM\ManyToMany(targetEntity="Glavweb\UploaderBundle\Entity\Media", inversedBy="entities", orphanRemoval=true)
 * @ORM\OrderBy({"position" = "ASC"})
 * @Glavweb\UploadableField(mapping="entity_images")
 */
private $images;

/**
 * Constructor
 */
public function __construct()
{
    ...
    $this->images = new \Doctrine\Common\Collections\ArrayCollection();
}

Or many-to-one:, (*6)

/**
 * @var Media
 *
 * @ORM\OneToOne(targetEntity="Glavweb\UploaderBundle\Entity\Media", orphanRemoval=true)
 * @ORM\JoinColumn(name="image_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
 */
private $image;
  1. For build form, you can use GlavwebUploaderDropzoneBundle.

Events

Bundle has 3 events:, (*7)

  • glavweb_uploader.validation; // First event, will execute before your file will be uploaded
  • glavweb_uploader.pre_upload; // Will execute before your file will be uploaded
  • glavweb_uploader.post_upload. // Will execute after your file will be uploaded

Example

As example we use post upload event., (*8)

services.yml:, (*9)

post_upload_listener:
    class: AppBundle\Listener\PostUploadListener
    tags:
        - { name: kernel.event_listener, event: glavweb_uploader.post_upload, method: onPostUpload }

Listener class:, (*10)

namespace AppBundle\Listener;

use Glavweb\UploaderBundle\Event\PostUploadEvent;

class PostUploadListener
{
    /**
     * @param PostUploadEvent $event
     */
    public function onPostUpload(PostUploadEvent $event)
    {
        // Some logic
    }
}

Other listeners work on a similar logics., (*11)

Also you can define listeners only for your context, as example if context is "article":, (*12)

article_post_upload_listener:
    class: AppBundle\Listener\ArticlePostUploadListener
    tags:
        - { name: kernel.event_listener, event: glavweb_uploader.post_upload.article, method: onPostUpload }

The Versions

03/05 2018

dev-master

9999999-dev

Symfony GlavwebUploaderBundle

  Sources   Download

The Requires

 

03/05 2018

v2.1.1

2.1.1.0

Symfony GlavwebUploaderBundle

  Sources   Download

The Requires

 

16/04 2018
17/03 2017
03/02 2017
11/11 2016

v1.1.1

1.1.1.0

Symfony GlavwebUploaderBundle

  Sources   Download

The Requires

 

04/11 2016

v1.0.2

1.0.2.0

Symfony GlavwebUploaderBundle

  Sources   Download

The Requires

 

04/11 2016

v1.1.0

1.1.0.0

Symfony GlavwebUploaderBundle

  Sources   Download

The Requires

 

01/11 2016

v1.0.1

1.0.1.0

Symfony GlavwebUploaderBundle

  Sources   Download

The Requires

 

22/07 2016
04/07 2016

v0.2.6

0.2.6.0

Symfony GlavwebUploaderBundle

  Sources   Download

The Requires

 

01/07 2016

v0.2.5

0.2.5.0

Symfony GlavwebUploaderBundle

  Sources   Download

The Requires

 

30/06 2016

v0.2.4

0.2.4.0

Symfony GlavwebUploaderBundle

  Sources   Download

The Requires

 

30/06 2016

v0.2.3

0.2.3.0

Symfony GlavwebUploaderBundle

  Sources   Download

The Requires

 

17/02 2016

dev-cutomize_templates

dev-cutomize_templates

Symfony GlavwebUploaderBundle

  Sources   Download

The Requires