/** * Unserializes the {DAV:}acl xml element. * * @param DOMElement $dom * @return Sabre_DAVACL_Property_Acl */ public static function unserialize(DOMElement $dom) { $privileges = array(); $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 Sabre_DAV_Exception_BadRequest('Each {DAV:}ace element must have one {DAV:}principal element'); } $principal = Sabre_DAVACL_Property_Principal::unserialize($principal->item(0)); if ($principal->getType() !== Sabre_DAVACL_Property_Principal::HREF) { throw new Sabre_DAV_Exception_NotImplemented('Currently only uri based principals are support, {DAV:}all, {DAV:}unauthenticated and {DAV:}authenticated are not implemented yet'); } $principal = $principal->getHref(); $protected = false; if ($xace->getElementsByTagNameNS('urn:DAV', 'protected')->length > 0) { $protected = true; } $grants = $xace->getElementsByTagNameNS('urn:DAV', 'grant'); if ($grants->length < 1) { throw new Sabre_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 = Sabre_DAV_XMLUtil::toClarkNotation($childNode)) { $privilegeName = $t; break; } } if (is_null($privilegeName)) { throw new Sabre_DAV_Exception_BadRequest('{DAV:}privilege elements must have a privilege element contained within them.'); } $privileges[] = array('principal' => $principal, 'protected' => $protected, 'privilege' => $privilegeName); } } return new self($privileges); }
/** * @expectedException Sabre_DAV_Exception_BadRequest */ function testUnserializeUnknown() { $xml = '<?xml version="1.0"?> <d:principal xmlns:d="DAV:">' . ' <d:foo />' . '</d:principal>'; $dom = Sabre_DAV_XMLUtil::loadDOMDocument($xml); Sabre_DAVACL_Property_Principal::unserialize($dom->firstChild); }