php Sabre-DAV-XMLUtil类(方法)实例源码

下面列出了php Sabre-DAV-XMLUtil 类(方法)源码代码实例,从而了解它的用法。

作者:MetallianFR6    项目:myroundcub   
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');
        }
    }

作者:samj191    项目:rep   
/**
     * @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));
    }

作者:samj191    项目:rep   
function parse($xml)
 {
     $xml = implode("\n", $xml);
     $dom = DAV\XMLUtil::loadDOMDocument($xml);
     $q = new AddressBookQueryParser($dom);
     $q->parse();
     return $q;
 }

作者:TamirA    项目:hubzill   
/**
     * @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());
    }

作者:MetallianFR6    项目:myroundcub   
/**
     * @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());
    }

作者:bogolubo    项目:owncollab_talks-   
/**
  * 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);
 }

作者:nem0xf    项目:cor   
/**
  * 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);
 }

作者:GTAWWEKI    项目:tsiserver.u   
/**
  * 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);
 }

作者:ingoratsdor    项目:Tine-2.0-Open-Source-Groupware-and-CR   
/**
  * 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);
 }

作者:enoch8    项目:owncloud-testserve   
/**
  * 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));
     }
 }

作者:TamirA    项目:hubzill   
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'));
    }

作者:enoch8    项目:owncloud-testserve   
/**
  * 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);
 }

作者:Kevin-Z    项目:vaneDis   
/**
  * 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;
 }

作者:enoch8    项目:owncloud-testserve   
/**
  * 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;
 }

作者:bogolubo    项目:owncollab_talks-   
/**
  * 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);
 }

作者:MetallianFR6    项目:myroundcub   
/**
  * Unserializes this property from a DOM Element
  *
  * This method returns an instance of this class.
  * It will only decode {DAV:}href values. For non-compatible elements null will be returned.
  *
  * @param \DOMElement $dom
  * @param array $propertyMap
  * @return DAV\Property\Href
  */
 static function unserialize(\DOMElement $dom, array $propertyMap)
 {
     if ($dom->firstChild && DAV\XMLUtil::toClarkNotation($dom->firstChild) === '{DAV:}href') {
         return new self($dom->firstChild->textContent, false);
     }
 }

作者:floffel0    项目:pydio-cor   
/**
  * Unserializes a DOM element into a ResourceType property.
  *
  * @param \DOMElement $dom
  * @return DAV\Property\ResourceType
  */
 public static function unserialize(\DOMElement $dom)
 {
     $value = array();
     foreach ($dom->childNodes as $child) {
         $value[] = DAV\XMLUtil::toClarkNotation($child);
     }
     return new self($value);
 }

作者:samj191    项目:rep   
/**
  * Unserializes the {DAV:}current-user-privilege-set element.
  *
  * @param \DOMElement $node
  * @param array $propertyMap
  * @return CurrentUserPrivilegeSet
  */
 static function unserialize(\DOMElement $node, array $propertyMap)
 {
     $result = [];
     $xprivs = $node->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;
             }
         }
         $result[] = $privilegeName;
     }
     return new self($result);
 }

作者:floffel0    项目:pydio-cor   
/**
  * 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));
 }

作者:MetallianFR6    项目:myroundcub   
/**
  * parsePrincipalPropertySearchReportRequest
  *
  * This method parses the request body from a
  * {DAV:}principal-property-search report.
  *
  * This method returns an array with two elements:
  *  1. an array with properties to search on, and their values
  *  2. a list of propertyvalues that should be returned for the request.
  *
  * @param \DOMDocument $dom
  * @return array
  */
 protected function parsePrincipalPropertySearchReportRequest($dom)
 {
     $httpDepth = $this->server->getHTTPDepth(0);
     if ($httpDepth !== 0) {
         throw new DAV\Exception\BadRequest('This report is only defined when Depth: 0');
     }
     $searchProperties = [];
     $applyToPrincipalCollectionSet = false;
     $test = $dom->firstChild->getAttribute('test') === 'anyof' ? 'anyof' : 'allof';
     // Parsing the search request
     foreach ($dom->firstChild->childNodes as $searchNode) {
         if (DAV\XMLUtil::toClarkNotation($searchNode) == '{DAV:}apply-to-principal-collection-set') {
             $applyToPrincipalCollectionSet = true;
         }
         if (DAV\XMLUtil::toClarkNotation($searchNode) !== '{DAV:}property-search') {
             continue;
         }
         $propertyName = null;
         $propertyValue = null;
         foreach ($searchNode->childNodes as $childNode) {
             switch (DAV\XMLUtil::toClarkNotation($childNode)) {
                 case '{DAV:}prop':
                     $property = DAV\XMLUtil::parseProperties($searchNode);
                     reset($property);
                     $propertyName = key($property);
                     break;
                 case '{DAV:}match':
                     $propertyValue = $childNode->textContent;
                     break;
             }
         }
         if (is_null($propertyName) || is_null($propertyValue)) {
             throw new DAV\Exception\BadRequest('Invalid search request. propertyname: ' . $propertyName . '. propertvvalue: ' . $propertyValue);
         }
         $searchProperties[$propertyName] = $propertyValue;
     }
     return [$searchProperties, array_keys(DAV\XMLUtil::parseProperties($dom->firstChild)), $applyToPrincipalCollectionSet, $test];
 }


问题


面经


文章

微信
公众号

扫码关注公众号