1 | <?php |
||
16 | class WorkingDirectory |
||
17 | { |
||
18 | |||
19 | /** |
||
20 | * Name of sub folder placed in user's home directory. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | private $_subFolder; |
||
25 | |||
26 | /** |
||
27 | * WorkingDirectory constructor. |
||
28 | * |
||
29 | * @param string $sub_folder Sub folder. |
||
30 | * |
||
31 | * @throws ApplicationException When $sub_folder is a path or empty. |
||
32 | */ |
||
33 | 13 | public function __construct($sub_folder) |
|
41 | |||
42 | /** |
||
43 | * Creates (if missing) working directory and returns full path to it. |
||
44 | * |
||
45 | * @return string |
||
46 | */ |
||
47 | 11 | public function get() |
|
48 | { |
||
49 | 11 | $working_directory = $this->getUserHomeDirectory() . '/' . $this->_subFolder; |
|
50 | |||
51 | 9 | if ( !file_exists($working_directory) ) { |
|
52 | 9 | mkdir($working_directory, 0777, true); |
|
53 | 9 | } |
|
54 | |||
55 | 9 | return $working_directory; |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * Returns path to user's home directory. |
||
60 | * |
||
61 | * @return string |
||
62 | * @throws ApplicationException When user's home directory can't be found. |
||
63 | */ |
||
64 | 11 | protected function getUserHomeDirectory() |
|
80 | |||
81 | } |
||
82 |