diff --git a/src/FFMpeg/Driver/FFMpegDriver.php b/src/FFMpeg/Driver/FFMpegDriver.php index 12b64c8..62aae29 100644 --- a/src/FFMpeg/Driver/FFMpegDriver.php +++ b/src/FFMpeg/Driver/FFMpegDriver.php @@ -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); + } } } diff --git a/src/FFMpeg/Driver/FFProbeDriver.php b/src/FFMpeg/Driver/FFProbeDriver.php index 00c4892..4063611 100644 --- a/src/FFMpeg/Driver/FFProbeDriver.php +++ b/src/FFMpeg/Driver/FFProbeDriver.php @@ -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); + } } } diff --git a/src/FFMpeg/Exception/ExecutableNotFoundException.php b/src/FFMpeg/Exception/ExecutableNotFoundException.php new file mode 100644 index 0000000..28736d8 --- /dev/null +++ b/src/FFMpeg/Exception/ExecutableNotFoundException.php @@ -0,0 +1,16 @@ + + * + * 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 +{ +} diff --git a/src/FFMpeg/FFMpeg.php b/src/FFMpeg/FFMpeg.php index f619af7..54aa300 100644 --- a/src/FFMpeg/FFMpeg.php +++ b/src/FFMpeg/FFMpeg.php @@ -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); } } diff --git a/tests/FFMpeg/Tests/Driver/FFMpegDriverTest.php b/tests/FFMpeg/Tests/Driver/FFMpegDriverTest.php index 3463c81..26a2b34 100644 --- a/tests/FFMpeg/Tests/Driver/FFMpegDriverTest.php +++ b/tests/FFMpeg/Tests/Driver/FFMpegDriverTest.php @@ -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')); + } } diff --git a/tests/FFMpeg/Tests/Driver/FFProbeDriverTest.php b/tests/FFMpeg/Tests/Driver/FFProbeDriverTest.php index 3ec3de5..62d2cd0 100644 --- a/tests/FFMpeg/Tests/Driver/FFProbeDriverTest.php +++ b/tests/FFMpeg/Tests/Driver/FFProbeDriverTest.php @@ -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')); + } } diff --git a/tests/FFMpeg/Tests/FFMpegServiceProviderTest.php b/tests/FFMpeg/Tests/FFMpegServiceProviderTest.php index 371133e..ac9f8a9 100644 --- a/tests/FFMpeg/Tests/FFMpegServiceProviderTest.php +++ b/tests/FFMpeg/Tests/FFMpegServiceProviderTest.php @@ -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']; } }