ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\HTTP\Sapi Class Reference

PHP SAPI. More...

+ Inheritance diagram for Sabre\HTTP\Sapi:
+ Collaboration diagram for Sabre\HTTP\Sapi:

Static Public Member Functions

static getRequest ()
 This static method will create a new Request object, based on the current PHP request. More...
 
static sendResponse (ResponseInterface $response)
 Sends the HTTP response back to a HTTP client. More...
 
static createFromServerArray (array $serverArray)
 This static method will create a new Request object, based on a PHP $_SERVER array. More...
 

Detailed Description

PHP SAPI.

This object is responsible for:

  1. Constructing a Request object based on the current HTTP request sent to the PHP process.
  2. Sending the Response object back to the client.

It could be said that this class provides a mapping between the Request and Response objects, and php's:

  • $_SERVER
  • $_POST
  • $_FILES
  • php://input
  • echo()
  • header()
  • php://output

You can choose to either call all these methods statically, but you can also instantiate this as an object to allow for polymorhpism.

Author
Evert Pot (http://evertpot.com/) http://sabre.io/license/ Modified BSD License

Definition at line 31 of file Sapi.php.

Member Function Documentation

◆ createFromServerArray()

static Sabre\HTTP\Sapi::createFromServerArray ( array  $serverArray)
static

This static method will create a new Request object, based on a PHP $_SERVER array.

Parameters
array$serverArray
Returns
Request

Definition at line 107 of file Sapi.php.

References $header, $key, GuzzleHttp\Psr7\$protocol, $r, and $url.

Referenced by Sabre\DAV\Locks\MSWordTest\getLockRequest(), Sabre\DAV\Locks\MSWordTest\getLockRequest2(), Sabre\DAV\Locks\MSWordTest\getPutRequest(), Sabre\DAV\Property\SupportedReportSetTest\sendPROPFIND(), Sabre\CalDAV\Schedule\FreeBusyRequestTest\setUp(), Sabre\CalDAV\FreeBusyReportTest\setUp(), Sabre\DAV\GetIfConditionsTest\test2Etags(), Sabre\DAV\GetIfConditionsTest\test2LockTokens(), Sabre\DAV\GetIfConditionsTest\test2UriLockTokens(), Sabre\DAV\GetIfConditionsTest\test2UriMultiLockTokens(), Sabre\DAVACL\PluginAdminTest\testAdminAccess(), Sabre\DAV\ServerEventsTest\testAfterResponse(), Sabre\DAVACL\PrincipalPropertySearchTest\testAND(), Sabre\DAV\ServerSimpleTest\testBaseUri(), Sabre\DAV\ServerEventsTest\testBeforeBindCancel(), Sabre\DAV\HTTPPreferParsingTest\testBrief(), Sabre\DAV\Auth\Backend\BasicCallBackTest\testCallBack(), Sabre\DAV\Auth\Backend\AbstractDigestTest\testCheck(), Sabre\DAV\Auth\Backend\AbstractDigestTest\testCheckBadGetUserInfoResponse(), Sabre\DAV\Auth\Backend\AbstractDigestTest\testCheckBadGetUserInfoResponse2(), Sabre\DAV\Auth\Backend\AbstractDigestTest\testCheckBadPassword(), Sabre\DAV\Auth\Backend\AbstractBearerTest\testCheckInvalidToken(), Sabre\DAV\Auth\Backend\AbstractBasicTest\testCheckSuccess(), Sabre\DAV\Auth\Backend\AbstractBearerTest\testCheckSuccess(), Sabre\DAV\Auth\Backend\AbstractBasicTest\testCheckUnknownUser(), Sabre\DAV\Auth\Backend\AbstractDigestTest\testCheckUnknownUser(), Sabre\DAV\Browser\MapGetToPropFindTest\testCollectionGet(), Sabre\DAV\GetIfConditionsTest\testComplexIf(), Sabre\HTTP\SapiTest\testConstructFromServerArray(), Sabre\HTTP\SapiTest\testConstructPHPAuth(), Sabre\HTTP\SapiTest\testConstructPHPAuthDigest(), Sabre\HTTP\SapiTest\testConstructRedirectAuth(), Sabre\DAV\Issue33Test\testCopyMoveInfo(), Sabre\DAVACL\PrincipalSearchPropertySetTest\testCorrect(), Sabre\DAVACL\PrincipalPropertySearchTest\testCorrect(), Sabre\CalDAV\ValidateICalTest\testCreateFile(), Sabre\CardDAV\ValidateVCardTest\testCreateFile(), Sabre\CalDAV\ValidateICalTest\testCreateFile2Components(), Sabre\CalDAV\ValidateICalTest\testCreateFile2UIDS(), Sabre\CalDAV\ValidateICalTest\testCreateFileInvalidComponent(), Sabre\CalDAV\ValidateICalTest\testCreateFileNoUID(), Sabre\CardDAV\ValidateVCardTest\testCreateFileVCalendar(), Sabre\CalDAV\ValidateICalTest\testCreateFileVCard(), Sabre\CalDAV\ValidateICalTest\testCreateFileWrongComponent(), Sabre\DAV\Locks\PluginTest\testDeleteWithETagOnCollection(), Sabre\DAVACL\PrincipalSearchPropertySetTest\testDepth1(), Sabre\DAVACL\PrincipalPropertySearchTest\testDepth1(), Sabre\DAVACL\PrincipalSearchPropertySetTest\testDepthIncorrectXML(), Sabre\DAV\GetIfConditionsTest\testEtag(), Sabre\DAV\Issue33Test\testEverything(), Sabre\DAV\ServerEventsTest\testException(), Sabre\CalDAV\ExpandEventsDoubleEventsTest\testExpand(), Sabre\DAVACL\ExpandPropertiesTest\testExpand(), Sabre\DAVACL\ExpandPropertiesTest\testExpandDeep(), Sabre\DAVACL\ExpandPropertiesTest\testExpandHrefList(), Sabre\CardDAV\VCFExportTest\testExport(), Sabre\CalDAV\FreeBusyReportTest\testFreeBusyReportWrongNode(), Sabre\HTTP\RequestTest\testGetAbsoluteUrl(), Sabre\DAV\Locks\PluginTest\testGetTimeoutHeader(), Sabre\DAV\Locks\PluginTest\testGetTimeoutHeaderInfinite(), Sabre\DAV\Locks\PluginTest\testGetTimeoutHeaderInvalid(), Sabre\DAV\Locks\PluginTest\testGetTimeoutHeaderTwoItems(), Sabre\DAV\ServerSimpleTest\testGuessBaseUri(), Sabre\DAV\ServerSimpleTest\testGuessBaseUri2(), Sabre\DAV\ServerSimpleTest\testGuessBaseUriBadConfig(), Sabre\DAV\ServerSimpleTest\testGuessBaseUriNoPathInfo(), Sabre\DAV\ServerSimpleTest\testGuessBaseUriNoPathInfo2(), Sabre\DAV\ServerSimpleTest\testGuessBaseUriPercentEncoding(), Sabre\DAV\ServerSimpleTest\testGuessBaseUriQueryString(), Sabre\DAV\Sync\PluginTest\testIfConditions(), Sabre\DAV\Sync\PluginTest\testIfConditionsNoSyncToken(), Sabre\DAV\Sync\PluginTest\testIfConditionsNot(), Sabre\DAV\ServerPreconditionsTest\testIfModifiedSinceInvalidDate(), Sabre\DAV\ServerPreconditionsTest\testIfModifiedSinceInvalidDate2(), Sabre\DAV\ServerPreconditionsTest\testIfModifiedSinceModified(), Sabre\DAV\ServerPreconditionsTest\testIfModifiedSinceUnModified(), Sabre\DAV\ServerPreconditionsTest\testIfUnmodifiedSinceInvalidDate(), Sabre\DAV\ServerPreconditionsTest\testIfUnmodifiedSinceModified(), Sabre\DAV\ServerPreconditionsTest\testIfUnmodifiedSinceUnModified(), Sabre\CalDAV\Schedule\OutboxPostTest\testInvalidIcalBody(), Sabre\CalDAV\SharingPluginTest\testInviteBadXML(), Sabre\CalDAV\SharingPluginTest\testInviteReply(), Sabre\CalDAV\SharingPluginTest\testInviteWrongUrl(), Sabre\CalDAV\Issue205Test\testIssue205(), Sabre\CalDAV\Issue211Test\testIssue211(), Sabre\CalDAV\Issue220Test\testIssue220(), Sabre\CalDAV\Issue228Test\testIssue228(), Sabre\DAV\Locks\PluginTest\testLockCopyLockDestination(), Sabre\DAV\Locks\PluginTest\testLockCopyLockSource(), Sabre\DAV\Locks\PluginTest\testLockDeleteParent(), Sabre\DAV\Locks\PluginTest\testLockDeleteSucceed(), Sabre\DAV\Locks\PluginTest\testLockMoveLockDestination(), Sabre\DAV\Locks\PluginTest\testLockMoveLockParent(), Sabre\DAV\Locks\PluginTest\testLockMoveLockSourceLocked(), Sabre\DAV\Locks\PluginTest\testLockMoveLockSourceSucceed(), Sabre\DAV\Locks\PluginTest\testLockPutBadToken(), Sabre\DAV\Locks\PluginTest\testLockPutGoodToken(), Sabre\DAV\Locks\PluginTest\testLockRetainOwner(), Sabre\DAV\GetIfConditionsTest\testLockTokenUrl(), Sabre\CalDAV\PluginTest\testMkCalendarExistingCalendar(), Sabre\DAV\ServerMKCOLTest\testMkcol(), Sabre\DAV\ServerMKCOLTest\testMKCOLAlreadyExists(), Sabre\DAV\ServerMKCOLTest\testMKCOLBrokenXML(), Sabre\DAV\ServerMKCOLTest\testMKCOLIncorrectResourceType(), Sabre\DAV\ServerMKCOLTest\testMKCOLNoParent(), Sabre\DAV\ServerMKCOLTest\testMKCOLNoResourceType(), Sabre\DAV\ServerMKCOLTest\testMKCOLParentIsNoCollection(), Sabre\DAV\ServerMKCOLTest\testMKCOLSuccess(), Sabre\DAV\ServerMKCOLTest\testMKCOLUnknownBody(), Sabre\DAV\ServerMKCOLTest\testMKCOLUnknownXML(), Sabre\DAV\ServerMKCOLTest\testMKCOLWhiteSpaceResourceType(), Sabre\DAV\Mount\PluginTest\testMountResponse(), Sabre\CardDAV\MultiGetTest\testMultiGet(), Sabre\CardDAV\MultiGetTest\testMultiGetVCard4(), Sabre\DAVACL\PluginAdminTest\testNoAdminAccess(), Sabre\CalDAV\Schedule\OutboxPostTest\testNoMETHOD(), Sabre\DAV\ServerSimpleTest\testNonExistantMethod(), Sabre\DAV\GetIfConditionsTest\testNotLockToken(), Sabre\CalDAV\Schedule\OutboxPostTest\testNoVEVENT(), Sabre\DAV\ServerPluginTest\testOptions(), Sabre\DAVACL\PrincipalPropertySearchTest\testOR(), Sabre\DAV\HTTPPreferParsingTest\testParseMultiple(), Sabre\DAV\HTTPPreferParsingTest\testParseSimple(), Sabre\DAV\HTTPPreferParsingTest\testParseValue(), Sabre\DAV\HTTPPreferParsingTest\testParseWeirdValue(), Sabre\DAV\Mount\PluginTest\testPassThrough(), Sabre\DAV\PartialUpdate\PluginTest\testPatchNoRange(), Sabre\DAV\Browser\PluginTest\testPostMkCol(), Sabre\CalDAV\Schedule\OutboxPostTest\testPostPassThruNoOutBox(), Sabre\CalDAV\Schedule\OutboxPostTest\testPostPassThruNotFound(), Sabre\CalDAV\Schedule\OutboxPostTest\testPostPassThruNotTextCalendar(), Sabre\DAV\HTTPPreferParsingTest\testpropfindMinimal(), Sabre\DAV\Locks\PluginTest\testPutWithCorrectETag(), Sabre\DAV\Locks\PluginTest\testPutWithIncorrectETag(), Sabre\CardDAV\AddressBookQueryTest\testQueryLimit(), Sabre\DAV\Auth\Backend\ApacheTest\testRedirectRemoteUser(), Sabre\DAV\Auth\Backend\ApacheTest\testRemoteUser(), Sabre\DAV\ServerSimpleTest\testReportIntercepted(), Sabre\DAV\ServerSimpleTest\testReportNotFound(), Sabre\DAVACL\ExpandPropertiesTest\testSimple(), Sabre\CardDAV\SogoStripContentTypeTest\testStrip(), Sabre\DAV\Sync\PluginTest\testSubsequentSyncSyncCollection(), Sabre\DAV\Sync\PluginTest\testSubsequentSyncSyncCollectionDepthFallBack(), Sabre\DAV\Sync\PluginTest\testSubsequentSyncSyncCollectionLimit(), Sabre\DAV\Sync\PluginTest\testSyncInvalidToken(), Sabre\DAV\Sync\PluginTest\testSyncInvalidTokenNoPrefix(), Sabre\DAV\Sync\PluginTest\testSyncNoProp(), Sabre\DAV\Sync\PluginTest\testSyncNoSyncCollection(), Sabre\DAV\Sync\PluginTest\testSyncNoSyncInfo(), Sabre\DAV\Sync\PluginTest\testSyncNoSyncToken(), Sabre\DAV\ServerSimpleTest\testTriggerException(), Sabre\CalDAV\SharingPluginTest\testUnknownMethodNoNode(), Sabre\CalDAV\SharingPluginTest\testUnknownMethodNoPOST(), Sabre\CalDAV\SharingPluginTest\testUnknownMethodNoXML(), Sabre\DAVACL\PrincipalPropertySearchTest\testUnknownSearchField(), Sabre\CalDAV\Schedule\OutboxPostTest\testUnsupportedMethod(), Sabre\CalDAV\ValidateICalTest\testUpdateFile(), Sabre\CalDAV\ValidateICalTest\testUpdateFileInvalidComponent(), and Sabre\DAVACL\PrincipalPropertySearchTest\testWrongUri().

107  {
108 
109  $headers = [];
110  $method = null;
111  $url = null;
112  $httpVersion = '1.1';
113 
114  $protocol = 'http';
115  $hostName = 'localhost';
116 
117  foreach ($serverArray as $key => $value) {
118 
119  switch ($key) {
120 
121  case 'SERVER_PROTOCOL' :
122  if ($value === 'HTTP/1.0') {
123  $httpVersion = '1.0';
124  }
125  break;
126  case 'REQUEST_METHOD' :
127  $method = $value;
128  break;
129  case 'REQUEST_URI' :
130  $url = $value;
131  break;
132 
133  // These sometimes show up without a HTTP_ prefix
134  case 'CONTENT_TYPE' :
135  $headers['Content-Type'] = $value;
136  break;
137  case 'CONTENT_LENGTH' :
138  $headers['Content-Length'] = $value;
139  break;
140 
141  // mod_php on apache will put credentials in these variables.
142  // (fast)cgi does not usually do this, however.
143  case 'PHP_AUTH_USER' :
144  if (isset($serverArray['PHP_AUTH_PW'])) {
145  $headers['Authorization'] = 'Basic ' . base64_encode($value . ':' . $serverArray['PHP_AUTH_PW']);
146  }
147  break;
148 
149  // Similarly, mod_php may also screw around with digest auth.
150  case 'PHP_AUTH_DIGEST' :
151  $headers['Authorization'] = 'Digest ' . $value;
152  break;
153 
154  // Apache may prefix the HTTP_AUTHORIZATION header with
155  // REDIRECT_, if mod_rewrite was used.
156  case 'REDIRECT_HTTP_AUTHORIZATION' :
157  $headers['Authorization'] = $value;
158  break;
159 
160  case 'HTTP_HOST' :
161  $hostName = $value;
162  $headers['Host'] = $value;
163  break;
164 
165  case 'HTTPS' :
166  if (!empty($value) && $value !== 'off') {
167  $protocol = 'https';
168  }
169  break;
170 
171  default :
172  if (substr($key, 0, 5) === 'HTTP_') {
173  // It's a HTTP header
174 
175  // Normalizing it to be prettier
176  $header = strtolower(substr($key, 5));
177 
178  // Transforming dashes into spaces, and uppercasing
179  // every first letter.
180  $header = ucwords(str_replace('_', ' ', $header));
181 
182  // Turning spaces into dashes.
183  $header = str_replace(' ', '-', $header);
184  $headers[$header] = $value;
185 
186  }
187  break;
188 
189 
190  }
191 
192  }
193 
194  $r = new Request($method, $url, $headers);
195  $r->setHttpVersion($httpVersion);
196  $r->setRawServerData($serverArray);
197  $r->setAbsoluteUrl($protocol . '://' . $hostName . $url);
198  return $r;
199 
200  }
$r
Definition: example_031.php:79
$url
$key
Definition: croninfo.php:18
+ Here is the caller graph for this function:

◆ getRequest()

static Sabre\HTTP\Sapi::getRequest ( )
static

This static method will create a new Request object, based on the current PHP request.

Returns
Request

Definition at line 39 of file Sapi.php.

References $_POST, $_SERVER, and $r.

Referenced by Sabre\HTTP\RequestTest\testCreateFromPHPRequest().

39  {
40 
41  $r = self::createFromServerArray($_SERVER);
42  $r->setBody(fopen('php://input', 'r'));
43  $r->setPostData($_POST);
44  return $r;
45 
46  }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$r
Definition: example_031.php:79
$_POST["username"]
+ Here is the caller graph for this function:

◆ sendResponse()

static Sabre\HTTP\Sapi::sendResponse ( ResponseInterface  $response)
static

Sends the HTTP response back to a HTTP client.

This calls php's header() function and streams the body to php://output.

Parameters
ResponseInterface$response
Returns
void

Definition at line 56 of file Sapi.php.

References $contentLength, $key, Sabre\VObject\$output, Sabre\HTTP\MessageInterface\getBody(), Sabre\HTTP\MessageInterface\getHeader(), Sabre\HTTP\MessageInterface\getHeaders(), Sabre\HTTP\MessageInterface\getHttpVersion(), Sabre\HTTP\ResponseInterface\getStatus(), and Sabre\HTTP\ResponseInterface\getStatusText().

Referenced by Sabre\HTTP\SapiTest\testSend(), Sabre\HTTP\SapiTest\testSendLimitedByContentLengthStream(), and Sabre\HTTP\SapiTest\testSendLimitedByContentLengthString().

56  {
57 
58  header('HTTP/' . $response->getHttpVersion() . ' ' . $response->getStatus() . ' ' . $response->getStatusText());
59  foreach ($response->getHeaders() as $key => $value) {
60 
61  foreach ($value as $k => $v) {
62  if ($k === 0) {
63  header($key . ': ' . $v);
64  } else {
65  header($key . ': ' . $v, false);
66  }
67  }
68 
69  }
70 
71  $body = $response->getBody();
72  if (is_null($body)) return;
73 
74  $contentLength = $response->getHeader('Content-Length');
75  if ($contentLength !== null) {
76  $output = fopen('php://output', 'wb');
77  if (is_resource($body) && get_resource_type($body) == 'stream') {
78  if (PHP_INT_SIZE !== 4){
79  // use the dedicated function on 64 Bit systems
80  stream_copy_to_stream($body, $output, $contentLength);
81  } else {
82  // workaround for 32 Bit systems to avoid stream_copy_to_stream
83  while (!feof($body)) {
84  fwrite($output, fread($body, 8192));
85  }
86  }
87  } else {
88  fwrite($output, $body, $contentLength);
89  }
90  } else {
91  file_put_contents('php://output', $body);
92  }
93 
94  if (is_resource($body)) {
95  fclose($body);
96  }
97 
98  }
if(preg_match('#\.( $contentLength[^/\.]+)$#D', $path, $type)) if($contentType===null)
Definition: module.php:165
$response
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: