Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

http_parser.php
Go to the documentation of this file.
1 <?php
19 class ezpRestHttpRequestParser extends ezcMvcHttpRequestParser
20 {
24 protected $request;
25
31 protected function createRequestObject()
32 {
33 return new ezpRestRequest();
34 }
35
43 protected function processVariables()
44 {
45 $this->request->variables = $this->fillVariables();
46 $this->request->contentVariables = $this->fillContentVariables();
47 $this->request->get = $_GET;
48 $this->request->post = $_POST;
49 }
50
56 protected function processStandardHeaders()
57 {
58 $this->processEncryption();
59 parent::processStandardHeaders( );
60 }
61
67 protected function processEncryption()
68 {
69 if ( eZSys::isSSLNow() )
70 $this->request->isEncrypted = true;
71 }
72
76 protected function processBody()
77 {
78 $this->request->body = file_get_contents( "php://input" );
79 }
80
86 protected function fillVariables()
87 {
88 $variables = array();
89 $internalVariables = array( 'ResponseGroups' ); // Expected variables
90
91 foreach( $internalVariables as $internalVariable )
92 {
93 if( isset( $_GET[$internalVariable] ) )
94 {
95 // Extract and organize variables as expected
96 switch( $internalVariable )
97 {
98 case 'ResponseGroups':
99 $variables[$internalVariable] = explode( ',', $_GET[$internalVariable] );
100 break;
101
102 default:
103 $variables[$internalVariable] = $_GET[$internalVariable];
104 }
105
106 unset( $_GET[$internalVariable] );
107 }
108 else
109 {
110 switch( $internalVariable )
111 {
112 case 'ResponseGroups':
113 $variables[$internalVariable] = array();
114 break;
115
116 default:
117 $variables[$internalVariable] = null;
118 }
119 }
120 }
121
122 return $variables;
123 }
124
130 protected function fillContentVariables()
131 {
132 $contentVariables = array();
133 $expectedVariables = array( 'Translation', 'OutputFormat' );
134
135 foreach( $expectedVariables as $variable )
136 {
137 if( isset( $_GET[$variable] ) )
138 {
139 // Extract and organize variables as expected
140 switch( $variable )
141 {
142 case 'Translation': // @TODO => Make some control on the locale provided
143 default:
144 $contentVariables[$variable] = $_GET[$variable];
145 }
146
147 unset( $_GET[$variable] );
148 }
149 else
150 {
151 $contentVariables[$variable] = null;
152 }
153 }
154
155 return $contentVariables;
156 }
157
161 protected function processProtocol()
162 {
163 $req = $this->request;
164 $req->originalProtocol = $req->protocol = 'http-' . ( isset( $_SERVER['REQUEST_METHOD'] ) ? strtolower( $_SERVER['REQUEST_METHOD'] ) : "get" );
165
166 // Adds support for using POST for PUT and DELETE for legacy browsers that does not support these.
167 // If a post param "_method" is set to either PUT or DELETE, then ->protocol is changed to that.
168 // (original protocol is kept on ->originalProtocol param)
169 // Post is used as this is only meant for forms in legacy browsers.
170 if ( $req->protocol === 'http-post' && isset( $_POST['_method'] ) )
171 {
172 $method = strtolower( $_POST['_method'] );
173 if ( $method === 'put' || $method === 'delete' )
174 $req->protocol = "http-{$method}";
175
176 unset( $_POST['_method'] );
177 }
178 }
179
185 protected function processDate()
186 {
187 $this->request->date = isset( $_SERVER['REQUEST_TIME'] )
188 ? new DateTime( '@' . (int)$_SERVER['REQUEST_TIME'] )
189 : new DateTime();
190 }
191 }
eZSys\isSSLNow
static isSSLNow()
Definition: ezsys.php:745
ezpRestHttpRequestParser
Definition: http_parser.php:20
ezpRestHttpRequestParser\$request
$request
Definition: http_parser.php:24
ezpRestHttpRequestParser\processProtocol
processProtocol()
Definition: http_parser.php:161
ezpRestHttpRequestParser\processEncryption
processEncryption()
Definition: http_parser.php:67
ezpRestHttpRequestParser\processVariables
processVariables()
Definition: http_parser.php:43
ezpRestHttpRequestParser\fillVariables
fillVariables()
Definition: http_parser.php:86
ezpRestHttpRequestParser\processBody
processBody()
Definition: http_parser.php:76
ezpRestHttpRequestParser\processStandardHeaders
processStandardHeaders()
Definition: http_parser.php:56
ezpRestHttpRequestParser\fillContentVariables
fillContentVariables()
Definition: http_parser.php:130
ezpRestHttpRequestParser\processDate
processDate()
Definition: http_parser.php:185
ezpRestHttpRequestParser\createRequestObject
createRequestObject()
Definition: http_parser.php:31
ezpRestRequest
Definition: rest_request.php:21
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.