Issues (38)

cache/cache.php (2 issues)

1
<?php
2
/**
3
 *
4
 * phpBB Media Embed PlugIn extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2020 phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\mediaembed\cache;
12
13
use phpbb\cache\driver\driver_interface as cache_driver;
0 ignored issues
show
The type phpbb\cache\driver\driver_interface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Symfony\Component\Finder\Finder;
0 ignored issues
show
The type Symfony\Component\Finder\Finder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
16
/**
17
 * Media Embed cache handling class.
18
 */
19
class cache
20
{
21
	/** @var cache_driver */
22
	protected $cache;
23
24
	/** @var string Cache key used for the parser */
25
	protected $cache_key_parser;
26
27
	/** @var string Cache key used for the renderer */
28
	protected $cache_key_renderer;
29
30
	/**
31
	 * Constructor
32
	 *
33
	 * @param cache_driver $cache              Cache driver object
34
	 * @param string       $cache_key_parser   Cache key used for the parser
35
	 * @param string       $cache_key_renderer Cache key used for the renderer
36
	 */
37
	public function __construct(cache_driver $cache, $cache_key_parser, $cache_key_renderer)
38
	{
39
		$this->cache = $cache;
40
		$this->cache_key_parser = $cache_key_parser;
41
		$this->cache_key_renderer = $cache_key_renderer;
42
	}
43
44
	/**
45
	 * Purge cached MediaEmbed files
46
	 *
47
	 * @return void
48
	 */
49
	public function purge_mediaembed_cache()
50
	{
51
		$finder = new Finder();
52
		$finder
53
			->name('http.*')
54
			->in($this->cache->cache_dir)
55
			->files();
56
57
		foreach ($finder as $file)
58
		{
59
			$this->cache->remove_file($file->getRealPath());
60
		}
61
	}
62
63
	/**
64
	 * Purge cached TextFormatter files
65
	 *
66
	 * @return void
67
	 */
68
	public function purge_textformatter_cache()
69
	{
70
		$this->cache->destroy($this->cache_key_parser);
71
		$this->cache->destroy($this->cache_key_renderer);
72
	}
73
}
74