@@ -14,77 +14,77 @@ |
||
14 | 14 | */ |
15 | 15 | class PassThrough |
16 | 16 | { |
17 | - public static $mimeTypes = array( |
|
18 | - 'js' => 'text/javascript', |
|
19 | - 'css' => 'text/css', |
|
20 | - 'png' => 'image/png', |
|
21 | - 'jpg' => 'image/jpeg', |
|
22 | - 'gif' => 'image/gif', |
|
23 | - 'html' => 'text/html', |
|
24 | - ); |
|
17 | + public static $mimeTypes = array( |
|
18 | + 'js' => 'text/javascript', |
|
19 | + 'css' => 'text/css', |
|
20 | + 'png' => 'image/png', |
|
21 | + 'jpg' => 'image/jpeg', |
|
22 | + 'gif' => 'image/gif', |
|
23 | + 'html' => 'text/html', |
|
24 | + ); |
|
25 | 25 | |
26 | - /** |
|
27 | - * Serve a file outside web root |
|
28 | - * |
|
29 | - * Respond with a file stored outside web accessible path |
|
30 | - * |
|
31 | - * @param string $filename full path for the file to be served |
|
32 | - * @param bool $forceDownload should the we download instead of viewing |
|
33 | - * @param int $expires cache expiry in number of seconds |
|
34 | - * @param bool $isPublic cache control, is it public or private |
|
35 | - * |
|
36 | - * @throws RestException |
|
37 | - * |
|
38 | - */ |
|
39 | - public static function file($filename, $forceDownload = false, $expires = 0, $isPublic = true) |
|
40 | - { |
|
41 | - if (!is_file($filename)) |
|
42 | - throw new RestException(404); |
|
43 | - if (!is_readable($filename)) |
|
44 | - throw new RestException(403); |
|
45 | - $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); |
|
46 | - if (!$mime = Util::nestedValue(static::$mimeTypes, $extension)) { |
|
47 | - if (!function_exists('finfo_open')) { |
|
48 | - throw new RestException( |
|
49 | - 500, |
|
50 | - 'Unable to find media type of ' . |
|
51 | - basename($filename) . |
|
52 | - ' either enable fileinfo php extension or update ' . |
|
53 | - 'PassThrough::$mimeTypes to include mime type for ' . $extension . |
|
54 | - ' extension' |
|
55 | - ); |
|
56 | - } |
|
57 | - $finfo = finfo_open(FILEINFO_MIME_TYPE); |
|
58 | - $mime = finfo_file($finfo, $filename); |
|
59 | - } |
|
60 | - if (!is_array(Defaults::$headerCacheControl)) |
|
61 | - Defaults::$headerCacheControl = array(Defaults::$headerCacheControl); |
|
62 | - $cacheControl = Defaults::$headerCacheControl[0]; |
|
63 | - if ($expires > 0) { |
|
64 | - $cacheControl = $isPublic ? 'public' : 'private'; |
|
65 | - $cacheControl .= end(Defaults::$headerCacheControl); |
|
66 | - $cacheControl = str_replace('{expires}', $expires, $cacheControl); |
|
67 | - $expires = gmdate('D, d M Y H:i:s \G\M\T', time() + $expires); |
|
68 | - } |
|
69 | - header('Cache-Control: ' . $cacheControl); |
|
70 | - header('Expires: ' . $expires); |
|
71 | - $lastModified = filemtime($filename); |
|
72 | - if ( |
|
73 | - isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && |
|
74 | - strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $lastModified |
|
75 | - ) { |
|
76 | - header("{$_SERVER['SERVER_PROTOCOL']} 304 Not Modified"); |
|
77 | - exit; |
|
78 | - } |
|
79 | - header('Last-Modified: ' . date('r', $lastModified)); |
|
80 | - header('X-Powered-By: Luracast Restler v' . Restler::VERSION); |
|
81 | - header('Content-type: ' . $mime); |
|
82 | - header("Content-Length: " . filesize($filename)); |
|
83 | - if ($forceDownload) { |
|
84 | - header("Content-Transfer-Encoding: binary"); |
|
85 | - header('Content-Disposition: attachment; filename="' . $filename . '"'); |
|
86 | - } |
|
87 | - readfile($filename); |
|
88 | - exit; |
|
89 | - } |
|
26 | + /** |
|
27 | + * Serve a file outside web root |
|
28 | + * |
|
29 | + * Respond with a file stored outside web accessible path |
|
30 | + * |
|
31 | + * @param string $filename full path for the file to be served |
|
32 | + * @param bool $forceDownload should the we download instead of viewing |
|
33 | + * @param int $expires cache expiry in number of seconds |
|
34 | + * @param bool $isPublic cache control, is it public or private |
|
35 | + * |
|
36 | + * @throws RestException |
|
37 | + * |
|
38 | + */ |
|
39 | + public static function file($filename, $forceDownload = false, $expires = 0, $isPublic = true) |
|
40 | + { |
|
41 | + if (!is_file($filename)) |
|
42 | + throw new RestException(404); |
|
43 | + if (!is_readable($filename)) |
|
44 | + throw new RestException(403); |
|
45 | + $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); |
|
46 | + if (!$mime = Util::nestedValue(static::$mimeTypes, $extension)) { |
|
47 | + if (!function_exists('finfo_open')) { |
|
48 | + throw new RestException( |
|
49 | + 500, |
|
50 | + 'Unable to find media type of ' . |
|
51 | + basename($filename) . |
|
52 | + ' either enable fileinfo php extension or update ' . |
|
53 | + 'PassThrough::$mimeTypes to include mime type for ' . $extension . |
|
54 | + ' extension' |
|
55 | + ); |
|
56 | + } |
|
57 | + $finfo = finfo_open(FILEINFO_MIME_TYPE); |
|
58 | + $mime = finfo_file($finfo, $filename); |
|
59 | + } |
|
60 | + if (!is_array(Defaults::$headerCacheControl)) |
|
61 | + Defaults::$headerCacheControl = array(Defaults::$headerCacheControl); |
|
62 | + $cacheControl = Defaults::$headerCacheControl[0]; |
|
63 | + if ($expires > 0) { |
|
64 | + $cacheControl = $isPublic ? 'public' : 'private'; |
|
65 | + $cacheControl .= end(Defaults::$headerCacheControl); |
|
66 | + $cacheControl = str_replace('{expires}', $expires, $cacheControl); |
|
67 | + $expires = gmdate('D, d M Y H:i:s \G\M\T', time() + $expires); |
|
68 | + } |
|
69 | + header('Cache-Control: ' . $cacheControl); |
|
70 | + header('Expires: ' . $expires); |
|
71 | + $lastModified = filemtime($filename); |
|
72 | + if ( |
|
73 | + isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && |
|
74 | + strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $lastModified |
|
75 | + ) { |
|
76 | + header("{$_SERVER['SERVER_PROTOCOL']} 304 Not Modified"); |
|
77 | + exit; |
|
78 | + } |
|
79 | + header('Last-Modified: ' . date('r', $lastModified)); |
|
80 | + header('X-Powered-By: Luracast Restler v' . Restler::VERSION); |
|
81 | + header('Content-type: ' . $mime); |
|
82 | + header("Content-Length: " . filesize($filename)); |
|
83 | + if ($forceDownload) { |
|
84 | + header("Content-Transfer-Encoding: binary"); |
|
85 | + header('Content-Disposition: attachment; filename="' . $filename . '"'); |
|
86 | + } |
|
87 | + readfile($filename); |
|
88 | + exit; |
|
89 | + } |
|
90 | 90 | } |
91 | 91 | \ No newline at end of file |
@@ -16,48 +16,48 @@ |
||
16 | 16 | */ |
17 | 17 | interface iIdentifyUser |
18 | 18 | { |
19 | - /** |
|
20 | - * A way to uniquely identify the current api consumer |
|
21 | - * |
|
22 | - * When his user id is known it should be used otherwise ip address |
|
23 | - * can be used |
|
24 | - * |
|
25 | - * @param bool $includePlatform Should we consider user alone or should |
|
26 | - * consider the application/platform/device |
|
27 | - * as well for generating unique id |
|
28 | - * |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public static function getUniqueIdentifier($includePlatform = false); |
|
19 | + /** |
|
20 | + * A way to uniquely identify the current api consumer |
|
21 | + * |
|
22 | + * When his user id is known it should be used otherwise ip address |
|
23 | + * can be used |
|
24 | + * |
|
25 | + * @param bool $includePlatform Should we consider user alone or should |
|
26 | + * consider the application/platform/device |
|
27 | + * as well for generating unique id |
|
28 | + * |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public static function getUniqueIdentifier($includePlatform = false); |
|
32 | 32 | |
33 | - /** |
|
34 | - * User identity to be used for caching purpose |
|
35 | - * |
|
36 | - * When the dynamic cache service places an object in the cache, it needs to |
|
37 | - * label it with a unique identifying string known as a cache ID. This |
|
38 | - * method gives that identifier |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public static function getCacheIdentifier(); |
|
33 | + /** |
|
34 | + * User identity to be used for caching purpose |
|
35 | + * |
|
36 | + * When the dynamic cache service places an object in the cache, it needs to |
|
37 | + * label it with a unique identifying string known as a cache ID. This |
|
38 | + * method gives that identifier |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public static function getCacheIdentifier(); |
|
43 | 43 | |
44 | - /** |
|
45 | - * Authentication classes should call this method |
|
46 | - * |
|
47 | - * @param string $id user id as identified by the authentication classes |
|
48 | - * |
|
49 | - * @return void |
|
50 | - */ |
|
51 | - public static function setUniqueIdentifier($id); |
|
44 | + /** |
|
45 | + * Authentication classes should call this method |
|
46 | + * |
|
47 | + * @param string $id user id as identified by the authentication classes |
|
48 | + * |
|
49 | + * @return void |
|
50 | + */ |
|
51 | + public static function setUniqueIdentifier($id); |
|
52 | 52 | |
53 | - /** |
|
54 | - * User identity for caching purpose |
|
55 | - * |
|
56 | - * In a role based access control system this will be based on role |
|
57 | - * |
|
58 | - * @param $id |
|
59 | - * |
|
60 | - * @return void |
|
61 | - */ |
|
62 | - public static function setCacheIdentifier($id); |
|
53 | + /** |
|
54 | + * User identity for caching purpose |
|
55 | + * |
|
56 | + * In a role based access control system this will be based on role |
|
57 | + * |
|
58 | + * @param $id |
|
59 | + * |
|
60 | + * @return void |
|
61 | + */ |
|
62 | + public static function setCacheIdentifier($id); |
|
63 | 63 | } |
64 | 64 | \ No newline at end of file |
@@ -15,86 +15,86 @@ |
||
15 | 15 | */ |
16 | 16 | class User implements iIdentifyUser |
17 | 17 | { |
18 | - private static $initialized = false; |
|
19 | - public static $id = null; |
|
20 | - public static $cacheId = null; |
|
21 | - public static $ip; |
|
22 | - public static $browser = ''; |
|
23 | - public static $platform = ''; |
|
18 | + private static $initialized = false; |
|
19 | + public static $id = null; |
|
20 | + public static $cacheId = null; |
|
21 | + public static $ip; |
|
22 | + public static $browser = ''; |
|
23 | + public static $platform = ''; |
|
24 | 24 | |
25 | - public static function init() |
|
26 | - { |
|
27 | - static::$initialized = true; |
|
28 | - static::$ip = static::getIpAddress(); |
|
29 | - } |
|
25 | + public static function init() |
|
26 | + { |
|
27 | + static::$initialized = true; |
|
28 | + static::$ip = static::getIpAddress(); |
|
29 | + } |
|
30 | 30 | |
31 | - public static function getUniqueIdentifier($includePlatform = false) |
|
32 | - { |
|
33 | - if (!static::$initialized) static::init(); |
|
34 | - return static::$id ? : base64_encode('ip:' . ($includePlatform |
|
35 | - ? static::$ip . '-' . static::$platform |
|
36 | - : static::$ip |
|
37 | - )); |
|
38 | - } |
|
31 | + public static function getUniqueIdentifier($includePlatform = false) |
|
32 | + { |
|
33 | + if (!static::$initialized) static::init(); |
|
34 | + return static::$id ? : base64_encode('ip:' . ($includePlatform |
|
35 | + ? static::$ip . '-' . static::$platform |
|
36 | + : static::$ip |
|
37 | + )); |
|
38 | + } |
|
39 | 39 | |
40 | - public static function getIpAddress($ignoreProxies = false) |
|
41 | - { |
|
42 | - foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', |
|
43 | - 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', |
|
44 | - 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', |
|
45 | - 'REMOTE_ADDR') as $key) { |
|
46 | - if (array_key_exists($key, $_SERVER) === true) { |
|
47 | - foreach (explode(',', $_SERVER[$key]) as $ip) { |
|
48 | - $ip = trim($ip); // just to be safe |
|
40 | + public static function getIpAddress($ignoreProxies = false) |
|
41 | + { |
|
42 | + foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', |
|
43 | + 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', |
|
44 | + 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', |
|
45 | + 'REMOTE_ADDR') as $key) { |
|
46 | + if (array_key_exists($key, $_SERVER) === true) { |
|
47 | + foreach (explode(',', $_SERVER[$key]) as $ip) { |
|
48 | + $ip = trim($ip); // just to be safe |
|
49 | 49 | |
50 | - if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 |
|
51 | - | FILTER_FLAG_NO_PRIV_RANGE |
|
52 | - | FILTER_FLAG_NO_RES_RANGE) !== false |
|
53 | - ) { |
|
54 | - return $ip; |
|
55 | - } |
|
56 | - } |
|
57 | - } |
|
58 | - } |
|
59 | - } |
|
50 | + if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 |
|
51 | + | FILTER_FLAG_NO_PRIV_RANGE |
|
52 | + | FILTER_FLAG_NO_RES_RANGE) !== false |
|
53 | + ) { |
|
54 | + return $ip; |
|
55 | + } |
|
56 | + } |
|
57 | + } |
|
58 | + } |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Authentication classes should call this method |
|
63 | - * |
|
64 | - * @param string $id user id as identified by the authentication classes |
|
65 | - * |
|
66 | - * @return void |
|
67 | - */ |
|
68 | - public static function setUniqueIdentifier($id) |
|
69 | - { |
|
70 | - static::$id = $id; |
|
71 | - } |
|
61 | + /** |
|
62 | + * Authentication classes should call this method |
|
63 | + * |
|
64 | + * @param string $id user id as identified by the authentication classes |
|
65 | + * |
|
66 | + * @return void |
|
67 | + */ |
|
68 | + public static function setUniqueIdentifier($id) |
|
69 | + { |
|
70 | + static::$id = $id; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * User identity to be used for caching purpose |
|
75 | - * |
|
76 | - * When the dynamic cache service places an object in the cache, it needs to |
|
77 | - * label it with a unique identifying string known as a cache ID. This |
|
78 | - * method gives that identifier |
|
79 | - * |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public static function getCacheIdentifier() |
|
83 | - { |
|
84 | - return static::$cacheId ?: static::$id; |
|
85 | - } |
|
73 | + /** |
|
74 | + * User identity to be used for caching purpose |
|
75 | + * |
|
76 | + * When the dynamic cache service places an object in the cache, it needs to |
|
77 | + * label it with a unique identifying string known as a cache ID. This |
|
78 | + * method gives that identifier |
|
79 | + * |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public static function getCacheIdentifier() |
|
83 | + { |
|
84 | + return static::$cacheId ?: static::$id; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * User identity for caching purpose |
|
89 | - * |
|
90 | - * In a role based access control system this will be based on role |
|
91 | - * |
|
92 | - * @param $id |
|
93 | - * |
|
94 | - * @return void |
|
95 | - */ |
|
96 | - public static function setCacheIdentifier($id) |
|
97 | - { |
|
98 | - static::$cacheId = $id; |
|
99 | - } |
|
87 | + /** |
|
88 | + * User identity for caching purpose |
|
89 | + * |
|
90 | + * In a role based access control system this will be based on role |
|
91 | + * |
|
92 | + * @param $id |
|
93 | + * |
|
94 | + * @return void |
|
95 | + */ |
|
96 | + public static function setCacheIdentifier($id) |
|
97 | + { |
|
98 | + static::$cacheId = $id; |
|
99 | + } |
|
100 | 100 | } |
@@ -19,156 +19,156 @@ |
||
19 | 19 | */ |
20 | 20 | class Flash implements ArrayAccess |
21 | 21 | { |
22 | - const SUCCESS = 'success'; |
|
23 | - const INFO = 'info'; |
|
24 | - const WARNING = 'warning'; |
|
25 | - const DANGER = 'danger'; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var Flash |
|
29 | - */ |
|
30 | - private static $instance; |
|
31 | - private $usedOnce = false; |
|
32 | - |
|
33 | - /** |
|
34 | - * Flash a success message to user |
|
35 | - * |
|
36 | - * @param string $message |
|
37 | - * @param string $header |
|
38 | - * |
|
39 | - * @return Flash |
|
40 | - */ |
|
41 | - public static function success($message, $header = '') |
|
42 | - { |
|
43 | - return static::message($message, $header, Flash::SUCCESS); |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Flash a info message to user |
|
48 | - * |
|
49 | - * @param string $message |
|
50 | - * @param string $header |
|
51 | - * |
|
52 | - * @return Flash |
|
53 | - */ |
|
54 | - public static function info($message, $header = '') |
|
55 | - { |
|
56 | - return static::message($message, $header, Flash::INFO); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Flash a warning message to user |
|
61 | - * |
|
62 | - * @param string $message |
|
63 | - * @param string $header |
|
64 | - * |
|
65 | - * @return Flash |
|
66 | - */ |
|
67 | - public static function warning($message, $header = '') |
|
68 | - { |
|
69 | - return static::message($message, $header, Flash::WARNING); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Flash a error message to user |
|
74 | - * |
|
75 | - * @param string $message |
|
76 | - * @param string $header |
|
77 | - * |
|
78 | - * @return Flash |
|
79 | - */ |
|
80 | - public static function danger($message, $header = '') |
|
81 | - { |
|
82 | - return static::message($message, $header, Flash::DANGER); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Flash a message to user |
|
87 | - * |
|
88 | - * @param string $text message text |
|
89 | - * @param string $header |
|
90 | - * @param string $type |
|
91 | - * |
|
92 | - * @return Flash |
|
93 | - */ |
|
94 | - public static function message($text, $header = '', $type = Flash::WARNING) |
|
95 | - { |
|
96 | - return static::set(array('message' => $text, 'header' => $header, 'type' => $type)); |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Set some data for one time use |
|
101 | - * |
|
102 | - * @param array $data array of key value pairs {@type associative} |
|
103 | - * |
|
104 | - * @return Flash |
|
105 | - */ |
|
106 | - public static function set(array $data) |
|
107 | - { |
|
108 | - if (!static::$instance) { |
|
109 | - static::$instance = new Flash(); |
|
110 | - } |
|
111 | - if (!isset($_SESSION['flash'])) { |
|
112 | - $_SESSION['flash'] = array(); |
|
113 | - } |
|
114 | - $_SESSION['flash'] += $data; |
|
115 | - HtmlFormat::$data['flash'] = static::$instance; |
|
116 | - |
|
117 | - return static::$instance; |
|
118 | - } |
|
119 | - |
|
120 | - public function __get($name) |
|
121 | - { |
|
122 | - $this->usedOnce = true; |
|
123 | - |
|
124 | - return Util::nestedValue($_SESSION, 'flash', $name); |
|
125 | - } |
|
126 | - |
|
127 | - public function __isset($name) |
|
128 | - { |
|
129 | - return !is_null(Util::nestedValue($_SESSION, 'flash', $name)); |
|
130 | - } |
|
131 | - |
|
132 | - public function __destruct() |
|
133 | - { |
|
134 | - if ($this->usedOnce) { |
|
135 | - unset($_SESSION['flash']); |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Specify data which should be serialized to JSON |
|
141 | - * @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
|
142 | - * @return mixed data which can be serialized by <b>json_encode</b>, |
|
143 | - * which is a value of any type other than a resource. |
|
144 | - */ |
|
145 | - public function jsonSerialize() |
|
146 | - { |
|
147 | - $this->usedOnce = true; |
|
148 | - |
|
149 | - return isset($_SESSION['flash']) |
|
150 | - ? $_SESSION['flash'] |
|
151 | - : array(); |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - public function offsetExists($offset) |
|
156 | - { |
|
157 | - return $this->__isset($offset); |
|
158 | - } |
|
159 | - |
|
160 | - public function offsetGet($offset) |
|
161 | - { |
|
162 | - return $this->__get($offset); |
|
163 | - } |
|
164 | - |
|
165 | - public function offsetSet($offset, $value) |
|
166 | - { |
|
167 | - //not implemented |
|
168 | - } |
|
169 | - |
|
170 | - public function offsetUnset($offset) |
|
171 | - { |
|
172 | - //not implemented |
|
173 | - } |
|
22 | + const SUCCESS = 'success'; |
|
23 | + const INFO = 'info'; |
|
24 | + const WARNING = 'warning'; |
|
25 | + const DANGER = 'danger'; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var Flash |
|
29 | + */ |
|
30 | + private static $instance; |
|
31 | + private $usedOnce = false; |
|
32 | + |
|
33 | + /** |
|
34 | + * Flash a success message to user |
|
35 | + * |
|
36 | + * @param string $message |
|
37 | + * @param string $header |
|
38 | + * |
|
39 | + * @return Flash |
|
40 | + */ |
|
41 | + public static function success($message, $header = '') |
|
42 | + { |
|
43 | + return static::message($message, $header, Flash::SUCCESS); |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Flash a info message to user |
|
48 | + * |
|
49 | + * @param string $message |
|
50 | + * @param string $header |
|
51 | + * |
|
52 | + * @return Flash |
|
53 | + */ |
|
54 | + public static function info($message, $header = '') |
|
55 | + { |
|
56 | + return static::message($message, $header, Flash::INFO); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Flash a warning message to user |
|
61 | + * |
|
62 | + * @param string $message |
|
63 | + * @param string $header |
|
64 | + * |
|
65 | + * @return Flash |
|
66 | + */ |
|
67 | + public static function warning($message, $header = '') |
|
68 | + { |
|
69 | + return static::message($message, $header, Flash::WARNING); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Flash a error message to user |
|
74 | + * |
|
75 | + * @param string $message |
|
76 | + * @param string $header |
|
77 | + * |
|
78 | + * @return Flash |
|
79 | + */ |
|
80 | + public static function danger($message, $header = '') |
|
81 | + { |
|
82 | + return static::message($message, $header, Flash::DANGER); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Flash a message to user |
|
87 | + * |
|
88 | + * @param string $text message text |
|
89 | + * @param string $header |
|
90 | + * @param string $type |
|
91 | + * |
|
92 | + * @return Flash |
|
93 | + */ |
|
94 | + public static function message($text, $header = '', $type = Flash::WARNING) |
|
95 | + { |
|
96 | + return static::set(array('message' => $text, 'header' => $header, 'type' => $type)); |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Set some data for one time use |
|
101 | + * |
|
102 | + * @param array $data array of key value pairs {@type associative} |
|
103 | + * |
|
104 | + * @return Flash |
|
105 | + */ |
|
106 | + public static function set(array $data) |
|
107 | + { |
|
108 | + if (!static::$instance) { |
|
109 | + static::$instance = new Flash(); |
|
110 | + } |
|
111 | + if (!isset($_SESSION['flash'])) { |
|
112 | + $_SESSION['flash'] = array(); |
|
113 | + } |
|
114 | + $_SESSION['flash'] += $data; |
|
115 | + HtmlFormat::$data['flash'] = static::$instance; |
|
116 | + |
|
117 | + return static::$instance; |
|
118 | + } |
|
119 | + |
|
120 | + public function __get($name) |
|
121 | + { |
|
122 | + $this->usedOnce = true; |
|
123 | + |
|
124 | + return Util::nestedValue($_SESSION, 'flash', $name); |
|
125 | + } |
|
126 | + |
|
127 | + public function __isset($name) |
|
128 | + { |
|
129 | + return !is_null(Util::nestedValue($_SESSION, 'flash', $name)); |
|
130 | + } |
|
131 | + |
|
132 | + public function __destruct() |
|
133 | + { |
|
134 | + if ($this->usedOnce) { |
|
135 | + unset($_SESSION['flash']); |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Specify data which should be serialized to JSON |
|
141 | + * @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
|
142 | + * @return mixed data which can be serialized by <b>json_encode</b>, |
|
143 | + * which is a value of any type other than a resource. |
|
144 | + */ |
|
145 | + public function jsonSerialize() |
|
146 | + { |
|
147 | + $this->usedOnce = true; |
|
148 | + |
|
149 | + return isset($_SESSION['flash']) |
|
150 | + ? $_SESSION['flash'] |
|
151 | + : array(); |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + public function offsetExists($offset) |
|
156 | + { |
|
157 | + return $this->__isset($offset); |
|
158 | + } |
|
159 | + |
|
160 | + public function offsetGet($offset) |
|
161 | + { |
|
162 | + return $this->__get($offset); |
|
163 | + } |
|
164 | + |
|
165 | + public function offsetSet($offset, $value) |
|
166 | + { |
|
167 | + //not implemented |
|
168 | + } |
|
169 | + |
|
170 | + public function offsetUnset($offset) |
|
171 | + { |
|
172 | + //not implemented |
|
173 | + } |
|
174 | 174 | } |
175 | 175 | \ No newline at end of file |
@@ -16,15 +16,15 @@ |
||
16 | 16 | */ |
17 | 17 | interface iFilter |
18 | 18 | { |
19 | - /** |
|
20 | - * Access verification method. |
|
21 | - * |
|
22 | - * API access will be denied when this method returns false |
|
23 | - * |
|
24 | - * @abstract |
|
25 | - * @return boolean true when api access is allowed false otherwise |
|
26 | - */ |
|
27 | - public function __isAllowed(); |
|
19 | + /** |
|
20 | + * Access verification method. |
|
21 | + * |
|
22 | + * API access will be denied when this method returns false |
|
23 | + * |
|
24 | + * @abstract |
|
25 | + * @return boolean true when api access is allowed false otherwise |
|
26 | + */ |
|
27 | + public function __isAllowed(); |
|
28 | 28 | |
29 | 29 | } |
30 | 30 |
@@ -6,5 +6,5 @@ |
||
6 | 6 | */ |
7 | 7 | interface iAuthenticate |
8 | 8 | { |
9 | - public function __isAuthenticated(); |
|
9 | + public function __isAuthenticated(); |
|
10 | 10 | } |
11 | 11 | \ No newline at end of file |
@@ -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> |