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