1 <?php
2 /* --------------------------------------------------------------
3 WriteableFile.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 WritableFile
14 *
15 * @category System
16 * @package Shared
17 * @subpackage FileSystem
18 */
19 class WritableFile extends ExistingFile
20 {
21 /**
22 * WritableFile constructor.
23 *
24 * @param string $absoluteFilePath
25 *
26 * @throws InvalidArgumentException
27 */
28 public function __construct($absoluteFilePath)
29 {
30 // Check for string type.
31 if(!is_string($absoluteFilePath))
32 {
33 throw new InvalidArgumentException('$absoluteFilePath must be a string, '
34 . gettype($absoluteFilePath) . ' given');
35 }
36
37 $realpath = realpath($absoluteFilePath);
38
39 // Check for file existence.
40 if(!is_file($realpath))
41 {
42 throw new InvalidArgumentException("'$absoluteFilePath' is not a valid file path");
43 }
44
45 // Check whether file is writable.
46 if(!is_writable($realpath))
47 {
48 throw new InvalidArgumentException("'$absoluteFilePath' is not writable");
49 }
50
51 $this->absoluteFilePath = $realpath;
52 }
53
54 }