1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the m1\vars library |
5
|
|
|
* |
6
|
|
|
* (c) m1 <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @package m1/vars |
12
|
|
|
* @version 1.1.0 |
13
|
|
|
* @author Miles Croxford <[email protected]> |
14
|
|
|
* @copyright Copyright (c) Miles Croxford <[email protected]> |
15
|
|
|
* @license http://github.com/m1/vars/blob/master/LICENSE |
16
|
|
|
* @link http://github.com/m1/vars/blob/master/README.MD Documentation |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace M1\Vars\Traits; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* This trait manages the resource flags that you can use |
23
|
|
|
* |
24
|
|
|
* @since 0.3.0 |
25
|
|
|
*/ |
26
|
|
|
trait ResourceFlagsTrait |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Explodes the ?: flag into pieces |
30
|
|
|
* |
31
|
|
|
* @param string $resource The resource string |
32
|
|
|
* |
33
|
|
|
* @return array The parsed resources |
34
|
|
|
*/ |
35
|
80 |
|
protected function explodeResourceIfElse($resource) |
36
|
|
|
{ |
37
|
80 |
|
$resource = explode("?:", $resource, 2); |
38
|
80 |
|
$resources = array(); |
39
|
|
|
|
40
|
80 |
|
foreach ($resource as $r) { |
41
|
80 |
|
$resources[] = trim($r); |
42
|
|
|
} |
43
|
|
|
|
44
|
80 |
|
return $resources; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Returns the array pieces of the exploded ?: into a string |
49
|
|
|
* |
50
|
|
|
* @param array $resource The resource array |
51
|
|
|
* |
52
|
|
|
* @return string The parsed string resource |
53
|
|
|
*/ |
54
|
53 |
|
protected function implodeResourceIfElse($resource) |
55
|
|
|
{ |
56
|
53 |
|
if (count($resource) > 1) { |
57
|
6 |
|
return implode(" ?: ", $resource); |
58
|
|
|
} |
59
|
|
|
|
60
|
47 |
|
return $resource[0]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Returns trimmed resource string |
65
|
|
|
* |
66
|
|
|
* @param string $resource The resource |
67
|
|
|
* |
68
|
|
|
* @return string The parsed string resource |
69
|
|
|
*/ |
70
|
80 |
|
protected function trimFlags($resource) |
71
|
|
|
{ |
72
|
80 |
|
$resource = trim($resource, '@'); |
73
|
80 |
|
$resource = trim($resource, '*'); |
74
|
|
|
|
75
|
80 |
|
return $resource; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Duplicates the flags from one string to another |
80
|
|
|
* |
81
|
|
|
* @param string $resource The resource to add the flags to |
82
|
|
|
* @param string $resource The resource to duplicate the flags from |
83
|
|
|
* |
84
|
|
|
* @return string The parsed string resource |
85
|
|
|
*/ |
86
|
53 |
|
protected function replicateFlags($resource, $original_resource) |
87
|
|
|
{ |
88
|
53 |
|
return sprintf( |
89
|
53 |
|
'%s%s%s', |
90
|
53 |
|
($this->checkSuppression($original_resource)) ? '@' : null, |
91
|
53 |
|
$resource, |
92
|
53 |
|
($this->checkRecursive($original_resource)) ? '*' : null |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Checks to see if the recursive flag is set |
98
|
|
|
* |
99
|
|
|
* @param string $resource The resource |
100
|
|
|
* |
101
|
|
|
* @return bool Is the recursive flag set |
102
|
|
|
*/ |
103
|
80 |
|
private function checkRecursive($resource) |
104
|
|
|
{ |
105
|
80 |
|
return substr($resource, -1) === "*"; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Checks to see if the file not found exception is suppressed |
110
|
|
|
* |
111
|
|
|
* @param string $resource The resource |
112
|
|
|
* |
113
|
|
|
* @return bool Is the exception suppressed |
114
|
|
|
*/ |
115
|
80 |
|
private function checkSuppression($resource) |
116
|
|
|
{ |
117
|
80 |
|
return substr($resource, 0, 1) === "@"; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|