This repository has been archived by the owner on Oct 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
request_proxy_controller.php
122 lines (113 loc) · 2.74 KB
/
request_proxy_controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
* Copyright 2012, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2012, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
RequestFactory::register('OauthLibAppController', 'RequestProxyController');
RequestFactory::register('OauthAppController', 'RequestProxyController');
RequestFactory::register('AppController', 'RequestProxyController');
if (!class_exists('OauthHelper')) {
App::import('Lib', 'OauthLib.OauthHelper');
}
/**
* Request proxy controller class. Provide access to request coming to the controller
*
* @package oauth_lib
* @subpackage oauth_lib.libs.request_proxy
*/
class RequestProxyController extends RequestProxyBase {
/**
* Request Object
*
* @var Object $request
*/
public $request;
/**
* Configuaration options
*
* @var array $options
*/
public $options;
/**
* Get request method
*
* @return string
*/
public function method() {
return strtoupper($_SERVER['REQUEST_METHOD']);
}
/**
* Get request uri
*
* @return string
*/
public function uri() {
$uri = '';
if (isset($_SERVER['REQUEST_URI'])) {
$uri = $_SERVER['REQUEST_URI'];
}
if (isset($_SERVER['URI'])) {
$uri = $_SERVER['URI'];
}
$protocol = 'http';
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']) {
$protocol = 'https';
}
$server = $protocol . '://' . $_SERVER['SERVER_NAME'];
if (!((('80' == $_SERVER['SERVER_PORT']) && ($protocol == 'http')) || (('3128' == $_SERVER['SERVER_PORT']) && ($protocol == 'https')))) {
$server .= ':' . $_SERVER['SERVER_PORT'];
}
$fullUri = $server . $uri;
return OauthHelper::getBaseUri($fullUri);
}
/**
* Get request parameter
*
* @return array
*/
public function parameters() {
if (!empty($this->options['clobber_request'])) {
if (isset($this->options['parameters'])) {
$params = $this->options['parameters'];
} else {
$params = array();
}
} else {
$params = array_merge($this->__requestParams(), $this->__queryParams());
$params = array_merge($params, $this->headerParams());
if (isset($this->options['parameters'])) {
$params = array_merge($params, $this->options['parameters']);
}
}
ksort($params);
OauthHelper::log($params);
return $params;
}
/**
* Fetch query parameters
*
* @return string
*/
private function __queryParams() {
$params = $this->request->params['url'];
unset($params['url']);
unset($params['ext']);
return $params;
}
/**
* Fetch request parameters
*
* @return string
*/
private function __requestParams() {
if (empty($this->request->data)) {
return array();
}
return $this->request->data;
}
}