1 <?php
2
3 /*
4 * This file is part of the ICanBoogie package.
5 *
6 * (c) Olivier Laviale <olivier.laviale@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace ICanBoogie\CLDR;
13
14 class Provider
15 {
16 protected $cache;
17 protected $retriever;
18
19 public function __construct($cache, $retriever)
20 {
21 $this->cache = $cache;
22 $this->retriever = $retriever;
23 }
24
25 /**
26 * Fetches the data available at the specified path.
27 *
28 * @param string $path
29 *
30 * @return array
31 */
32 public function fetch($path)
33 {
34 $json = $this->cache->retrieve($path);
35
36 if (!$json)
37 {
38 $retriever = $this->retriever;
39 $json = $retriever($path);
40
41 if ($json)
42 {
43 $this->cache->store($path, $json);
44 }
45 }
46
47 return json_decode($json, true);
48 }
49
50 public function __invoke($path)
51 {
52 return $this->fetch($path);
53 }
54 }