1 <?php
2 /* --------------------------------------------------------------
3 ExistingDirectory.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 ExistingDirectory
14 *
15 * @category System
16 * @package Shared
17 * @subpackage FileSystem
18 */
19 class ExistingDirectory
20 {
21 /**
22 * Absolute directory path.
23 *
24 * @var string
25 */
26 protected $absoluteDirPath = '';
27
28
29 /**
30 * ExistingDirectory constructor.
31 *
32 * @param string $absoluteDirPath
33 *
34 * @throws InvalidArgumentException
35 */
36 public function __construct($absoluteDirPath)
37 {
38 // Check for string type.
39 if(!is_string($absoluteDirPath))
40 {
41 throw new InvalidArgumentException('$absoluteDirPath must be a string, '
42 . gettype($absoluteDirPath) . ' given');
43 }
44
45 $realpath = realpath($absoluteDirPath);
46
47 // Check for directory existence.
48 if(!is_dir($realpath))
49 {
50 throw new InvalidArgumentException("'$absoluteDirPath' is not a valid directory path");
51 }
52
53 $this->absoluteDirPath = $realpath;
54 }
55
56
57 /**
58 * Returns the absolute directory path.
59 *
60 * @return string
61 */
62 public function getDirPath()
63 {
64 return $this->absoluteDirPath;
65 }
66
67 }