当前位置: 首页>>代码示例>>PHP>>正文


PHP HTTP\Util类代码示例

本文整理汇总了PHP中Sabre\HTTP\Util的典型用法代码示例。如果您正苦于以下问题:PHP Util类的具体用法?PHP Util怎么用?PHP Util使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Util类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: propFind

 /**
  * Fetches properties for a path.
  *
  * This method received a PropFind object, which contains all the
  * information about the properties that need to be fetched.
  *
  * Ususually you would just want to call 'get404Properties' on this object,
  * as this will give you the _exact_ list of properties that need to be
  * fetched, and haven't yet.
  *
  * @param string $path
  * @param PropFind $propFind
  * @return void
  */
 public function propFind($path, PropFind $propFind)
 {
     $propertyNames = $propFind->get404Properties();
     if (!$propertyNames) {
         return;
     }
     // error_log("propFind: path($path), " . print_r($propertyNames, true));
     $cachedNodes = \CB\Cache::get('DAVNodes');
     // error_log("propFind: " . print_r($cachedNodes, true));
     $path = trim($path, '/');
     $path = str_replace('\\', '/', $path);
     // Node with $path is not in cached nodes, return
     if (!array_key_exists($path, $cachedNodes)) {
         return;
     }
     $node = $cachedNodes[$path];
     // while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
     //     $propFind->set($row['name'], $row['value']);
     // }
     foreach ($propertyNames as $prop) {
         if ($prop == '{DAV:}creationdate') {
             $dttm = new \DateTime($node['cdate']);
             // $dttm->getTimestamp()
             $propFind->set($prop, \Sabre\HTTP\Util::toHTTPDate($dttm));
         } elseif ($prop == '{urn:schemas-microsoft-com:office:office}modifiedby' or $prop == '{DAV:}getmodifiedby') {
             // This has to be revised, because the User.login differs from User.DisplayName
             // moreover, during an edit, Word will check for File Properties and we
             // tell Word that the file is modified by another user
             // $propFind->set($prop, \CB\User::getDisplayName($node['uid']));
         }
     }
 }
开发者ID:youprofit,项目名称:casebox,代码行数:46,代码来源:PropertyStorageBackend.php

示例2: testSerialize

    function testSerialize()
    {
        $dt = new \DateTime('2010-03-14 16:35', new \DateTimeZone('UTC'));
        $lastMod = new GetLastModified($dt);
        $doc = new \DOMDocument();
        $root = $doc->createElement('d:getlastmodified');
        $root->setAttribute('xmlns:d', 'DAV:');
        $doc->appendChild($root);
        $server = new DAV\Server();
        $lastMod->serialize($server, $root);
        $xml = $doc->saveXML();
        /*
        $this->assertEquals(
        '<?xml version="1.0"?>
        <d:getlastmodified xmlns:d="DAV:" xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/" b:dt="dateTime.rfc1123">' .
        HTTP\Util::toHTTPDate($dt) .
        '</d:getlastmodified>
        ', $xml);
        */
        $this->assertEquals('<?xml version="1.0"?>
<d:getlastmodified xmlns:d="DAV:">' . HTTP\Util::toHTTPDate($dt) . '</d:getlastmodified>
', $xml);
        $ok = false;
        try {
            GetLastModified::unserialize(DAV\XMLUtil::loadDOMDocument($xml)->firstChild, array());
        } catch (DAV\Exception $e) {
            $ok = true;
        }
        if (!$ok) {
            $this->markTestFailed('Unserialize should not be supported');
        }
    }
开发者ID:MetallianFR68,项目名称:myroundcube,代码行数:32,代码来源:GetLastModifiedTest.php

示例3: serialize

 /**
  * serialize
  *
  * @param DAV\Server $server
  * @param \DOMElement $prop
  * @return void
  */
 public function serialize(DAV\Server $server, \DOMElement $prop)
 {
     $doc = $prop->ownerDocument;
     //$prop->setAttribute('xmlns:b','urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/');
     //$prop->setAttribute('b:dt','dateTime.rfc1123');
     $prop->nodeValue = HTTP\Util::toHTTPDate($this->time);
 }
开发者ID:samj1912,项目名称:repo,代码行数:14,代码来源:GetLastModified.php

示例4: testHEAD

 function testHEAD()
 {
     $request = new HTTP\Request('HEAD', '/test.txt');
     $this->server->httpRequest = $request;
     $this->server->exec();
     $this->assertEquals(['X-Sabre-Version' => [DAV\Version::VERSION], 'Content-Type' => ['application/octet-stream'], 'Content-Length' => [13], 'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))], 'ETag' => ['"' . md5_file($this->tempDir . '/test.txt') . '"']], $this->response->getHeaders());
     $this->assertEquals(200, $this->response->status);
     $this->assertEquals('', $this->response->body);
 }
开发者ID:MetallianFR68,项目名称:myroundcube,代码行数:9,代码来源:ServerTest.php

示例5: setUp

 function setUp()
 {
     parent::setUp();
     $this->server->createFile('files/test.txt', 'Test contents');
     $this->lastModified = HTTP\Util::toHTTPDate(new DateTime('@' . $this->server->tree->getNodeForPath('files/test.txt')->getLastModified()));
     $stream = popen('echo "Test contents"', 'r');
     $streamingFile = new Mock\StreamingFile('no-seeking.txt', $stream);
     $streamingFile->setSize(12);
     $this->server->tree->getNodeForPath('files')->addNode($streamingFile);
 }
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:10,代码来源:ServerRangeTest.php

示例6: testHEAD

 function testHEAD()
 {
     $serverVars = array('REQUEST_URI' => '/test.txt', 'REQUEST_METHOD' => 'HEAD');
     $request = new HTTP\Request($serverVars);
     $this->server->httpRequest = $request;
     $this->server->exec();
     $this->assertEquals(array('Content-Type' => 'application/octet-stream', 'Content-Length' => 13, 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), 'ETag' => '"' . md5_file($this->tempDir . '/test.txt') . '"'), $this->response->headers);
     $this->assertEquals('HTTP/1.1 200 OK', $this->response->status);
     $this->assertEquals('', $this->response->body);
 }
开发者ID:samj1912,项目名称:repo,代码行数:10,代码来源:ServerTest.php

示例7: testBaseUri

 function testBaseUri()
 {
     $serverVars = ['REQUEST_URI' => '/blabla/test.txt', 'REQUEST_METHOD' => 'GET'];
     $filename = $this->tempDir . '/test.txt';
     $request = HTTP\Sapi::createFromServerArray($serverVars);
     $this->server->setBaseUri('/blabla/');
     $this->assertEquals('/blabla/', $this->server->getBaseUri());
     $this->server->httpRequest = $request;
     $this->server->exec();
     $this->assertEquals(['X-Sabre-Version' => [Version::VERSION], 'Content-Type' => ['application/octet-stream'], 'Content-Length' => [13], 'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($filename)))], 'ETag' => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"']], $this->response->getHeaders());
     $this->assertEquals(200, $this->response->status);
     $this->assertEquals('Test contents', stream_get_contents($this->response->body));
 }
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:13,代码来源:ServerSimpleTest.php

示例8: checkPreconditions


//.........这里部分代码省略.........

                    foreach ($ifNoneMatch as $ifNoneMatchItem) {

                        // Stripping any extra spaces
                        $ifNoneMatchItem = trim($ifNoneMatchItem, ' ');

                        if ($etag === $ifNoneMatchItem) $haveMatch = true;

                    }

                }

                if ($haveMatch) {
                    if ($etag) $response->setHeader('ETag', $etag);
                    if ($request->getMethod() === 'GET') {
                        $response->setStatus(304);
                        return false;
                    } else {
                        throw new Exception\PreconditionFailed('An If-None-Match header was specified, but the ETag matched (or * was specified).', 'If-None-Match');
                    }
                }
            }

        }

        if (!$ifNoneMatch && ($ifModifiedSince = $request->getHeader('If-Modified-Since'))) {

            // The If-Modified-Since header contains a date. We
            // will only return the entity if it has been changed since
            // that date. If it hasn't been changed, we return a 304
            // header
            // Note that this header only has to be checked if there was no If-None-Match header
            // as per the HTTP spec.
            $date = HTTP\Util::parseHTTPDate($ifModifiedSince);

            if ($date) {
                if (is_null($node)) {
                    $node = $this->tree->getNodeForPath($path);
                }
                $lastMod = $node->getLastModified();
                if ($lastMod) {
                    $lastMod = new \DateTime('@' . $lastMod);
                    if ($lastMod <= $date) {
                        $response->setStatus(304);
                        $response->setHeader('Last-Modified', HTTP\Util::toHTTPDate($lastMod));
                        return false;
                    }
                }
            }
        }

        if ($ifUnmodifiedSince = $request->getHeader('If-Unmodified-Since')) {

            // The If-Unmodified-Since will allow allow the request if the
            // entity has not changed since the specified date.
            $date = HTTP\Util::parseHTTPDate($ifUnmodifiedSince);

            // We must only check the date if it's valid
            if ($date) {
                if (is_null($node)) {
                    $node = $this->tree->getNodeForPath($path);
                }
                $lastMod = $node->getLastModified();
                if ($lastMod) {
                    $lastMod = new \DateTime('@' . $lastMod);
                    if ($lastMod > $date) {
开发者ID:nikosv,项目名称:openeclass,代码行数:67,代码来源:Server.php

示例9: testIfRangeModificationDateModified

 /**
  * @depends testRange
  */
 function testIfRangeModificationDateModified()
 {
     $node = $this->server->tree->getNodeForPath('test.txt');
     $serverVars = array('REQUEST_URI' => '/test.txt', 'REQUEST_METHOD' => 'GET', 'HTTP_RANGE' => 'bytes=2-5', 'HTTP_IF_RANGE' => '-2 years');
     $request = HTTP\Sapi::createFromServerArray($serverVars);
     $this->server->httpRequest = $request;
     $this->server->exec();
     $this->assertEquals(array('X-Sabre-Version' => [Version::VERSION], 'Content-Type' => ['application/octet-stream'], 'Content-Length' => [13], 'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))], 'ETag' => ['"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"']), $this->response->getHeaders());
     $this->assertEquals(200, $this->response->status);
     $this->assertEquals('Test contents', stream_get_contents($this->response->body));
 }
开发者ID:MetallianFR68,项目名称:myroundcube,代码行数:14,代码来源:ServerRangeTest.php

示例10: httpAfterGet

 /**
  * This event is triggered after GET requests.
  *
  * This is used to transform data into jCal, if this was requested.
  *
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @return void
  */
 function httpAfterGet(RequestInterface $request, ResponseInterface $response)
 {
     if (strpos($response->getHeader('Content-Type'), 'text/calendar') === false) {
         return;
     }
     $result = HTTP\Util::negotiate($request->getHeader('Accept'), ['text/calendar', 'application/calendar+json']);
     if ($result !== 'application/calendar+json') {
         // Do nothing
         return;
     }
     // Transforming.
     $vobj = VObject\Reader::read($response->getBody());
     $jsonBody = json_encode($vobj->jsonSerialize());
     $response->setBody($jsonBody);
     $response->setHeader('Content-Type', 'application/calendar+json');
     $response->setHeader('Content-Length', strlen($jsonBody));
 }
开发者ID:sebbie42,项目名称:casebox,代码行数:26,代码来源:Plugin.php

示例11: httpGet

 /**
  * Intercepts GET requests on calendar urls ending with ?export.
  *
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @return bool
  */
 function httpGet(RequestInterface $request, ResponseInterface $response)
 {
     $queryParams = $request->getQueryParameters();
     if (!array_key_exists('export', $queryParams)) {
         return;
     }
     $path = $request->getPath();
     $node = $this->server->getProperties($path, ['{DAV:}resourcetype', '{DAV:}displayname', '{http://sabredav.org/ns}sync-token', '{DAV:}sync-token', '{http://apple.com/ns/ical/}calendar-color']);
     if (!isset($node['{DAV:}resourcetype']) || !$node['{DAV:}resourcetype']->is('{' . Plugin::NS_CALDAV . '}calendar')) {
         return;
     }
     // Marking the transactionType, for logging purposes.
     $this->server->transactionType = 'get-calendar-export';
     $properties = $node;
     $start = null;
     $end = null;
     $expand = false;
     $componentType = false;
     if (isset($queryParams['start'])) {
         if (!ctype_digit($queryParams['start'])) {
             throw new BadRequest('The start= parameter must contain a unix timestamp');
         }
         $start = DateTime::createFromFormat('U', $queryParams['start']);
     }
     if (isset($queryParams['end'])) {
         if (!ctype_digit($queryParams['end'])) {
             throw new BadRequest('The end= parameter must contain a unix timestamp');
         }
         $end = DateTime::createFromFormat('U', $queryParams['end']);
     }
     if (isset($queryParams['expand']) && !!$queryParams['expand']) {
         if (!$start || !$end) {
             throw new BadRequest('If you\'d like to expand recurrences, you must specify both a start= and end= parameter.');
         }
         $expand = true;
         $componentType = 'VEVENT';
     }
     if (isset($queryParams['componentType'])) {
         if (!in_array($queryParams['componentType'], ['VEVENT', 'VTODO', 'VJOURNAL'])) {
             throw new BadRequest('You are not allowed to search for components of type: ' . $queryParams['componentType'] . ' here');
         }
         $componentType = $queryParams['componentType'];
     }
     $format = \Sabre\HTTP\Util::Negotiate($request->getHeader('Accept'), ['text/calendar', 'application/calendar+json']);
     if (isset($queryParams['accept'])) {
         if ($queryParams['accept'] === 'application/calendar+json' || $queryParams['accept'] === 'jcal') {
             $format = 'application/calendar+json';
         }
     }
     if (!$format) {
         $format = 'text/calendar';
     }
     $this->generateResponse($path, $start, $end, $expand, $componentType, $format, $properties, $response);
     // Returning false to break the event chain
     return false;
 }
开发者ID:pageer,项目名称:sabre-dav,代码行数:63,代码来源:ICSExportPlugin.php

示例12: validateRFC2616Date

 /**
  * Makes sure the supplied value is a valid RFC2616 date.
  *
  * If we would just use strtotime to get a valid timestamp, we have no way of checking if a
  * user just supplied the word 'now' for the date header.
  *
  * This function also makes sure the Date header is within 15 minutes of the operating
  * system date, to prevent replay attacks.
  *
  * @param string $dateHeader
  * @return bool
  */
 protected function validateRFC2616Date($dateHeader)
 {
     $date = Util::parseHTTPDate($dateHeader);
     // Unknown format
     if (!$date) {
         $this->errorCode = self::ERR_INVALIDDATEFORMAT;
         return false;
     }
     $min = new \DateTime('-15 minutes');
     $max = new \DateTime('+15 minutes');
     // We allow 15 minutes around the current date/time
     if ($date > $max || $date < $min) {
         $this->errorCode = self::ERR_REQUESTTIMESKEWED;
         return false;
     }
     return $date;
 }
开发者ID:sebbie42,项目名称:casebox,代码行数:29,代码来源:AWS.php

示例13: testBaseUri

 function testBaseUri()
 {
     $serverVars = array('REQUEST_URI' => '/blabla/test.txt', 'REQUEST_METHOD' => 'GET');
     $request = HTTP\Sapi::createFromServerArray($serverVars);
     $this->server->setBaseUri('/blabla/');
     $this->assertEquals('/blabla/', $this->server->getBaseUri());
     $this->server->httpRequest = $request;
     $this->server->exec();
     $this->assertEquals(array('X-Sabre-Version' => Version::VERSION, 'Content-Type' => 'application/octet-stream', 'Content-Length' => 13, 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))), $this->response->getHeaders());
     $this->assertEquals(200, $this->response->status);
     $this->assertEquals('Test contents', stream_get_contents($this->response->body));
 }
开发者ID:mattes,项目名称:sabre-dav,代码行数:12,代码来源:ServerSimpleTest.php

示例14: testIfRangeModificationDateModified

 /**
  * @depends testRange
  * @covers \Sabre\DAV\Server::httpGet
  */
 function testIfRangeModificationDateModified()
 {
     $node = $this->server->tree->getNodeForPath('test.txt');
     $serverVars = array('REQUEST_URI' => '/test.txt', 'REQUEST_METHOD' => 'GET', 'HTTP_RANGE' => 'bytes=2-5', 'HTTP_IF_RANGE' => '-2 years');
     $request = new HTTP\Request($serverVars);
     $this->server->httpRequest = $request;
     $this->server->exec();
     $this->assertEquals(array('Content-Type' => 'application/octet-stream', 'Content-Length' => 13, 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"'), $this->response->headers);
     $this->assertEquals('HTTP/1.1 200 OK', $this->response->status);
     $this->assertEquals('Test contents', stream_get_contents($this->response->body));
 }
开发者ID:TamirAl,项目名称:hubzilla,代码行数:15,代码来源:ServerRangeTest.php

示例15: negotiateVCard

    /**
     * This helper function performs the content-type negotiation for vcards.
     *
     * It will return one of the following strings:
     * 1. vcard3
     * 2. vcard4
     * 3. jcard
     *
     * It defaults to vcard3.
     *
     * @param string $input
     * @param string $mimeType
     * @return string
     */
    protected function negotiateVCard($input, &$mimeType = null) {

        $result = HTTP\Util::negotiate(
            $input,
            [
                // Most often used mime-type. Version 3
                'text/x-vcard',
                // The correct standard mime-type. Defaults to version 3 as
                // well.
                'text/vcard',
                // vCard 4
                'text/vcard; version=4.0',
                // vCard 3
                'text/vcard; version=3.0',
                // jCard
                'application/vcard+json',
            ]
        );

        $mimeType = $result;
        switch ($result) {

            default :
            case 'text/x-vcard' :
            case 'text/vcard' :
            case 'text/vcard; version=3.0' :
                $mimeType = 'text/vcard';
                return 'vcard3';
            case 'text/vcard; version=4.0' :
                return 'vcard4';
            case 'application/vcard+json' :
                return 'jcard';

        // @codeCoverageIgnoreStart
        }
        // @codeCoverageIgnoreEnd

    }
开发者ID:nikosv,项目名称:openeclass,代码行数:52,代码来源:Plugin.php


注:本文中的Sabre\HTTP\Util类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。