1 | <?php |
||||
2 | |||||
3 | namespace Nip\Dispatcher\Resolver\Cache; |
||||
4 | |||||
5 | /** |
||||
6 | * Class FileManager |
||||
7 | * @package Nip\Dispatcher\Resolver\Cache |
||||
8 | */ |
||||
9 | class FileManager |
||||
10 | { |
||||
11 | /** |
||||
12 | * @param DefinitionsCollection $definitionCollection |
||||
13 | * @param null $path |
||||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||||
14 | */ |
||||
15 | 3 | public static function write($definitionCollection, $path = null) |
|||
16 | { |
||||
17 | 3 | $path = $path ? $path : static::filePath(); |
|||
0 ignored issues
–
show
|
|||||
18 | 3 | $content = '<?php return ' . var_export($definitionCollection->all(), true) . ';'; |
|||
19 | 3 | file_put_contents($path, $content); |
|||
20 | 3 | } |
|||
21 | |||||
22 | /** |
||||
23 | * @param DefinitionsCollection $definitionCollection |
||||
24 | * @param null $path |
||||
0 ignored issues
–
show
|
|||||
25 | */ |
||||
26 | 2 | public static function read($definitionCollection, $path = null) |
|||
27 | { |
||||
28 | 2 | $path = $path ? $path : static::filePath(); |
|||
0 ignored issues
–
show
|
|||||
29 | /** @noinspection PhpIncludeInspection */ |
||||
30 | 2 | $items = require $path; |
|||
31 | 2 | $definitionCollection->replace($items); |
|||
32 | 2 | } |
|||
33 | |||||
34 | /** |
||||
35 | * @param null $path |
||||
0 ignored issues
–
show
|
|||||
36 | */ |
||||
37 | public static function empty($path = null) |
||||
38 | { |
||||
39 | $path = $path ? $path : static::filePath(); |
||||
0 ignored issues
–
show
|
|||||
40 | $content = '<?php return [];'; |
||||
41 | file_put_contents($path, $content); |
||||
42 | } |
||||
43 | |||||
44 | /** |
||||
45 | * @return bool |
||||
46 | */ |
||||
47 | 1 | public static function hasCacheFile() |
|||
48 | { |
||||
49 | 1 | $path = static::filePath(); |
|||
50 | 1 | return is_file($path); |
|||
51 | } |
||||
52 | |||||
53 | /** |
||||
54 | * @return string |
||||
55 | */ |
||||
56 | 3 | public static function filePath() |
|||
57 | { |
||||
58 | 3 | return static::filePathBase() . '/dispatcher.php'; |
|||
59 | } |
||||
60 | |||||
61 | /** |
||||
62 | * @return string |
||||
63 | */ |
||||
64 | 3 | public static function filePathBase() |
|||
65 | { |
||||
66 | 3 | return function_exists('app') && app()->has('path.storage') |
|||
67 | ? app('path.storage') . DIRECTORY_SEPARATOR . 'cache' |
||||
0 ignored issues
–
show
Are you sure
app('path.storage') of type mixed|object can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
68 | 3 | : dirname(dirname(dirname(__DIR__))) . '/cache'; |
|||
69 | } |
||||
70 | } |
||||
71 |