Add ExecutableNotFoundException

This commit is contained in:
Romain Neutron 2013-07-03 14:13:29 +02:00
commit 8e87d243d9
7 changed files with 61 additions and 18 deletions

View file

@ -13,6 +13,9 @@ namespace FFMpeg\Driver;
use Alchemy\BinaryDriver\AbstractBinary;
use Alchemy\BinaryDriver\Configuration;
use Alchemy\BinaryDriver\ConfigurationInterface;
use Alchemy\BinaryDriver\Exception\ExecutableNotFoundException as BinaryDriverExecutableNotFound;
use FFMpeg\Exception\ExecutableNotFoundException;
use Psr\Log\LoggerInterface;
class FFMpegDriver extends AbstractBinary
@ -33,8 +36,22 @@ class FFMpegDriver extends AbstractBinary
*
* @return FFMpegDriver
*/
public static function create(LoggerInterface $logger, $configuration)
public static function create(LoggerInterface $logger = null, $configuration = array())
{
return static::load(array('avconv', 'ffmpeg'), $logger, $configuration);
if (!$configuration instanceof ConfigurationInterface) {
$configuration = new Configuration($configuration);
}
$binaries = $configuration->get('ffmpeg.binaries', array('avconv', 'ffmpeg'));
if (!$configuration->has('timeout')) {
$configuration->set('timeout', 300);
}
try {
return static::load($binaries, $logger, $configuration);
} catch (BinaryDriverExecutableNotFound $e) {
throw new ExecutableNotFoundException('Unable to load FFMpeg', $e->getCode(), $e);
}
}
}

View file

@ -14,6 +14,8 @@ namespace FFMpeg\Driver;
use Alchemy\BinaryDriver\AbstractBinary;
use Alchemy\BinaryDriver\Configuration;
use Alchemy\BinaryDriver\ConfigurationInterface;
use Alchemy\BinaryDriver\Exception\ExecutableNotFoundException as BinaryDriverExecutableNotFound;
use FFMpeg\Exception\ExecutableNotFoundException;
use Psr\Log\LoggerInterface;
class FFProbeDriver extends AbstractBinary
@ -42,6 +44,10 @@ class FFProbeDriver extends AbstractBinary
$binaries = $configuration->get('ffprobe.binaries', array('avprobe', 'ffprobe'));
return static::load($binaries, $logger, $configuration);
try {
return static::load($binaries, $logger, $configuration);
} catch (BinaryDriverExecutableNotFound $e) {
throw new ExecutableNotFoundException('Unable to load FFProbe', $e->getCode(), $e);
}
}
}

View file

@ -0,0 +1,16 @@
<?php
/*
* This file is part of PHP-FFmpeg.
*
* (c) Alchemy <info@alchemy.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FFMpeg\Exception;
class ExecutableNotFoundException extends RuntimeException
{
}

View file

@ -115,22 +115,10 @@ class FFMpeg
*/
public static function create($configuration = array(), LoggerInterface $logger = null, FFProbe $probe = null)
{
if (!$configuration instanceof ConfigurationInterface) {
$configuration = new Configuration($configuration);
}
$binaries = $configuration->get('ffmpeg.binaries', array('avconv', 'ffmpeg'));
if (!$configuration->has('timeout')) {
$configuration->set('timeout', 300);
}
$driver = FFMpegDriver::load($binaries, $logger, $configuration);
if (null === $probe) {
$probe = FFProbe::create($configuration, $logger, null);
}
return new static($driver, $probe);
return new static(FFMpegDriver::create($logger, $configuration), $probe);
}
}

View file

@ -40,4 +40,12 @@ class FFMpegDriverTest extends TestCase
$ffmpeg = FFMpegDriver::create($this->getLoggerMock(), $conf);
$this->assertEquals($conf, $ffmpeg->getConfiguration());
}
/**
* @expectedException FFMpeg\Exception\ExecutableNotFoundException
*/
public function testCreateFailureThrowsAnException()
{
FFMpegDriver::create($this->getLoggerMock(), array('ffmpeg.binaries' => '/path/to/nowhere'));
}
}

View file

@ -40,4 +40,12 @@ class FFProbeDriverTest extends TestCase
$ffprobe = FFProbeDriver::create($conf, $this->getLoggerMock());
$this->assertEquals($conf, $ffprobe->getConfiguration());
}
/**
* @expectedException FFMpeg\Exception\ExecutableNotFoundException
*/
public function testCreateFailureThrowsAnException()
{
FFProbeDriver::create(array('ffprobe.binaries' => '/path/to/nowhere'));
}
}

View file

@ -50,7 +50,7 @@ class FFMpegServiceProviderTest extends \PHPUnit_Framework_TestCase
)
));
$this->setExpectedException('Alchemy\BinaryDriver\Exception\ExecutableNotFoundException', 'Executable not found, proposed : /path/to/ffmpeg');
$this->setExpectedException('FFMpeg\Exception\ExecutableNotFoundException', 'Unable to load FFMpeg');
$app['ffmpeg'];
}
@ -63,7 +63,7 @@ class FFMpegServiceProviderTest extends \PHPUnit_Framework_TestCase
)
));
$this->setExpectedException('Alchemy\BinaryDriver\Exception\ExecutableNotFoundException', 'Executable not found, proposed : /path/to/ffprobe');
$this->setExpectedException('FFMpeg\Exception\ExecutableNotFoundException', 'Unable to load FFProbe');
$app['ffmpeg.ffprobe'];
}
}