PHP 5.5+ and replaced doctrine/cache with symfony/cache
This commit is contained in:
parent
bb5cb190bd
commit
7eace8852a
12 changed files with 142 additions and 127 deletions
|
|
@ -11,9 +11,9 @@
|
|||
|
||||
namespace FFMpeg;
|
||||
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Silex\Application;
|
||||
use Silex\ServiceProviderInterface;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
|
||||
class FFMpegServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
|
|
@ -44,7 +44,7 @@ class FFMpegServiceProvider implements ServiceProviderInterface
|
|||
});
|
||||
|
||||
$app['ffprobe.cache'] = $app->share(function () {
|
||||
return new ArrayCache();
|
||||
return new ArrayAdapter;
|
||||
});
|
||||
|
||||
$app['ffmpeg.ffprobe'] = $app->share(function (Application $app) {
|
||||
|
|
|
|||
|
|
@ -13,27 +13,27 @@ namespace FFMpeg;
|
|||
|
||||
use Alchemy\BinaryDriver\ConfigurationInterface;
|
||||
use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
use FFMpeg\Driver\FFProbeDriver;
|
||||
use FFMpeg\Exception\InvalidArgumentException;
|
||||
use FFMpeg\Exception\RuntimeException;
|
||||
use FFMpeg\FFProbe\DataMapping\Format;
|
||||
use FFMpeg\FFProbe\DataMapping\StreamCollection;
|
||||
use FFMpeg\FFProbe\Mapper;
|
||||
use FFMpeg\FFProbe\MapperInterface;
|
||||
use FFMpeg\FFProbe\OptionsTester;
|
||||
use FFMpeg\FFProbe\OptionsTesterInterface;
|
||||
use FFMpeg\FFProbe\OutputParser;
|
||||
use FFMpeg\FFProbe\OutputParserInterface;
|
||||
use FFMpeg\Exception\InvalidArgumentException;
|
||||
use FFMpeg\Exception\RuntimeException;
|
||||
use FFMpeg\FFProbe\DataMapping\StreamCollection;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
|
||||
class FFProbe
|
||||
{
|
||||
const TYPE_STREAMS = 'streams';
|
||||
const TYPE_FORMAT = 'format';
|
||||
|
||||
/** @var Cache */
|
||||
/** @var CacheItemPoolInterface */
|
||||
private $cache;
|
||||
/** @var OptionsTesterInterface */
|
||||
private $optionsTester;
|
||||
|
|
@ -44,7 +44,7 @@ class FFProbe
|
|||
/** @var MapperInterface */
|
||||
private $mapper;
|
||||
|
||||
public function __construct(FFProbeDriver $ffprobe, Cache $cache)
|
||||
public function __construct(FFProbeDriver $ffprobe, CacheItemPoolInterface $cache)
|
||||
{
|
||||
$this->ffprobe = $ffprobe;
|
||||
$this->optionsTester = new OptionsTester($ffprobe, $cache);
|
||||
|
|
@ -114,11 +114,11 @@ class FFProbe
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Cache $cache
|
||||
* @param CacheItemPoolInterface $cache
|
||||
*
|
||||
* @return FFProbe
|
||||
*/
|
||||
public function setCache(Cache $cache)
|
||||
public function setCache(CacheItemPoolInterface $cache)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
|
||||
|
|
@ -213,14 +213,14 @@ class FFProbe
|
|||
*
|
||||
* @param array|ConfigurationInterface $configuration
|
||||
* @param LoggerInterface $logger
|
||||
* @param Cache $cache
|
||||
* @param CacheItemPoolInterface $cache
|
||||
*
|
||||
* @return FFProbe
|
||||
*/
|
||||
public static function create($configuration = array(), LoggerInterface $logger = null, Cache $cache = null)
|
||||
public static function create($configuration = array(), LoggerInterface $logger = null, CacheItemPoolInterface $cache = null)
|
||||
{
|
||||
if (null === $cache) {
|
||||
$cache = new ArrayCache();
|
||||
$cache = new ArrayAdapter();
|
||||
}
|
||||
|
||||
return new static(FFProbeDriver::create($configuration, $logger), $cache);
|
||||
|
|
@ -228,10 +228,10 @@ class FFProbe
|
|||
|
||||
private function probe($pathfile, $command, $type, $allowJson = true)
|
||||
{
|
||||
$id = sprintf('%s-%s', $command, $pathfile);
|
||||
$id = md5(sprintf('%s-%s', $command, $pathfile));
|
||||
|
||||
if ($this->cache->contains($id)) {
|
||||
return $this->cache->fetch($id);
|
||||
if ($this->cache->hasItem($id)) {
|
||||
return $this->cache->getItem($id)->get();
|
||||
}
|
||||
|
||||
if (!$this->optionsTester->has($command)) {
|
||||
|
|
@ -276,7 +276,9 @@ class FFProbe
|
|||
|
||||
$ret = $this->mapper->map($type, $data);
|
||||
|
||||
$this->cache->save($id, $ret);
|
||||
$cacheItem = $this->cache->getItem($id);
|
||||
$cacheItem->set($ret);
|
||||
$this->cache->save($cacheItem);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ abstract class AbstractData implements \Countable
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function count()
|
||||
{
|
||||
return count($this->properties);
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ class StreamCollection implements \Countable, \IteratorAggregate
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function count()
|
||||
{
|
||||
return count($this->streams);
|
||||
|
|
@ -92,6 +93,7 @@ class StreamCollection implements \Countable, \IteratorAggregate
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator($this->streams);
|
||||
|
|
|
|||
|
|
@ -12,18 +12,18 @@
|
|||
namespace FFMpeg\FFProbe;
|
||||
|
||||
use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
use FFMpeg\Driver\FFProbeDriver;
|
||||
use FFMpeg\Exception\RuntimeException;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
|
||||
class OptionsTester implements OptionsTesterInterface
|
||||
{
|
||||
/** @var FFProbeDriver */
|
||||
private $ffprobe;
|
||||
/** @var Cache */
|
||||
/** @var CacheItemPoolInterface */
|
||||
private $cache;
|
||||
|
||||
public function __construct(FFProbeDriver $ffprobe, Cache $cache)
|
||||
public function __construct(FFProbeDriver $ffprobe, CacheItemPoolInterface $cache)
|
||||
{
|
||||
$this->ffprobe = $ffprobe;
|
||||
$this->cache = $cache;
|
||||
|
|
@ -34,17 +34,19 @@ class OptionsTester implements OptionsTesterInterface
|
|||
*/
|
||||
public function has($name)
|
||||
{
|
||||
$id = sprintf('option-%s', $name);
|
||||
$id = md5(sprintf('option-%s', $name));
|
||||
|
||||
if ($this->cache->contains($id)) {
|
||||
return $this->cache->fetch($id);
|
||||
if ($this->cache->hasItem($id)) {
|
||||
return $this->cache->getItem($id)->get();
|
||||
}
|
||||
|
||||
$output = $this->retrieveHelpOutput();
|
||||
|
||||
$ret = (bool) preg_match('/^'.$name.'/m', $output);
|
||||
|
||||
$this->cache->save($id, $ret);
|
||||
$cacheItem = $this->cache->getItem($id);
|
||||
$cacheItem->set($ret);
|
||||
$this->cache->save($cacheItem);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
|
@ -53,8 +55,8 @@ class OptionsTester implements OptionsTesterInterface
|
|||
{
|
||||
$id = 'help';
|
||||
|
||||
if ($this->cache->contains($id)) {
|
||||
return $this->cache->fetch($id);
|
||||
if ($this->cache->hasItem($id)) {
|
||||
return $this->cache->getItem($id)->get();
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
@ -63,7 +65,9 @@ class OptionsTester implements OptionsTesterInterface
|
|||
throw new RuntimeException('Your FFProbe version is too old and does not support `-help` option, please upgrade.', $e->getCode(), $e);
|
||||
}
|
||||
|
||||
$this->cache->save($id, $output);
|
||||
$cacheItem = $this->cache->getItem($id);
|
||||
$cacheItem->set($output);
|
||||
$this->cache->save($cacheItem);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ class FiltersCollection implements \Countable, \IteratorAggregate
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function count()
|
||||
{
|
||||
if (0 === count($this->filters)) {
|
||||
|
|
@ -44,6 +45,7 @@ class FiltersCollection implements \Countable, \IteratorAggregate
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
if (null === $this->sorted) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue