1
|
|
|
<?php |
2
|
|
|
namespace Agavi\Request; |
3
|
|
|
|
4
|
|
|
// +---------------------------------------------------------------------------+ |
5
|
|
|
// | This file is part of the Agavi package. | |
6
|
|
|
// | Copyright (c) 2005-2011 the Agavi Project. | |
7
|
|
|
// | | |
8
|
|
|
// | For the full copyright and license information, please view the LICENSE | |
9
|
|
|
// | file that was distributed with this source code. You can also view the | |
10
|
|
|
// | LICENSE file online at http://www.agavi.org/LICENSE.txt | |
11
|
|
|
// | vi: set noexpandtab: | |
12
|
|
|
// | Local Variables: | |
13
|
|
|
// | indent-tabs-mode: t | |
14
|
|
|
// | End: | |
15
|
|
|
// +---------------------------------------------------------------------------+ |
16
|
|
|
use Agavi\Core\Context; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* AgaviWebserviceRequest is the base class for Web Service requests |
20
|
|
|
* |
21
|
|
|
* @package agavi |
22
|
|
|
* @subpackage request |
23
|
|
|
* |
24
|
|
|
* @author David Zülke <[email protected]> |
25
|
|
|
* @copyright Authors |
26
|
|
|
* @copyright The Agavi Project |
27
|
|
|
* |
28
|
|
|
* @since 0.11.0 |
29
|
|
|
* |
30
|
|
|
* @version $Id$ |
31
|
|
|
*/ |
32
|
|
|
abstract class WebserviceRequest extends Request |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var string The Input Data. |
36
|
|
|
*/ |
37
|
|
|
protected $input = ''; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string The method called by the web service request. |
41
|
|
|
*/ |
42
|
|
|
protected $invokedMethod = ''; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Constructor. |
46
|
|
|
* |
47
|
|
|
* @author David Zülke <[email protected]> |
48
|
|
|
* @since 0.11.0 |
49
|
|
|
*/ |
50
|
|
|
public function __construct() |
51
|
|
|
{ |
52
|
|
|
parent::__construct(); |
53
|
|
|
$this->setParameters(array( |
54
|
|
|
'request_data_holder_class' => 'AgaviWebserviceRequestDataHolder', |
55
|
|
|
)); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Initialize this Request. |
60
|
|
|
* |
61
|
|
|
* @param Context $context A Context instance. |
62
|
|
|
* @param array $parameters An associative array of initialization parameters. |
63
|
|
|
* |
64
|
|
|
* @throws <b>AgaviInitializationException</b> If an error occurs while |
65
|
|
|
* initializing this Request. |
66
|
|
|
* |
67
|
|
|
* @author David Zülke <[email protected]> |
68
|
|
|
* @since 0.11.0 |
69
|
|
|
*/ |
70
|
|
|
public function initialize(Context $context, array $parameters = array()) |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
// empty $_POST just to be sure |
73
|
|
|
$_POST = array(); |
74
|
|
|
|
75
|
|
|
// grab the POST body |
76
|
|
|
$this->input = file_get_contents('php://input'); |
77
|
|
|
|
78
|
|
|
parent::initialize($context, $parameters); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Get the input data, usually the request from the POST body. |
83
|
|
|
* |
84
|
|
|
* @return string The input data. |
85
|
|
|
* |
86
|
|
|
* @author David Zülke <[email protected]> |
87
|
|
|
* @since 0.11.0 |
88
|
|
|
*/ |
89
|
|
|
public function getInput() |
90
|
|
|
{ |
91
|
|
|
return $this->input; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Set the input data. Useful for debugging purposes. |
96
|
|
|
* |
97
|
|
|
* @param string $input The input data. |
98
|
|
|
* |
99
|
|
|
* @author David Zülke <[email protected]> |
100
|
|
|
* @since 0.11.0 |
101
|
|
|
*/ |
102
|
|
|
public function setInput($input) |
103
|
|
|
{ |
104
|
|
|
$this->input = $input; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Set the name of the method called by the web service request. |
109
|
|
|
* |
110
|
|
|
* @return string $method A method name. |
111
|
|
|
* |
112
|
|
|
* @author David Zülke <[email protected]> |
113
|
|
|
* @since 0.11.0 |
114
|
|
|
*/ |
115
|
|
|
public function setInvokedMethod($method) |
116
|
|
|
{ |
117
|
|
|
$this->invokedMethod = $method; |
118
|
|
|
|
119
|
|
|
// let the routing update its input |
120
|
|
|
$this->context->getRouting()->updateInput(); |
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Get the name of the method called by the web service request. |
125
|
|
|
* |
126
|
|
|
* @return string A method name. |
127
|
|
|
* |
128
|
|
|
* @author David Zülke <[email protected]> |
129
|
|
|
* @since 0.11.0 |
130
|
|
|
*/ |
131
|
|
|
public function getInvokedMethod() |
132
|
|
|
{ |
133
|
|
|
return $this->invokedMethod; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: