1 <?php
2 /* --------------------------------------------------------------
3 WritableDirectory.inc.php 2016-01-27
4 Gambio GmbH
5 http://www.gambio.de
6 Copyright (c) 2016 Gambio GmbH
7 Released under the GNU General Public License (Version 2)
8 [http://www.gnu.org/licenses/gpl-2.0.html]
9 --------------------------------------------------------------
10 */
11
12 /**
13 * Class WritableDirectory
14 *
15 * @category System
16 * @package Shared
17 * @subpackage FileSystem
18 */
19 class WritableDirectory extends ExistingDirectory
20 {
21
22 /**
23 * WritableDirectory constructor.
24 *
25 * @param string $absoluteDirPath
26 *
27 * @throws InvalidArgumentException
28 */
29 public function __construct($absoluteDirPath)
30 {
31 // Check for string type.
32 if(!is_string($absoluteDirPath))
33 {
34 throw new InvalidArgumentException('$absoluteDirPath must be a string, '
35 . gettype($absoluteDirPath) . ' given');
36 }
37
38 $realpath = realpath($absoluteDirPath);
39
40 // Check for directory existence.
41 if(!is_dir($realpath))
42 {
43 throw new InvalidArgumentException("'$absoluteDirPath' is not a valid directory path");
44 }
45
46 // Check whether directory is writable.
47 if(!is_writable($realpath))
48 {
49 throw new InvalidArgumentException("'$absoluteDirPath' is not writable");
50 }
51
52 $this->absoluteDirPath = $realpath;
53 }
54 }