本文整理汇总了PHP中Sabre\DAV\XMLUtil::loadDOMDocument方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLUtil::loadDOMDocument方法的具体用法?PHP XMLUtil::loadDOMDocument怎么用?PHP XMLUtil::loadDOMDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sabre\DAV\XMLUtil
的用法示例。
在下文中一共展示了XMLUtil::loadDOMDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testUnserializerBadData
/**
* @depends testSimple
*/
function testUnserializerBadData()
{
$xml = '<?xml version="1.0"?>
<d:root xmlns:d="DAV:" xmlns:cal="' . CalDAV\Plugin::NS_CALDAV . '">' . '<cal:foo/>' . '</d:root>';
$dom = DAV\XMLUtil::loadDOMDocument($xml);
$this->assertNull(ScheduleCalendarTransp::unserialize($dom->firstChild));
}
示例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');
}
}
示例3: parse
function parse($xml)
{
$xml = implode("\n", $xml);
$dom = DAV\XMLUtil::loadDOMDocument($xml);
$q = new AddressBookQueryParser($dom);
$q->parse();
return $q;
}
示例4: testUnserializer
/**
* @depends testSimple
*/
function testUnserializer()
{
$xml = '<?xml version="1.0"?>
<d:root xmlns:d="DAV:" xmlns:cal="' . \Sabre\CalDAV\Plugin::NS_CALDAV . '">' . '<cal:comp name="VEVENT"/>' . '<cal:comp name="VJOURNAL"/>' . '</d:root>';
$dom = \Sabre\DAV\XMLUtil::loadDOMDocument($xml);
$property = SupportedCalendarComponentSet::unserialize($dom->firstChild);
$this->assertTrue($property instanceof SupportedCalendarComponentSet);
$this->assertEquals(array('VEVENT', 'VJOURNAL'), $property->getValue());
}
示例5: testUnserialize
/**
* @depends testConstruct
*/
function testUnserialize()
{
$xml = '<?xml version="1.0"?>
<d:anything xmlns:d="DAV:"><d:collection/><d:principal/></d:anything>
';
$dom = DAV\XMLUtil::loadDOMDocument($xml);
$resourceType = ResourceType::unserialize($dom->firstChild, array());
$this->assertEquals(array('{DAV:}collection', '{DAV:}principal'), $resourceType->getValue());
}
示例6: testUnserialize
function testUnserialize()
{
$source = '<?xml version="1.0"?>
<d:root xmlns:d="DAV:">
<d:privilege>
<d:write-properties />
</d:privilege>
<d:privilege>
<d:read />
</d:privilege>
</d:root>
';
$dom = DAV\XMLUtil::loadDOMDocument($source);
$result = CurrentUserPrivilegeSet::unserialize($dom->firstChild, array());
$this->assertTrue($result->has('{DAV:}read'));
$this->assertTrue($result->has('{DAV:}write-properties'));
$this->assertFalse($result->has('{DAV:}bind'));
}
示例7: unknownMethod
/**
* This event is triggered when the server didn't know how to handle a
* certain request.
*
* We intercept this to handle POST requests on calendars.
*
* @param string $method
* @param string $uri
* @return null|bool
*/
public function unknownMethod($method, $uri)
{
if ($method !== 'POST') {
return;
}
// Only handling xml
$contentType = $this->server->httpRequest->getHeader('Content-Type');
if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) {
return;
}
// Making sure the node exists
try {
$node = $this->server->tree->getNodeForPath($uri);
} catch (DAV\Exception\NotFound $e) {
return;
}
$requestBody = $this->server->httpRequest->getBody(true);
// If this request handler could not deal with this POST request, it
// will return 'null' and other plugins get a chance to handle the
// request.
//
// However, we already requested the full body. This is a problem,
// because a body can only be read once. This is why we preemptively
// re-populated the request body with the existing data.
$this->server->httpRequest->setBody($requestBody);
$dom = DAV\XMLUtil::loadDOMDocument($requestBody);
$documentType = DAV\XMLUtil::toClarkNotation($dom->firstChild);
switch ($documentType) {
// Dealing with the 'share' document, which modified invitees on a
// calendar.
case '{' . Plugin::NS_CALENDARSERVER . '}share':
// We can only deal with IShareableCalendar objects
if (!$node instanceof IShareableCalendar) {
return;
}
// Getting ACL info
$acl = $this->server->getPlugin('acl');
// If there's no ACL support, we allow everything
if ($acl) {
$acl->checkPrivileges($uri, '{DAV:}write');
}
$mutations = $this->parseShareRequest($dom);
$node->updateShares($mutations[0], $mutations[1]);
$this->server->httpResponse->sendStatus(200);
// Adding this because sending a response body may cause issues,
// and I wanted some type of indicator the response was handled.
$this->server->httpResponse->setHeader('X-Sabre-Status', 'everything-went-well');
// Breaking the event chain
return false;
// The invite-reply document is sent when the user replies to an
// invitation of a calendar share.
// The invite-reply document is sent when the user replies to an
// invitation of a calendar share.
case '{' . Plugin::NS_CALENDARSERVER . '}invite-reply':
// This only works on the calendar-home-root node.
if (!$node instanceof UserCalendars) {
return;
}
// Getting ACL info
$acl = $this->server->getPlugin('acl');
// If there's no ACL support, we allow everything
if ($acl) {
$acl->checkPrivileges($uri, '{DAV:}write');
}
$message = $this->parseInviteReplyRequest($dom);
$url = $node->shareReply($message['href'], $message['status'], $message['calendarUri'], $message['inReplyTo'], $message['summary']);
$this->server->httpResponse->sendStatus(200);
// Adding this because sending a response body may cause issues,
// and I wanted some type of indicator the response was handled.
$this->server->httpResponse->setHeader('X-Sabre-Status', 'everything-went-well');
if ($url) {
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true;
$root = $dom->createElement('cs:shared-as');
foreach ($this->server->xmlNamespaces as $namespace => $prefix) {
$root->setAttribute('xmlns:' . $prefix, $namespace);
}
$dom->appendChild($root);
$href = new DAV\Property\Href($url);
$href->serialize($this->server, $root);
$this->server->httpResponse->setHeader('Content-Type', 'application/xml');
$this->server->httpResponse->sendBody($dom->saveXML());
}
// Breaking the event chain
return false;
case '{' . Plugin::NS_CALENDARSERVER . '}publish-calendar':
// We can only deal with IShareableCalendar objects
if (!$node instanceof IShareableCalendar) {
return;
}
//.........这里部分代码省略.........
示例8: testSubsequentSyncSyncCollectionDepthFallBack
public function testSubsequentSyncSyncCollectionDepthFallBack()
{
// Making a change
$this->collection->addChange(['file1.txt'], [], []);
// Making another change
$this->collection->addChange([], ['file2.txt'], ['file3.txt']);
$request = HTTP\Sapi::createFromServerArray(['REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/coll/', 'CONTENT_TYPE' => 'application/xml', 'HTTP_DEPTH' => "1"]);
$body = <<<BLA
<?xml version="1.0" encoding="utf-8" ?>
<D:sync-collection xmlns:D="DAV:">
<D:sync-token>http://sabre.io/ns/sync/1</D:sync-token>
<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);
$dom = DAV\XMLUtil::loadDOMDocument($response->body);
// Checking the sync-token
$this->assertEquals('http://sabre.io/ns/sync/2', $dom->getElementsByTagNameNS('urn:DAV', 'sync-token')->item(0)->nodeValue);
$responses = DAV\Property\ResponseList::unserialize($dom->documentElement, []);
$responses = $responses->getResponses();
$this->assertEquals(2, count($responses), 'We expected exactly 2 {DAV:}response');
$response = $responses[0];
$this->assertNull($response->getHttpStatus());
$this->assertEquals('/coll/file2.txt', $response->getHref());
$this->assertEquals([200 => ['{DAV:}getcontentlength' => 3]], $response->getResponseProperties());
$response = $responses[1];
$this->assertEquals('404', $response->getHttpStatus());
$this->assertEquals('/coll/file3.txt', $response->getHref());
$this->assertEquals([], $response->getResponseProperties());
}
示例9: testUnserializeMissingPriv
/**
* @expectedException Sabre\DAV\Exception\BadRequest
*/
function testUnserializeMissingPriv()
{
$source = '<?xml version="1.0"?>
<d:root xmlns:d="DAV:">
<d:ace>
<d:grant>
<d:privilege />
</d:grant>
<d:principal><d:href>/principals/evert</d:href></d:principal>
</d:ace>
</d:root>
';
$dom = DAV\XMLUtil::loadDOMDocument($source);
Acl::unserialize($dom->firstChild, array());
}
示例10: testExpandBadTimes
/**
* @expectedException Sabre\DAV\Exception\BadRequest
*/
function testExpandBadTimes()
{
$xml = array('<d:prop>', ' <c:calendar-data>', ' <c:expand start="20120101T000000Z" end="19980101T000000Z"/>', ' </c:calendar-data>', '</d:prop>', '<c:filter>', ' <c:comp-filter name="VCALENDAR" />', '</c:filter>');
$xml = '<?xml version="1.0"?>
<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">
' . implode("\n", $xml) . '
</c:calendar-query>';
$dom = DAV\XMLUtil::loadDOMDocument($xml);
$q = new CalendarQueryParser($dom);
$q->parse();
}
示例11: httpReport
/**
* HTTP REPORT method implementation
*
* Although the REPORT method is not part of the standard WebDAV spec (it's from rfc3253)
* It's used in a lot of extensions, so it made sense to implement it into the core.
*
* @param RequestInterface $request
* @param ResponseInterface $response
* @return bool
*/
function httpReport(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
$body = $request->getBodyAsString();
$dom = XMLUtil::loadDOMDocument($body);
$reportName = XMLUtil::toClarkNotation($dom->firstChild);
if ($this->server->emit('report', [$reportName, $dom, $path])) {
// If emit returned true, it means the report was not supported
throw new Exception\ReportNotSupported();
}
// Sending back false will interupt the event chain and tell the server
// we've handled this method.
return false;
}
示例12: httpAcl
/**
* This method is responsible for handling the 'ACL' event.
*
* @param RequestInterface $request
* @param ResponseInterface $response
* @return bool
*/
function httpAcl(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
$body = $request->getBodyAsString();
$dom = DAV\XMLUtil::loadDOMDocument($body);
$newAcl = Property\Acl::unserialize($dom->firstChild, $this->server->propertyMap)->getPrivileges();
// Normalizing urls
foreach ($newAcl as $k => $newAce) {
$newAcl[$k]['principal'] = $this->server->calculateUri($newAce['principal']);
}
$node = $this->server->tree->getNodeForPath($path);
if (!$node instanceof IACL) {
throw new DAV\Exception\MethodNotAllowed('This node does not support the ACL method');
}
$oldAcl = $this->getACL($node);
$supportedPrivileges = $this->getFlatPrivilegeSet($node);
/* Checking if protected principals from the existing principal set are
not overwritten. */
foreach ($oldAcl as $oldAce) {
if (!isset($oldAce['protected']) || !$oldAce['protected']) {
continue;
}
$found = false;
foreach ($newAcl as $newAce) {
if ($newAce['privilege'] === $oldAce['privilege'] && $newAce['principal'] === $oldAce['principal'] && $newAce['protected']) {
$found = true;
}
}
if (!$found) {
throw new Exception\AceConflict('This resource contained a protected {DAV:}ace, but this privilege did not occur in the ACL request');
}
}
foreach ($newAcl as $newAce) {
// Do we recognize the privilege
if (!isset($supportedPrivileges[$newAce['privilege']])) {
throw new Exception\NotSupportedPrivilege('The privilege you specified (' . $newAce['privilege'] . ') is not recognized by this server');
}
if ($supportedPrivileges[$newAce['privilege']]['abstract']) {
throw new Exception\NoAbstract('The privilege you specified (' . $newAce['privilege'] . ') is an abstract privilege');
}
// Looking up the principal
try {
$principal = $this->server->tree->getNodeForPath($newAce['principal']);
} catch (DAV\Exception\NotFound $e) {
throw new Exception\NotRecognizedPrincipal('The specified principal (' . $newAce['principal'] . ') does not exist');
}
if (!$principal instanceof IPrincipal) {
throw new Exception\NotRecognizedPrincipal('The specified uri (' . $newAce['principal'] . ') is not a principal');
}
}
$node->setACL($newAcl);
$response->setStatus(200);
// Breaking the event chain, because we handled this method.
return false;
}
示例13: testUnserializeUnknown
/**
* @expectedException Sabre\DAV\Exception\BadRequest
*/
function testUnserializeUnknown()
{
$xml = '<?xml version="1.0"?>
<d:principal xmlns:d="DAV:">' . ' <d:foo />' . '</d:principal>';
$dom = DAV\XMLUtil::loadDOMDocument($xml);
Principal::unserialize($dom->firstChild, array());
}
示例14: testFreeBusyReportNoACLPlugin
/**
* @expectedException Sabre\DAV\Exception
*/
function testFreeBusyReportNoACLPlugin()
{
$this->server = new DAV\Server();
$this->plugin = new Plugin();
$this->server->addPlugin($this->plugin);
$reportXML = <<<XML
<?xml version="1.0"?>
<c:free-busy-query xmlns:c="urn:ietf:params:xml:ns:caldav">
<c:time-range start="20111001T000000Z" end="20111101T000000Z" />
</c:free-busy-query>
XML;
$dom = DAV\XMLUtil::loadDOMDocument($reportXML);
$this->plugin->report('{urn:ietf:params:xml:ns:caldav}free-busy-query', $dom);
}
示例15: parsePropFindRequest
/**
* This method parses the PROPFIND request and returns its information
*
* This will either be a list of properties, or an empty array; in which case
* an {DAV:}allprop was requested.
*
* @param string $body
* @return array
*/
public function parsePropFindRequest($body)
{
// If the propfind body was empty, it means IE is requesting 'all' properties
if (!$body) {
return array();
}
$dom = XMLUtil::loadDOMDocument($body);
$elem = $dom->getElementsByTagNameNS('urn:DAV', 'propfind')->item(0);
return array_keys(XMLUtil::parseProperties($elem));
}