Get support for KnpLabs/MediaExposer
If you're new to LTH, please see our FAQ for more information on what it is we do.
Support Options
Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:
View Open IssuesTake a look to see if anyone else has experienced the same issue as you and if they managed to solve it.
Open an IssueMake sure to read any relevant guidelines for opening issues on this repo before posting a new issue.
Sponsor directlyCheck out the page and see if there are any options to sponsor this project or it's developers directly.
KnpLabs/MediaExposer
Media Exposer
The Media Exposer is a PHP (5.3+) library that helps you expose your media files to the clients of your web application.
Principle
When you develop a web application, you always need to set up a strategy to serve your medias to the clients. This is the problem this library tries to help you solve.
The Exposer is the main entry point of the library. It is responsible for returning the right source or the right path for the given media and options. To do that, it iterates over the registered resolvers to find the first one supporting the given media and options. The source or path generation is delegated to it. So the first thing to do when you want to set up an exposer is to register resolvers. When you register a resolver, you give it a priority.
All resolvers implement the Resolver interface. They indicate if they support a given media and options. But this only interface is not sufficient so a proper resolver must also implement either the SourceResolver interface or the PathResolver (or both).
Quick Exemple
Enough discussion, let's try it.
As an exemple, will take the following simple image model:
<?php
class FooImage
{
private $filename;
public function getFilename()
{
return $this->filename;
}
}
Then, we create an associated resolver:
<?php
use MediaExposer\PathResolver,
MediaExposer\SourceResolver;
class FooImageResolver implements PathResolver, SourceResolver
{
/**
* {@inheritDoc}
*/
public function supports($media, array $options)
{
return $media instanceof FooImage;
}
/**
* {@inheritDoc}
*/
public function getPath($media, array $options)
{
return '/path/to/the/images/directory/' . $media->getFilename();
}
/**
* {@inheritDoc}
*/
public function getSource($media, array $options)
{
return '/media/foo/' . $media->getFilename();
}
/**
* {@inheritDoc}
*/
public function getSourceType($media, array $options)
{
return SourceResolver::TYPE_RELATIVE; // or SourceResolver::TYPE_ABSOLUTE
}
}
Finally, you can register it in your exposer:
<?php
use MediaExposer\Exposer;
$exposer = new Exposer('http://the-host');
$exposer->addResolver(new FooImageResolver(), 10);
The first Exposer
's argument is called $baseUrl
. It's only required
if you want to generate absolute URLs with relative SourceResolver
instances.
If so, it will be prepended to the relative source returned by the resolver
to turn it absolute.
Our Mission
We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.
From the Blog
Interesting Articles
-
Generating income from open source
Jun 23 • 8 min read
-
2023 State of OSS
Apr 23 • 45 min read ★
-
A funding experiment...
Aug 19 • 10 min read
-
But You Said I could
Aug 19 • 2 min read
Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated
p-e622a1a2