1 | <?php |
||
30 | class Path |
||
31 | { |
||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | private $path; |
||
36 | |||
37 | /** |
||
38 | * Path constructor. |
||
39 | * @param string $path |
||
40 | */ |
||
41 | 15 | private function __construct($path) |
|
45 | |||
46 | /** |
||
47 | * @throws OptimiseException on problems during creation of tmp dir |
||
48 | */ |
||
49 | 15 | static public function createPath() |
|
50 | { |
||
51 | 15 | $path = new Path(tempnam(sys_get_temp_dir(), 'OPT')); //TODO check the return in case of errors this return false on failure |
|
52 | 15 | unlink($path->getPath()); //remove file to create a dir |
|
53 | 15 | if (file_exists($path->getPath())) |
|
54 | 10 | throw new OptimiseException('problem during creation of tmp dir (the directory already exists)'); |
|
55 | 15 | if (!@mkdir($path->getPath())) |
|
56 | 10 | throw new OptimiseException('problem during creation of tmp dir (mkdir problem)');; |
|
57 | 15 | if (!is_dir($path->getPath())) |
|
58 | 10 | throw new OptimiseException('problem during creation of tmp dir (it is not possible to create directory)'); |
|
59 | 15 | return $path; |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * @return string |
||
64 | */ |
||
65 | 15 | public function getPath() |
|
66 | { |
||
67 | 15 | return $this->path; |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * @param string $path |
||
72 | */ |
||
73 | public function setPath($path) |
||
74 | { |
||
75 | $this->path = $path; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @throws OptimiseException |
||
80 | */ |
||
81 | 8 | public function __destruct() |
|
82 | { |
||
83 | 8 | if ($this->path && is_dir($this->path) && !self::delTree($this->path)) |
|
84 | 6 | throw new OptimiseException('problems during removing of path directory'); |
|
85 | 8 | } |
|
86 | |||
87 | /** |
||
88 | * remove a no empty dir |
||
89 | * @param $dir |
||
90 | * @return bool |
||
91 | */ |
||
92 | 8 | private static function delTree($dir) |
|
93 | { |
||
94 | 8 | $files = array_diff(scandir($dir), array('.', '..')); |
|
95 | 8 | foreach ($files as $file) { |
|
96 | 2 | (is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file"); |
|
97 | 6 | } |
|
98 | 8 | return rmdir($dir); |
|
99 | } |
||
100 | |||
101 | |||
102 | /** |
||
103 | * @return string |
||
104 | */ |
||
105 | 9 | public function getModelPath() |
|
109 | |||
110 | /** |
||
111 | * @return string |
||
112 | */ |
||
113 | 9 | public function getUsersPath() |
|
117 | |||
118 | /** |
||
119 | * @return string |
||
120 | */ |
||
121 | 9 | public function getMeetingsPath() |
|
125 | |||
126 | /** |
||
127 | * @return string |
||
128 | */ |
||
129 | 9 | public function getMeetingsDurationPath() |
|
133 | |||
134 | /** |
||
135 | * @return string |
||
136 | */ |
||
137 | 9 | public function getMeetingsAvailabilityPath() |
|
141 | |||
142 | /** |
||
143 | * @return string |
||
144 | */ |
||
145 | 9 | public function getUsersAvailabilityPath() |
|
149 | |||
150 | /** |
||
151 | * @return string |
||
152 | */ |
||
153 | 9 | public function getUsersMeetingsPath() |
|
157 | |||
158 | /** |
||
159 | * @return string |
||
160 | */ |
||
161 | 9 | public function getXPath() |
|
165 | |||
166 | /** |
||
167 | * @return string |
||
168 | */ |
||
169 | 9 | public function getYPath() |
|
173 | |||
174 | /** |
||
175 | * @return string |
||
176 | */ |
||
177 | 9 | public function getOutputPath() |
|
181 | } |