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


PHP Server::getHTTPPrefer方法代码示例

本文整理汇总了PHP中Sabre\DAV\Server::getHTTPPrefer方法的典型用法代码示例。如果您正苦于以下问题:PHP Server::getHTTPPrefer方法的具体用法?PHP Server::getHTTPPrefer怎么用?PHP Server::getHTTPPrefer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sabre\DAV\Server的用法示例。


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

示例1: testBrief

 function testBrief()
 {
     $httpRequest = HTTP\Sapi::createFromServerArray(array('HTTP_BRIEF' => 't'));
     $server = new Server();
     $server->httpRequest = $httpRequest;
     $this->assertEquals(array('strict' => false, 'lenient' => false, 'wait' => null, 'return-asynch' => false, 'return-minimal' => true, 'return-representation' => false), $server->getHTTPPrefer());
 }
开发者ID:MetallianFR68,项目名称:myroundcube,代码行数:7,代码来源:HTTPPreferParsingTest.php

示例2: testBrief

 function testBrief()
 {
     $httpRequest = HTTP\Sapi::createFromServerArray(['HTTP_BRIEF' => 't']);
     $server = new Server();
     $server->httpRequest = $httpRequest;
     $this->assertEquals(['respond-async' => false, 'return' => 'minimal', 'handling' => null, 'wait' => null], $server->getHTTPPrefer());
 }
开发者ID:sebbie42,项目名称:casebox,代码行数:7,代码来源:HTTPPreferParsingTest.php

示例3: httpPropPatch

 /**
  * WebDAV PROPPATCH
  *
  * This method is called to update properties on a Node. The request is an XML body with all the mutations.
  * In this XML body it is specified which properties should be set/updated and/or deleted
  *
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @return bool
  */
 function httpPropPatch(RequestInterface $request, ResponseInterface $response)
 {
     $path = $request->getPath();
     try {
         $propPatch = $this->server->xml->expect('{DAV:}propertyupdate', $request->getBody());
     } catch (ParseException $e) {
         throw new BadRequest($e->getMessage(), null, $e);
     }
     $newProperties = $propPatch->properties;
     $result = $this->server->updateProperties($path, $newProperties);
     $prefer = $this->server->getHTTPPrefer();
     $response->setHeader('Vary', 'Brief,Prefer');
     if ($prefer['return'] === 'minimal') {
         // If return-minimal is specified, we only have to check if the
         // request was succesful, and don't need to return the
         // multi-status.
         $ok = true;
         foreach ($result as $prop => $code) {
             if ((int) $code > 299) {
                 $ok = false;
             }
         }
         if ($ok) {
             $response->setStatus(204);
             return false;
         }
     }
     $response->setStatus(207);
     $response->setHeader('Content-Type', 'application/xml; charset=utf-8');
     // Reorganizing the result for generateMultiStatus
     $multiStatus = [];
     foreach ($result as $propertyName => $code) {
         if (isset($multiStatus[$code])) {
             $multiStatus[$code][$propertyName] = null;
         } else {
             $multiStatus[$code] = [$propertyName => null];
         }
     }
     $multiStatus['href'] = $path;
     $response->setBody($this->server->generateMultiStatus([$multiStatus]));
     // Sending back false will interupt the event chain and tell the server
     // we've handled this method.
     return false;
 }
开发者ID:drognisep,项目名称:Portfolio-Site,代码行数:54,代码来源:CorePlugin.php

示例4: calendarQueryReport


//.........这里部分代码省略.........
 {
     $path = $this->server->getRequestUri();
     $needsJson = $report->contentType === 'application/calendar+json';
     $node = $this->server->tree->getNodeForPath($this->server->getRequestUri());
     $depth = $this->server->getHTTPDepth(0);
     // The default result is an empty array
     $result = [];
     $calendarTimeZone = null;
     if ($report->expand) {
         // We're expanding, and for that we need to figure out the
         // calendar's timezone.
         $tzProp = '{' . self::NS_CALDAV . '}calendar-timezone';
         $tzResult = $this->server->getProperties($path, [$tzProp]);
         if (isset($tzResult[$tzProp])) {
             // This property contains a VCALENDAR with a single
             // VTIMEZONE.
             $vtimezoneObj = VObject\Reader::read($tzResult[$tzProp]);
             $calendarTimeZone = $vtimezoneObj->VTIMEZONE->getTimeZone();
             unset($vtimezoneObj);
         } else {
             // Defaulting to UTC.
             $calendarTimeZone = new DateTimeZone('UTC');
         }
     }
     // The calendarobject was requested directly. In this case we handle
     // this locally.
     if ($depth == 0 && $node instanceof ICalendarObject) {
         $requestedCalendarData = true;
         $requestedProperties = $report->properties;
         if (!in_array('{urn:ietf:params:xml:ns:caldav}calendar-data', $requestedProperties)) {
             // We always retrieve calendar-data, as we need it for filtering.
             $requestedProperties[] = '{urn:ietf:params:xml:ns:caldav}calendar-data';
             // If calendar-data wasn't explicitly requested, we need to remove
             // it after processing.
             $requestedCalendarData = false;
         }
         $properties = $this->server->getPropertiesForPath($path, $requestedProperties, 0);
         // This array should have only 1 element, the first calendar
         // object.
         $properties = current($properties);
         // If there wasn't any calendar-data returned somehow, we ignore
         // this.
         if (isset($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data'])) {
             $validator = new CalendarQueryValidator();
             $vObject = VObject\Reader::read($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
             if ($validator->validate($vObject, $report->filters)) {
                 // If the client didn't require the calendar-data property,
                 // we won't give it back.
                 if (!$requestedCalendarData) {
                     unset($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
                 } else {
                     if ($report->expand) {
                         $vObject->expand($report->expand['start'], $report->expand['end'], $calendarTimeZone);
                     }
                     if ($needsJson) {
                         $properties[200]['{' . self::NS_CALDAV . '}calendar-data'] = json_encode($vObject->jsonSerialize());
                     } elseif ($report->expand) {
                         $properties[200]['{' . self::NS_CALDAV . '}calendar-data'] = $vObject->serialize();
                     }
                 }
                 $result = [$properties];
             }
         }
     }
     if ($node instanceof ICalendarObjectContainer && $depth === 0) {
         if (strpos($this->server->httpRequest->getHeader('User-Agent'), 'MSFT-WP/') === 0) {
             // Windows phone incorrectly supplied depth as 0, when it actually
             // should have set depth to 1. We're implementing a workaround here
             // to deal with this.
             $depth = 1;
         } else {
             throw new BadRequest('A calendar-query REPORT on a calendar with a Depth: 0 is undefined. Set Depth to 1');
         }
     }
     // If we're dealing with a calendar, the calendar itself is responsible
     // for the calendar-query.
     if ($node instanceof ICalendarObjectContainer && $depth == 1) {
         $nodePaths = $node->calendarQuery($report->filters);
         foreach ($nodePaths as $path) {
             list($properties) = $this->server->getPropertiesForPath($this->server->getRequestUri() . '/' . $path, $report->properties);
             if ($needsJson || $report->expand) {
                 $vObject = VObject\Reader::read($properties[200]['{' . self::NS_CALDAV . '}calendar-data']);
                 if ($report->expand) {
                     $vObject->expand($report->expand['start'], $report->expand['end'], $calendarTimeZone);
                 }
                 if ($needsJson) {
                     $properties[200]['{' . self::NS_CALDAV . '}calendar-data'] = json_encode($vObject->jsonSerialize());
                 } else {
                     $properties[200]['{' . self::NS_CALDAV . '}calendar-data'] = $vObject->serialize();
                 }
             }
             $result[] = $properties;
         }
     }
     $prefer = $this->server->getHTTPPrefer();
     $this->server->httpResponse->setStatus(207);
     $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
     $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer');
     $this->server->httpResponse->setBody($this->server->generateMultiStatus($result, $prefer['return'] === 'minimal'));
 }
开发者ID:sebbie42,项目名称:casebox,代码行数:101,代码来源:Plugin.php

示例5: validateICalendar

 /**
  * Checks if the submitted iCalendar data is in fact, valid.
  *
  * An exception is thrown if it's not.
  *
  * @param resource|string $data
  * @param string $path
  * @param bool $modified Should be set to true, if this event handler
  *                       changed &$data.
  * @param RequestInterface $request The http request.
  * @param ResponseInterface $response The http response.
  * @param bool $isNew Is the item a new one, or an update.
  * @return void
  */
 protected function validateICalendar(&$data, $path, &$modified, RequestInterface $request, ResponseInterface $response, $isNew)
 {
     // If it's a stream, we convert it to a string first.
     if (is_resource($data)) {
         $data = stream_get_contents($data);
     }
     $before = $data;
     try {
         // If the data starts with a [, we can reasonably assume we're dealing
         // with a jCal object.
         if (substr($data, 0, 1) === '[') {
             $vobj = VObject\Reader::readJson($data);
             // Converting $data back to iCalendar, as that's what we
             // technically support everywhere.
             $data = $vobj->serialize();
             $modified = true;
         } else {
             $vobj = VObject\Reader::read($data);
         }
     } catch (VObject\ParseException $e) {
         throw new DAV\Exception\UnsupportedMediaType('This resource only supports valid iCalendar 2.0 data. Parse error: ' . $e->getMessage());
     }
     if ($vobj->name !== 'VCALENDAR') {
         throw new DAV\Exception\UnsupportedMediaType('This collection can only support iCalendar objects.');
     }
     $sCCS = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set';
     // Get the Supported Components for the target calendar
     list($parentPath) = Uri\split($path);
     $calendarProperties = $this->server->getProperties($parentPath, [$sCCS]);
     if (isset($calendarProperties[$sCCS])) {
         $supportedComponents = $calendarProperties[$sCCS]->getValue();
     } else {
         $supportedComponents = ['VJOURNAL', 'VTODO', 'VEVENT'];
     }
     $foundType = null;
     foreach ($vobj->getComponents() as $component) {
         switch ($component->name) {
             case 'VTIMEZONE':
                 continue 2;
             case 'VEVENT':
             case 'VTODO':
             case 'VJOURNAL':
                 $foundType = $component->name;
                 break;
         }
     }
     if (!$foundType || !in_array($foundType, $supportedComponents)) {
         throw new Exception\InvalidComponentType('iCalendar objects must at least have a component of type ' . implode(', ', $supportedComponents));
     }
     $options = VObject\Node::PROFILE_CALDAV;
     $prefer = $this->server->getHTTPPrefer();
     if ($prefer['handling'] !== 'strict') {
         $options |= VObject\Node::REPAIR;
     }
     $messages = $vobj->validate($options);
     $highestLevel = 0;
     $warningMessage = null;
     // $messages contains a list of problems with the vcard, along with
     // their severity.
     foreach ($messages as $message) {
         if ($message['level'] > $highestLevel) {
             // Recording the highest reported error level.
             $highestLevel = $message['level'];
             $warningMessage = $message['message'];
         }
         switch ($message['level']) {
             case 1:
                 // Level 1 means that there was a problem, but it was repaired.
                 $modified = true;
                 break;
             case 2:
                 // Level 2 means a warning, but not critical
                 break;
             case 3:
                 // Level 3 means a critical error
                 throw new DAV\Exception\UnsupportedMediaType('Validation error in iCalendar: ' . $message['message']);
         }
     }
     if ($warningMessage) {
         $response->setHeader('X-Sabre-Ew-Gross', 'iCalendar validation warning: ' . $warningMessage);
     }
     // We use an extra variable to allow event handles to tell us wether
     // the object was modified or not.
     //
     // This helps us determine if we need to re-serialize the object.
     $subModified = false;
//.........这里部分代码省略.........
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:101,代码来源:Plugin.php


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