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