1 | <?php |
||
7 | class File |
||
8 | { |
||
9 | /** |
||
10 | * Root path |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | private $root; |
||
15 | |||
16 | /** |
||
17 | * Container |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | private $container = []; |
||
22 | |||
23 | /** |
||
24 | * Constructor |
||
25 | * |
||
26 | * @param string $root |
||
27 | */ |
||
28 | public function __construct($root) |
||
32 | |||
33 | /** |
||
34 | * Root |
||
35 | * |
||
36 | * @return string $root |
||
37 | */ |
||
38 | public function root() |
||
42 | |||
43 | /** |
||
44 | * Add the given path file to the container |
||
45 | * |
||
46 | * @param string $key |
||
47 | * @param mixed $value |
||
48 | * @return void |
||
49 | */ |
||
50 | private function share($key, $value) |
||
54 | |||
55 | /** |
||
56 | * Check if the given path file exists in the container |
||
57 | * |
||
58 | * @param string $key |
||
59 | * @return bool |
||
60 | */ |
||
61 | private function isSharing($key) |
||
65 | |||
66 | /** |
||
67 | * Determine if the given file path exists |
||
68 | * |
||
69 | * @param string $file |
||
70 | * @return bool |
||
71 | */ |
||
72 | public function exists($file) |
||
76 | |||
77 | /** |
||
78 | * Require the given file |
||
79 | * |
||
80 | * @param string $path |
||
81 | * @return mixed |
||
82 | */ |
||
83 | public function call($path) |
||
87 | |||
88 | /** |
||
89 | * Get file content |
||
90 | * |
||
91 | * @param string $path |
||
92 | * @return mixed |
||
93 | */ |
||
94 | public function fileContent($path) |
||
98 | |||
99 | /** |
||
100 | * After getting the $path, check if the file or the conent of the file |
||
101 | * is already exists: |
||
102 | * -if so: just return it from the container. |
||
103 | * -if not: check if the file exits: |
||
104 | * - if so: share it to the container. the $path as the key plus :content or :file |
||
105 | * to avoid conflict bewtween the keys. |
||
106 | * :file: it's mean the file |
||
107 | * :content: it's mean the content of the file |
||
108 | * - if not: theow an Exception. |
||
109 | * |
||
110 | * @param string $path |
||
111 | * @param string $share |
||
112 | * @return mixed |
||
113 | */ |
||
114 | private function processSharing($path, $share) |
||
128 | |||
129 | /** |
||
130 | * Generate full path to the given path |
||
131 | * |
||
132 | * @param string $path |
||
133 | * @return string |
||
134 | */ |
||
135 | public function fullPath($path) |
||
139 | } |
||
140 |