5f5c8ffd9745b6bb8f9e5ed1e56f373d2cd5ce96
[yaffs-website] / vendor / drush / drush / src / Cache / JSONCache.php
1 <?php
2
3 /**
4  * @file
5  * Definition of Drush\Cache\JSONCache.
6  */
7
8 namespace Drush\Cache;
9
10 /**
11  * JSON cache storage backend.
12  *
13  * @deprecated
14  */
15 class JSONCache extends FileCache
16 {
17     const EXTENSION = '.json';
18
19     public function readFile($filename)
20     {
21         $item = file_get_contents($filename);
22         return $item ? (object)json_decode($item, true) : false;
23     }
24
25     public function writeFile($filename, $cache)
26     {
27         $json = json_encode($cache, JSON_PRETTY_PRINT);
28         // json_encode() does not escape <, > and &, so we do it with str_replace().
29         $json = str_replace(['<', '>', '&'], ['\u003c', '\u003e', '\u0026'], $json);
30         return file_put_contents($filename, $json);
31     }
32 }