@@ -10,18 +10,18 @@ |
||
10 | 10 | $classMap = array(); |
11 | 11 | //find lowercase php files representing a class/interface |
12 | 12 | foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) |
13 | - foreach (new DirectoryIterator($path) as $fileInfo) |
|
14 | - if ($fileInfo->isFile() |
|
15 | - && 'php' === $fileInfo->getExtension() |
|
16 | - && ctype_lower($fileInfo->getBasename('.php')) |
|
17 | - && preg_match( |
|
18 | - '/^ *(class|interface|abstract +class)' |
|
19 | - . ' +([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/m', |
|
20 | - file_get_contents($fileInfo->getPathname()), |
|
21 | - $matches |
|
22 | - ) |
|
23 | - ) |
|
24 | - $classMap[$matches[2]] = $fileInfo->getPathname(); |
|
13 | + foreach (new DirectoryIterator($path) as $fileInfo) |
|
14 | + if ($fileInfo->isFile() |
|
15 | + && 'php' === $fileInfo->getExtension() |
|
16 | + && ctype_lower($fileInfo->getBasename('.php')) |
|
17 | + && preg_match( |
|
18 | + '/^ *(class|interface|abstract +class)' |
|
19 | + . ' +([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/m', |
|
20 | + file_get_contents($fileInfo->getPathname()), |
|
21 | + $matches |
|
22 | + ) |
|
23 | + ) |
|
24 | + $classMap[$matches[2]] = $fileInfo->getPathname(); |
|
25 | 25 | |
26 | 26 | AutoLoader::seen($classMap); |
27 | 27 |
@@ -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> |
@@ -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 |
@@ -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 |
@@ -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 |
@@ -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 |
@@ -14,46 +14,46 @@ |
||
14 | 14 | */ |
15 | 15 | class FormStyles |
16 | 16 | { |
17 | - public static $html = array( |
|
18 | - 'form' => 'form[role=form id=$id# name=$name# method=$method# action=$action# enctype=$enctype#]', |
|
19 | - 'input' => '.row>section>label{$label#}^input[id=$id# name=$name# value=$value# type=$type# required=$required# autofocus=$autofocus# placeholder=$default# accept=$accept# disabled=$disabled#]', |
|
20 | - 'textarea' => '.row>label{$label#}^textarea[id=$id# name=$name# required=$required# autofocus=$autofocus# placeholder=$default# rows=3 disabled=$disabled#]{$value#}', |
|
21 | - 'radio' => '.row>section>label{$label#}^span>label*options>input[id=$id# name=$name# value=$value# type=radio checked=$selected# required=$required# disabled=$disabled#]+{ $text#}', |
|
22 | - 'select' => '.row>label{$label#}^select[id=$id# name=$name# required=$required#]>option[value]+option[value=$value# selected=$selected# disabled=$disabled#]{$text#}*options', |
|
23 | - 'submit' => '.row>label{ }^button[id=$id# type=submit disabled=$disabled#]{$label#}', |
|
24 | - 'fieldset' => 'fieldset>legend{$label#}', |
|
25 | - 'checkbox' => '.row>label>input[id=$id# name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus# accept=$accept# disabled=$disabled#]+{$label#}', |
|
26 | - //------------- TYPE BASED STYLES ---------------------// |
|
27 | - 'checkbox-array' => 'fieldset>legend{$label#}+section*options>label>input[name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus# accept=$accept#]+{ $text#}', |
|
28 | - 'select-array' => 'label{$label#}+select[name=$name# required=$required# multiple style="height: auto;background-image: none; outline: inherit;"]>option[value=$value# selected=$selected#]{$text#}*options', |
|
29 | - ); |
|
30 | - public static $bootstrap3 = array( |
|
31 | - 'form' => 'form[role=form id=$id# name=$name# method=$method# action=$action# enctype=$enctype#]', |
|
32 | - 'input' => '.form-group.$error#>label{$label#}+input.form-control[id=$id# name=$name# value=$value# type=$type# required=$required# autofocus=$autofocus# placeholder=$default# accept=$accept# disabled=$disabled#]+small.help-block>{$message#}', |
|
33 | - 'textarea' => '.form-group>label{$label#}+textarea.form-control[id=$id# name=$name# required=$required# autofocus=$autofocus# placeholder=$default# rows=3 disabled=$disabled#]{$value#}+small.help-block>{$message#}', |
|
34 | - 'radio' => 'fieldset>legend{$label#}>.radio*options>label>input.radio[name=$name# value=$value# type=radio checked=$selected# required=$required# disabled=$disabled#]{$text#}+p.help-block>{$message#}', |
|
35 | - 'select' => '.form-group>label{$label#}+select.form-control[id=$id# name=$name# multiple=$multiple# required=$required#]>option[value]+option[value=$value# selected=$selected# disabled=$disabled#]{$text#}*options', |
|
36 | - 'submit' => 'button.btn.btn-primary[id=$id# type=submit]{$label#} disabled=$disabled#', |
|
37 | - 'fieldset' => 'fieldset>legend{$label#}', |
|
38 | - 'checkbox' => '.checkbox>label>input[id=$id# name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus# disabled=$disabled#]+{$label#}^p.help-block>{$error#}', |
|
39 | - //------------- TYPE BASED STYLES ---------------------// |
|
40 | - 'checkbox-array' => 'fieldset>legend{$label#}>.checkbox*options>label>input[name=$name# value=$value# type=checkbox checked=$selected# required=$required#]{$text#}', |
|
41 | - 'select-array' => '.form-group>label{$label#}+select.form-control[name=$name# multiple=$multiple# required=$required#] size=$options#>option[value=$value# selected=$selected#]{$text#}*options', |
|
42 | - //------------- CUSTOM STYLES ---------------------// |
|
43 | - 'radio-inline' => '.form-group>label{$label# : }+label.radio-inline*options>input.radio[name=$name# value=$value# type=radio checked=$selected# required=$required#]+{$text#}', |
|
44 | - ); |
|
45 | - public static $foundation5 = array( |
|
46 | - 'form' => 'form[id=$id# name=$name# method=$method# action=$action# enctype=$enctype#]', |
|
47 | - 'input' => 'label{$label#}+input[id=$id# name=$name# value=$value# type=$type# required=$required# autofocus=$autofocus# placeholder=$default# accept=$accept# disabled=$disabled#]', |
|
48 | - 'textarea' => 'label{$label#}+textarea[id=$id# name=$name# required=$required# autofocus=$autofocus# placeholder=$default# rows=3 disabled=$disabled#]{$value#}', |
|
49 | - 'radio' => 'label{$label# : }+label.radio-inline*options>input.radio[name=$name# value=$value# type=radio checked=$selected# required=$required# disabled=$disabled#]+{$text#}', |
|
50 | - 'select' => 'label{$label#}+select[id=$id# name=$name# required=$required#]>option[value]+option[value=$value# selected=$selected# disabled=$disabled#]{$text#}*options', |
|
51 | - 'submit' => 'button.button[id=$id# type=submit disabled=$disabled#]{$label#}', |
|
52 | - 'fieldset' => 'fieldset>legend{$label#}', |
|
53 | - 'checkbox' => 'label>input[id=$id# name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus# disabled=$disabled#]+{ $label#}', |
|
54 | - //------------- TYPE BASED STYLES ---------------------// |
|
55 | - 'checkbox-array' => 'fieldset>legend{$label#}+label*options>input[name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus#]+{ $text#}', |
|
56 | - 'select-array' => 'label{$label#}+select[name=$name# required=$required# multiple style="height: auto;background-image: none; outline: inherit;"]>option[value=$value# selected=$selected#]{$text#}*options', |
|
57 | - //------------- CUSTOM STYLES ---------------------// |
|
58 | - ); |
|
17 | + public static $html = array( |
|
18 | + 'form' => 'form[role=form id=$id# name=$name# method=$method# action=$action# enctype=$enctype#]', |
|
19 | + 'input' => '.row>section>label{$label#}^input[id=$id# name=$name# value=$value# type=$type# required=$required# autofocus=$autofocus# placeholder=$default# accept=$accept# disabled=$disabled#]', |
|
20 | + 'textarea' => '.row>label{$label#}^textarea[id=$id# name=$name# required=$required# autofocus=$autofocus# placeholder=$default# rows=3 disabled=$disabled#]{$value#}', |
|
21 | + 'radio' => '.row>section>label{$label#}^span>label*options>input[id=$id# name=$name# value=$value# type=radio checked=$selected# required=$required# disabled=$disabled#]+{ $text#}', |
|
22 | + 'select' => '.row>label{$label#}^select[id=$id# name=$name# required=$required#]>option[value]+option[value=$value# selected=$selected# disabled=$disabled#]{$text#}*options', |
|
23 | + 'submit' => '.row>label{ }^button[id=$id# type=submit disabled=$disabled#]{$label#}', |
|
24 | + 'fieldset' => 'fieldset>legend{$label#}', |
|
25 | + 'checkbox' => '.row>label>input[id=$id# name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus# accept=$accept# disabled=$disabled#]+{$label#}', |
|
26 | + //------------- TYPE BASED STYLES ---------------------// |
|
27 | + 'checkbox-array' => 'fieldset>legend{$label#}+section*options>label>input[name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus# accept=$accept#]+{ $text#}', |
|
28 | + 'select-array' => 'label{$label#}+select[name=$name# required=$required# multiple style="height: auto;background-image: none; outline: inherit;"]>option[value=$value# selected=$selected#]{$text#}*options', |
|
29 | + ); |
|
30 | + public static $bootstrap3 = array( |
|
31 | + 'form' => 'form[role=form id=$id# name=$name# method=$method# action=$action# enctype=$enctype#]', |
|
32 | + 'input' => '.form-group.$error#>label{$label#}+input.form-control[id=$id# name=$name# value=$value# type=$type# required=$required# autofocus=$autofocus# placeholder=$default# accept=$accept# disabled=$disabled#]+small.help-block>{$message#}', |
|
33 | + 'textarea' => '.form-group>label{$label#}+textarea.form-control[id=$id# name=$name# required=$required# autofocus=$autofocus# placeholder=$default# rows=3 disabled=$disabled#]{$value#}+small.help-block>{$message#}', |
|
34 | + 'radio' => 'fieldset>legend{$label#}>.radio*options>label>input.radio[name=$name# value=$value# type=radio checked=$selected# required=$required# disabled=$disabled#]{$text#}+p.help-block>{$message#}', |
|
35 | + 'select' => '.form-group>label{$label#}+select.form-control[id=$id# name=$name# multiple=$multiple# required=$required#]>option[value]+option[value=$value# selected=$selected# disabled=$disabled#]{$text#}*options', |
|
36 | + 'submit' => 'button.btn.btn-primary[id=$id# type=submit]{$label#} disabled=$disabled#', |
|
37 | + 'fieldset' => 'fieldset>legend{$label#}', |
|
38 | + 'checkbox' => '.checkbox>label>input[id=$id# name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus# disabled=$disabled#]+{$label#}^p.help-block>{$error#}', |
|
39 | + //------------- TYPE BASED STYLES ---------------------// |
|
40 | + 'checkbox-array' => 'fieldset>legend{$label#}>.checkbox*options>label>input[name=$name# value=$value# type=checkbox checked=$selected# required=$required#]{$text#}', |
|
41 | + 'select-array' => '.form-group>label{$label#}+select.form-control[name=$name# multiple=$multiple# required=$required#] size=$options#>option[value=$value# selected=$selected#]{$text#}*options', |
|
42 | + //------------- CUSTOM STYLES ---------------------// |
|
43 | + 'radio-inline' => '.form-group>label{$label# : }+label.radio-inline*options>input.radio[name=$name# value=$value# type=radio checked=$selected# required=$required#]+{$text#}', |
|
44 | + ); |
|
45 | + public static $foundation5 = array( |
|
46 | + 'form' => 'form[id=$id# name=$name# method=$method# action=$action# enctype=$enctype#]', |
|
47 | + 'input' => 'label{$label#}+input[id=$id# name=$name# value=$value# type=$type# required=$required# autofocus=$autofocus# placeholder=$default# accept=$accept# disabled=$disabled#]', |
|
48 | + 'textarea' => 'label{$label#}+textarea[id=$id# name=$name# required=$required# autofocus=$autofocus# placeholder=$default# rows=3 disabled=$disabled#]{$value#}', |
|
49 | + 'radio' => 'label{$label# : }+label.radio-inline*options>input.radio[name=$name# value=$value# type=radio checked=$selected# required=$required# disabled=$disabled#]+{$text#}', |
|
50 | + 'select' => 'label{$label#}+select[id=$id# name=$name# required=$required#]>option[value]+option[value=$value# selected=$selected# disabled=$disabled#]{$text#}*options', |
|
51 | + 'submit' => 'button.button[id=$id# type=submit disabled=$disabled#]{$label#}', |
|
52 | + 'fieldset' => 'fieldset>legend{$label#}', |
|
53 | + 'checkbox' => 'label>input[id=$id# name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus# disabled=$disabled#]+{ $label#}', |
|
54 | + //------------- TYPE BASED STYLES ---------------------// |
|
55 | + 'checkbox-array' => 'fieldset>legend{$label#}+label*options>input[name=$name# value=$value# type=checkbox checked=$selected# required=$required# autofocus=$autofocus#]+{ $text#}', |
|
56 | + 'select-array' => 'label{$label#}+select[name=$name# required=$required# multiple style="height: auto;background-image: none; outline: inherit;"]>option[value=$value# selected=$selected#]{$text#}*options', |
|
57 | + //------------- CUSTOM STYLES ---------------------// |
|
58 | + ); |
|
59 | 59 | } |
60 | 60 | \ No newline at end of file |
@@ -23,201 +23,201 @@ |
||
23 | 23 | */ |
24 | 24 | class Nav |
25 | 25 | { |
26 | - protected static $tree = array(); |
|
27 | - public static $root = 'home'; |
|
26 | + protected static $tree = array(); |
|
27 | + public static $root = 'home'; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var array all paths beginning with any of the following will be excluded |
|
31 | - * from documentation. if an empty string is given it will exclude the root |
|
32 | - */ |
|
33 | - public static $excludedPaths = array(''); |
|
34 | - /** |
|
35 | - * @var array prefix additional menu items with one of the following syntax |
|
36 | - * [$path => $text] |
|
37 | - * [$path] |
|
38 | - * [$path => ['text' => $text, 'url' => $url, 'trail'=> $trail]] |
|
39 | - */ |
|
40 | - public static $prepends = array(); |
|
41 | - /** |
|
42 | - * @var array suffix additional menu items with one of the following syntax |
|
43 | - * [$path => $text] |
|
44 | - * [$path] |
|
45 | - * [$path => ['text' => $text, 'url' => $url, 'trail'=> $trail]] |
|
46 | - */ |
|
47 | - public static $appends = array(); |
|
29 | + /** |
|
30 | + * @var array all paths beginning with any of the following will be excluded |
|
31 | + * from documentation. if an empty string is given it will exclude the root |
|
32 | + */ |
|
33 | + public static $excludedPaths = array(''); |
|
34 | + /** |
|
35 | + * @var array prefix additional menu items with one of the following syntax |
|
36 | + * [$path => $text] |
|
37 | + * [$path] |
|
38 | + * [$path => ['text' => $text, 'url' => $url, 'trail'=> $trail]] |
|
39 | + */ |
|
40 | + public static $prepends = array(); |
|
41 | + /** |
|
42 | + * @var array suffix additional menu items with one of the following syntax |
|
43 | + * [$path => $text] |
|
44 | + * [$path] |
|
45 | + * [$path => ['text' => $text, 'url' => $url, 'trail'=> $trail]] |
|
46 | + */ |
|
47 | + public static $appends = array(); |
|
48 | 48 | |
49 | - public static $addExtension = true; |
|
49 | + public static $addExtension = true; |
|
50 | 50 | |
51 | - protected static $extension = ''; |
|
52 | - protected static $activeTrail = ''; |
|
53 | - protected static $url; |
|
51 | + protected static $extension = ''; |
|
52 | + protected static $activeTrail = ''; |
|
53 | + protected static $url; |
|
54 | 54 | |
55 | - public static function get($for = '', $activeTrail = null) |
|
56 | - { |
|
57 | - if (empty(static::$tree)) { |
|
58 | - /** @var Restler $restler */ |
|
59 | - $restler = Scope::get('Restler'); |
|
60 | - if (static::$addExtension) |
|
61 | - static::$extension = isset($restler->responseFormat) |
|
62 | - ? '.' . $restler->responseFormat->getExtension() |
|
63 | - : '.html'; |
|
64 | - static::$url = $restler->getBaseUrl(); |
|
65 | - if (empty(static::$url)) |
|
66 | - static::$url = ''; |
|
67 | - static::$activeTrail = $activeTrail = empty($activeTrail) |
|
68 | - ? (empty($restler->url) || $restler->url == 'index' |
|
69 | - ? static::$root |
|
70 | - : $restler->url |
|
71 | - ) |
|
72 | - : $activeTrail; |
|
73 | - if (static::$addExtension) |
|
74 | - static::$extension = isset($restler->responseFormat) |
|
75 | - ? '.' . $restler->responseFormat->getExtension() |
|
76 | - : '.html'; |
|
77 | - static::addUrls(static::$prepends); |
|
78 | - $map = Routes::findAll( |
|
79 | - static::$excludedPaths, |
|
80 | - array('POST', 'DELETE', 'PUT', 'PATCH'), |
|
81 | - $restler->getRequestedApiVersion() |
|
82 | - ); |
|
83 | - foreach ($map as $path => $data) { |
|
84 | - foreach ($data as $item) { |
|
85 | - $access = $item['access']; |
|
86 | - $route = $item['route']; |
|
87 | - $url = $route['url']; |
|
88 | - if ($access && !Text::contains($url, '{')) { |
|
89 | - $label = Util::nestedValue( |
|
90 | - $route, |
|
91 | - 'metadata', |
|
92 | - CommentParser::$embeddedDataName, |
|
93 | - 'label' |
|
94 | - ); |
|
95 | - if (!empty($url)) { |
|
96 | - $url .= static::$extension; |
|
97 | - } |
|
98 | - static::add($url, $label); |
|
99 | - } |
|
100 | - } |
|
101 | - } |
|
102 | - static::addUrls(static::$appends); |
|
103 | - } elseif (empty($activeTrail)) { |
|
104 | - $activeTrail = static::$activeTrail; |
|
105 | - } |
|
106 | - $tree = static::$tree; |
|
107 | - $activeTrail = explode('/', $activeTrail); |
|
108 | - $nested = & static::nested($tree, $activeTrail); |
|
109 | - if (is_array($nested)) { |
|
110 | - $nested['active'] = true; |
|
111 | - } |
|
112 | - if (!empty($for)) { |
|
113 | - $for = explode('/', $for); |
|
114 | - $tree = static::nested($tree, $for)['children']; |
|
115 | - } |
|
116 | - return array_filter($tree); |
|
117 | - } |
|
55 | + public static function get($for = '', $activeTrail = null) |
|
56 | + { |
|
57 | + if (empty(static::$tree)) { |
|
58 | + /** @var Restler $restler */ |
|
59 | + $restler = Scope::get('Restler'); |
|
60 | + if (static::$addExtension) |
|
61 | + static::$extension = isset($restler->responseFormat) |
|
62 | + ? '.' . $restler->responseFormat->getExtension() |
|
63 | + : '.html'; |
|
64 | + static::$url = $restler->getBaseUrl(); |
|
65 | + if (empty(static::$url)) |
|
66 | + static::$url = ''; |
|
67 | + static::$activeTrail = $activeTrail = empty($activeTrail) |
|
68 | + ? (empty($restler->url) || $restler->url == 'index' |
|
69 | + ? static::$root |
|
70 | + : $restler->url |
|
71 | + ) |
|
72 | + : $activeTrail; |
|
73 | + if (static::$addExtension) |
|
74 | + static::$extension = isset($restler->responseFormat) |
|
75 | + ? '.' . $restler->responseFormat->getExtension() |
|
76 | + : '.html'; |
|
77 | + static::addUrls(static::$prepends); |
|
78 | + $map = Routes::findAll( |
|
79 | + static::$excludedPaths, |
|
80 | + array('POST', 'DELETE', 'PUT', 'PATCH'), |
|
81 | + $restler->getRequestedApiVersion() |
|
82 | + ); |
|
83 | + foreach ($map as $path => $data) { |
|
84 | + foreach ($data as $item) { |
|
85 | + $access = $item['access']; |
|
86 | + $route = $item['route']; |
|
87 | + $url = $route['url']; |
|
88 | + if ($access && !Text::contains($url, '{')) { |
|
89 | + $label = Util::nestedValue( |
|
90 | + $route, |
|
91 | + 'metadata', |
|
92 | + CommentParser::$embeddedDataName, |
|
93 | + 'label' |
|
94 | + ); |
|
95 | + if (!empty($url)) { |
|
96 | + $url .= static::$extension; |
|
97 | + } |
|
98 | + static::add($url, $label); |
|
99 | + } |
|
100 | + } |
|
101 | + } |
|
102 | + static::addUrls(static::$appends); |
|
103 | + } elseif (empty($activeTrail)) { |
|
104 | + $activeTrail = static::$activeTrail; |
|
105 | + } |
|
106 | + $tree = static::$tree; |
|
107 | + $activeTrail = explode('/', $activeTrail); |
|
108 | + $nested = & static::nested($tree, $activeTrail); |
|
109 | + if (is_array($nested)) { |
|
110 | + $nested['active'] = true; |
|
111 | + } |
|
112 | + if (!empty($for)) { |
|
113 | + $for = explode('/', $for); |
|
114 | + $tree = static::nested($tree, $for)['children']; |
|
115 | + } |
|
116 | + return array_filter($tree); |
|
117 | + } |
|
118 | 118 | |
119 | - protected static function & nested(array & $tree, array $parts) |
|
120 | - { |
|
121 | - if (!empty($parts)) { |
|
122 | - $part = array_shift($parts); |
|
123 | - if (empty($tree[$part])) { |
|
124 | - return $tree[$part]; |
|
125 | - } elseif (empty($parts)) { |
|
126 | - return static::nested($tree[$part], $parts); |
|
127 | - } elseif (!empty($tree[$part]['children'])) { |
|
128 | - return static::nested($tree[$part]['children'], $parts); |
|
129 | - } |
|
130 | - } else { |
|
131 | - return $tree; |
|
132 | - } |
|
133 | - $value = null; |
|
134 | - return $value; |
|
135 | - } |
|
119 | + protected static function & nested(array & $tree, array $parts) |
|
120 | + { |
|
121 | + if (!empty($parts)) { |
|
122 | + $part = array_shift($parts); |
|
123 | + if (empty($tree[$part])) { |
|
124 | + return $tree[$part]; |
|
125 | + } elseif (empty($parts)) { |
|
126 | + return static::nested($tree[$part], $parts); |
|
127 | + } elseif (!empty($tree[$part]['children'])) { |
|
128 | + return static::nested($tree[$part]['children'], $parts); |
|
129 | + } |
|
130 | + } else { |
|
131 | + return $tree; |
|
132 | + } |
|
133 | + $value = null; |
|
134 | + return $value; |
|
135 | + } |
|
136 | 136 | |
137 | - public static function addUrls(array $urls) |
|
138 | - { |
|
139 | - foreach ($urls as $url => $label) { |
|
140 | - $trail = null; |
|
141 | - if (is_array($label)) { |
|
142 | - if (isset($label['trail'])) { |
|
143 | - $trail = $label['trail']; |
|
144 | - } |
|
145 | - if (isset($label['url'])) { |
|
146 | - $url = $label['url']; |
|
147 | - $label = isset($label['label']) ? $label['label'] : null; |
|
148 | - } else { |
|
149 | - $url = current(array_keys($label)); |
|
150 | - $label = current($label); |
|
151 | - } |
|
137 | + public static function addUrls(array $urls) |
|
138 | + { |
|
139 | + foreach ($urls as $url => $label) { |
|
140 | + $trail = null; |
|
141 | + if (is_array($label)) { |
|
142 | + if (isset($label['trail'])) { |
|
143 | + $trail = $label['trail']; |
|
144 | + } |
|
145 | + if (isset($label['url'])) { |
|
146 | + $url = $label['url']; |
|
147 | + $label = isset($label['label']) ? $label['label'] : null; |
|
148 | + } else { |
|
149 | + $url = current(array_keys($label)); |
|
150 | + $label = current($label); |
|
151 | + } |
|
152 | 152 | |
153 | - } |
|
154 | - if (is_numeric($url)) { |
|
155 | - $url = $label; |
|
156 | - $label = null; |
|
157 | - } |
|
158 | - static::add($url, $label, $trail); |
|
159 | - } |
|
160 | - return static::$tree; |
|
161 | - } |
|
153 | + } |
|
154 | + if (is_numeric($url)) { |
|
155 | + $url = $label; |
|
156 | + $label = null; |
|
157 | + } |
|
158 | + static::add($url, $label, $trail); |
|
159 | + } |
|
160 | + return static::$tree; |
|
161 | + } |
|
162 | 162 | |
163 | - public static function add($url, $label = null, $trail = null) |
|
164 | - { |
|
165 | - $r = parse_url($url); |
|
166 | - if (is_null($trail)) { |
|
167 | - $trail = isset($r['path']) ? $r['path'] : static::$root; |
|
168 | - } |
|
169 | - //remove / prefix and / suffixes and any extension |
|
170 | - $trail = strtok(trim($trail, '/'), '.'); |
|
171 | - $parts = explode('/', $trail); |
|
172 | - if (count($parts) == 1 && empty($parts[0])) |
|
173 | - $parts = array(static::$root); |
|
174 | - if (isset($r['fragment'])) { |
|
175 | - $parts[] = $r['fragment']; |
|
176 | - if (is_null($label)) { |
|
177 | - $label = Text::title($r['fragment']); |
|
178 | - } |
|
179 | - } |
|
180 | - if (empty($r['scheme'])) { |
|
181 | - //relative url found |
|
182 | - if (empty($url)) { |
|
183 | - $label = Text::title(static::$root); |
|
184 | - $url = static::$url; |
|
185 | - } else { |
|
186 | - $url = static::$url . '/' . ltrim($url, '/'); |
|
187 | - } |
|
188 | - } |
|
189 | - if (is_null($label)) { |
|
190 | - $label = Text::title(strtok(end($parts), '.')); |
|
191 | - } |
|
192 | - $r['url'] = $url; |
|
193 | - $r['path'] = $trail; |
|
194 | - $r['parts'] = $parts; |
|
195 | - $r['label'] = $label; |
|
196 | - static::build($r); |
|
197 | - return $r; |
|
198 | - } |
|
163 | + public static function add($url, $label = null, $trail = null) |
|
164 | + { |
|
165 | + $r = parse_url($url); |
|
166 | + if (is_null($trail)) { |
|
167 | + $trail = isset($r['path']) ? $r['path'] : static::$root; |
|
168 | + } |
|
169 | + //remove / prefix and / suffixes and any extension |
|
170 | + $trail = strtok(trim($trail, '/'), '.'); |
|
171 | + $parts = explode('/', $trail); |
|
172 | + if (count($parts) == 1 && empty($parts[0])) |
|
173 | + $parts = array(static::$root); |
|
174 | + if (isset($r['fragment'])) { |
|
175 | + $parts[] = $r['fragment']; |
|
176 | + if (is_null($label)) { |
|
177 | + $label = Text::title($r['fragment']); |
|
178 | + } |
|
179 | + } |
|
180 | + if (empty($r['scheme'])) { |
|
181 | + //relative url found |
|
182 | + if (empty($url)) { |
|
183 | + $label = Text::title(static::$root); |
|
184 | + $url = static::$url; |
|
185 | + } else { |
|
186 | + $url = static::$url . '/' . ltrim($url, '/'); |
|
187 | + } |
|
188 | + } |
|
189 | + if (is_null($label)) { |
|
190 | + $label = Text::title(strtok(end($parts), '.')); |
|
191 | + } |
|
192 | + $r['url'] = $url; |
|
193 | + $r['path'] = $trail; |
|
194 | + $r['parts'] = $parts; |
|
195 | + $r['label'] = $label; |
|
196 | + static::build($r); |
|
197 | + return $r; |
|
198 | + } |
|
199 | 199 | |
200 | - public static function build(array $r) |
|
201 | - { |
|
202 | - $p = & static::$tree; |
|
203 | - $parts = $r['parts']; |
|
204 | - $last = count($parts) - 1; |
|
205 | - foreach ($parts as $i => $part) { |
|
206 | - if ($i == $last) { |
|
207 | - $p[$part]['text'] = $r['label']; |
|
208 | - $p[$part]['href'] = $r['url']; |
|
209 | - $p[$part]['class'] = Text::slug($part); |
|
210 | - /* dynamically do it at run time instead |
|
200 | + public static function build(array $r) |
|
201 | + { |
|
202 | + $p = & static::$tree; |
|
203 | + $parts = $r['parts']; |
|
204 | + $last = count($parts) - 1; |
|
205 | + foreach ($parts as $i => $part) { |
|
206 | + if ($i == $last) { |
|
207 | + $p[$part]['text'] = $r['label']; |
|
208 | + $p[$part]['href'] = $r['url']; |
|
209 | + $p[$part]['class'] = Text::slug($part); |
|
210 | + /* dynamically do it at run time instead |
|
211 | 211 | if ($r['path'] == static::$activeTrail) |
212 | 212 | $p[$part]['active'] = true; |
213 | 213 | */ |
214 | - } elseif (!isset($p[$part])) { |
|
215 | - $p[$part] = array(); |
|
216 | - $p[$part]['text'] = Text::title($part); |
|
217 | - $p[$part]['href'] = '#'; |
|
218 | - $p[$part]['children'] = array(); |
|
219 | - } |
|
220 | - $p = & $p[$part]['children']; |
|
221 | - } |
|
222 | - } |
|
214 | + } elseif (!isset($p[$part])) { |
|
215 | + $p[$part] = array(); |
|
216 | + $p[$part]['text'] = Text::title($part); |
|
217 | + $p[$part]['href'] = '#'; |
|
218 | + $p[$part]['children'] = array(); |
|
219 | + } |
|
220 | + $p = & $p[$part]['children']; |
|
221 | + } |
|
222 | + } |
|
223 | 223 | } |