glavweb / uploader-bundle
Symfony GlavwebUploaderBundle
Installs: 2 619
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 4
Forks: 2
Open Issues: 2
Requires
- php: >=7.2.5
- doctrine/doctrine-bundle: ^2.0
- doctrine/orm: ^2.3
- liip/imagine-bundle: ^2.3.1
- symfony/event-dispatcher: ^4.0|^5.0|^6.0
- symfony/filesystem: ^4.0|^5.0|^6.0
- symfony/finder: ^4.0|^5.0|^6.0
- symfony/form: ^4.0|^5.0|^6.0
- symfony/http-foundation: ^4.0|^5.0|^6.0
- symfony/mime: ^4.0|^5.0|^6.0
- symfony/routing: ^4.0|^5.0|^6.0
- symfony/templating: ^4.0|^5.0|^6.0
- symfony/translation: ^4.0|^5.0|^6.0
Suggests
- oneup/flysystem-bundle: Required for flysystem storage
- dev-master
- v3.5.1
- v3.5.0
- v3.4.2
- v3.4.1
- v3.4.0
- v3.3.0
- v3.2.1
- v3.2.0
- v3.1.0
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.x-dev
- v2.12.1
- v2.12.0
- v2.11.0
- v2.10.1
- v2.10.0
- v2.9.6
- v2.9.5
- v2.9.4
- v2.9.3
- v2.9.2
- v2.9.1
- v2.9.0
- v2.8.0
- v2.7.0
- v2.6.1
- v2.6.0
- 2.5.1
- 2.5.0
- 2.4.1
- v2.4.0
- v2.3.2
- v2.3.1
- v2.3.0
- v2.2.0
- v2.1.1
- v2.1
- v2.0
- v1.2
- v1.1.1
- v1.1.0
- v1.0.2
- v1.0.1
- v1.0
- v0.2.6
- v0.2.5
- v0.2.4
- v0.2.3
- v0.2.2
- v0.2.1
- v0.1.12
- v0.1.11
- v0.1.10
- v0.1.9
- v0.1.8
- v0.1.7
- v0.1.6.2
- v0.1.6.1
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.0.1
- dev-chunk-uploading
- dev-cutomize_templates
This package is auto-updated.
Last update: 2024-12-02 13:02:46 UTC
README
Get the bundle using composer
Add GlavwebUploaderBundle by running this command from the terminal at the root of your Symfony project:
php composer.phar require glavweb/uploader-bundle
Enable the bundle
To start using the bundle, register the bundle in your application's kernel class:
// 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.
# 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.
# app/config/routing.yml glavweb_uploader: resource: "@GlavwebUploaderBundle/Resources/config/routing.yml" prefix: /
Basic Usage
- 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:
/**
* @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:
/**
* @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;
- For build form, you can use GlavwebUploaderDropzoneBundle.
Events
Bundle has 3 events:
- 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.
services.yml:
post_upload_listener:
class: AppBundle\Listener\PostUploadListener
tags:
- { name: kernel.event_listener, event: glavweb_uploader.post_upload, method: onPostUpload }
Listener class:
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.
Also you can define listeners only for your context, as example if context is "article":
article_post_upload_listener:
class: AppBundle\Listener\ArticlePostUploadListener
tags:
- { name: kernel.event_listener, event: glavweb_uploader.post_upload.article, method: onPostUpload }