1<?php
2
3namespace Mpdf\Fonts;
4
5use Mpdf\Cache;
6
7class FontCache
8{
9
10	private $memoryCache = [];
11
12	private $cache;
13
14	public function __construct(Cache $cache)
15	{
16		$this->cache = $cache;
17	}
18
19	public function tempFilename($filename)
20	{
21		return $this->cache->tempFilename($filename);
22	}
23
24	public function has($filename)
25	{
26		return $this->cache->has($filename);
27	}
28
29	public function jsonHas($filename)
30	{
31		return (isset($this->memoryCache[$filename]) || $this->has($filename));
32	}
33
34	public function load($filename)
35	{
36		return $this->cache->load($filename);
37	}
38
39	public function jsonLoad($filename)
40	{
41		if (isset($this->memoryCache[$filename])) {
42			return $this->memoryCache[$filename];
43		}
44
45		$this->memoryCache[$filename] = json_decode($this->load($filename), true);
46		return $this->memoryCache[$filename];
47	}
48
49	public function write($filename, $data)
50	{
51		return $this->cache->write($filename, $data);
52	}
53
54	public function binaryWrite($filename, $data)
55	{
56		return $this->cache->write($filename, $data);
57	}
58
59	public function jsonWrite($filename, $data)
60	{
61		return $this->cache->write($filename, json_encode($data));
62	}
63
64	public function remove($filename)
65	{
66		return $this->cache->remove($filename);
67	}
68
69	public function jsonRemove($filename)
70	{
71		if (isset($this->memoryCache[$filename])) {
72			unset($this->memoryCache[$filename]);
73		}
74
75		$this->remove($filename);
76	}
77}
78