1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Phossa Project |
4
|
|
|
* |
5
|
|
|
* PHP version 5.4 |
6
|
|
|
* |
7
|
|
|
* @category Library |
8
|
|
|
* @package Phossa2\Storage |
9
|
|
|
* @copyright Copyright (c) 2016 phossa.com |
10
|
|
|
* @license http://mit-license.org/ MIT License |
11
|
|
|
* @link http://www.phossa.com/ |
12
|
|
|
*/ |
13
|
|
|
/*# declare(strict_types=1); */ |
14
|
|
|
|
15
|
|
|
namespace Phossa2\Storage\Traits; |
16
|
|
|
|
17
|
|
|
use Phossa2\Storage\Interfaces\FilesystemInterface; |
18
|
|
|
use Phossa2\Storage\Interfaces\FilesystemAwareInterface; |
19
|
|
|
use Phossa2\Storage\Message\Message; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* FilesystemAwareTrait |
23
|
|
|
* |
24
|
|
|
* Implementation of FilesystemAwareInterface |
25
|
|
|
* |
26
|
|
|
* @package Phossa2\Storage |
27
|
|
|
* @author Hong Zhang <[email protected]> |
28
|
|
|
* @see FilesystemAwareInterface |
29
|
|
|
* @version 2.0.0 |
30
|
|
|
* @since 2.0.0 added |
31
|
|
|
*/ |
32
|
|
|
trait FilesystemAwareTrait |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var FilesystemInterface |
36
|
|
|
* @access protected |
37
|
|
|
*/ |
38
|
|
|
protected $filesystem; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritDoc} |
42
|
|
|
*/ |
43
|
|
|
public function setFilesystem(FilesystemInterface $filesystem) |
44
|
|
|
{ |
45
|
|
|
$this->filesystem = $filesystem; |
46
|
|
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritDoc} |
51
|
|
|
*/ |
52
|
|
|
public function getFilesystem()/*# : FilesystemInterface */ |
53
|
|
|
{ |
54
|
|
|
return $this->filesystem; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Check filesystem readable or not |
59
|
|
|
* |
60
|
|
|
* @return bool |
61
|
|
|
* @access protected |
62
|
|
|
*/ |
63
|
|
|
protected function isFilesystemReadable()/*# : bool */ |
64
|
|
|
{ |
65
|
|
|
if ($this->getFilesystem()->isReadable()) { |
66
|
|
|
return true; |
67
|
|
|
} else { |
68
|
|
|
return $this->setError( |
69
|
|
|
Message::get(Message::STR_FS_NONREADABLE, $this->full), |
|
|
|
|
70
|
|
|
Message::STR_FS_NONREADABLE |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Check filesystem writable or not |
77
|
|
|
* |
78
|
|
|
* @return bool |
79
|
|
|
* @access protected |
80
|
|
|
*/ |
81
|
|
|
protected function isFilesystemWritable()/*# : bool */ |
82
|
|
|
{ |
83
|
|
|
if ($this->getFilesystem()->isWritable()) { |
84
|
|
|
return true; |
85
|
|
|
} else { |
86
|
|
|
return $this->setError( |
87
|
|
|
Message::get(Message::STR_FS_NONWRITABLE, $this->full), |
88
|
|
|
Message::STR_FS_NONWRITABLE |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Check filesystem file deletable or not |
95
|
|
|
* |
96
|
|
|
* @return bool |
97
|
|
|
* @access protected |
98
|
|
|
*/ |
99
|
|
|
protected function isFilesystemDeletable()/*# : bool */ |
100
|
|
|
{ |
101
|
|
|
if ($this->getFilesystem()->isDeletable()) { |
102
|
|
|
return true; |
103
|
|
|
} else { |
104
|
|
|
return $this->setError( |
105
|
|
|
Message::get(Message::STR_FS_NONDELETABLE, $this->full), |
106
|
|
|
Message::STR_FS_NONDELETABLE |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
abstract public function setError( |
112
|
|
|
/*# string */ $message = '', |
113
|
|
|
/*# string */ $code = '' |
114
|
|
|
)/*# : bool */; |
115
|
|
|
} |
116
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: