2012-04-13 10:20:54 +02:00
|
|
|
<?php
|
|
|
|
|
|
2012-04-13 14:34:53 +02:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-04-13 10:20:54 +02:00
|
|
|
namespace FFMpeg;
|
|
|
|
|
|
2012-04-13 15:27:10 +02:00
|
|
|
use \Symfony\Component\Process\ExecutableFinder;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Binary abstract class
|
|
|
|
|
*/
|
2012-04-13 10:20:54 +02:00
|
|
|
abstract class Binary implements AdapterInterface
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
protected $binary;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @var \Monolog\Logger
|
|
|
|
|
*/
|
|
|
|
|
protected $logger;
|
|
|
|
|
|
2012-04-13 15:27:10 +02:00
|
|
|
/**
|
|
|
|
|
* Binary constructor
|
|
|
|
|
*
|
|
|
|
|
* @param type $binary The path file to the binary
|
|
|
|
|
* @param \Monolog\Logger $logger A logger
|
|
|
|
|
*/
|
2012-04-13 10:20:54 +02:00
|
|
|
public function __construct($binary, $logger = null)
|
|
|
|
|
{
|
|
|
|
|
$this->binary = $binary;
|
|
|
|
|
|
|
|
|
|
if ( ! $logger)
|
|
|
|
|
{
|
|
|
|
|
$logger = new \Monolog\Logger('default');
|
|
|
|
|
$logger->pushHandler(new \Monolog\Handler\NullHandler());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->logger = $logger;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-13 15:27:10 +02:00
|
|
|
/**
|
|
|
|
|
* Load the static binary
|
|
|
|
|
*
|
|
|
|
|
* @param \Monolog\Logger $logger A logger
|
|
|
|
|
* @return \FFMpeg\Binary The binary
|
|
|
|
|
* @throws Exception\BinaryNotFoundException
|
|
|
|
|
*/
|
2012-04-13 10:20:54 +02:00
|
|
|
public static function load(\Monolog\Logger $logger = null)
|
|
|
|
|
{
|
2012-04-13 15:27:10 +02:00
|
|
|
$finder = new ExecutableFinder();
|
2012-04-13 14:43:35 +02:00
|
|
|
|
|
|
|
|
if (null === $binary = $finder->find(static::getBinaryName()))
|
2012-04-13 10:20:54 +02:00
|
|
|
{
|
2012-04-13 11:23:04 +02:00
|
|
|
throw new Exception\BinaryNotFoundException('Binary not found');
|
2012-04-13 10:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new static($binary, $logger);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-13 15:27:10 +02:00
|
|
|
/**
|
|
|
|
|
* Return the binary name
|
|
|
|
|
*
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
2012-04-13 10:20:54 +02:00
|
|
|
protected static function getBinaryName()
|
|
|
|
|
{
|
2012-04-13 15:27:10 +02:00
|
|
|
throw new \Exception('Should be implemented');
|
2012-04-13 10:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-13 15:27:10 +02:00
|
|
|
}
|