Add ExecutableNotFoundException
This commit is contained in:
		
					parent
					
						
							
								a39d8939db
							
						
					
				
			
			
				commit
				
					
						8e87d243d9
					
				
			
		
					 7 changed files with 61 additions and 18 deletions
				
			
		|  | @ -13,6 +13,9 @@ namespace FFMpeg\Driver; | ||||||
| 
 | 
 | ||||||
| use Alchemy\BinaryDriver\AbstractBinary; | use Alchemy\BinaryDriver\AbstractBinary; | ||||||
| use Alchemy\BinaryDriver\Configuration; | use Alchemy\BinaryDriver\Configuration; | ||||||
|  | use Alchemy\BinaryDriver\ConfigurationInterface; | ||||||
|  | use Alchemy\BinaryDriver\Exception\ExecutableNotFoundException as BinaryDriverExecutableNotFound; | ||||||
|  | use FFMpeg\Exception\ExecutableNotFoundException; | ||||||
| use Psr\Log\LoggerInterface; | use Psr\Log\LoggerInterface; | ||||||
| 
 | 
 | ||||||
| class FFMpegDriver extends AbstractBinary | class FFMpegDriver extends AbstractBinary | ||||||
|  | @ -33,8 +36,22 @@ class FFMpegDriver extends AbstractBinary | ||||||
|      * |      * | ||||||
|      * @return FFMpegDriver |      * @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); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -14,6 +14,8 @@ namespace FFMpeg\Driver; | ||||||
| use Alchemy\BinaryDriver\AbstractBinary; | use Alchemy\BinaryDriver\AbstractBinary; | ||||||
| use Alchemy\BinaryDriver\Configuration; | use Alchemy\BinaryDriver\Configuration; | ||||||
| use Alchemy\BinaryDriver\ConfigurationInterface; | use Alchemy\BinaryDriver\ConfigurationInterface; | ||||||
|  | use Alchemy\BinaryDriver\Exception\ExecutableNotFoundException as BinaryDriverExecutableNotFound; | ||||||
|  | use FFMpeg\Exception\ExecutableNotFoundException; | ||||||
| use Psr\Log\LoggerInterface; | use Psr\Log\LoggerInterface; | ||||||
| 
 | 
 | ||||||
| class FFProbeDriver extends AbstractBinary | class FFProbeDriver extends AbstractBinary | ||||||
|  | @ -42,6 +44,10 @@ class FFProbeDriver extends AbstractBinary | ||||||
| 
 | 
 | ||||||
|         $binaries = $configuration->get('ffprobe.binaries', array('avprobe', 'ffprobe')); |         $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); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										16
									
								
								src/FFMpeg/Exception/ExecutableNotFoundException.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/FFMpeg/Exception/ExecutableNotFoundException.php
									
										
									
									
									
										Normal 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 | ||||||
|  | { | ||||||
|  | } | ||||||
|  | @ -115,22 +115,10 @@ class FFMpeg | ||||||
|      */ |      */ | ||||||
|     public static function create($configuration = array(), LoggerInterface $logger = null, FFProbe $probe = null) |     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) { |         if (null === $probe) { | ||||||
|             $probe = FFProbe::create($configuration, $logger, null); |             $probe = FFProbe::create($configuration, $logger, null); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return new static($driver, $probe); |         return new static(FFMpegDriver::create($logger, $configuration), $probe); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -40,4 +40,12 @@ class FFMpegDriverTest extends TestCase | ||||||
|         $ffmpeg = FFMpegDriver::create($this->getLoggerMock(), $conf); |         $ffmpeg = FFMpegDriver::create($this->getLoggerMock(), $conf); | ||||||
|         $this->assertEquals($conf, $ffmpeg->getConfiguration()); |         $this->assertEquals($conf, $ffmpeg->getConfiguration()); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * @expectedException FFMpeg\Exception\ExecutableNotFoundException | ||||||
|  |      */ | ||||||
|  |     public function testCreateFailureThrowsAnException() | ||||||
|  |     { | ||||||
|  |         FFMpegDriver::create($this->getLoggerMock(), array('ffmpeg.binaries' => '/path/to/nowhere')); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -40,4 +40,12 @@ class FFProbeDriverTest extends TestCase | ||||||
|         $ffprobe = FFProbeDriver::create($conf, $this->getLoggerMock()); |         $ffprobe = FFProbeDriver::create($conf, $this->getLoggerMock()); | ||||||
|         $this->assertEquals($conf, $ffprobe->getConfiguration()); |         $this->assertEquals($conf, $ffprobe->getConfiguration()); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * @expectedException FFMpeg\Exception\ExecutableNotFoundException | ||||||
|  |      */ | ||||||
|  |     public function testCreateFailureThrowsAnException() | ||||||
|  |     { | ||||||
|  |         FFProbeDriver::create(array('ffprobe.binaries' => '/path/to/nowhere')); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -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']; |         $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']; |         $app['ffmpeg.ffprobe']; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue