@@ -6,7 +6,7 @@ |
||
6 | 6 | |
7 | 7 | //changes in iAuthenticate |
8 | 8 | Defaults::$authenticationMethod = 'isAuthenticated'; |
9 | -include __DIR__ . '/iAuthenticate.php'; |
|
9 | +include __DIR__.'/iAuthenticate.php'; |
|
10 | 10 | |
11 | 11 | //changes in routing |
12 | 12 | Defaults::$autoRoutingEnabled = false; |
@@ -13,51 +13,51 @@ |
||
13 | 13 | */ |
14 | 14 | interface iCache |
15 | 15 | { |
16 | - /** |
|
17 | - * store data in the cache |
|
18 | - * |
|
19 | - * @abstract |
|
20 | - * |
|
21 | - * @param string $name |
|
22 | - * @param mixed $data |
|
23 | - * |
|
24 | - * @return boolean true if successful |
|
25 | - */ |
|
26 | - public function set($name, $data); |
|
16 | + /** |
|
17 | + * store data in the cache |
|
18 | + * |
|
19 | + * @abstract |
|
20 | + * |
|
21 | + * @param string $name |
|
22 | + * @param mixed $data |
|
23 | + * |
|
24 | + * @return boolean true if successful |
|
25 | + */ |
|
26 | + public function set($name, $data); |
|
27 | 27 | |
28 | - /** |
|
29 | - * retrieve data from the cache |
|
30 | - * |
|
31 | - * @abstract |
|
32 | - * |
|
33 | - * @param string $name |
|
34 | - * @param bool $ignoreErrors |
|
35 | - * |
|
36 | - * @return mixed |
|
37 | - */ |
|
38 | - public function get($name, $ignoreErrors = false); |
|
28 | + /** |
|
29 | + * retrieve data from the cache |
|
30 | + * |
|
31 | + * @abstract |
|
32 | + * |
|
33 | + * @param string $name |
|
34 | + * @param bool $ignoreErrors |
|
35 | + * |
|
36 | + * @return mixed |
|
37 | + */ |
|
38 | + public function get($name, $ignoreErrors = false); |
|
39 | 39 | |
40 | - /** |
|
41 | - * delete data from the cache |
|
42 | - * |
|
43 | - * @abstract |
|
44 | - * |
|
45 | - * @param string $name |
|
46 | - * @param bool $ignoreErrors |
|
47 | - * |
|
48 | - * @return boolean true if successful |
|
49 | - */ |
|
50 | - public function clear($name, $ignoreErrors = false); |
|
40 | + /** |
|
41 | + * delete data from the cache |
|
42 | + * |
|
43 | + * @abstract |
|
44 | + * |
|
45 | + * @param string $name |
|
46 | + * @param bool $ignoreErrors |
|
47 | + * |
|
48 | + * @return boolean true if successful |
|
49 | + */ |
|
50 | + public function clear($name, $ignoreErrors = false); |
|
51 | 51 | |
52 | - /** |
|
53 | - * check if the given name is cached |
|
54 | - * |
|
55 | - * @abstract |
|
56 | - * |
|
57 | - * @param string $name |
|
58 | - * |
|
59 | - * @return boolean true if cached |
|
60 | - */ |
|
61 | - public function isCached($name); |
|
52 | + /** |
|
53 | + * check if the given name is cached |
|
54 | + * |
|
55 | + * @abstract |
|
56 | + * |
|
57 | + * @param string $name |
|
58 | + * |
|
59 | + * @return boolean true if cached |
|
60 | + */ |
|
61 | + public function isCached($name); |
|
62 | 62 | } |
63 | 63 |
@@ -15,41 +15,41 @@ discard block |
||
15 | 15 | |
16 | 16 | function exceptions() |
17 | 17 | { |
18 | - global $call_trace; |
|
19 | - $r = Util::$restler; |
|
20 | - $source = $r->_exceptions; |
|
21 | - if (count($source)) { |
|
22 | - $source = end($source); |
|
23 | - $traces = array(); |
|
24 | - do { |
|
25 | - $traces += $source->getTrace(); |
|
26 | - } while ($source = $source->getPrevious()); |
|
27 | - $traces += debug_backtrace(); |
|
28 | - $call_trace |
|
29 | - = parse_backtrace($traces, 0); |
|
30 | - } else { |
|
31 | - $call_trace |
|
32 | - = parse_backtrace(debug_backtrace()); |
|
33 | - } |
|
18 | + global $call_trace; |
|
19 | + $r = Util::$restler; |
|
20 | + $source = $r->_exceptions; |
|
21 | + if (count($source)) { |
|
22 | + $source = end($source); |
|
23 | + $traces = array(); |
|
24 | + do { |
|
25 | + $traces += $source->getTrace(); |
|
26 | + } while ($source = $source->getPrevious()); |
|
27 | + $traces += debug_backtrace(); |
|
28 | + $call_trace |
|
29 | + = parse_backtrace($traces, 0); |
|
30 | + } else { |
|
31 | + $call_trace |
|
32 | + = parse_backtrace(debug_backtrace()); |
|
33 | + } |
|
34 | 34 | |
35 | 35 | } |
36 | 36 | exceptions(); |
37 | 37 | |
38 | 38 | function parse_backtrace($raw, $skip = 1) |
39 | 39 | { |
40 | - $output = ""; |
|
41 | - foreach ($raw as $entry) { |
|
42 | - if ($skip-- > 0) { |
|
43 | - continue; |
|
44 | - } |
|
45 | - //$output .= print_r($entry, true) . "\n"; |
|
46 | - $output .= "\nFile: " . $entry['file'] . " (Line: " . $entry['line'] . ")\n"; |
|
47 | - if (isset($entry['class'])) |
|
48 | - $output .= $entry['class'] . "::"; |
|
49 | - $output .= $entry['function'] |
|
50 | - . "( " . json_encode($entry['args']) . " )\n"; |
|
51 | - } |
|
52 | - return $output; |
|
40 | + $output = ""; |
|
41 | + foreach ($raw as $entry) { |
|
42 | + if ($skip-- > 0) { |
|
43 | + continue; |
|
44 | + } |
|
45 | + //$output .= print_r($entry, true) . "\n"; |
|
46 | + $output .= "\nFile: " . $entry['file'] . " (Line: " . $entry['line'] . ")\n"; |
|
47 | + if (isset($entry['class'])) |
|
48 | + $output .= $entry['class'] . "::"; |
|
49 | + $output .= $entry['function'] |
|
50 | + . "( " . json_encode($entry['args']) . " )\n"; |
|
51 | + } |
|
52 | + return $output; |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | |
@@ -57,64 +57,64 @@ discard block |
||
57 | 57 | //print_r($response); |
58 | 58 | $icon; |
59 | 59 | if ($success && isset($api)) { |
60 | - $arguments = implode(', ', $api->parameters); |
|
61 | - $icon = "<icon class=\"success\"></icon>"; |
|
62 | - $title = "{$api->className}::" |
|
63 | - . "{$api->methodName}({$arguments})"; |
|
60 | + $arguments = implode(', ', $api->parameters); |
|
61 | + $icon = "<icon class=\"success\"></icon>"; |
|
62 | + $title = "{$api->className}::" |
|
63 | + . "{$api->methodName}({$arguments})"; |
|
64 | 64 | } else { |
65 | - if (isset($response['error']['message'])) { |
|
66 | - $icon = '<icon class="denied"></icon>'; |
|
67 | - $title = end(explode(':',$response['error']['message'],2)); |
|
68 | - } else { |
|
69 | - $icon = '<icon class="warning"></icon>'; |
|
70 | - $title = 'No Matching Resource'; |
|
71 | - } |
|
65 | + if (isset($response['error']['message'])) { |
|
66 | + $icon = '<icon class="denied"></icon>'; |
|
67 | + $title = end(explode(':',$response['error']['message'],2)); |
|
68 | + } else { |
|
69 | + $icon = '<icon class="warning"></icon>'; |
|
70 | + $title = 'No Matching Resource'; |
|
71 | + } |
|
72 | 72 | } |
73 | 73 | function render($data, $shadow=true) |
74 | 74 | { |
75 | - $r = ''; |
|
76 | - if (empty($data)) |
|
77 | - return $r; |
|
78 | - $r .= $shadow ? "<ul class=\"shadow\">\n": "<ul>\n"; |
|
79 | - if (is_array($data)) { |
|
80 | - // field name |
|
81 | - foreach ($data as $key => $value) { |
|
82 | - $r .= '<li>'; |
|
83 | - $r .= is_numeric($key) |
|
84 | - ? "<strong>[$key]</strong> " |
|
85 | - : "<strong>$key: </strong>"; |
|
86 | - $r .= '<span>'; |
|
87 | - if (is_array($value)) { |
|
88 | - // recursive |
|
89 | - $r .= render($value,false); |
|
90 | - } else { |
|
91 | - // value, with hyperlinked hyperlinks |
|
92 | - if (is_bool($value)) { |
|
93 | - $value = $value ? 'true' : 'false'; |
|
94 | - } |
|
95 | - $value = htmlentities($value, ENT_COMPAT, 'UTF-8'); |
|
96 | - if (strpos($value, 'http://') === 0) { |
|
97 | - $r .= '<a href="' . $value . '">' . $value . '</a>'; |
|
98 | - } else { |
|
99 | - $r .= $value; |
|
100 | - } |
|
101 | - } |
|
102 | - $r .= "</span></li>\n"; |
|
103 | - } |
|
104 | - } elseif (is_bool($data)) { |
|
105 | - $r .= '<li>' . ($data ? 'true' : 'false') . '</li>'; |
|
106 | - } else { |
|
107 | - $r .= "<li><strong>$data</strong></li>"; |
|
108 | - } |
|
109 | - $r .= "</ul>\n"; |
|
110 | - return $r; |
|
75 | + $r = ''; |
|
76 | + if (empty($data)) |
|
77 | + return $r; |
|
78 | + $r .= $shadow ? "<ul class=\"shadow\">\n": "<ul>\n"; |
|
79 | + if (is_array($data)) { |
|
80 | + // field name |
|
81 | + foreach ($data as $key => $value) { |
|
82 | + $r .= '<li>'; |
|
83 | + $r .= is_numeric($key) |
|
84 | + ? "<strong>[$key]</strong> " |
|
85 | + : "<strong>$key: </strong>"; |
|
86 | + $r .= '<span>'; |
|
87 | + if (is_array($value)) { |
|
88 | + // recursive |
|
89 | + $r .= render($value,false); |
|
90 | + } else { |
|
91 | + // value, with hyperlinked hyperlinks |
|
92 | + if (is_bool($value)) { |
|
93 | + $value = $value ? 'true' : 'false'; |
|
94 | + } |
|
95 | + $value = htmlentities($value, ENT_COMPAT, 'UTF-8'); |
|
96 | + if (strpos($value, 'http://') === 0) { |
|
97 | + $r .= '<a href="' . $value . '">' . $value . '</a>'; |
|
98 | + } else { |
|
99 | + $r .= $value; |
|
100 | + } |
|
101 | + } |
|
102 | + $r .= "</span></li>\n"; |
|
103 | + } |
|
104 | + } elseif (is_bool($data)) { |
|
105 | + $r .= '<li>' . ($data ? 'true' : 'false') . '</li>'; |
|
106 | + } else { |
|
107 | + $r .= "<li><strong>$data</strong></li>"; |
|
108 | + } |
|
109 | + $r .= "</ul>\n"; |
|
110 | + return $r; |
|
111 | 111 | } |
112 | 112 | $reqHeadersArr = array(); |
113 | 113 | $requestHeaders = $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . ' ' . $_SERVER['SERVER_PROTOCOL'] . PHP_EOL; |
114 | 114 | foreach ($reqHeadersArr as $key => $value) { |
115 | - if ($key == 'Host') |
|
116 | - continue; |
|
117 | - $requestHeaders .= "$key: $value" . PHP_EOL; |
|
115 | + if ($key == 'Host') |
|
116 | + continue; |
|
117 | + $requestHeaders .= "$key: $value" . PHP_EOL; |
|
118 | 118 | } |
119 | 119 | // $requestHeaders = $this->encode(apache_request_headers(), FALSE, |
120 | 120 | // FALSE); |
@@ -134,24 +134,24 @@ discard block |
||
134 | 134 | <body> |
135 | 135 | <div id="breadcrumbs-one"> |
136 | 136 | <?php |
137 | - if(Util::$restler->exception){ |
|
138 | - $stages = Util::$restler->exception->getStages(); |
|
139 | - $curStage = Util::$restler->exception->getStage(); |
|
140 | - foreach($stages['success'] as $stage){ |
|
141 | - echo "<a href=\"#\">$stage</a>"; |
|
142 | - } |
|
143 | - foreach($stages['failure'] as $stage){ |
|
144 | - echo '<a href="#" class="failure">' |
|
145 | - . $stage |
|
146 | - . ($stage==$curStage ? ' <span class="state"/> ' : '') |
|
147 | - . '</a>'; |
|
148 | - } |
|
149 | - } else { |
|
150 | - foreach(Util::$restler->_events as $stage){ |
|
151 | - echo "<a href=\"#\">$stage</a>"; |
|
152 | - } |
|
153 | - } |
|
154 | - ?> |
|
137 | + if(Util::$restler->exception){ |
|
138 | + $stages = Util::$restler->exception->getStages(); |
|
139 | + $curStage = Util::$restler->exception->getStage(); |
|
140 | + foreach($stages['success'] as $stage){ |
|
141 | + echo "<a href=\"#\">$stage</a>"; |
|
142 | + } |
|
143 | + foreach($stages['failure'] as $stage){ |
|
144 | + echo '<a href="#" class="failure">' |
|
145 | + . $stage |
|
146 | + . ($stage==$curStage ? ' <span class="state"/> ' : '') |
|
147 | + . '</a>'; |
|
148 | + } |
|
149 | + } else { |
|
150 | + foreach(Util::$restler->_events as $stage){ |
|
151 | + echo "<a href=\"#\">$stage</a>"; |
|
152 | + } |
|
153 | + } |
|
154 | + ?> |
|
155 | 155 | </div> |
156 | 156 | <header> |
157 | 157 | <h1><?php echo $title ?></h1> |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use Luracast\Restler\Restler; |
3 | 3 | use Luracast\Restler\Util; |
4 | 4 | |
5 | -$template_vars = $data;//get_defined_vars(); |
|
5 | +$template_vars = $data; //get_defined_vars(); |
|
6 | 6 | |
7 | 7 | unset($template_vars['response']); |
8 | 8 | unset($template_vars['api']); |
@@ -43,11 +43,11 @@ discard block |
||
43 | 43 | continue; |
44 | 44 | } |
45 | 45 | //$output .= print_r($entry, true) . "\n"; |
46 | - $output .= "\nFile: " . $entry['file'] . " (Line: " . $entry['line'] . ")\n"; |
|
46 | + $output .= "\nFile: ".$entry['file']." (Line: ".$entry['line'].")\n"; |
|
47 | 47 | if (isset($entry['class'])) |
48 | - $output .= $entry['class'] . "::"; |
|
48 | + $output .= $entry['class']."::"; |
|
49 | 49 | $output .= $entry['function'] |
50 | - . "( " . json_encode($entry['args']) . " )\n"; |
|
50 | + . "( ".json_encode($entry['args'])." )\n"; |
|
51 | 51 | } |
52 | 52 | return $output; |
53 | 53 | } |
@@ -64,18 +64,18 @@ discard block |
||
64 | 64 | } else { |
65 | 65 | if (isset($response['error']['message'])) { |
66 | 66 | $icon = '<icon class="denied"></icon>'; |
67 | - $title = end(explode(':',$response['error']['message'],2)); |
|
67 | + $title = end(explode(':', $response['error']['message'], 2)); |
|
68 | 68 | } else { |
69 | 69 | $icon = '<icon class="warning"></icon>'; |
70 | 70 | $title = 'No Matching Resource'; |
71 | 71 | } |
72 | 72 | } |
73 | -function render($data, $shadow=true) |
|
73 | +function render($data, $shadow = true) |
|
74 | 74 | { |
75 | 75 | $r = ''; |
76 | 76 | if (empty($data)) |
77 | 77 | return $r; |
78 | - $r .= $shadow ? "<ul class=\"shadow\">\n": "<ul>\n"; |
|
78 | + $r .= $shadow ? "<ul class=\"shadow\">\n" : "<ul>\n"; |
|
79 | 79 | if (is_array($data)) { |
80 | 80 | // field name |
81 | 81 | foreach ($data as $key => $value) { |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | $r .= '<span>'; |
87 | 87 | if (is_array($value)) { |
88 | 88 | // recursive |
89 | - $r .= render($value,false); |
|
89 | + $r .= render($value, false); |
|
90 | 90 | } else { |
91 | 91 | // value, with hyperlinked hyperlinks |
92 | 92 | if (is_bool($value)) { |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | } |
95 | 95 | $value = htmlentities($value, ENT_COMPAT, 'UTF-8'); |
96 | 96 | if (strpos($value, 'http://') === 0) { |
97 | - $r .= '<a href="' . $value . '">' . $value . '</a>'; |
|
97 | + $r .= '<a href="'.$value.'">'.$value.'</a>'; |
|
98 | 98 | } else { |
99 | 99 | $r .= $value; |
100 | 100 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | $r .= "</span></li>\n"; |
103 | 103 | } |
104 | 104 | } elseif (is_bool($data)) { |
105 | - $r .= '<li>' . ($data ? 'true' : 'false') . '</li>'; |
|
105 | + $r .= '<li>'.($data ? 'true' : 'false').'</li>'; |
|
106 | 106 | } else { |
107 | 107 | $r .= "<li><strong>$data</strong></li>"; |
108 | 108 | } |
@@ -110,11 +110,11 @@ discard block |
||
110 | 110 | return $r; |
111 | 111 | } |
112 | 112 | $reqHeadersArr = array(); |
113 | -$requestHeaders = $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . ' ' . $_SERVER['SERVER_PROTOCOL'] . PHP_EOL; |
|
113 | +$requestHeaders = $_SERVER['REQUEST_METHOD'].' '.$_SERVER['REQUEST_URI'].' '.$_SERVER['SERVER_PROTOCOL'].PHP_EOL; |
|
114 | 114 | foreach ($reqHeadersArr as $key => $value) { |
115 | 115 | if ($key == 'Host') |
116 | 116 | continue; |
117 | - $requestHeaders .= "$key: $value" . PHP_EOL; |
|
117 | + $requestHeaders .= "$key: $value".PHP_EOL; |
|
118 | 118 | } |
119 | 119 | // $requestHeaders = $this->encode(apache_request_headers(), FALSE, |
120 | 120 | // FALSE); |
@@ -134,20 +134,20 @@ discard block |
||
134 | 134 | <body> |
135 | 135 | <div id="breadcrumbs-one"> |
136 | 136 | <?php |
137 | - if(Util::$restler->exception){ |
|
138 | - $stages = Util::$restler->exception->getStages(); |
|
137 | + if (Util::$restler->exception) { |
|
138 | + $stages = Util::$restler->exception->getStages(); |
|
139 | 139 | $curStage = Util::$restler->exception->getStage(); |
140 | - foreach($stages['success'] as $stage){ |
|
140 | + foreach ($stages['success'] as $stage) { |
|
141 | 141 | echo "<a href=\"#\">$stage</a>"; |
142 | 142 | } |
143 | - foreach($stages['failure'] as $stage){ |
|
143 | + foreach ($stages['failure'] as $stage) { |
|
144 | 144 | echo '<a href="#" class="failure">' |
145 | 145 | . $stage |
146 | - . ($stage==$curStage ? ' <span class="state"/> ' : '') |
|
146 | + . ($stage == $curStage ? ' <span class="state"/> ' : '') |
|
147 | 147 | . '</a>'; |
148 | 148 | } |
149 | 149 | } else { |
150 | - foreach(Util::$restler->_events as $stage){ |
|
150 | + foreach (Util::$restler->_events as $stage) { |
|
151 | 151 | echo "<a href=\"#\">$stage</a>"; |
152 | 152 | } |
153 | 153 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | </header> |
159 | 159 | <article> |
160 | 160 | |
161 | - <h2>Response:<right><?php echo $icon;?></right></h2> |
|
161 | + <h2>Response:<right><?php echo $icon; ?></right></h2> |
|
162 | 162 | <pre class="header"><?php echo $responseHeaders ?></pre> |
163 | 163 | <?php echo render($response); ?> |
164 | 164 | <h2>Additional Template Data:</h2> |
@@ -44,8 +44,9 @@ discard block |
||
44 | 44 | } |
45 | 45 | //$output .= print_r($entry, true) . "\n"; |
46 | 46 | $output .= "\nFile: " . $entry['file'] . " (Line: " . $entry['line'] . ")\n"; |
47 | - if (isset($entry['class'])) |
|
48 | - $output .= $entry['class'] . "::"; |
|
47 | + if (isset($entry['class'])) { |
|
48 | + $output .= $entry['class'] . "::"; |
|
49 | + } |
|
49 | 50 | $output .= $entry['function'] |
50 | 51 | . "( " . json_encode($entry['args']) . " )\n"; |
51 | 52 | } |
@@ -73,8 +74,9 @@ discard block |
||
73 | 74 | function render($data, $shadow=true) |
74 | 75 | { |
75 | 76 | $r = ''; |
76 | - if (empty($data)) |
|
77 | - return $r; |
|
77 | + if (empty($data)) { |
|
78 | + return $r; |
|
79 | + } |
|
78 | 80 | $r .= $shadow ? "<ul class=\"shadow\">\n": "<ul>\n"; |
79 | 81 | if (is_array($data)) { |
80 | 82 | // field name |
@@ -112,8 +114,9 @@ discard block |
||
112 | 114 | $reqHeadersArr = array(); |
113 | 115 | $requestHeaders = $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . ' ' . $_SERVER['SERVER_PROTOCOL'] . PHP_EOL; |
114 | 116 | foreach ($reqHeadersArr as $key => $value) { |
115 | - if ($key == 'Host') |
|
116 | - continue; |
|
117 | + if ($key == 'Host') { |
|
118 | + continue; |
|
119 | + } |
|
117 | 120 | $requestHeaders .= "$key: $value" . PHP_EOL; |
118 | 121 | } |
119 | 122 | // $requestHeaders = $this->encode(apache_request_headers(), FALSE, |
@@ -19,348 +19,348 @@ |
||
19 | 19 | */ |
20 | 20 | class Defaults |
21 | 21 | { |
22 | - // ================================================================== |
|
23 | - // |
|
24 | - // Class Mappings |
|
25 | - // |
|
26 | - // ------------------------------------------------------------------ |
|
27 | - |
|
28 | - /** |
|
29 | - * @var string of name of the class that implements |
|
30 | - * \Luracast\Restler\iCache the cache class to be used |
|
31 | - */ |
|
32 | - public static $cacheClass = 'Luracast\\Restler\\HumanReadableCache'; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string full path of the directory where all the generated files will |
|
36 | - * be kept. When set to null (default) it will use the cache folder that is |
|
37 | - * in the same folder as index.php (gateway) |
|
38 | - */ |
|
39 | - public static $cacheDirectory; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var string of name of the class that implements |
|
43 | - * \Luracast\Restler\Data\iValidate the validator class to be used |
|
44 | - */ |
|
45 | - public static $validatorClass = 'Luracast\\Restler\\Data\\Validator'; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var string name of the class that implements \Luracast\Restler\iCompose |
|
49 | - * the class to be used to compose the response |
|
50 | - */ |
|
51 | - public static $composeClass = 'Luracast\\Restler\\Compose'; |
|
52 | - |
|
53 | - // ================================================================== |
|
54 | - // |
|
55 | - // Routing |
|
56 | - // |
|
57 | - // ------------------------------------------------------------------ |
|
58 | - |
|
59 | - /** |
|
60 | - * @var bool should auto routing for public and protected api methods |
|
61 | - * should be enabled by default or not. Set this to false to get |
|
62 | - * Restler 1.0 style behavior |
|
63 | - */ |
|
64 | - public static $autoRoutingEnabled = true; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var boolean avoids creating multiple routes that can increase the |
|
68 | - * ambiguity when set to true. when a method parameter is optional it is |
|
69 | - * not mapped to the url and should only be used in request body or as |
|
70 | - * query string `/resource?id=value`. When a parameter is required and is |
|
71 | - * scalar, it will be mapped as part of the url `/resource/{id}` |
|
72 | - */ |
|
73 | - public static $smartAutoRouting = true; |
|
74 | - |
|
75 | - /** |
|
76 | - * @var boolean enables more ways of finding the parameter data in the request. |
|
77 | - * If you need backward compatibility with Restler 2 or below turn this off |
|
78 | - */ |
|
79 | - public static $smartParameterParsing = true; |
|
80 | - |
|
81 | - // ================================================================== |
|
82 | - // |
|
83 | - // API Version Management |
|
84 | - // |
|
85 | - // ------------------------------------------------------------------ |
|
86 | - |
|
87 | - /** |
|
88 | - * @var null|string name that is used for vendor specific media type and |
|
89 | - * api version using the Accept Header for example |
|
90 | - * application/vnd.{vendor}-v1+json |
|
91 | - * |
|
92 | - * Keep this null if you do not want to use vendor MIME for specifying api version |
|
93 | - */ |
|
94 | - public static $apiVendor = null; |
|
95 | - |
|
96 | - /** |
|
97 | - * @var bool set it to true to force vendor specific MIME for versioning. |
|
98 | - * It will be automatically set to true when Defaults::$vendor is not |
|
99 | - * null and client is requesting for the custom MIME type |
|
100 | - */ |
|
101 | - public static $useVendorMIMEVersioning = false; |
|
102 | - |
|
103 | - /** |
|
104 | - * @var bool set it to true to use enableUrl based versioning |
|
105 | - */ |
|
106 | - public static $useUrlBasedVersioning = false; |
|
107 | - |
|
108 | - |
|
109 | - // ================================================================== |
|
110 | - // |
|
111 | - // Request |
|
112 | - // |
|
113 | - // ------------------------------------------------------------------ |
|
114 | - |
|
115 | - /** |
|
116 | - * @var string name to be used for the method parameter to capture the |
|
117 | - * entire request data |
|
118 | - */ |
|
119 | - public static $fullRequestDataName = 'request_data'; |
|
120 | - |
|
121 | - /** |
|
122 | - * @var string name of the property that can sent through $_GET or $_POST to |
|
123 | - * override the http method of the request. Set it to null or |
|
124 | - * blank string to disable http method override through request |
|
125 | - * parameters. |
|
126 | - */ |
|
127 | - public static $httpMethodOverrideProperty = 'http_method'; |
|
128 | - |
|
129 | - /** |
|
130 | - * @var bool should auto validating api parameters should be enabled by |
|
131 | - * default or not. Set this to false to avoid validation. |
|
132 | - */ |
|
133 | - public static $autoValidationEnabled = true; |
|
134 | - |
|
135 | - /** |
|
136 | - * @var string name of the class that implements iUser interface to identify |
|
137 | - * the user for caching purposes |
|
138 | - */ |
|
139 | - public static $userIdentifierClass = 'Luracast\\Restler\\User'; |
|
140 | - |
|
141 | - // ================================================================== |
|
142 | - // |
|
143 | - // Response |
|
144 | - // |
|
145 | - // ------------------------------------------------------------------ |
|
146 | - |
|
147 | - /** |
|
148 | - * @var bool HTTP status codes are set on all responses by default. |
|
149 | - * Some clients (like flash, mobile) have trouble dealing with non-200 |
|
150 | - * status codes on error responses. |
|
151 | - * |
|
152 | - * You can set it to true to force a HTTP 200 status code on all responses, |
|
153 | - * even when errors occur. If you suppress status codes, look for an error |
|
154 | - * response to determine if an error occurred. |
|
155 | - */ |
|
156 | - public static $suppressResponseCode = false; |
|
157 | - |
|
158 | - public static $supportedCharsets = array('utf-8', 'iso-8859-1'); |
|
159 | - public static $supportedLanguages = array('en', 'en-US'); |
|
160 | - |
|
161 | - public static $charset = 'utf-8'; |
|
162 | - public static $language = 'en'; |
|
163 | - |
|
164 | - /** |
|
165 | - * @var bool when set to true, it will exclude the response body |
|
166 | - */ |
|
167 | - public static $emptyBodyForNullResponse = true; |
|
168 | - |
|
169 | - /** |
|
170 | - * @var bool when set to true, the response will not be outputted directly into the buffer. |
|
171 | - * If set, Restler::handle() will return the response as a string. |
|
172 | - */ |
|
173 | - public static $returnResponse = false; |
|
174 | - |
|
175 | - /** |
|
176 | - * @var bool enables CORS support |
|
177 | - */ |
|
178 | - public static $crossOriginResourceSharing = false; |
|
179 | - public static $accessControlAllowOrigin = '*'; |
|
180 | - public static $accessControlAllowMethods = |
|
181 | - 'GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD'; |
|
182 | - |
|
183 | - // ================================================================== |
|
184 | - // |
|
185 | - // Header |
|
186 | - // |
|
187 | - // ------------------------------------------------------------------ |
|
188 | - |
|
189 | - /** |
|
190 | - * @var array default Cache-Control template that used to set the |
|
191 | - * Cache-Control header and has two values, first one is used when |
|
192 | - * Defaults::$headerExpires is 0 and second one when it has some time |
|
193 | - * value specified. When only one value is specified it will be used for |
|
194 | - * both cases |
|
195 | - */ |
|
196 | - public static $headerCacheControl = array( |
|
197 | - 'no-cache, must-revalidate', |
|
198 | - |
|
199 | - /* "public, " or "private, " will be prepended based on api method |
|
22 | + // ================================================================== |
|
23 | + // |
|
24 | + // Class Mappings |
|
25 | + // |
|
26 | + // ------------------------------------------------------------------ |
|
27 | + |
|
28 | + /** |
|
29 | + * @var string of name of the class that implements |
|
30 | + * \Luracast\Restler\iCache the cache class to be used |
|
31 | + */ |
|
32 | + public static $cacheClass = 'Luracast\\Restler\\HumanReadableCache'; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string full path of the directory where all the generated files will |
|
36 | + * be kept. When set to null (default) it will use the cache folder that is |
|
37 | + * in the same folder as index.php (gateway) |
|
38 | + */ |
|
39 | + public static $cacheDirectory; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var string of name of the class that implements |
|
43 | + * \Luracast\Restler\Data\iValidate the validator class to be used |
|
44 | + */ |
|
45 | + public static $validatorClass = 'Luracast\\Restler\\Data\\Validator'; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var string name of the class that implements \Luracast\Restler\iCompose |
|
49 | + * the class to be used to compose the response |
|
50 | + */ |
|
51 | + public static $composeClass = 'Luracast\\Restler\\Compose'; |
|
52 | + |
|
53 | + // ================================================================== |
|
54 | + // |
|
55 | + // Routing |
|
56 | + // |
|
57 | + // ------------------------------------------------------------------ |
|
58 | + |
|
59 | + /** |
|
60 | + * @var bool should auto routing for public and protected api methods |
|
61 | + * should be enabled by default or not. Set this to false to get |
|
62 | + * Restler 1.0 style behavior |
|
63 | + */ |
|
64 | + public static $autoRoutingEnabled = true; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var boolean avoids creating multiple routes that can increase the |
|
68 | + * ambiguity when set to true. when a method parameter is optional it is |
|
69 | + * not mapped to the url and should only be used in request body or as |
|
70 | + * query string `/resource?id=value`. When a parameter is required and is |
|
71 | + * scalar, it will be mapped as part of the url `/resource/{id}` |
|
72 | + */ |
|
73 | + public static $smartAutoRouting = true; |
|
74 | + |
|
75 | + /** |
|
76 | + * @var boolean enables more ways of finding the parameter data in the request. |
|
77 | + * If you need backward compatibility with Restler 2 or below turn this off |
|
78 | + */ |
|
79 | + public static $smartParameterParsing = true; |
|
80 | + |
|
81 | + // ================================================================== |
|
82 | + // |
|
83 | + // API Version Management |
|
84 | + // |
|
85 | + // ------------------------------------------------------------------ |
|
86 | + |
|
87 | + /** |
|
88 | + * @var null|string name that is used for vendor specific media type and |
|
89 | + * api version using the Accept Header for example |
|
90 | + * application/vnd.{vendor}-v1+json |
|
91 | + * |
|
92 | + * Keep this null if you do not want to use vendor MIME for specifying api version |
|
93 | + */ |
|
94 | + public static $apiVendor = null; |
|
95 | + |
|
96 | + /** |
|
97 | + * @var bool set it to true to force vendor specific MIME for versioning. |
|
98 | + * It will be automatically set to true when Defaults::$vendor is not |
|
99 | + * null and client is requesting for the custom MIME type |
|
100 | + */ |
|
101 | + public static $useVendorMIMEVersioning = false; |
|
102 | + |
|
103 | + /** |
|
104 | + * @var bool set it to true to use enableUrl based versioning |
|
105 | + */ |
|
106 | + public static $useUrlBasedVersioning = false; |
|
107 | + |
|
108 | + |
|
109 | + // ================================================================== |
|
110 | + // |
|
111 | + // Request |
|
112 | + // |
|
113 | + // ------------------------------------------------------------------ |
|
114 | + |
|
115 | + /** |
|
116 | + * @var string name to be used for the method parameter to capture the |
|
117 | + * entire request data |
|
118 | + */ |
|
119 | + public static $fullRequestDataName = 'request_data'; |
|
120 | + |
|
121 | + /** |
|
122 | + * @var string name of the property that can sent through $_GET or $_POST to |
|
123 | + * override the http method of the request. Set it to null or |
|
124 | + * blank string to disable http method override through request |
|
125 | + * parameters. |
|
126 | + */ |
|
127 | + public static $httpMethodOverrideProperty = 'http_method'; |
|
128 | + |
|
129 | + /** |
|
130 | + * @var bool should auto validating api parameters should be enabled by |
|
131 | + * default or not. Set this to false to avoid validation. |
|
132 | + */ |
|
133 | + public static $autoValidationEnabled = true; |
|
134 | + |
|
135 | + /** |
|
136 | + * @var string name of the class that implements iUser interface to identify |
|
137 | + * the user for caching purposes |
|
138 | + */ |
|
139 | + public static $userIdentifierClass = 'Luracast\\Restler\\User'; |
|
140 | + |
|
141 | + // ================================================================== |
|
142 | + // |
|
143 | + // Response |
|
144 | + // |
|
145 | + // ------------------------------------------------------------------ |
|
146 | + |
|
147 | + /** |
|
148 | + * @var bool HTTP status codes are set on all responses by default. |
|
149 | + * Some clients (like flash, mobile) have trouble dealing with non-200 |
|
150 | + * status codes on error responses. |
|
151 | + * |
|
152 | + * You can set it to true to force a HTTP 200 status code on all responses, |
|
153 | + * even when errors occur. If you suppress status codes, look for an error |
|
154 | + * response to determine if an error occurred. |
|
155 | + */ |
|
156 | + public static $suppressResponseCode = false; |
|
157 | + |
|
158 | + public static $supportedCharsets = array('utf-8', 'iso-8859-1'); |
|
159 | + public static $supportedLanguages = array('en', 'en-US'); |
|
160 | + |
|
161 | + public static $charset = 'utf-8'; |
|
162 | + public static $language = 'en'; |
|
163 | + |
|
164 | + /** |
|
165 | + * @var bool when set to true, it will exclude the response body |
|
166 | + */ |
|
167 | + public static $emptyBodyForNullResponse = true; |
|
168 | + |
|
169 | + /** |
|
170 | + * @var bool when set to true, the response will not be outputted directly into the buffer. |
|
171 | + * If set, Restler::handle() will return the response as a string. |
|
172 | + */ |
|
173 | + public static $returnResponse = false; |
|
174 | + |
|
175 | + /** |
|
176 | + * @var bool enables CORS support |
|
177 | + */ |
|
178 | + public static $crossOriginResourceSharing = false; |
|
179 | + public static $accessControlAllowOrigin = '*'; |
|
180 | + public static $accessControlAllowMethods = |
|
181 | + 'GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD'; |
|
182 | + |
|
183 | + // ================================================================== |
|
184 | + // |
|
185 | + // Header |
|
186 | + // |
|
187 | + // ------------------------------------------------------------------ |
|
188 | + |
|
189 | + /** |
|
190 | + * @var array default Cache-Control template that used to set the |
|
191 | + * Cache-Control header and has two values, first one is used when |
|
192 | + * Defaults::$headerExpires is 0 and second one when it has some time |
|
193 | + * value specified. When only one value is specified it will be used for |
|
194 | + * both cases |
|
195 | + */ |
|
196 | + public static $headerCacheControl = array( |
|
197 | + 'no-cache, must-revalidate', |
|
198 | + |
|
199 | + /* "public, " or "private, " will be prepended based on api method |
|
200 | 200 | * called (public or protected) |
201 | 201 | */ |
202 | - 'max-age={expires}, must-revalidate', |
|
203 | - |
|
204 | - ); |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * @var int sets the content to expire immediately when set to zero |
|
209 | - * alternatively you can specify the number of seconds the content will |
|
210 | - * expire. This setting can be altered at api level using php doc comment |
|
211 | - * with @expires numOfSeconds |
|
212 | - */ |
|
213 | - public static $headerExpires = 0; |
|
214 | - |
|
215 | - // ================================================================== |
|
216 | - // |
|
217 | - // Access Control |
|
218 | - // |
|
219 | - // ------------------------------------------------------------------ |
|
220 | - |
|
221 | - /** |
|
222 | - * @var null|callable if the api methods are under access control mechanism |
|
223 | - * you can attach a function here that returns true or false to determine |
|
224 | - * visibility of a protected api method. this function will receive method |
|
225 | - * info as the only parameter. |
|
226 | - */ |
|
227 | - public static $accessControlFunction = null; |
|
228 | - |
|
229 | - /** |
|
230 | - * @var int set the default api access mode |
|
231 | - * value of 0 = public api |
|
232 | - * value of 1 = hybrid api using `@access hybrid` comment |
|
233 | - * value of 2 = protected api using `@access protected` comment |
|
234 | - * value of 3 = protected api using `protected function` method |
|
235 | - */ |
|
236 | - public static $apiAccessLevel = 0; |
|
237 | - |
|
238 | - /** |
|
239 | - * @var string authentication method to be called in iAuthenticate |
|
240 | - * Interface |
|
241 | - */ |
|
242 | - public static $authenticationMethod = '__isAllowed'; |
|
243 | - |
|
244 | - /** |
|
245 | - * @var int time in milliseconds for bandwidth throttling, |
|
246 | - * which is the minimum response time for each api request. You can |
|
247 | - * change it per api method by setting `@throttle 3000` in php doc |
|
248 | - * comment either at the method level or class level |
|
249 | - */ |
|
250 | - public static $throttle = 0; |
|
251 | - |
|
252 | - // ================================================================== |
|
253 | - // |
|
254 | - // Overrides for API User |
|
255 | - // |
|
256 | - // ------------------------------------------------------------------ |
|
257 | - |
|
258 | - /** |
|
259 | - * @var array use 'alternativeName'=> 'actualName' to set alternative |
|
260 | - * names that can be used to represent the api method parameters and/or |
|
261 | - * static properties of Defaults |
|
262 | - */ |
|
263 | - public static $aliases = array( |
|
264 | - /** |
|
265 | - * suppress_response_codes=true as an URL parameter to force |
|
266 | - * a HTTP 200 status code on all responses |
|
267 | - */ |
|
268 | - 'suppress_response_codes' => 'suppressResponseCode', |
|
269 | - ); |
|
270 | - |
|
271 | - /** |
|
272 | - * @var array determines the defaults that can be overridden by the api |
|
273 | - * user by passing them as URL parameters |
|
274 | - */ |
|
275 | - public static $overridables = array( |
|
276 | - 'suppressResponseCode', |
|
277 | - ); |
|
278 | - |
|
279 | - /** |
|
280 | - * @var array contains validation details for defaults to be used when |
|
281 | - * set through URL parameters |
|
282 | - */ |
|
283 | - public static $validation = array( |
|
284 | - 'suppressResponseCode' => array('type' => 'bool'), |
|
285 | - 'headerExpires' => array('type' => 'int', 'min' => 0), |
|
286 | - ); |
|
287 | - |
|
288 | - // ================================================================== |
|
289 | - // |
|
290 | - // Overrides API Developer |
|
291 | - // |
|
292 | - // ------------------------------------------------------------------ |
|
293 | - |
|
294 | - /** |
|
295 | - * @var array determines what are the phpdoc comment tags that will |
|
296 | - * override the Defaults here with their values |
|
297 | - */ |
|
298 | - public static $fromComments = array( |
|
299 | - |
|
300 | - /** |
|
301 | - * use PHPDoc comments such as the following |
|
302 | - * ` |
|
303 | - * |
|
304 | - * @cache no-cache, must-revalidate` to set the Cache-Control header |
|
305 | - * for a specific api method |
|
306 | - */ |
|
307 | - 'cache' => 'headerCacheControl', |
|
308 | - |
|
309 | - /** |
|
310 | - * use PHPDoc comments such as the following |
|
311 | - * ` |
|
312 | - * |
|
313 | - * @expires 50` to set the Expires header |
|
314 | - * for a specific api method |
|
315 | - */ |
|
316 | - 'expires' => 'headerExpires', |
|
317 | - |
|
318 | - /** |
|
319 | - * use PHPDoc comments such as the following |
|
320 | - * ` |
|
321 | - * |
|
322 | - * @throttle 300` |
|
323 | - * to set the bandwidth throttling for 300 milliseconds |
|
324 | - * for a specific api method |
|
325 | - */ |
|
326 | - 'throttle' => 'throttle', |
|
327 | - |
|
328 | - /** |
|
329 | - * enable or disable smart auto routing from method comments |
|
330 | - * this one is hardwired so cant be turned off |
|
331 | - * it is placed here just for documentation purpose |
|
332 | - */ |
|
333 | - 'smart-auto-routing' => 'smartAutoRouting', |
|
334 | - ); |
|
335 | - |
|
336 | - // ================================================================== |
|
337 | - // |
|
338 | - // Util |
|
339 | - // |
|
340 | - // ------------------------------------------------------------------ |
|
341 | - |
|
342 | - /** |
|
343 | - * Use this method to set value to a static properly of Defaults when |
|
344 | - * you want to make sure only proper values are taken in with the help of |
|
345 | - * validation |
|
346 | - * |
|
347 | - * @static |
|
348 | - * |
|
349 | - * @param string $name name of the static property |
|
350 | - * @param mixed $value value to set the property to |
|
351 | - * |
|
352 | - * @return bool |
|
353 | - */ |
|
354 | - public static function setProperty($name, $value) |
|
355 | - { |
|
356 | - if (!property_exists(__CLASS__, $name)) return false; |
|
357 | - if (@is_array(Defaults::$validation[$name])) { |
|
358 | - $info = new ValidationInfo(Defaults::$validation[$name]); |
|
359 | - $value = Validator::validate($value, $info); |
|
360 | - } |
|
361 | - Defaults::$$name = $value; |
|
362 | - return true; |
|
363 | - } |
|
202 | + 'max-age={expires}, must-revalidate', |
|
203 | + |
|
204 | + ); |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * @var int sets the content to expire immediately when set to zero |
|
209 | + * alternatively you can specify the number of seconds the content will |
|
210 | + * expire. This setting can be altered at api level using php doc comment |
|
211 | + * with @expires numOfSeconds |
|
212 | + */ |
|
213 | + public static $headerExpires = 0; |
|
214 | + |
|
215 | + // ================================================================== |
|
216 | + // |
|
217 | + // Access Control |
|
218 | + // |
|
219 | + // ------------------------------------------------------------------ |
|
220 | + |
|
221 | + /** |
|
222 | + * @var null|callable if the api methods are under access control mechanism |
|
223 | + * you can attach a function here that returns true or false to determine |
|
224 | + * visibility of a protected api method. this function will receive method |
|
225 | + * info as the only parameter. |
|
226 | + */ |
|
227 | + public static $accessControlFunction = null; |
|
228 | + |
|
229 | + /** |
|
230 | + * @var int set the default api access mode |
|
231 | + * value of 0 = public api |
|
232 | + * value of 1 = hybrid api using `@access hybrid` comment |
|
233 | + * value of 2 = protected api using `@access protected` comment |
|
234 | + * value of 3 = protected api using `protected function` method |
|
235 | + */ |
|
236 | + public static $apiAccessLevel = 0; |
|
237 | + |
|
238 | + /** |
|
239 | + * @var string authentication method to be called in iAuthenticate |
|
240 | + * Interface |
|
241 | + */ |
|
242 | + public static $authenticationMethod = '__isAllowed'; |
|
243 | + |
|
244 | + /** |
|
245 | + * @var int time in milliseconds for bandwidth throttling, |
|
246 | + * which is the minimum response time for each api request. You can |
|
247 | + * change it per api method by setting `@throttle 3000` in php doc |
|
248 | + * comment either at the method level or class level |
|
249 | + */ |
|
250 | + public static $throttle = 0; |
|
251 | + |
|
252 | + // ================================================================== |
|
253 | + // |
|
254 | + // Overrides for API User |
|
255 | + // |
|
256 | + // ------------------------------------------------------------------ |
|
257 | + |
|
258 | + /** |
|
259 | + * @var array use 'alternativeName'=> 'actualName' to set alternative |
|
260 | + * names that can be used to represent the api method parameters and/or |
|
261 | + * static properties of Defaults |
|
262 | + */ |
|
263 | + public static $aliases = array( |
|
264 | + /** |
|
265 | + * suppress_response_codes=true as an URL parameter to force |
|
266 | + * a HTTP 200 status code on all responses |
|
267 | + */ |
|
268 | + 'suppress_response_codes' => 'suppressResponseCode', |
|
269 | + ); |
|
270 | + |
|
271 | + /** |
|
272 | + * @var array determines the defaults that can be overridden by the api |
|
273 | + * user by passing them as URL parameters |
|
274 | + */ |
|
275 | + public static $overridables = array( |
|
276 | + 'suppressResponseCode', |
|
277 | + ); |
|
278 | + |
|
279 | + /** |
|
280 | + * @var array contains validation details for defaults to be used when |
|
281 | + * set through URL parameters |
|
282 | + */ |
|
283 | + public static $validation = array( |
|
284 | + 'suppressResponseCode' => array('type' => 'bool'), |
|
285 | + 'headerExpires' => array('type' => 'int', 'min' => 0), |
|
286 | + ); |
|
287 | + |
|
288 | + // ================================================================== |
|
289 | + // |
|
290 | + // Overrides API Developer |
|
291 | + // |
|
292 | + // ------------------------------------------------------------------ |
|
293 | + |
|
294 | + /** |
|
295 | + * @var array determines what are the phpdoc comment tags that will |
|
296 | + * override the Defaults here with their values |
|
297 | + */ |
|
298 | + public static $fromComments = array( |
|
299 | + |
|
300 | + /** |
|
301 | + * use PHPDoc comments such as the following |
|
302 | + * ` |
|
303 | + * |
|
304 | + * @cache no-cache, must-revalidate` to set the Cache-Control header |
|
305 | + * for a specific api method |
|
306 | + */ |
|
307 | + 'cache' => 'headerCacheControl', |
|
308 | + |
|
309 | + /** |
|
310 | + * use PHPDoc comments such as the following |
|
311 | + * ` |
|
312 | + * |
|
313 | + * @expires 50` to set the Expires header |
|
314 | + * for a specific api method |
|
315 | + */ |
|
316 | + 'expires' => 'headerExpires', |
|
317 | + |
|
318 | + /** |
|
319 | + * use PHPDoc comments such as the following |
|
320 | + * ` |
|
321 | + * |
|
322 | + * @throttle 300` |
|
323 | + * to set the bandwidth throttling for 300 milliseconds |
|
324 | + * for a specific api method |
|
325 | + */ |
|
326 | + 'throttle' => 'throttle', |
|
327 | + |
|
328 | + /** |
|
329 | + * enable or disable smart auto routing from method comments |
|
330 | + * this one is hardwired so cant be turned off |
|
331 | + * it is placed here just for documentation purpose |
|
332 | + */ |
|
333 | + 'smart-auto-routing' => 'smartAutoRouting', |
|
334 | + ); |
|
335 | + |
|
336 | + // ================================================================== |
|
337 | + // |
|
338 | + // Util |
|
339 | + // |
|
340 | + // ------------------------------------------------------------------ |
|
341 | + |
|
342 | + /** |
|
343 | + * Use this method to set value to a static properly of Defaults when |
|
344 | + * you want to make sure only proper values are taken in with the help of |
|
345 | + * validation |
|
346 | + * |
|
347 | + * @static |
|
348 | + * |
|
349 | + * @param string $name name of the static property |
|
350 | + * @param mixed $value value to set the property to |
|
351 | + * |
|
352 | + * @return bool |
|
353 | + */ |
|
354 | + public static function setProperty($name, $value) |
|
355 | + { |
|
356 | + if (!property_exists(__CLASS__, $name)) return false; |
|
357 | + if (@is_array(Defaults::$validation[$name])) { |
|
358 | + $info = new ValidationInfo(Defaults::$validation[$name]); |
|
359 | + $value = Validator::validate($value, $info); |
|
360 | + } |
|
361 | + Defaults::$$name = $value; |
|
362 | + return true; |
|
363 | + } |
|
364 | 364 | |
365 | 365 | } |
366 | 366 |
@@ -353,7 +353,9 @@ |
||
353 | 353 | */ |
354 | 354 | public static function setProperty($name, $value) |
355 | 355 | { |
356 | - if (!property_exists(__CLASS__, $name)) return false; |
|
356 | + if (!property_exists(__CLASS__, $name)) { |
|
357 | + return false; |
|
358 | + } |
|
357 | 359 | if (@is_array(Defaults::$validation[$name])) { |
358 | 360 | $info = new ValidationInfo(Defaults::$validation[$name]); |
359 | 361 | $value = Validator::validate($value, $info); |
@@ -152,8 +152,8 @@ discard block |
||
152 | 152 | $filename == 'index.html' |
153 | 153 | ) { |
154 | 154 | $status = 302; |
155 | - $url = $this->restler->getBaseUrl() . '/' . $this->base() . '/'; |
|
156 | - header("{$_SERVER['SERVER_PROTOCOL']} $status " . RestException::$codes[$status]); |
|
155 | + $url = $this->restler->getBaseUrl().'/'.$this->base().'/'; |
|
156 | + header("{$_SERVER['SERVER_PROTOCOL']} $status ".RestException::$codes[$status]); |
|
157 | 157 | header("Location: $url"); |
158 | 158 | exit; |
159 | 159 | } |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | ) { |
164 | 164 | $filename .= '.js'; |
165 | 165 | } |
166 | - PassThrough::file(__DIR__ . '/explorer/' . (empty($filename) ? 'index.html' : $filename), false, |
|
166 | + PassThrough::file(__DIR__.'/explorer/'.(empty($filename) ? 'index.html' : $filename), false, |
|
167 | 167 | 0); //60 * 60 * 24); |
168 | 168 | } |
169 | 169 | |
@@ -173,15 +173,15 @@ discard block |
||
173 | 173 | public function swagger() |
174 | 174 | { |
175 | 175 | $r = new stdClass(); |
176 | - $version = (string)$this->restler->getRequestedApiVersion(); |
|
176 | + $version = (string) $this->restler->getRequestedApiVersion(); |
|
177 | 177 | $r->swagger = static::SWAGGER; |
178 | 178 | |
179 | 179 | $info = parse_url($this->restler->getBaseUrl()); |
180 | 180 | $r->host = $info['host']; |
181 | 181 | if (isset($info['port'])) { |
182 | - $r->host .= ':' . $info['port']; |
|
182 | + $r->host .= ':'.$info['port']; |
|
183 | 183 | } |
184 | - $r->basePath = isset($info['path']) ? $info['path'] : ''; |
|
184 | + $r->basePath = isset($info['path']) ? $info['path'] : ''; |
|
185 | 185 | if (!empty(static::$schemes)) { |
186 | 186 | $r->schemes = static::$schemes; |
187 | 187 | } |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | $r->consumes = $this->restler->getReadableMimeTypes(); |
191 | 191 | |
192 | 192 | $r->paths = $this->paths($version); |
193 | - $r->definitions = (object)$this->models; |
|
193 | + $r->definitions = (object) $this->models; |
|
194 | 194 | $r->securityDefinitions = $this->securityDefinitions(); |
195 | 195 | $r->info = compact('version') + array_filter(get_class_vars(static::$infoClass)); |
196 | 196 | |
@@ -302,8 +302,8 @@ discard block |
||
302 | 302 | $description = ''; //'<section class="body-param">'; |
303 | 303 | foreach ($firstChild['children'] as $child) { |
304 | 304 | $description .= isset($child['required']) && $child['required'] |
305 | - ? '**' . $child['name'] . '** (required) '.PHP_EOL |
|
306 | - : $child['name'] . ' '.PHP_EOL; |
|
305 | + ? '**'.$child['name'].'** (required) '.PHP_EOL |
|
306 | + : $child['name'].' '.PHP_EOL; |
|
307 | 307 | } |
308 | 308 | //$description .= '</section>'; |
309 | 309 | } |
@@ -312,8 +312,8 @@ discard block |
||
312 | 312 | $description = ''; //'<section class="body-param">'; |
313 | 313 | foreach ($children as $child) { |
314 | 314 | $description .= isset($child['required']) && $child['required'] |
315 | - ? '**' . $child['name'] . '** (required) '.PHP_EOL |
|
316 | - : $child['name'] . ' '.PHP_EOL; |
|
315 | + ? '**'.$child['name'].'** (required) '.PHP_EOL |
|
316 | + : $child['name'].' '.PHP_EOL; |
|
317 | 317 | } |
318 | 318 | //$description .= '</section>'; |
319 | 319 | |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | //$p->allowMultiple = false; |
367 | 367 | |
368 | 368 | if (isset($p->{'$ref'})) { |
369 | - $p->schema = (object)array('$ref' => ($p->{'$ref'})); |
|
369 | + $p->schema = (object) array('$ref' => ($p->{'$ref'})); |
|
370 | 370 | unset($p->{'$ref'}); |
371 | 371 | } |
372 | 372 | |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | { |
378 | 378 | $code = '200'; |
379 | 379 | $r = array( |
380 | - $code => (object)array( |
|
380 | + $code => (object) array( |
|
381 | 381 | 'description' => 'Success', |
382 | 382 | 'schema' => new stdClass() |
383 | 383 | ) |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | if ($info->children) { |
446 | 446 | $contentType = Util::getShortName($info->contentType); |
447 | 447 | $model = $this->model($contentType, $info->children); |
448 | - $object->items = (object)array( |
|
448 | + $object->items = (object) array( |
|
449 | 449 | '$ref' => "#/definitions/$contentType" |
450 | 450 | ); |
451 | 451 | } elseif ($info->contentType && $info->contentType == 'associative') { |
@@ -463,23 +463,23 @@ discard block |
||
463 | 463 | if (is_string($info->contentType) && $t = Util::nestedValue(static::$dataTypeAlias, |
464 | 464 | strtolower($info->contentType))) { |
465 | 465 | if (is_array($t)) { |
466 | - $object->items = (object)array( |
|
466 | + $object->items = (object) array( |
|
467 | 467 | 'type' => $t[0], |
468 | 468 | 'format' => $t[1], |
469 | 469 | ); |
470 | 470 | } else { |
471 | - $object->items = (object)array( |
|
471 | + $object->items = (object) array( |
|
472 | 472 | 'type' => $t, |
473 | 473 | ); |
474 | 474 | } |
475 | 475 | } else { |
476 | 476 | $contentType = Util::getShortName($info->contentType); |
477 | - $object->items = (object)array( |
|
477 | + $object->items = (object) array( |
|
478 | 478 | '$ref' => "#/definitions/$contentType" |
479 | 479 | ); |
480 | 480 | } |
481 | 481 | } else { |
482 | - $object->items = (object)array( |
|
482 | + $object->items = (object) array( |
|
483 | 483 | 'type' => 'string' |
484 | 484 | ); |
485 | 485 | } |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | private function operationId(array $route) |
514 | 514 | { |
515 | 515 | static $hash = array(); |
516 | - $id = $route['httpMethod'] . ' ' . $route['url']; |
|
516 | + $id = $route['httpMethod'].' '.$route['url']; |
|
517 | 517 | if (isset($hash[$id])) { |
518 | 518 | return $hash[$id]; |
519 | 519 | } |
@@ -521,14 +521,14 @@ discard block |
||
521 | 521 | $method = $route['methodName']; |
522 | 522 | |
523 | 523 | if (isset(static::$prefixes[$method])) { |
524 | - $method = static::$prefixes[$method] . $class; |
|
524 | + $method = static::$prefixes[$method].$class; |
|
525 | 525 | } else { |
526 | 526 | $method = str_replace( |
527 | 527 | array_keys(static::$prefixes), |
528 | 528 | array_values(static::$prefixes), |
529 | 529 | $method |
530 | 530 | ); |
531 | - $method = lcfirst($class) . ucfirst($method); |
|
531 | + $method = lcfirst($class).ucfirst($method); |
|
532 | 532 | } |
533 | 533 | $hash[$id] = $method; |
534 | 534 | |
@@ -537,13 +537,13 @@ discard block |
||
537 | 537 | |
538 | 538 | private function modelName(array $route) |
539 | 539 | { |
540 | - return $this->operationId($route) . 'Model'; |
|
540 | + return $this->operationId($route).'Model'; |
|
541 | 541 | } |
542 | 542 | |
543 | 543 | private function securityDefinitions() |
544 | 544 | { |
545 | 545 | $r = new stdClass(); |
546 | - $r->api_key = (object)array( |
|
546 | + $r->api_key = (object) array( |
|
547 | 547 | 'type' => 'apiKey', |
548 | 548 | 'name' => 'api_key', |
549 | 549 | 'in' => 'query', |
@@ -16,238 +16,238 @@ |
||
16 | 16 | */ |
17 | 17 | class Explorer implements iProvideMultiVersionApi |
18 | 18 | { |
19 | - const SWAGGER = '2.0'; |
|
20 | - |
|
21 | - /** |
|
22 | - * @var array http schemes supported. http or https or both http and https |
|
23 | - */ |
|
24 | - public static $schemes = array(); |
|
25 | - /** |
|
26 | - * @var bool should protected resources be shown to unauthenticated users? |
|
27 | - */ |
|
28 | - public static $hideProtected = true; |
|
29 | - /** |
|
30 | - * @var bool should we use format as extension? |
|
31 | - */ |
|
32 | - public static $useFormatAsExtension = true; |
|
33 | - /* |
|
19 | + const SWAGGER = '2.0'; |
|
20 | + |
|
21 | + /** |
|
22 | + * @var array http schemes supported. http or https or both http and https |
|
23 | + */ |
|
24 | + public static $schemes = array(); |
|
25 | + /** |
|
26 | + * @var bool should protected resources be shown to unauthenticated users? |
|
27 | + */ |
|
28 | + public static $hideProtected = true; |
|
29 | + /** |
|
30 | + * @var bool should we use format as extension? |
|
31 | + */ |
|
32 | + public static $useFormatAsExtension = true; |
|
33 | + /* |
|
34 | 34 | * @var bool can we accept scalar values (string, int, float etc) as the request body? |
35 | 35 | */ |
36 | - public static $allowScalarValueOnRequestBody = false; |
|
37 | - /** |
|
38 | - * @var array all http methods specified here will be excluded from |
|
39 | - * documentation |
|
40 | - */ |
|
41 | - public static $excludedHttpMethods = array('OPTIONS'); |
|
42 | - /** |
|
43 | - * @var array all paths beginning with any of the following will be excluded |
|
44 | - * from documentation |
|
45 | - */ |
|
46 | - public static $excludedPaths = array(); |
|
47 | - /** |
|
48 | - * @var bool |
|
49 | - */ |
|
50 | - public static $placeFormatExtensionBeforeDynamicParts = true; |
|
51 | - /** |
|
52 | - * @var bool should we group all the operations with the same url or not |
|
53 | - */ |
|
54 | - public static $groupOperations = false; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var string class that holds metadata as static properties |
|
58 | - */ |
|
59 | - public static $infoClass = 'Luracast\Restler\ExplorerInfo'; |
|
60 | - /** |
|
61 | - * Injected at runtime |
|
62 | - * |
|
63 | - * @var Restler instance of restler |
|
64 | - */ |
|
65 | - public $restler; |
|
66 | - /** |
|
67 | - * @var string when format is not used as the extension this property is |
|
68 | - * used to set the extension manually |
|
69 | - */ |
|
70 | - public $formatString = ''; |
|
71 | - |
|
72 | - /** |
|
73 | - * @var array type mapping for converting data types to JSON-Schema Draft 4 |
|
74 | - * Which is followed by swagger 1.2 spec |
|
75 | - */ |
|
76 | - public static $dataTypeAlias = array( |
|
77 | - //'string' => 'string', |
|
78 | - 'int' => 'integer', |
|
79 | - 'number' => 'number', |
|
80 | - 'float' => array('number', 'float'), |
|
81 | - 'bool' => 'boolean', |
|
82 | - //'boolean' => 'boolean', |
|
83 | - //'NULL' => 'null', |
|
84 | - 'array' => 'array', |
|
85 | - //'object' => 'object', |
|
86 | - 'stdClass' => 'object', |
|
87 | - 'mixed' => 'string', |
|
88 | - 'date' => array('string', 'date'), |
|
89 | - 'datetime' => array('string', 'date-time'), |
|
90 | - ); |
|
91 | - |
|
92 | - /** |
|
93 | - * @var array configurable symbols to differentiate public, hybrid and |
|
94 | - * protected api |
|
95 | - */ |
|
96 | - public static $apiDescriptionSuffixSymbols = array( |
|
97 | - 0 => ' |
@@ -17,98 +17,98 @@ |
||
17 | 17 | */ |
18 | 18 | class ApcCache implements iCache |
19 | 19 | { |
20 | - /** |
|
21 | - * The namespace that all of the cached entries will be stored under. This allows multiple APIs to run concurrently. |
|
22 | - * |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - static public $namespace = 'restler'; |
|
20 | + /** |
|
21 | + * The namespace that all of the cached entries will be stored under. This allows multiple APIs to run concurrently. |
|
22 | + * |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + static public $namespace = 'restler'; |
|
26 | 26 | |
27 | - /** |
|
28 | - * store data in the cache |
|
29 | - * |
|
30 | - * |
|
31 | - * @param string $name |
|
32 | - * @param mixed $data |
|
33 | - * |
|
34 | - * @return boolean true if successful |
|
35 | - */ |
|
36 | - public function set($name, $data) |
|
37 | - { |
|
38 | - function_exists('apc_store') || $this->apcNotAvailable(); |
|
27 | + /** |
|
28 | + * store data in the cache |
|
29 | + * |
|
30 | + * |
|
31 | + * @param string $name |
|
32 | + * @param mixed $data |
|
33 | + * |
|
34 | + * @return boolean true if successful |
|
35 | + */ |
|
36 | + public function set($name, $data) |
|
37 | + { |
|
38 | + function_exists('apc_store') || $this->apcNotAvailable(); |
|
39 | 39 | |
40 | - try { |
|
41 | - return apc_store(self::$namespace . "-" . $name, $data); |
|
42 | - } catch |
|
43 | - (\Exception $exception) { |
|
44 | - return false; |
|
45 | - } |
|
46 | - } |
|
40 | + try { |
|
41 | + return apc_store(self::$namespace . "-" . $name, $data); |
|
42 | + } catch |
|
43 | + (\Exception $exception) { |
|
44 | + return false; |
|
45 | + } |
|
46 | + } |
|
47 | 47 | |
48 | - private function apcNotAvailable() |
|
49 | - { |
|
50 | - throw new \Exception('APC is not available for use as Restler Cache. Please make sure the module is installed. http://php.net/manual/en/apc.installation.php'); |
|
51 | - } |
|
48 | + private function apcNotAvailable() |
|
49 | + { |
|
50 | + throw new \Exception('APC is not available for use as Restler Cache. Please make sure the module is installed. http://php.net/manual/en/apc.installation.php'); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * retrieve data from the cache |
|
55 | - * |
|
56 | - * |
|
57 | - * @param string $name |
|
58 | - * @param bool $ignoreErrors |
|
59 | - * |
|
60 | - * @throws \Exception |
|
61 | - * @return mixed |
|
62 | - */ |
|
63 | - public function get($name, $ignoreErrors = false) |
|
64 | - { |
|
65 | - function_exists('apc_fetch') || $this->apcNotAvailable(); |
|
53 | + /** |
|
54 | + * retrieve data from the cache |
|
55 | + * |
|
56 | + * |
|
57 | + * @param string $name |
|
58 | + * @param bool $ignoreErrors |
|
59 | + * |
|
60 | + * @throws \Exception |
|
61 | + * @return mixed |
|
62 | + */ |
|
63 | + public function get($name, $ignoreErrors = false) |
|
64 | + { |
|
65 | + function_exists('apc_fetch') || $this->apcNotAvailable(); |
|
66 | 66 | |
67 | - try { |
|
68 | - return apc_fetch(self::$namespace . "-" . $name); |
|
69 | - } catch (\Exception $exception) { |
|
70 | - if (!$ignoreErrors) { |
|
71 | - throw $exception; |
|
72 | - } |
|
73 | - return null; |
|
74 | - } |
|
75 | - } |
|
67 | + try { |
|
68 | + return apc_fetch(self::$namespace . "-" . $name); |
|
69 | + } catch (\Exception $exception) { |
|
70 | + if (!$ignoreErrors) { |
|
71 | + throw $exception; |
|
72 | + } |
|
73 | + return null; |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * delete data from the cache |
|
79 | - * |
|
80 | - * |
|
81 | - * @param string $name |
|
82 | - * @param bool $ignoreErrors |
|
83 | - * |
|
84 | - * @throws \Exception |
|
85 | - * @return boolean true if successful |
|
86 | - */ |
|
87 | - public function clear($name, $ignoreErrors = false) |
|
88 | - { |
|
89 | - function_exists('apc_delete') || $this->apcNotAvailable(); |
|
77 | + /** |
|
78 | + * delete data from the cache |
|
79 | + * |
|
80 | + * |
|
81 | + * @param string $name |
|
82 | + * @param bool $ignoreErrors |
|
83 | + * |
|
84 | + * @throws \Exception |
|
85 | + * @return boolean true if successful |
|
86 | + */ |
|
87 | + public function clear($name, $ignoreErrors = false) |
|
88 | + { |
|
89 | + function_exists('apc_delete') || $this->apcNotAvailable(); |
|
90 | 90 | |
91 | - try { |
|
92 | - apc_delete(self::$namespace . "-" . $name); |
|
93 | - } catch (\Exception $exception) { |
|
94 | - if (!$ignoreErrors) { |
|
95 | - throw $exception; |
|
96 | - } |
|
97 | - } |
|
98 | - } |
|
91 | + try { |
|
92 | + apc_delete(self::$namespace . "-" . $name); |
|
93 | + } catch (\Exception $exception) { |
|
94 | + if (!$ignoreErrors) { |
|
95 | + throw $exception; |
|
96 | + } |
|
97 | + } |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * check if the given name is cached |
|
102 | - * |
|
103 | - * |
|
104 | - * @param string $name |
|
105 | - * |
|
106 | - * @return boolean true if cached |
|
107 | - */ |
|
108 | - public function isCached($name) |
|
109 | - { |
|
110 | - function_exists('apc_exists') || $this->apcNotAvailable(); |
|
111 | - return apc_exists(self::$namespace . "-" . $name); |
|
112 | - } |
|
100 | + /** |
|
101 | + * check if the given name is cached |
|
102 | + * |
|
103 | + * |
|
104 | + * @param string $name |
|
105 | + * |
|
106 | + * @return boolean true if cached |
|
107 | + */ |
|
108 | + public function isCached($name) |
|
109 | + { |
|
110 | + function_exists('apc_exists') || $this->apcNotAvailable(); |
|
111 | + return apc_exists(self::$namespace . "-" . $name); |
|
112 | + } |
|
113 | 113 | |
114 | 114 | } |
115 | 115 | \ No newline at end of file |
@@ -38,9 +38,8 @@ discard block |
||
38 | 38 | function_exists('apc_store') || $this->apcNotAvailable(); |
39 | 39 | |
40 | 40 | try { |
41 | - return apc_store(self::$namespace . "-" . $name, $data); |
|
42 | - } catch |
|
43 | - (\Exception $exception) { |
|
41 | + return apc_store(self::$namespace."-".$name, $data); |
|
42 | + } catch (\Exception $exception) { |
|
44 | 43 | return false; |
45 | 44 | } |
46 | 45 | } |
@@ -65,7 +64,7 @@ discard block |
||
65 | 64 | function_exists('apc_fetch') || $this->apcNotAvailable(); |
66 | 65 | |
67 | 66 | try { |
68 | - return apc_fetch(self::$namespace . "-" . $name); |
|
67 | + return apc_fetch(self::$namespace."-".$name); |
|
69 | 68 | } catch (\Exception $exception) { |
70 | 69 | if (!$ignoreErrors) { |
71 | 70 | throw $exception; |
@@ -89,7 +88,7 @@ discard block |
||
89 | 88 | function_exists('apc_delete') || $this->apcNotAvailable(); |
90 | 89 | |
91 | 90 | try { |
92 | - apc_delete(self::$namespace . "-" . $name); |
|
91 | + apc_delete(self::$namespace."-".$name); |
|
93 | 92 | } catch (\Exception $exception) { |
94 | 93 | if (!$ignoreErrors) { |
95 | 94 | throw $exception; |
@@ -108,7 +107,7 @@ discard block |
||
108 | 107 | public function isCached($name) |
109 | 108 | { |
110 | 109 | function_exists('apc_exists') || $this->apcNotAvailable(); |
111 | - return apc_exists(self::$namespace . "-" . $name); |
|
110 | + return apc_exists(self::$namespace."-".$name); |
|
112 | 111 | } |
113 | 112 | |
114 | 113 | } |
115 | 114 | \ No newline at end of file |
@@ -15,238 +15,238 @@ |
||
15 | 15 | */ |
16 | 16 | class Util |
17 | 17 | { |
18 | - /** |
|
19 | - * @var Restler instance injected at runtime |
|
20 | - */ |
|
21 | - public static $restler; |
|
18 | + /** |
|
19 | + * @var Restler instance injected at runtime |
|
20 | + */ |
|
21 | + public static $restler; |
|
22 | 22 | |
23 | - /** |
|
24 | - * verify if the given data type string is scalar or not |
|
25 | - * |
|
26 | - * @static |
|
27 | - * |
|
28 | - * @param string $type data type as string |
|
29 | - * |
|
30 | - * @return bool true or false |
|
31 | - */ |
|
32 | - public static function isObjectOrArray($type) |
|
33 | - { |
|
34 | - if (is_array($type)) { |
|
35 | - foreach ($type as $t) { |
|
36 | - if (static::isObjectOrArray($t)) { |
|
37 | - return true; |
|
38 | - } |
|
39 | - } |
|
40 | - return false; |
|
41 | - } |
|
42 | - return !(boolean)strpos('|bool|boolean|int|float|string|', $type); |
|
43 | - } |
|
23 | + /** |
|
24 | + * verify if the given data type string is scalar or not |
|
25 | + * |
|
26 | + * @static |
|
27 | + * |
|
28 | + * @param string $type data type as string |
|
29 | + * |
|
30 | + * @return bool true or false |
|
31 | + */ |
|
32 | + public static function isObjectOrArray($type) |
|
33 | + { |
|
34 | + if (is_array($type)) { |
|
35 | + foreach ($type as $t) { |
|
36 | + if (static::isObjectOrArray($t)) { |
|
37 | + return true; |
|
38 | + } |
|
39 | + } |
|
40 | + return false; |
|
41 | + } |
|
42 | + return !(boolean)strpos('|bool|boolean|int|float|string|', $type); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Get the value deeply nested inside an array / object |
|
47 | - * |
|
48 | - * Using isset() to test the presence of nested value can give a false positive |
|
49 | - * |
|
50 | - * This method serves that need |
|
51 | - * |
|
52 | - * When the deeply nested property is found its value is returned, otherwise |
|
53 | - * false is returned. |
|
54 | - * |
|
55 | - * @param array|object $from array to extract the value from |
|
56 | - * @param string|array $key ... pass more to go deeply inside the array |
|
57 | - * alternatively you can pass a single array |
|
58 | - * |
|
59 | - * @return null|mixed null when not found, value otherwise |
|
60 | - */ |
|
61 | - public static function nestedValue($from, $key/**, $key2 ... $key`n` */) |
|
62 | - { |
|
63 | - if (is_array($key)) { |
|
64 | - $keys = $key; |
|
65 | - } else { |
|
66 | - $keys = func_get_args(); |
|
67 | - array_shift($keys); |
|
68 | - } |
|
69 | - foreach ($keys as $key) { |
|
70 | - if (is_array($from) && isset($from[$key])) { |
|
71 | - $from = $from[$key]; |
|
72 | - continue; |
|
73 | - } elseif (is_object($from) && isset($from->{$key})) { |
|
74 | - $from = $from->{$key}; |
|
75 | - continue; |
|
76 | - } |
|
77 | - return null; |
|
78 | - } |
|
79 | - return $from; |
|
80 | - } |
|
45 | + /** |
|
46 | + * Get the value deeply nested inside an array / object |
|
47 | + * |
|
48 | + * Using isset() to test the presence of nested value can give a false positive |
|
49 | + * |
|
50 | + * This method serves that need |
|
51 | + * |
|
52 | + * When the deeply nested property is found its value is returned, otherwise |
|
53 | + * false is returned. |
|
54 | + * |
|
55 | + * @param array|object $from array to extract the value from |
|
56 | + * @param string|array $key ... pass more to go deeply inside the array |
|
57 | + * alternatively you can pass a single array |
|
58 | + * |
|
59 | + * @return null|mixed null when not found, value otherwise |
|
60 | + */ |
|
61 | + public static function nestedValue($from, $key/**, $key2 ... $key`n` */) |
|
62 | + { |
|
63 | + if (is_array($key)) { |
|
64 | + $keys = $key; |
|
65 | + } else { |
|
66 | + $keys = func_get_args(); |
|
67 | + array_shift($keys); |
|
68 | + } |
|
69 | + foreach ($keys as $key) { |
|
70 | + if (is_array($from) && isset($from[$key])) { |
|
71 | + $from = $from[$key]; |
|
72 | + continue; |
|
73 | + } elseif (is_object($from) && isset($from->{$key})) { |
|
74 | + $from = $from->{$key}; |
|
75 | + continue; |
|
76 | + } |
|
77 | + return null; |
|
78 | + } |
|
79 | + return $from; |
|
80 | + } |
|
81 | 81 | |
82 | - public static function getResourcePath( |
|
83 | - $className, |
|
84 | - $resourcePath = null, |
|
85 | - $prefix = '' |
|
86 | - ) { |
|
87 | - if (is_null($resourcePath)) { |
|
88 | - if (Defaults::$autoRoutingEnabled) { |
|
89 | - $resourcePath = strtolower($className); |
|
90 | - if (false !== ($index = strrpos($className, '\\'))) { |
|
91 | - $resourcePath = substr($resourcePath, $index + 1); |
|
92 | - } |
|
93 | - if (false !== ($index = strrpos($resourcePath, '_'))) { |
|
94 | - $resourcePath = substr($resourcePath, $index + 1); |
|
95 | - } |
|
96 | - } else { |
|
97 | - $resourcePath = ''; |
|
98 | - } |
|
99 | - } else { |
|
100 | - $resourcePath = trim($resourcePath, '/'); |
|
101 | - } |
|
102 | - if (strlen($resourcePath) > 0) { |
|
103 | - $resourcePath .= '/'; |
|
104 | - } |
|
105 | - return $prefix . $resourcePath; |
|
106 | - } |
|
82 | + public static function getResourcePath( |
|
83 | + $className, |
|
84 | + $resourcePath = null, |
|
85 | + $prefix = '' |
|
86 | + ) { |
|
87 | + if (is_null($resourcePath)) { |
|
88 | + if (Defaults::$autoRoutingEnabled) { |
|
89 | + $resourcePath = strtolower($className); |
|
90 | + if (false !== ($index = strrpos($className, '\\'))) { |
|
91 | + $resourcePath = substr($resourcePath, $index + 1); |
|
92 | + } |
|
93 | + if (false !== ($index = strrpos($resourcePath, '_'))) { |
|
94 | + $resourcePath = substr($resourcePath, $index + 1); |
|
95 | + } |
|
96 | + } else { |
|
97 | + $resourcePath = ''; |
|
98 | + } |
|
99 | + } else { |
|
100 | + $resourcePath = trim($resourcePath, '/'); |
|
101 | + } |
|
102 | + if (strlen($resourcePath) > 0) { |
|
103 | + $resourcePath .= '/'; |
|
104 | + } |
|
105 | + return $prefix . $resourcePath; |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Compare two strings and remove the common |
|
110 | - * sub string from the first string and return it |
|
111 | - * |
|
112 | - * @static |
|
113 | - * |
|
114 | - * @param string $fromPath |
|
115 | - * @param string $usingPath |
|
116 | - * @param string $char |
|
117 | - * optional, set it as |
|
118 | - * blank string for char by char comparison |
|
119 | - * |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - public static function removeCommonPath($fromPath, $usingPath, $char = '/') |
|
123 | - { |
|
124 | - if (empty($fromPath)) { |
|
125 | - return ''; |
|
126 | - } |
|
127 | - $fromPath = explode($char, $fromPath); |
|
128 | - $usingPath = explode($char, $usingPath); |
|
129 | - while (count($usingPath)) { |
|
130 | - if (count($fromPath) && $fromPath[0] == $usingPath[0]) { |
|
131 | - array_shift($fromPath); |
|
132 | - } else { |
|
133 | - break; |
|
134 | - } |
|
135 | - array_shift($usingPath); |
|
136 | - } |
|
137 | - return implode($char, $fromPath); |
|
138 | - } |
|
108 | + /** |
|
109 | + * Compare two strings and remove the common |
|
110 | + * sub string from the first string and return it |
|
111 | + * |
|
112 | + * @static |
|
113 | + * |
|
114 | + * @param string $fromPath |
|
115 | + * @param string $usingPath |
|
116 | + * @param string $char |
|
117 | + * optional, set it as |
|
118 | + * blank string for char by char comparison |
|
119 | + * |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + public static function removeCommonPath($fromPath, $usingPath, $char = '/') |
|
123 | + { |
|
124 | + if (empty($fromPath)) { |
|
125 | + return ''; |
|
126 | + } |
|
127 | + $fromPath = explode($char, $fromPath); |
|
128 | + $usingPath = explode($char, $usingPath); |
|
129 | + while (count($usingPath)) { |
|
130 | + if (count($fromPath) && $fromPath[0] == $usingPath[0]) { |
|
131 | + array_shift($fromPath); |
|
132 | + } else { |
|
133 | + break; |
|
134 | + } |
|
135 | + array_shift($usingPath); |
|
136 | + } |
|
137 | + return implode($char, $fromPath); |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * Compare two strings and split the common |
|
142 | - * sub string from the first string and return it as array |
|
143 | - * |
|
144 | - * @static |
|
145 | - * |
|
146 | - * @param string $fromPath |
|
147 | - * @param string $usingPath |
|
148 | - * @param string $char |
|
149 | - * optional, set it as |
|
150 | - * blank string for char by char comparison |
|
151 | - * |
|
152 | - * @return array with 2 strings first is the common string and second is the remaining in $fromPath |
|
153 | - */ |
|
154 | - public static function splitCommonPath($fromPath, $usingPath, $char = '/') |
|
155 | - { |
|
156 | - if (empty($fromPath)) { |
|
157 | - return array('', ''); |
|
158 | - } |
|
159 | - $fromPath = explode($char, $fromPath); |
|
160 | - $usingPath = explode($char, $usingPath); |
|
161 | - $commonPath = array(); |
|
162 | - while (count($usingPath)) { |
|
163 | - if (count($fromPath) && $fromPath[0] == $usingPath[0]) { |
|
164 | - $commonPath [] = array_shift($fromPath); |
|
165 | - } else { |
|
166 | - break; |
|
167 | - } |
|
168 | - array_shift($usingPath); |
|
169 | - } |
|
170 | - return array(implode($char, $commonPath), implode($char, $fromPath)); |
|
171 | - } |
|
140 | + /** |
|
141 | + * Compare two strings and split the common |
|
142 | + * sub string from the first string and return it as array |
|
143 | + * |
|
144 | + * @static |
|
145 | + * |
|
146 | + * @param string $fromPath |
|
147 | + * @param string $usingPath |
|
148 | + * @param string $char |
|
149 | + * optional, set it as |
|
150 | + * blank string for char by char comparison |
|
151 | + * |
|
152 | + * @return array with 2 strings first is the common string and second is the remaining in $fromPath |
|
153 | + */ |
|
154 | + public static function splitCommonPath($fromPath, $usingPath, $char = '/') |
|
155 | + { |
|
156 | + if (empty($fromPath)) { |
|
157 | + return array('', ''); |
|
158 | + } |
|
159 | + $fromPath = explode($char, $fromPath); |
|
160 | + $usingPath = explode($char, $usingPath); |
|
161 | + $commonPath = array(); |
|
162 | + while (count($usingPath)) { |
|
163 | + if (count($fromPath) && $fromPath[0] == $usingPath[0]) { |
|
164 | + $commonPath [] = array_shift($fromPath); |
|
165 | + } else { |
|
166 | + break; |
|
167 | + } |
|
168 | + array_shift($usingPath); |
|
169 | + } |
|
170 | + return array(implode($char, $commonPath), implode($char, $fromPath)); |
|
171 | + } |
|
172 | 172 | |
173 | - /** |
|
174 | - * Parses the request to figure out the http request type |
|
175 | - * |
|
176 | - * @static |
|
177 | - * |
|
178 | - * @return string which will be one of the following |
|
179 | - * [GET, POST, PUT, PATCH, DELETE] |
|
180 | - * @example GET |
|
181 | - */ |
|
182 | - public static function getRequestMethod() |
|
183 | - { |
|
184 | - $method = $_SERVER['REQUEST_METHOD']; |
|
185 | - if (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) { |
|
186 | - $method = $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']; |
|
187 | - } elseif ( |
|
188 | - !empty(Defaults::$httpMethodOverrideProperty) |
|
189 | - && isset($_REQUEST[Defaults::$httpMethodOverrideProperty]) |
|
190 | - ) { |
|
191 | - // support for exceptional clients who can't set the header |
|
192 | - $m = strtoupper($_REQUEST[Defaults::$httpMethodOverrideProperty]); |
|
193 | - if ($m == 'PUT' || $m == 'DELETE' || |
|
194 | - $m == 'POST' || $m == 'PATCH' |
|
195 | - ) { |
|
196 | - $method = $m; |
|
197 | - } |
|
198 | - } |
|
199 | - // support for HEAD request |
|
200 | - if ($method == 'HEAD') { |
|
201 | - $method = 'GET'; |
|
202 | - } |
|
203 | - return $method; |
|
204 | - } |
|
173 | + /** |
|
174 | + * Parses the request to figure out the http request type |
|
175 | + * |
|
176 | + * @static |
|
177 | + * |
|
178 | + * @return string which will be one of the following |
|
179 | + * [GET, POST, PUT, PATCH, DELETE] |
|
180 | + * @example GET |
|
181 | + */ |
|
182 | + public static function getRequestMethod() |
|
183 | + { |
|
184 | + $method = $_SERVER['REQUEST_METHOD']; |
|
185 | + if (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) { |
|
186 | + $method = $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']; |
|
187 | + } elseif ( |
|
188 | + !empty(Defaults::$httpMethodOverrideProperty) |
|
189 | + && isset($_REQUEST[Defaults::$httpMethodOverrideProperty]) |
|
190 | + ) { |
|
191 | + // support for exceptional clients who can't set the header |
|
192 | + $m = strtoupper($_REQUEST[Defaults::$httpMethodOverrideProperty]); |
|
193 | + if ($m == 'PUT' || $m == 'DELETE' || |
|
194 | + $m == 'POST' || $m == 'PATCH' |
|
195 | + ) { |
|
196 | + $method = $m; |
|
197 | + } |
|
198 | + } |
|
199 | + // support for HEAD request |
|
200 | + if ($method == 'HEAD') { |
|
201 | + $method = 'GET'; |
|
202 | + } |
|
203 | + return $method; |
|
204 | + } |
|
205 | 205 | |
206 | - /** |
|
207 | - * Pass any content negotiation header such as Accept, |
|
208 | - * Accept-Language to break it up and sort the resulting array by |
|
209 | - * the order of negotiation. |
|
210 | - * |
|
211 | - * @static |
|
212 | - * |
|
213 | - * @param string $accept header value |
|
214 | - * |
|
215 | - * @return array sorted by the priority |
|
216 | - */ |
|
217 | - public static function sortByPriority($accept) |
|
218 | - { |
|
219 | - $acceptList = array(); |
|
220 | - $accepts = explode(',', strtolower($accept)); |
|
221 | - if (!is_array($accepts)) { |
|
222 | - $accepts = array($accepts); |
|
223 | - } |
|
224 | - foreach ($accepts as $pos => $accept) { |
|
225 | - $parts = explode(';', $accept); |
|
226 | - $type = trim(array_shift($parts)); |
|
227 | - $parameters = []; |
|
228 | - foreach ($parts as $part) { |
|
229 | - $part = explode('=', $part); |
|
230 | - if (2 !== count($part)) { |
|
231 | - continue; |
|
232 | - } |
|
233 | - $key = strtolower(trim($part[0])); |
|
234 | - $parameters[$key] = trim($part[1], ' "'); |
|
235 | - } |
|
236 | - $quality = isset($parameters['q']) ? (float)$parameters['q'] : (1000 - $pos) / 1000; |
|
237 | - $acceptList[$type] = $quality; |
|
238 | - } |
|
239 | - arsort($acceptList); |
|
240 | - return $acceptList; |
|
241 | - } |
|
206 | + /** |
|
207 | + * Pass any content negotiation header such as Accept, |
|
208 | + * Accept-Language to break it up and sort the resulting array by |
|
209 | + * the order of negotiation. |
|
210 | + * |
|
211 | + * @static |
|
212 | + * |
|
213 | + * @param string $accept header value |
|
214 | + * |
|
215 | + * @return array sorted by the priority |
|
216 | + */ |
|
217 | + public static function sortByPriority($accept) |
|
218 | + { |
|
219 | + $acceptList = array(); |
|
220 | + $accepts = explode(',', strtolower($accept)); |
|
221 | + if (!is_array($accepts)) { |
|
222 | + $accepts = array($accepts); |
|
223 | + } |
|
224 | + foreach ($accepts as $pos => $accept) { |
|
225 | + $parts = explode(';', $accept); |
|
226 | + $type = trim(array_shift($parts)); |
|
227 | + $parameters = []; |
|
228 | + foreach ($parts as $part) { |
|
229 | + $part = explode('=', $part); |
|
230 | + if (2 !== count($part)) { |
|
231 | + continue; |
|
232 | + } |
|
233 | + $key = strtolower(trim($part[0])); |
|
234 | + $parameters[$key] = trim($part[1], ' "'); |
|
235 | + } |
|
236 | + $quality = isset($parameters['q']) ? (float)$parameters['q'] : (1000 - $pos) / 1000; |
|
237 | + $acceptList[$type] = $quality; |
|
238 | + } |
|
239 | + arsort($acceptList); |
|
240 | + return $acceptList; |
|
241 | + } |
|
242 | 242 | |
243 | - public static function getShortName($className) |
|
244 | - { |
|
245 | - // @CHANGE LDR |
|
246 | - if (!is_string($className)) return; |
|
243 | + public static function getShortName($className) |
|
244 | + { |
|
245 | + // @CHANGE LDR |
|
246 | + if (!is_string($className)) return; |
|
247 | 247 | |
248 | - $className = explode('\\', $className); |
|
249 | - return end($className); |
|
250 | - } |
|
248 | + $className = explode('\\', $className); |
|
249 | + return end($className); |
|
250 | + } |
|
251 | 251 | } |
252 | 252 |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | } |
40 | 40 | return false; |
41 | 41 | } |
42 | - return !(boolean)strpos('|bool|boolean|int|float|string|', $type); |
|
42 | + return !(boolean) strpos('|bool|boolean|int|float|string|', $type); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | if (strlen($resourcePath) > 0) { |
103 | 103 | $resourcePath .= '/'; |
104 | 104 | } |
105 | - return $prefix . $resourcePath; |
|
105 | + return $prefix.$resourcePath; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | $key = strtolower(trim($part[0])); |
234 | 234 | $parameters[$key] = trim($part[1], ' "'); |
235 | 235 | } |
236 | - $quality = isset($parameters['q']) ? (float)$parameters['q'] : (1000 - $pos) / 1000; |
|
236 | + $quality = isset($parameters['q']) ? (float) $parameters['q'] : (1000 - $pos) / 1000; |
|
237 | 237 | $acceptList[$type] = $quality; |
238 | 238 | } |
239 | 239 | arsort($acceptList); |
@@ -243,7 +243,9 @@ |
||
243 | 243 | public static function getShortName($className) |
244 | 244 | { |
245 | 245 | // @CHANGE LDR |
246 | - if (!is_string($className)) return; |
|
246 | + if (!is_string($className)) { |
|
247 | + return; |
|
248 | + } |
|
247 | 249 | |
248 | 250 | $className = explode('\\', $className); |
249 | 251 | return end($className); |
@@ -177,14 +177,14 @@ |
||
177 | 177 | break; |
178 | 178 | case 1 : |
179 | 179 | if ($addNewline) { |
180 | - $line = ' ' . $line; |
|
180 | + $line = ' '.$line; |
|
181 | 181 | } |
182 | 182 | $longDescription[] = $line; |
183 | 183 | break; |
184 | 184 | case 2 : |
185 | 185 | $newParam |
186 | 186 | ? $params[] = $line |
187 | - : $params[count($params) - 1] .= ' ' . $line; |
|
187 | + : $params[count($params) - 1] .= ' '.$line; |
|
188 | 188 | } |
189 | 189 | $addNewline = false; |
190 | 190 | } |
@@ -34,249 +34,249 @@ |
||
34 | 34 | */ |
35 | 35 | class Tags implements ArrayAccess, Countable |
36 | 36 | { |
37 | - public static $humanReadable = true; |
|
38 | - public static $initializer = null; |
|
39 | - protected static $instances = array(); |
|
40 | - public $prefix = ''; |
|
41 | - public $indent = ' '; |
|
42 | - public $tag; |
|
43 | - protected $attributes = array(); |
|
44 | - protected $children = array(); |
|
45 | - protected $_parent; |
|
37 | + public static $humanReadable = true; |
|
38 | + public static $initializer = null; |
|
39 | + protected static $instances = array(); |
|
40 | + public $prefix = ''; |
|
41 | + public $indent = ' '; |
|
42 | + public $tag; |
|
43 | + protected $attributes = array(); |
|
44 | + protected $children = array(); |
|
45 | + protected $_parent; |
|
46 | 46 | |
47 | - public function __construct($name = null, array $children = array()) |
|
48 | - { |
|
49 | - $this->tag = $name; |
|
50 | - $c = array(); |
|
51 | - foreach ($children as $child) { |
|
52 | - is_array($child) |
|
53 | - ? $c = array_merge($c, $child) |
|
54 | - : $c [] = $child; |
|
55 | - } |
|
56 | - $this->markAsChildren($c); |
|
57 | - $this->children = $c; |
|
58 | - if (static::$initializer) |
|
59 | - call_user_func_array(static::$initializer, array(& $this)); |
|
60 | - } |
|
47 | + public function __construct($name = null, array $children = array()) |
|
48 | + { |
|
49 | + $this->tag = $name; |
|
50 | + $c = array(); |
|
51 | + foreach ($children as $child) { |
|
52 | + is_array($child) |
|
53 | + ? $c = array_merge($c, $child) |
|
54 | + : $c [] = $child; |
|
55 | + } |
|
56 | + $this->markAsChildren($c); |
|
57 | + $this->children = $c; |
|
58 | + if (static::$initializer) |
|
59 | + call_user_func_array(static::$initializer, array(& $this)); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Get Tag by id |
|
64 | - * |
|
65 | - * Retrieve a tag by its id attribute |
|
66 | - * |
|
67 | - * @param string $id |
|
68 | - * |
|
69 | - * @return Tags|null |
|
70 | - */ |
|
71 | - public static function byId($id) |
|
72 | - { |
|
73 | - return Util::nestedValue(static::$instances, $id); |
|
74 | - } |
|
62 | + /** |
|
63 | + * Get Tag by id |
|
64 | + * |
|
65 | + * Retrieve a tag by its id attribute |
|
66 | + * |
|
67 | + * @param string $id |
|
68 | + * |
|
69 | + * @return Tags|null |
|
70 | + */ |
|
71 | + public static function byId($id) |
|
72 | + { |
|
73 | + return Util::nestedValue(static::$instances, $id); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @param $name |
|
78 | - * @param array $children |
|
79 | - * |
|
80 | - * @return Tags |
|
81 | - */ |
|
82 | - public static function __callStatic($name, array $children) |
|
83 | - { |
|
84 | - return new static($name, $children); |
|
85 | - } |
|
76 | + /** |
|
77 | + * @param $name |
|
78 | + * @param array $children |
|
79 | + * |
|
80 | + * @return Tags |
|
81 | + */ |
|
82 | + public static function __callStatic($name, array $children) |
|
83 | + { |
|
84 | + return new static($name, $children); |
|
85 | + } |
|
86 | 86 | |
87 | - public function toString($prefix = '', $indent = ' ') |
|
88 | - { |
|
89 | - $this->prefix = $prefix; |
|
90 | - $this->indent = $indent; |
|
91 | - return $this->__toString(); |
|
92 | - } |
|
87 | + public function toString($prefix = '', $indent = ' ') |
|
88 | + { |
|
89 | + $this->prefix = $prefix; |
|
90 | + $this->indent = $indent; |
|
91 | + return $this->__toString(); |
|
92 | + } |
|
93 | 93 | |
94 | - public function __toString() |
|
95 | - { |
|
96 | - $children = ''; |
|
97 | - if (static::$humanReadable) { |
|
98 | - $lineBreak = false; |
|
99 | - foreach ($this->children as $key => $child) { |
|
100 | - $prefix = $this->prefix; |
|
101 | - if (!is_null($this->tag)) |
|
102 | - $prefix .= $this->indent; |
|
103 | - if ($child instanceof $this) { |
|
104 | - $child->prefix = $prefix; |
|
105 | - $child->indent = $this->indent; |
|
106 | - $children .= PHP_EOL . $child; |
|
107 | - $lineBreak = true; |
|
108 | - } else { |
|
109 | - $children .= $child; |
|
110 | - } |
|
111 | - } |
|
112 | - if ($lineBreak) |
|
113 | - $children .= PHP_EOL . $this->prefix; |
|
114 | - } else { |
|
115 | - $children = implode('', $this->children); |
|
116 | - } |
|
117 | - if (is_null($this->tag)) |
|
118 | - return $children; |
|
119 | - $attributes = ''; |
|
120 | - foreach ($this->attributes as $attribute => &$value) |
|
121 | - $attributes .= " $attribute=\"$value\""; |
|
94 | + public function __toString() |
|
95 | + { |
|
96 | + $children = ''; |
|
97 | + if (static::$humanReadable) { |
|
98 | + $lineBreak = false; |
|
99 | + foreach ($this->children as $key => $child) { |
|
100 | + $prefix = $this->prefix; |
|
101 | + if (!is_null($this->tag)) |
|
102 | + $prefix .= $this->indent; |
|
103 | + if ($child instanceof $this) { |
|
104 | + $child->prefix = $prefix; |
|
105 | + $child->indent = $this->indent; |
|
106 | + $children .= PHP_EOL . $child; |
|
107 | + $lineBreak = true; |
|
108 | + } else { |
|
109 | + $children .= $child; |
|
110 | + } |
|
111 | + } |
|
112 | + if ($lineBreak) |
|
113 | + $children .= PHP_EOL . $this->prefix; |
|
114 | + } else { |
|
115 | + $children = implode('', $this->children); |
|
116 | + } |
|
117 | + if (is_null($this->tag)) |
|
118 | + return $children; |
|
119 | + $attributes = ''; |
|
120 | + foreach ($this->attributes as $attribute => &$value) |
|
121 | + $attributes .= " $attribute=\"$value\""; |
|
122 | 122 | |
123 | - if (count($this->children)) |
|
124 | - return static::$humanReadable |
|
125 | - ? "$this->prefix<{$this->tag}{$attributes}>" |
|
126 | - . "$children" |
|
127 | - . "</{$this->tag}>" |
|
128 | - : "<{$this->tag}{$attributes}>$children</{$this->tag}>"; |
|
123 | + if (count($this->children)) |
|
124 | + return static::$humanReadable |
|
125 | + ? "$this->prefix<{$this->tag}{$attributes}>" |
|
126 | + . "$children" |
|
127 | + . "</{$this->tag}>" |
|
128 | + : "<{$this->tag}{$attributes}>$children</{$this->tag}>"; |
|
129 | 129 | |
130 | - return "$this->prefix<{$this->tag}{$attributes}/>"; |
|
131 | - } |
|
130 | + return "$this->prefix<{$this->tag}{$attributes}/>"; |
|
131 | + } |
|
132 | 132 | |
133 | - public function toArray() |
|
134 | - { |
|
135 | - $r = array(); |
|
136 | - $r['attributes'] = $this->attributes; |
|
137 | - $r['tag'] = $this->tag; |
|
138 | - $children = array(); |
|
139 | - foreach ($this->children as $key => $child) { |
|
140 | - $children[$key] = $child instanceof $this |
|
141 | - ? $child->toArray() |
|
142 | - : $child; |
|
143 | - } |
|
144 | - $r['children'] = $children; |
|
145 | - return $r; |
|
146 | - } |
|
133 | + public function toArray() |
|
134 | + { |
|
135 | + $r = array(); |
|
136 | + $r['attributes'] = $this->attributes; |
|
137 | + $r['tag'] = $this->tag; |
|
138 | + $children = array(); |
|
139 | + foreach ($this->children as $key => $child) { |
|
140 | + $children[$key] = $child instanceof $this |
|
141 | + ? $child->toArray() |
|
142 | + : $child; |
|
143 | + } |
|
144 | + $r['children'] = $children; |
|
145 | + return $r; |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * Set the id attribute of the current tag |
|
150 | - * |
|
151 | - * @param string $value |
|
152 | - * |
|
153 | - * @return string |
|
154 | - */ |
|
155 | - public function id($value) |
|
156 | - { |
|
157 | - if (!empty($value) && is_string($value)) { |
|
158 | - $this->attributes['id'] = $value; |
|
159 | - static::$instances[$value] = $this; |
|
160 | - } |
|
161 | - return $this; |
|
162 | - } |
|
148 | + /** |
|
149 | + * Set the id attribute of the current tag |
|
150 | + * |
|
151 | + * @param string $value |
|
152 | + * |
|
153 | + * @return string |
|
154 | + */ |
|
155 | + public function id($value) |
|
156 | + { |
|
157 | + if (!empty($value) && is_string($value)) { |
|
158 | + $this->attributes['id'] = $value; |
|
159 | + static::$instances[$value] = $this; |
|
160 | + } |
|
161 | + return $this; |
|
162 | + } |
|
163 | 163 | |
164 | - public function __get($name) |
|
165 | - { |
|
166 | - if ('parent' == $name) |
|
167 | - return $this->_parent; |
|
168 | - if (isset($this->attributes[$name])) |
|
169 | - return $this->attributes[$name]; |
|
170 | - return; |
|
171 | - } |
|
164 | + public function __get($name) |
|
165 | + { |
|
166 | + if ('parent' == $name) |
|
167 | + return $this->_parent; |
|
168 | + if (isset($this->attributes[$name])) |
|
169 | + return $this->attributes[$name]; |
|
170 | + return; |
|
171 | + } |
|
172 | 172 | |
173 | - public function __set($name, $value) |
|
174 | - { |
|
175 | - if ('parent' == $name) { |
|
176 | - if ($this->_parent) { |
|
177 | - unset($this->_parent[array_search($this, $this->_parent->children)]); |
|
178 | - } |
|
179 | - if (!empty($value)) { |
|
180 | - $value[] = $this; |
|
181 | - } |
|
182 | - } |
|
183 | - } |
|
173 | + public function __set($name, $value) |
|
174 | + { |
|
175 | + if ('parent' == $name) { |
|
176 | + if ($this->_parent) { |
|
177 | + unset($this->_parent[array_search($this, $this->_parent->children)]); |
|
178 | + } |
|
179 | + if (!empty($value)) { |
|
180 | + $value[] = $this; |
|
181 | + } |
|
182 | + } |
|
183 | + } |
|
184 | 184 | |
185 | - public function __isset($name) |
|
186 | - { |
|
187 | - return isset($this->attributes[$name]); |
|
188 | - } |
|
185 | + public function __isset($name) |
|
186 | + { |
|
187 | + return isset($this->attributes[$name]); |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * @param $attribute |
|
192 | - * @param $value |
|
193 | - * |
|
194 | - * @return Tags |
|
195 | - */ |
|
196 | - public function __call($attribute, $value) |
|
197 | - { |
|
198 | - if (is_null($value)) { |
|
199 | - return isset($this->attributes[$attribute]) |
|
200 | - ? $this->attributes[$attribute] |
|
201 | - : null; |
|
202 | - } |
|
203 | - $value = $value[0]; |
|
204 | - if (is_null($value)) { |
|
205 | - unset($this->attributes[$attribute]); |
|
206 | - return $this; |
|
207 | - } |
|
208 | - $this->attributes[$attribute] = is_bool($value) |
|
209 | - ? ($value ? 'true' : 'false') |
|
210 | - : @(string)$value; |
|
211 | - return $this; |
|
212 | - } |
|
190 | + /** |
|
191 | + * @param $attribute |
|
192 | + * @param $value |
|
193 | + * |
|
194 | + * @return Tags |
|
195 | + */ |
|
196 | + public function __call($attribute, $value) |
|
197 | + { |
|
198 | + if (is_null($value)) { |
|
199 | + return isset($this->attributes[$attribute]) |
|
200 | + ? $this->attributes[$attribute] |
|
201 | + : null; |
|
202 | + } |
|
203 | + $value = $value[0]; |
|
204 | + if (is_null($value)) { |
|
205 | + unset($this->attributes[$attribute]); |
|
206 | + return $this; |
|
207 | + } |
|
208 | + $this->attributes[$attribute] = is_bool($value) |
|
209 | + ? ($value ? 'true' : 'false') |
|
210 | + : @(string)$value; |
|
211 | + return $this; |
|
212 | + } |
|
213 | 213 | |
214 | - public function offsetGet($index) |
|
215 | - { |
|
216 | - if ($this->offsetExists($index)) { |
|
217 | - return $this->children[$index]; |
|
218 | - } |
|
219 | - return false; |
|
220 | - } |
|
214 | + public function offsetGet($index) |
|
215 | + { |
|
216 | + if ($this->offsetExists($index)) { |
|
217 | + return $this->children[$index]; |
|
218 | + } |
|
219 | + return false; |
|
220 | + } |
|
221 | 221 | |
222 | - public function offsetExists($index) |
|
223 | - { |
|
224 | - return isset($this->children[$index]); |
|
225 | - } |
|
222 | + public function offsetExists($index) |
|
223 | + { |
|
224 | + return isset($this->children[$index]); |
|
225 | + } |
|
226 | 226 | |
227 | - public function offsetSet($index, $value) |
|
228 | - { |
|
229 | - if ($index) { |
|
230 | - $this->children[$index] = $value; |
|
231 | - } elseif (is_array($value)) { |
|
232 | - $c = array(); |
|
233 | - foreach ($value as $child) { |
|
234 | - is_array($child) |
|
235 | - ? $c = array_merge($c, $child) |
|
236 | - : $c [] = $child; |
|
237 | - } |
|
238 | - $this->markAsChildren($c); |
|
239 | - $this->children += $c; |
|
240 | - } else { |
|
241 | - $c = array($value); |
|
242 | - $this->markAsChildren($c); |
|
243 | - $this->children[] = $value; |
|
244 | - } |
|
245 | - return true; |
|
246 | - } |
|
227 | + public function offsetSet($index, $value) |
|
228 | + { |
|
229 | + if ($index) { |
|
230 | + $this->children[$index] = $value; |
|
231 | + } elseif (is_array($value)) { |
|
232 | + $c = array(); |
|
233 | + foreach ($value as $child) { |
|
234 | + is_array($child) |
|
235 | + ? $c = array_merge($c, $child) |
|
236 | + : $c [] = $child; |
|
237 | + } |
|
238 | + $this->markAsChildren($c); |
|
239 | + $this->children += $c; |
|
240 | + } else { |
|
241 | + $c = array($value); |
|
242 | + $this->markAsChildren($c); |
|
243 | + $this->children[] = $value; |
|
244 | + } |
|
245 | + return true; |
|
246 | + } |
|
247 | 247 | |
248 | - public function offsetUnset($index) |
|
249 | - { |
|
250 | - $this->children[$index]->_parent = null; |
|
251 | - unset($this->children[$index]); |
|
252 | - return true; |
|
253 | - } |
|
248 | + public function offsetUnset($index) |
|
249 | + { |
|
250 | + $this->children[$index]->_parent = null; |
|
251 | + unset($this->children[$index]); |
|
252 | + return true; |
|
253 | + } |
|
254 | 254 | |
255 | - public function getContents() |
|
256 | - { |
|
257 | - return $this->children; |
|
258 | - } |
|
255 | + public function getContents() |
|
256 | + { |
|
257 | + return $this->children; |
|
258 | + } |
|
259 | 259 | |
260 | - public function count() |
|
261 | - { |
|
262 | - return count($this->children); |
|
263 | - } |
|
260 | + public function count() |
|
261 | + { |
|
262 | + return count($this->children); |
|
263 | + } |
|
264 | 264 | |
265 | - private function markAsChildren(& $children) |
|
266 | - { |
|
267 | - foreach ($children as $i => $child) { |
|
268 | - if (is_string($child)) |
|
269 | - continue; |
|
270 | - if (!is_object($child)) { |
|
271 | - unset($children[$i]); |
|
272 | - continue; |
|
273 | - } |
|
274 | - //echo $child; |
|
275 | - if (isset($child->_parent) && $child->_parent != $this) { |
|
276 | - //remove from current parent |
|
277 | - unset($child->_parent[array_search($child, $child->_parent->children)]); |
|
278 | - } |
|
279 | - $child->_parent = $this; |
|
280 | - } |
|
281 | - } |
|
265 | + private function markAsChildren(& $children) |
|
266 | + { |
|
267 | + foreach ($children as $i => $child) { |
|
268 | + if (is_string($child)) |
|
269 | + continue; |
|
270 | + if (!is_object($child)) { |
|
271 | + unset($children[$i]); |
|
272 | + continue; |
|
273 | + } |
|
274 | + //echo $child; |
|
275 | + if (isset($child->_parent) && $child->_parent != $this) { |
|
276 | + //remove from current parent |
|
277 | + unset($child->_parent[array_search($child, $child->_parent->children)]); |
|
278 | + } |
|
279 | + $child->_parent = $this; |
|
280 | + } |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |
@@ -103,14 +103,14 @@ discard block |
||
103 | 103 | if ($child instanceof $this) { |
104 | 104 | $child->prefix = $prefix; |
105 | 105 | $child->indent = $this->indent; |
106 | - $children .= PHP_EOL . $child; |
|
106 | + $children .= PHP_EOL.$child; |
|
107 | 107 | $lineBreak = true; |
108 | 108 | } else { |
109 | 109 | $children .= $child; |
110 | 110 | } |
111 | 111 | } |
112 | 112 | if ($lineBreak) |
113 | - $children .= PHP_EOL . $this->prefix; |
|
113 | + $children .= PHP_EOL.$this->prefix; |
|
114 | 114 | } else { |
115 | 115 | $children = implode('', $this->children); |
116 | 116 | } |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | } |
208 | 208 | $this->attributes[$attribute] = is_bool($value) |
209 | 209 | ? ($value ? 'true' : 'false') |
210 | - : @(string)$value; |
|
210 | + : @(string) $value; |
|
211 | 211 | return $this; |
212 | 212 | } |
213 | 213 |
@@ -55,8 +55,9 @@ discard block |
||
55 | 55 | } |
56 | 56 | $this->markAsChildren($c); |
57 | 57 | $this->children = $c; |
58 | - if (static::$initializer) |
|
59 | - call_user_func_array(static::$initializer, array(& $this)); |
|
58 | + if (static::$initializer) { |
|
59 | + call_user_func_array(static::$initializer, array(& $this)); |
|
60 | + } |
|
60 | 61 | } |
61 | 62 | |
62 | 63 | /** |
@@ -98,8 +99,9 @@ discard block |
||
98 | 99 | $lineBreak = false; |
99 | 100 | foreach ($this->children as $key => $child) { |
100 | 101 | $prefix = $this->prefix; |
101 | - if (!is_null($this->tag)) |
|
102 | - $prefix .= $this->indent; |
|
102 | + if (!is_null($this->tag)) { |
|
103 | + $prefix .= $this->indent; |
|
104 | + } |
|
103 | 105 | if ($child instanceof $this) { |
104 | 106 | $child->prefix = $prefix; |
105 | 107 | $child->indent = $this->indent; |
@@ -109,23 +111,27 @@ discard block |
||
109 | 111 | $children .= $child; |
110 | 112 | } |
111 | 113 | } |
112 | - if ($lineBreak) |
|
113 | - $children .= PHP_EOL . $this->prefix; |
|
114 | + if ($lineBreak) { |
|
115 | + $children .= PHP_EOL . $this->prefix; |
|
116 | + } |
|
114 | 117 | } else { |
115 | 118 | $children = implode('', $this->children); |
116 | 119 | } |
117 | - if (is_null($this->tag)) |
|
118 | - return $children; |
|
120 | + if (is_null($this->tag)) { |
|
121 | + return $children; |
|
122 | + } |
|
119 | 123 | $attributes = ''; |
120 | - foreach ($this->attributes as $attribute => &$value) |
|
121 | - $attributes .= " $attribute=\"$value\""; |
|
124 | + foreach ($this->attributes as $attribute => &$value) { |
|
125 | + $attributes .= " $attribute=\"$value\""; |
|
126 | + } |
|
122 | 127 | |
123 | - if (count($this->children)) |
|
124 | - return static::$humanReadable |
|
128 | + if (count($this->children)) { |
|
129 | + return static::$humanReadable |
|
125 | 130 | ? "$this->prefix<{$this->tag}{$attributes}>" |
126 | 131 | . "$children" |
127 | 132 | . "</{$this->tag}>" |
128 | 133 | : "<{$this->tag}{$attributes}>$children</{$this->tag}>"; |
134 | + } |
|
129 | 135 | |
130 | 136 | return "$this->prefix<{$this->tag}{$attributes}/>"; |
131 | 137 | } |
@@ -163,10 +169,12 @@ discard block |
||
163 | 169 | |
164 | 170 | public function __get($name) |
165 | 171 | { |
166 | - if ('parent' == $name) |
|
167 | - return $this->_parent; |
|
168 | - if (isset($this->attributes[$name])) |
|
169 | - return $this->attributes[$name]; |
|
172 | + if ('parent' == $name) { |
|
173 | + return $this->_parent; |
|
174 | + } |
|
175 | + if (isset($this->attributes[$name])) { |
|
176 | + return $this->attributes[$name]; |
|
177 | + } |
|
170 | 178 | return; |
171 | 179 | } |
172 | 180 | |
@@ -265,8 +273,9 @@ discard block |
||
265 | 273 | private function markAsChildren(& $children) |
266 | 274 | { |
267 | 275 | foreach ($children as $i => $child) { |
268 | - if (is_string($child)) |
|
269 | - continue; |
|
276 | + if (is_string($child)) { |
|
277 | + continue; |
|
278 | + } |
|
270 | 279 | if (!is_object($child)) { |
271 | 280 | unset($children[$i]); |
272 | 281 | continue; |