本文整理汇总了PHP中Sabre\DAV\XMLUtil类的典型用法代码示例。如果您正苦于以下问题:PHP XMLUtil类的具体用法?PHP XMLUtil怎么用?PHP XMLUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XMLUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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');
}
}
示例2: 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));
}
示例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: unserialize
/**
* Unserializes this property from a DOM Element
*
* This method returns an instance of this class.
* It will only decode {DAV:}href values.
*
* @param \DOMElement $dom
* @param array $propertyMap
* @return DAV\Property\HrefList
*/
static function unserialize(\DOMElement $dom, array $propertyMap)
{
$hrefs = [];
foreach ($dom->childNodes as $child) {
if (DAV\XMLUtil::toClarkNotation($child) === '{DAV:}href') {
$hrefs[] = $child->textContent;
}
}
return new self($hrefs, false);
}
示例7: unserialize
/**
* Unserializes this property from a DOM Element
*
* This method returns an instance of this class.
* It will only decode tag values.
*
* @param \DOMElement $dom
* @param array $propertyMap
* @return \OCA\DAV\Connector\Sabre\TagList
*/
static function unserialize(\DOMElement $dom, array $propertyMap)
{
$tags = array();
foreach ($dom->childNodes as $child) {
if (DAV\XMLUtil::toClarkNotation($child) === '{' . self::NS_OWNCLOUD . '}tag') {
$tags[] = $child->textContent;
}
}
return new self($tags);
}
示例8: unserialize
/**
* Unserializes the DOMElement back into a Property class.
*
* @param \DOMElement $node
* @return Property_SupportedCalendarComponentSet
*/
static function unserialize(\DOMElement $node)
{
$components = array();
foreach ($node->childNodes as $childNode) {
if (DAV\XMLUtil::toClarkNotation($childNode) === '{' . CalDAV\Plugin::NS_CALDAV . '}comp') {
$components[] = $childNode->getAttribute('name');
}
}
return new self($components);
}
示例9: calendarMultiGetReport
/**
* This function handles the calendar-multiget REPORT.
*
* prefetch events into calendar container class, to avoid single lookup of events
*
* @param \DOMNode $dom
* @return void
*/
public function calendarMultiGetReport($dom)
{
$properties = array_keys(\Sabre\DAV\XMLUtil::parseProperties($dom->firstChild));
$hrefElems = $dom->getElementsByTagNameNS('urn:DAV', 'href');
$filters = array('name' => 'VCALENDAR', 'comp-filters' => array(array('name' => 'VEVENT', 'prop-filters' => array())));
foreach ($hrefElems as $elem) {
list($dirName, $baseName) = \Sabre\DAV\URLUtil::splitPath($elem->nodeValue);
$filters['comp-filters'][0]['prop-filters'][] = array('name' => 'UID', 'text-match' => array('value' => $baseName));
}
$node = $this->server->tree->getNodeForPath($this->server->getRequestUri());
$node->calendarQuery($filters);
}
示例10: parse
/**
* Parses the request.
*
* @return void
*/
function parse()
{
$filter = $this->xpath->query('/cal:calendar-query/cal:filter');
if ($filter->length !== 1) {
throw new \Sabre\DAV\Exception\BadRequest('Only one filter element is allowed');
}
$compFilters = $this->parseCompFilters($filter->item(0));
if (count($compFilters) !== 1) {
throw new \Sabre\DAV\Exception\BadRequest('There must be exactly 1 top-level comp-filter.');
}
$this->filters = $compFilters[0];
$this->requestedProperties = array_keys(\Sabre\DAV\XMLUtil::parseProperties($this->dom->firstChild));
$expand = $this->xpath->query('/cal:calendar-query/dav:prop/cal:calendar-data/cal:expand');
if ($expand->length > 0) {
$this->expand = $this->parseExpand($expand->item(0));
}
}
示例11: 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'));
}
示例12: unserialize
/**
* Unserializes the DOMElement back into a Property class.
*
* @param \DOMElement $node
* @param array $propertyMap
* @return ScheduleCalendarTransp
*/
static function unserialize(\DOMElement $node, array $propertyMap)
{
$value = null;
foreach ($node->childNodes as $childNode) {
switch (DAV\XMLUtil::toClarkNotation($childNode)) {
case '{' . CalDAV\Plugin::NS_CALDAV . '}opaque':
$value = self::OPAQUE;
break;
case '{' . CalDAV\Plugin::NS_CALDAV . '}transparent':
$value = self::TRANSPARENT;
break;
}
}
if (is_null($value)) {
return null;
}
return new self($value);
}
示例13: parse
/**
* Parses the request.
*
* @return void
*/
function parse()
{
$limit = $this->xpath->evaluate('number(/card:addressbook-query/card:limit/card:nresults)');
if (is_nan($limit)) {
$limit = null;
}
$filter = $this->xpath->query('/card:addressbook-query/card:filter');
// According to the CardDAV spec there needs to be exactly 1 filter
// element. However, KDE 4.8.2 contains a bug that will encode 0 filter
// elements, so this is a workaround for that.
//
// See: https://bugs.kde.org/show_bug.cgi?id=300047
if ($filter->length === 0) {
$test = null;
$filter = null;
} elseif ($filter->length === 1) {
$filter = $filter->item(0);
$test = $this->xpath->evaluate('string(@test)', $filter);
} else {
throw new DAV\Exception\BadRequest('Only one filter element is allowed');
}
if (!$test) {
$test = self::TEST_ANYOF;
}
if ($test !== self::TEST_ANYOF && $test !== self::TEST_ALLOF) {
throw new DAV\Exception\BadRequest('The test attribute must either hold "anyof" or "allof"');
}
$propFilters = [];
if (!is_null($filter)) {
$propFilterNodes = $this->xpath->query('card:prop-filter', $filter);
for ($ii = 0; $ii < $propFilterNodes->length; $ii++) {
$propFilters[] = $this->parsePropFilterNode($propFilterNodes->item($ii));
}
}
$this->filters = $propFilters;
$this->limit = $limit;
$this->requestedProperties = array_keys(DAV\XMLUtil::parseProperties($this->dom->firstChild));
$this->test = $test;
}
示例14: 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;
}
示例15: unserialize
/**
* Unserializes the {DAV:}acl xml element.
*
* @param \DOMElement $dom
* @param array $propertyMap
* @return Acl
*/
static function unserialize(\DOMElement $dom, array $propertyMap)
{
$privileges = [];
$xaces = $dom->getElementsByTagNameNS('urn:DAV', 'ace');
for ($ii = 0; $ii < $xaces->length; $ii++) {
$xace = $xaces->item($ii);
$principal = $xace->getElementsByTagNameNS('urn:DAV', 'principal');
if ($principal->length !== 1) {
throw new DAV\Exception\BadRequest('Each {DAV:}ace element must have one {DAV:}principal element');
}
$principal = Principal::unserialize($principal->item(0), $propertyMap);
switch ($principal->getType()) {
case Principal::HREF:
$principal = $principal->getHref();
break;
case Principal::AUTHENTICATED:
$principal = '{DAV:}authenticated';
break;
case Principal::UNAUTHENTICATED:
$principal = '{DAV:}unauthenticated';
break;
case Principal::ALL:
$principal = '{DAV:}all';
break;
}
$protected = false;
if ($xace->getElementsByTagNameNS('urn:DAV', 'protected')->length > 0) {
$protected = true;
}
$grants = $xace->getElementsByTagNameNS('urn:DAV', 'grant');
if ($grants->length < 1) {
throw new DAV\Exception\NotImplemented('Every {DAV:}ace element must have a {DAV:}grant element. {DAV:}deny is not yet supported');
}
$grant = $grants->item(0);
$xprivs = $grant->getElementsByTagNameNS('urn:DAV', 'privilege');
for ($jj = 0; $jj < $xprivs->length; $jj++) {
$xpriv = $xprivs->item($jj);
$privilegeName = null;
for ($kk = 0; $kk < $xpriv->childNodes->length; $kk++) {
$childNode = $xpriv->childNodes->item($kk);
if ($t = DAV\XMLUtil::toClarkNotation($childNode)) {
$privilegeName = $t;
break;
}
}
if (is_null($privilegeName)) {
throw new DAV\Exception\BadRequest('{DAV:}privilege elements must have a privilege element contained within them.');
}
$privileges[] = ['principal' => $principal, 'protected' => $protected, 'privilege' => $privilegeName];
}
}
return new self($privileges);
}