本文整理汇总了PHP中Sabre\HTTP\Request类的典型用法代码示例。如果您正苦于以下问题:PHP Request类的具体用法?PHP Request怎么用?PHP Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: substr
function testIssue205()
{
$request = new HTTP\Request(array('REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', 'HTTP_DEPTH' => '1'));
$request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<C:calendar-data>
<C:expand start="20120325T220000Z" end="20120401T215959Z"/>
</C:calendar-data>
<D:getetag/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:comp-filter name="VALARM">
<C:time-range start="20120325T220000Z" end="20120401T215959Z"/>
</C:comp-filter>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>');
$response = $this->request($request);
$this->assertFalse(strpos($response->body, '<s:exception>Exception</s:exception>'), 'Exception occurred: ' . $response->body);
$this->assertFalse(strpos($response->body, 'Unknown or bad format'), 'DateTime unknown format Exception: ' . $response->body);
// Everts super awesome xml parser.
$body = substr($response->body, $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13);
$body = str_replace(' ', '', $body);
$vObject = VObject\Reader::read($body);
$this->assertEquals(1, count($vObject->VEVENT));
}
示例2: testSyncInitialSyncCollection
function testSyncInitialSyncCollection()
{
// Making a change
$this->collection->addChange(['file1.txt'], [], []);
$request = new HTTP\Request('REPORT', '/coll/', ['Content-Type' => 'application/xml']);
$body = <<<BLA
<?xml version="1.0" encoding="utf-8" ?>
<D:sync-collection xmlns:D="DAV:">
<D:sync-token/>
<D:sync-level>1</D:sync-level>
<D:prop>
<D:getcontentlength/>
</D:prop>
</D:sync-collection>
BLA;
$request->setBody($body);
$response = $this->request($request);
$this->assertEquals(207, $response->status, 'Full response body:' . $response->body);
$multiStatus = $this->server->xml->parse($response->getBodyAsString());
// Checking the sync-token
$this->assertEquals('http://sabre.io/ns/sync/1', $multiStatus->getSyncToken());
$responses = $multiStatus->getResponses();
$this->assertEquals(2, count($responses), 'We expected exactly 2 {DAV:}response');
$response = $responses[0];
$this->assertNull($response->getHttpStatus());
$this->assertEquals('/coll/file1.txt', $response->getHref());
$this->assertEquals([200 => ['{DAV:}getcontentlength' => 3]], $response->getResponseProperties());
$response = $responses[1];
$this->assertNull($response->getHttpStatus());
$this->assertEquals('/coll/file2.txt', $response->getHref());
$this->assertEquals([200 => ['{DAV:}getcontentlength' => 3]], $response->getResponseProperties());
}
示例3: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$parameters = json_decode(file_get_contents('parameters.json'));
$url = $parameters->url;
$HostID = $parameters->host;
// Template pour requête HEV
$xsl = new DOMDocument();
$xsl->load('xslt/hev.xsl');
// Configuration du moteur de template
$proc = new XSLTProcessor();
$proc->setParameter('', 'HostID', $HostID);
$proc->importStylesheet($xsl);
// Récupération du résultat
$doc = $proc->transformToDoc(new DOMDocument());
$request = new Request('POST', $url);
$request->setBody($doc->saveXML());
$client = new Client();
$client->addCurlSetting(CURLOPT_SSL_VERIFYPEER, false);
$response = $client->send($request);
$dom = new DOMDocument();
$dom->loadXML($response->getBodyAsString());
//echo "\nVoici la liste des versions compatibles avec ce serveur:\n\n";
$result = array();
foreach ($dom->getElementsByTagName('VersionNumber') as $version) {
$result[] = array($version->getAttribute('ProtocolVersion'), "EBICS version {$version->nodeValue}");
}
$table = new Table($output);
$table->setHeaders(array('Protocole', 'Description'))->setRows($result);
$table->render();
}
示例4: testCorrect
function testCorrect()
{
$xml = '<?xml version="1.0"?>
<d:principal-search-property-set xmlns:d="DAV:"/>';
$serverVars = array('REQUEST_METHOD' => 'REPORT', 'HTTP_DEPTH' => '0', 'REQUEST_URI' => '/principals');
$request = new HTTP\Request($serverVars);
$request->setBody($xml);
$server = $this->getServer();
$server->httpRequest = $request;
$server->exec();
$this->assertEquals('HTTP/1.1 200 OK', $server->httpResponse->status, $server->httpResponse->body);
$this->assertEquals(array('Content-Type' => 'application/xml; charset=utf-8'), $server->httpResponse->headers);
$check = array('/d:principal-search-property-set', '/d:principal-search-property-set/d:principal-search-property' => 2, '/d:principal-search-property-set/d:principal-search-property/d:prop' => 2, '/d:principal-search-property-set/d:principal-search-property/d:prop/d:displayname' => 1, '/d:principal-search-property-set/d:principal-search-property/d:prop/s:email-address' => 1, '/d:principal-search-property-set/d:principal-search-property/d:description' => 2);
$xml = simplexml_load_string($server->httpResponse->body);
$xml->registerXPathNamespace('d', 'DAV:');
$xml->registerXPathNamespace('s', 'http://sabredav.org/ns');
foreach ($check as $v1 => $v2) {
$xpath = is_int($v1) ? $v2 : $v1;
$result = $xml->xpath($xpath);
$count = 1;
if (!is_int($v1)) {
$count = $v2;
}
$this->assertEquals($count, count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result) . '. Full response body: ' . $server->httpResponse->body);
}
}
示例5: parseUserPass
public static function parseUserPass(HTTP\Request $httpRequest)
{
// Apache and mod_php
if ($user = $httpRequest->getRawServerValue('PHP_AUTH_USER')) {
$pass = "";
if ($passw = $httpRequest->getRawServerValue('PHP_AUTH_PW')) {
$pass = $passw;
}
return array($user, $pass);
}
// Most other webservers
$auth = $httpRequest->getHeader('Authorization');
// Apache could prefix environment variables with REDIRECT_ when urls
// are passed through mod_rewrite
if (!$auth) {
$auth = $httpRequest->getRawServerValue('REDIRECT_HTTP_AUTHORIZATION');
}
if (!$auth) {
return false;
}
if (strpos(strtolower($auth), 'basic') !== 0) {
return false;
}
return explode(':', base64_decode(substr($auth, 6)), 2);
}
示例6: testExpand
function testExpand()
{
$request = new HTTP\Request(array('REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', 'HTTP_DEPTH' => '1'));
$request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<C:calendar-data>
<C:expand start="20120205T230000Z" end="20120212T225959Z"/>
</C:calendar-data>
<D:getetag/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:time-range start="20120205T230000Z" end="20120212T225959Z"/>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>');
$response = $this->request($request);
// Everts super awesome xml parser.
$body = substr($response->body, $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13);
$body = str_replace(' ', '', $body);
$vObject = VObject\Reader::read($body);
// We only expect 3 events
$this->assertEquals(3, count($vObject->VEVENT), 'We got 6 events instead of 3. Output: ' . $body);
// TZID should be gone
$this->assertFalse(isset($vObject->VEVENT->DTSTART['TZID']));
}
示例7: redirectToInstall
/**
* Redirect to the installation page of the application.
* This method does not send the response.
*
* @param Response $response HTTP response.
* @param Request $request HTTP request.
* @return void
*/
static function redirectToInstall(Response $response, Request $request)
{
list($dirname) = Uri\split($request->getUrl());
$response->setStatus(307);
$response->setHeader('Location', $dirname . '/install.php');
$response->setBody('The application is not installed. ' . 'You are going to be redirected to the installation page.');
}
示例8: testPrincipalMatchPrincipalProperty
function testPrincipalMatchPrincipalProperty()
{
$xml = <<<XML
<?xml version="1.0"?>
<principal-match xmlns="DAV:">
<principal-property>
<principal-URL />
</principal-property>
<prop>
<resourcetype />
</prop>
</principal-match>
XML;
$request = new Request('REPORT', '/principals', ['Content-Type' => 'application/xml']);
$request->setBody($xml);
$response = $this->request($request, 207);
$expected = <<<XML
<?xml version="1.0"?>
<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
<d:status>HTTP/1.1 200 OK</d:status>
<d:href>/principals/user1/</d:href>
<d:propstat>
<d:prop>
<d:resourcetype><d:principal/></d:resourcetype>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:multistatus>
XML;
$this->assertXmlStringEqualsXmlString($expected, $response->getBodyAsString());
}
示例9: testQueryTimerange
function testQueryTimerange()
{
$request = new HTTP\Request('REPORT', '/calendars/user1/calendar1', ['Content-Type' => 'application/xml', 'Depth' => '1']);
$request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<C:calendar-data>
<C:expand start="20120226T230000Z" end="20120228T225959Z"/>
</C:calendar-data>
<D:getetag/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:time-range start="20120226T230000Z" end="20120228T225959Z"/>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>');
$response = $this->request($request);
if (strpos($response->body, 'BEGIN:VCALENDAR') === false) {
$this->fail('Got no events instead of 1. Output: ' . $response->body);
}
// Everts super awesome xml parser.
$body = substr($response->body, $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13);
$body = str_replace(' ', '', $body);
$vObject = VObject\Reader::read($body);
// We expect 1 event
$this->assertEquals(1, count($vObject->VEVENT), 'We got 0 events instead of 1. Output: ' . $body);
}
示例10: sendPROPFIND
function sendPROPFIND($body)
{
$request = new HTTP\Request('PROPFIND', '/', ['Depth' => '0']);
$request->setBody($body);
$this->server->httpRequest = $request;
$this->server->exec();
}
示例11: sendPROPFIND
public function sendPROPFIND($body)
{
$serverVars = array('REQUEST_URI' => '/', 'REQUEST_METHOD' => 'PROPFIND', 'HTTP_DEPTH' => '0');
$request = new HTTP\Request($serverVars);
$request->setBody($body);
$this->server->httpRequest = $request;
$this->server->exec();
}
示例12: testPostNoSabreAction
function testPostNoSabreAction()
{
$request = new HTTP\Request('POST', '/', ['Content-Type' => 'application/x-www-form-urlencoded']);
$request->setPostData([]);
$this->server->httpRequest = $request;
$this->server->exec();
$this->assertEquals(501, $this->response->status);
}
示例13: testPatchNoEndRange
function testPatchNoEndRange()
{
$this->node->put('00000');
$request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-', 'Content-Type' => 'application/x-sabredav-partialupdate', 'Content-Length' => '3']);
$request->setBody('111');
$response = $this->request($request);
$this->assertEquals(204, $response->getStatus(), 'Full response body:' . $response->getBodyAsString());
$this->assertEquals('00111', $this->node->get());
}
示例14: testCreateFileJson
function testCreateFileJson()
{
$request = new HTTP\Request('PUT', '/addressbooks/admin/addressbook1/blabla.vcf');
$request->setBody('[ "vcard" , [ [ "UID" , {}, "text", "foo" ] ] ]');
$response = $this->request($request);
$this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
$foo = $this->cardBackend->getCard('addressbook1', 'blabla.vcf');
$this->assertEquals("BEGIN:VCARD\r\nUID:foo\r\nEND:VCARD\r\n", $foo['carddata']);
}
示例15: testPatchNoEndRange
public function testPatchNoEndRange()
{
$this->node->put('00000');
$request = new HTTP\Request(array('REQUEST_METHOD' => 'PATCH', 'REQUEST_URI' => '/partial', 'HTTP_X_UPDATE_RANGE' => 'bytes=3-', 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate', 'HTTP_CONTENT_LENGTH' => 3));
$request->setBody('111');
$response = $this->request($request);
$this->assertEquals('HTTP/1.1 204 No Content', $response->status, 'Full response body:' . $response->body);
$this->assertEquals('00111', $this->node->get());
}