1 | <?php |
||
8 | class HackedFileGroup { |
||
9 | /** |
||
10 | * @var string |
||
11 | */ |
||
12 | protected $base_path = ''; |
||
13 | |||
14 | /** |
||
15 | * @var array |
||
16 | */ |
||
17 | protected $files = array(); |
||
18 | |||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $files_hashes = array(); |
||
23 | |||
24 | /** |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $file_mtimes = array(); |
||
28 | |||
29 | /** |
||
30 | * @var HackedFileHasher |
||
31 | */ |
||
32 | protected $hasher; |
||
33 | |||
34 | /** |
||
35 | * Constructor. |
||
36 | * |
||
37 | * @param string $base_path |
||
38 | * @param HackedFileHasher $hasher |
||
39 | */ |
||
40 | public function __construct($base_path, HackedFileHasher $hasher = null) { |
||
48 | |||
49 | /** |
||
50 | * @return array |
||
51 | */ |
||
52 | public function getFiles() |
||
56 | |||
57 | /** |
||
58 | * @param string $file |
||
59 | * |
||
60 | * @return string|bool |
||
61 | */ |
||
62 | public function getFileHash($file) |
||
70 | |||
71 | /** |
||
72 | * Return a new hackedFileGroup listing all files inside the given $path. |
||
73 | * |
||
74 | * @param string $path |
||
75 | * |
||
76 | * @return HackedFileGroup |
||
77 | */ |
||
78 | public static function fromDirectory($path) { |
||
85 | |||
86 | /** |
||
87 | * Return a new hackedFileGroup listing all files specified. |
||
88 | * |
||
89 | * @param string $path |
||
90 | * @param array $files |
||
91 | * |
||
92 | * @return HackedFileGroup |
||
93 | */ |
||
94 | public static function fromList($path, array $files) { |
||
101 | |||
102 | /** |
||
103 | * Locate all sensible files at the base path of the file group. |
||
104 | */ |
||
105 | public function scanBasePath() { |
||
119 | |||
120 | /** |
||
121 | * Hash all files listed in the file group. |
||
122 | */ |
||
123 | public function computeHashes() { |
||
128 | |||
129 | /** |
||
130 | * Determine if the given file is readable. |
||
131 | * @param string $file |
||
132 | * @return bool |
||
133 | */ |
||
134 | public function isReadable($file) { |
||
137 | |||
138 | /** |
||
139 | * Determine if a file exists. |
||
140 | * @param string $file |
||
141 | * @return bool |
||
142 | */ |
||
143 | public function fileExists($file) { |
||
146 | |||
147 | /** |
||
148 | * Determine if the given file is binary. |
||
149 | * @param string $file |
||
150 | * @return bool |
||
151 | */ |
||
152 | public function isNotBinary($file) { |
||
156 | |||
157 | /** |
||
158 | * @param string $file |
||
159 | * @return string |
||
160 | */ |
||
161 | public function getFileLocation($file) { |
||
164 | |||
165 | /** |
||
166 | * Determine if a file is a binary file. |
||
167 | * |
||
168 | * Taken from: http://www.ultrashock.com/forums/server-side/checking-if-a-file-is-binary-98391.html |
||
169 | * and then tweaked in: http://drupal.org/node/760362. |
||
170 | * |
||
171 | * @param string $file |
||
172 | * |
||
173 | * @return bool |
||
174 | */ |
||
175 | public static function isBinary($file) { |
||
193 | |||
194 | /** |
||
195 | * @param string $dir |
||
196 | * @param int $mask |
||
197 | * @param array $nomask |
||
198 | * @param callable $callback |
||
199 | * @param bool|true $recurse |
||
200 | * @param string $key |
||
201 | * @param int $min_depth |
||
202 | * @param int $depth |
||
203 | * |
||
204 | * @return array |
||
205 | */ |
||
206 | public static function scanDirectory($dir, $mask, $nomask = array('.', '..', 'CVS'), $callback = null, $recurse = TRUE, $key = 'filename', $min_depth = 0, $depth = 0) { |
||
238 | } |
||
239 |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.