Index: src/PHPFFMpegFactory.php IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/src/PHPFFMpegFactory.php b/src/PHPFFMpegFactory.php --- a/src/PHPFFMpegFactory.php (revision 729c340f6249d536e34dc2138cdfb8ef9827fd07) +++ b/src/PHPFFMpegFactory.php (date 1656035097000) @@ -4,7 +4,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Logger\LoggerChannelInterface; -use Doctrine\Common\Cache\Cache; +use Psr\Cache\CacheItemPoolInterface; use FFMpeg\FFMpeg; use FFMpeg\FFProbe; @@ -16,7 +16,7 @@ /** * The cache backend that should be passed to the FFMpeg extension. * - * @var \Doctrine\Common\Cache\Cache + * @var \Psr\Cache\CacheItemPoolInterface */ protected $cache; @@ -38,14 +38,14 @@ /** * Constructs a the factory object with injected dependencies. * - * @param \Doctrine\Common\Cache\Cache $cache + * @param \Psr\Cache\CacheItemPoolInterface $cache * The cache backend. * @param \Drupal\Core\Logger\LoggerChannelInterface $logger * Prefix used for appending to cached item identifiers. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * A configuration factory instance. */ - public function __construct(Cache $cache, LoggerChannelInterface $logger, ConfigFactoryInterface $config_factory) { + public function __construct(CacheItemPoolInterface $cache, LoggerChannelInterface $logger, ConfigFactoryInterface $config_factory) { $this->cache = $cache; $this->logger = $logger; $this->config = $config_factory->getEditable('php_ffmpeg.settings'); Index: tests/src/Unit/PHPFFMpegCacheTest.php IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/tests/src/Unit/PHPFFMpegCacheTest.php b/tests/src/Unit/PHPFFMpegCacheTest.php --- a/tests/src/Unit/PHPFFMpegCacheTest.php (revision 729c340f6249d536e34dc2138cdfb8ef9827fd07) +++ b/tests/src/Unit/PHPFFMpegCacheTest.php (date 1656067073000) @@ -59,8 +59,8 @@ $cid = $this->randomMachineName(); $value = $this->randomMachineName(); $this->backend->set("{$this->prefix}:{$cid}", $value); - self::assertEquals($this->cache->fetch($cid), $value, 'PHPFFMpeg::get() should return the value stored in the backend when it exists.'); - $this->assertFalse($this->cache->fetch($this->randomMachineName()), 'PHPFFMpeg::get() should return FALSE when no value exist in the backend.'); + self::assertEquals($value, $this->cache->getItem($cid)->get(),'PHPFFMpeg::get() should return the value stored in the backend when it exists.'); + $this->assertFalse($this->cache->getItem($this->randomMachineName())->isHit(), 'PHPFFMpeg::get() should return FALSE when no value exist in the backend.'); } /** @@ -70,8 +70,8 @@ $cid = $this->randomMachineName(); $value = $this->randomMachineName(); $this->backend->set("{$this->prefix}:{$cid}", $value); - self::assertTrue($this->cache->contains($cid), 'PHPFFMpeg::contains() should return TRUE when a value exists in the backend.'); - self::assertFalse($this->cache->contains($this->randomMachineName()), 'PHPFFMpeg::contains() should return FALSE when no value exist in the backend.'); + self::assertTrue($this->cache->hasItem($cid), 'PHPFFMpeg::contains() should return TRUE when a value exists in the backend.'); + self::assertFalse($this->cache->hasItem($this->randomMachineName()), 'PHPFFMpeg::contains() should return FALSE when no value exist in the backend.'); } /** @@ -80,8 +80,10 @@ public function testSave() { $cid = $this->randomMachineName(); $value = $this->randomMachineName(); - $this->cache->save($cid, $value); - self::assertEquals($this->backend->get("{$this->prefix}:{$cid}")->data, $value, 'PHPFFMpeg::save() should set the value in the backend.'); + $item = $this->cache->getItem($cid); + $item->set($value); + $this->cache->save($item); + self::assertEquals($value, $this->backend->get("{$this->prefix}:{$cid}")->data, 'PHPFFMpeg::save() should set the value in the backend.'); } /** @@ -91,15 +93,8 @@ $cid = $this->randomMachineName(); $value = $this->randomMachineName(); $this->backend->set("{$this->prefix}:{$cid}", $value); - $this->cache->delete($cid); + $this->cache->deleteItem($cid); self::assertFalse($this->backend->get("{$this->prefix}:{$cid}"), 'PHPFFMpeg::delete() should clear the value in the backend.'); } - /** - * Test for PHPFFMpeg::getStats(). - */ - public function testGetStats() { - self::assertNull($this->cache->getStats(), 'PHPFFMpeg::getStats() should return NULL.'); - } - } Index: src/PHPFFMpegCache.php IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/src/PHPFFMpegCache.php b/src/PHPFFMpegCache.php --- a/src/PHPFFMpegCache.php (revision 729c340f6249d536e34dc2138cdfb8ef9827fd07) +++ b/src/PHPFFMpegCache.php (date 1656067073000) @@ -2,13 +2,13 @@ namespace Drupal\php_ffmpeg; -use Doctrine\Common\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; +use Symfony\Component\Cache\Adapter\AbstractAdapter; /** - * Adapter between Doctrine cache needed by FFMPeg library and Drupal cache. + * Adapter between Symfony cache needed by FFMPeg library and Drupal cache. */ -class PHPFFMpegCache implements Cache { +class PHPFFMpegCache extends AbstractAdapter { /** * The cache backend that should be used. @@ -17,13 +17,6 @@ */ protected $cache; - /** - * Prefix for the cache ids. - * - * @var string - */ - protected $prefix; - /** * Constructs a CacheCollector object. * @@ -33,61 +26,53 @@ * Prefix used for appending to cached item identifiers. */ public function __construct(CacheBackendInterface $cache, $prefix) { + parent::__construct($prefix); $this->cache = $cache; - $this->prefix = (string) $prefix; } /** * {@inheritdoc} */ - public function fetch($id) { - if ($cache = $this->cache->get($this->getCid($id))) { - return $cache->data; - } - return FALSE; + protected function doFetch(array $ids) { + $items = $this->cache->getMultiple($ids); + array_walk($items, function (&$item) { + $item = $item->data; + }); + return $items; } /** * {@inheritdoc} */ - public function contains($id) { - return (bool) $this->fetch($id); + protected function doHave(string $id) { + return ($this->cache->get($id) !== FALSE); } /** * {@inheritdoc} */ - public function save($id, $data, $lifeTime = 0) { - $this->cache->set($this->getCid($id), $data, time() + $lifeTime); - return TRUE; + protected function doSave(array $values, int $lifetime) { + array_walk($values, function (&$value) use ($lifetime) { + $value = [ + "data" => $value, + "expire" => ($lifetime == 0) ? CacheBackendInterface::CACHE_PERMANENT : time() + $lifetime + ]; + }); + $this->cache->setMultiple($values); } /** * {@inheritdoc} */ - public function delete($id) { - $this->cache->delete($this->getCid($id)); - return TRUE; + protected function doDelete(array $ids) { + $this->cache->deleteMultiple($ids); } /** * {@inheritdoc} */ - public function getStats() { - return NULL; - } - - /** - * Returns a prefixed cache id based on given id. - * - * @param string $id - * The id string to prefix. - * - * @return string - * A prefixed cache id. - */ - protected function getCid($id) { - return "{$this->prefix}:{$id}"; + protected function doClear(string $namespace) { + $this->cache->deleteAll(); } } Index: composer.json IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/composer.json b/composer.json --- a/composer.json (revision 729c340f6249d536e34dc2138cdfb8ef9827fd07) +++ b/composer.json (date 1656036153000) @@ -16,6 +16,6 @@ }, "require": { "drupal/core": "^8.0 | ^9.0", - "php-ffmpeg/php-ffmpeg": "*" + "php-ffmpeg/php-ffmpeg": "^0.19 | ^1.1" } }