dev-master
9999999-dev http://knplabs.comAllows to easily use the media exposer library in a Symfony project
MIT
The Requires
file image media path source
Allows to easily use the media exposer library in a Symfony project
The KnpMediaExposerBundle provides a simple integration of the MediaExposer library for your Symfony project., (*1)
The MediaExposer library allows you to easily expose you medias to the users of your application by computing their urls or paths., (*2)
You can find more informations on the official page., (*3)
The bundle depends on the MediaExposer library, so you
need to copy it under the vendor/media-exposer
directory of your Symfony
project., (*4)
deps
fileYou can add the following lines to your deps
file:, (*5)
[media-exposer] git=http://github.com/KnpLabs/MediaExposer.git [KnpMediaExposerBundle] git=http://github.com/KnpLabs/KnpMediaExposerBundle.git target=/bundles/Knp/Bundle/MediaExposerBundle
And run the command:, (*6)
./bin/vendors install
You can run the following git commands to add both library and bundle as submodules:, (*7)
git submodule add https://github.com/KnpLabs/MediaExposer.git vendor/media-exposer git submodule add https://github.com/KnpLabs/KnpMediaExposerBundle.git vendor/bundle/Knp/Bundle/MediaExposerBundle
Once you have copied the sources in your project, you must update your autoloader:, (*8)
<?php // app/autoload.php $loader->registerNamespaces(array( // ... other namespaces 'Knp\\Bundle' => __DIR__.'/vendor/bundles', 'MediaExposer' => __DIR__.'/vendor/media-exposer/src' ));
Finally, register the bundle to your kernel:, (*9)
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... the other bundles new Knp\Bundle\MediaExposerBundle\KnpMediaExposerBundle() ); }
You can now proceed to the configuration., (*10)
To "absolutify" urls, the media exposer needs a base url that will be prepended to the relatives sources. By default, the host of the request will be used, but you can also specify it in your configuration:, (*11)
# app/config/config.yml knp_media_exposer: base_url: 'http://the-base.url'
After the installation & configuration, the media exposer is almost ready for use. But there is still one step: registering your resolvers., (*12)
With this bundle, adding a resolver to the exposer is as simple as registering
a service having the knp_media_exposer.resolver
tag., (*13)
Here is an exemple of resolver service registration in yml:, (*14)
services: foo.bar_resolver: class: 'Foo\BarResolver' tags: - { name: 'knp_media_exposer.resolver' }
An optional priority
can also be specified:, (*15)
services: foo.bar_resolver: class: 'Foo\BarResolver' tags: - { name: 'knp_media_exposer.resolver', priority: 10 }
Note: Don't forget that the highest priority is the first and the lowest is the last., (*16)
The bundle registers a Twig extension adding the necessary to use the Exposer
in your templates., (*17)
media_has_source
functionThe media_has_source
function indicates whether the resolver can return
a source for the given media:, (*18)
{{ media_has_source(picture) }}
You can pass a hash of options as second argument:, (*19)
{{ media_has_source(picture, {'foo':'bar'}) }}
media_source
functionThe media_source
function returns the source for the given media:, (*20)
{{ media_source(picture) }}
You can specify an options hash as second argument:, (*21)
{{ media_source(picture, {'foo':'bar'}) }}
If you want the Exposer
to generate absolute sources (URLs), you can force
it passing true
as third argument:, (*22)
{{ media_source(picture, {}, true) }}
media_has_path
functionThe media_has_path
function indicates whether the resolver can return
a path for the given media:, (*23)
{{ media_has_path(picture) }}
An hash of options can be passed as second argument:, (*24)
{{ media_has_path(picture, {'foo':'bar'}) }}
media_path
functionThe media_path
function is responsible of returning a path for the given
media:, (*25)
{{ media_path(picture) }}
You can also specifiy options as second argument:, (*26)
{{ media_path(picture, {'foo':'bar'}}
The bundle registers an extension for the PHP templating engine. You can
access it using $view['media_exposer']
in your templates. It only contains
proxy methods for the Exposer
instances:, (*27)
->getSource($media [, array $options [, $forceAbsolute]])
->hasSource($media [, array $options])
->getPath($media [, array $options])
->hasPath($media [, array $options])
Allows to easily use the media exposer library in a Symfony project
MIT
file image media path source