Add Silex FFMpegServiceProvider

This commit is contained in:
Romain Neutron 2012-09-03 14:52:53 +02:00
commit 20a3c21d82
3 changed files with 122 additions and 0 deletions

View file

@ -38,6 +38,10 @@ abstract class Binary implements AdapterInterface
*/
public function __construct($binary, Logger $logger)
{
if (!is_executable($binary)) {
throw new \FFMpeg\Exception\BinaryNotFoundException(sprintf('`%s` is not a valid binary', $binary));
}
$this->binary = $binary;
$this->logger = $logger;
}

View file

@ -0,0 +1,46 @@
<?php
namespace FFMpeg;
use FFMpeg\FFMpeg;
use FFMpeg\FFProbe;
use Monolog\Logger;
use Monolog\Handler\NullHandler;
use Silex\Application;
use Silex\ServiceProviderInterface;
class FFMpegServiceProvider implements ServiceProviderInterface
{
public function register(Application $app)
{
if ( ! isset($app['ffmpeg.logger'])) {
$app['ffmpeg.logger'] = $app->share(function(Application $app) {
$logger = new Logger('FFMpeg logger');
$logger->pushHandler(new NullHandler());
return $logger;
});
}
$app['ffmpeg.ffmpeg'] = $app->share(function(Application $app) {
if (isset($app['ffmpeg.ffmpeg.binary'])) {
return new FFMpeg($app['ffmpeg.ffmpeg.binary'], $app['ffmpeg.logger']);
} else {
return FFMpeg::load($app['ffmpeg.logger']);
}
});
$app['ffmpeg.ffprobe'] = $app->share(function(Application $app) {
if (isset($app['ffmpeg.ffprobe.binary'])) {
return new FFProbe($app['ffmpeg.ffprobe.binary'], $app['ffmpeg.logger']);
} else {
return FFProbe::load($app['ffmpeg.logger']);
}
});
}
public function boot(Application $app)
{
}
}