Download the PHP package lch/media-bundle without Composer

On this page you can find all versions of the php package lch/media-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package media-bundle

MediaBundle

This bundle brings to you a comprehensive and code-close way of handling media for Symfony 3. Features:

Installation and pre-requisites

Imagick is used to generate thumbnails and images sizes sets. On the GUI side, the bundle use Bootstrap 4 and jQuery. Be sure those 2 dependencies are fullfilled, especially on admin screens (media selection/creation)

For installing, use simply : composer require lch/media-bundle

Configuration and usage

  1. General explanations
  2. Media types declaration
  3. Twig extensions and tools
  4. Events
  5. Form types
  6. Validators
  7. Storage strategy
  8. Image sizes
  9. Practical use cases
    1. Download control

General explanations

Out of the box, MediaBundle defines 2 types : image and pdf. You can use those types as base for you custom ones.

Below is shown types and available fields :

Media relations and fields

Media types declaration

You need to define your media types in config.yml. You can define as many types as you need, using the following syntax :

Let's review an example for each given key :

Entity

Minimal class for above declared image could be :

It extends Lch\MediaBundle\Entity\Image. If you want to start from scratch, you have to extends from Media and use Storable behavior in order to trigger all stuff link to file storage in the bundle.

Form

Minimal form class could be :

Add view

You can find below the add view for generic Image defined by the bundle :

If you define your own, you have to use mediaForm as the form variable.

Thumbnail view

You can find below the thumbnail view for generic Image defined by the bundle :

Note : as indicated below, most of logic is event related. Thumbnail generation is one those things, so access to thumbnail data goes through event object

List item view

You can find below the list item view for generic Image defined by the bundle. You will find further explanations on twig methods below

Note : as indicated below, most of logic is event related. Thumbnail generation is one those things, so access to thumbnail data goes through event object

Extensions

Here you define extensions allowed for this media type, as an array.

Thumbnail sizes

More informations in dedicated section

Twig extension & tools

You can find below a graphical render for several methods listed above :

Media Twig extension methods

Events

You can find below the complete event list thrown by the bundle (listed in Lch\Media\LchMediaEvents) :

Form types

The bundle provides 2 form types for easing media selection/creation. First of all, be assured to add the correct form theme file in your admin twig files, which is LchMediaBundle:form:fields.html.twig

AddOrChooseMediaType

Here is a classical use :

Although it's quite clear, note that entity_reference is the media class you want to link here. Regarding validation, you can pass

Have a look to validators section in order to have more details.

You must then register a Twig namespace, and add the bundle field.html.twig as a form_theme :

Then, assuming you added form_theme as stated above, the twig parent form type become :

You have to add those 3 javascript files in order to make things work.

Result (after custom styling):

Button chooser in parent form : Media button

After click on button, media popin appears with media chooser among available (limited to entity_reference you provided) Media chooser

You can also add a media from here (limited to entity_reference you provided, and using form and add_view you provided for media type in config.yml) Media addition

Note : as you can see in LchMediaBundle:form:fields.html.twig, we postfixed all relevant HTML input ids with a random unique number, therefore safely allowing multiple media type usage in same form.

AddOrChooseMultipleMediasType

This type is useful to select a collection of media. It only makes the AddOrChooseMediaType repeatable

We suggest using the excellent Symfony collection plugin to handle collection easily. We still have to elaborate JS part a lot, so for now you have to repeat the random number change when dynamically adding media button.

Example below linked to above AddOrChooseMultipleMediasType (with symfony collection)

Result (after custom styling):

Repeatable media selector : Media button

Validators

You will find in Lch\MediaBundle\Validator several built-in validators :

All validators work both on class and property level. So you need to define them on your media classes once for all :

Storage strategy

TODO

Image sizes

Using Imagick, the bundle does 2 things :

  1. Generating thumbnails for all images
  2. Generating viewable thumbnails for PDF files (thumbnails for list item and previewer)

Using the correct key (thumbnail_sizes) in media type declaration in config.yml, you can produce as many thumbnails you need.

Note : so far, we use the image longer dimension and adapt the other one to keep homothetic transforms. Therefore, resulting images might not be in the exact good resolution. To be completed...

Practical use cases

Download control

  1. Declare media (see above)
  2. Register a Listener/Subscriber to LchMediaEvents::STORAGE to change storage for your media (example : to add a "/private/" subfolder)
  3. Add matching route, to force Symfony to handle request :

  4. Add a Voter to restrain service
  5. Option : Register a Listener/Subscriber to LchMediaEvents::DOWNLOAD to control what to serve (add watermark...)

    TODO : to be completed with detailled event usage examples


All versions of media-bundle with dependencies

PHP Build Version
Package Version
Requires ext-imagick Version *
php Version ^7.2
symfony/framework-bundle Version ^4.4
friendsofsymfony/jsrouting-bundle Version ^2.3
knplabs/doctrine-behaviors Version ^2.0
lch/components-bundle Version ^1.2
twig/extensions Version 1.5.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package lch/media-bundle contains the following files

Loading the files please wait ....