4 * This class represents the {DAV:}resourcetype property
6 * Normally for files this is empty, and for collection {DAV:}collection.
7 * However, other specs define different values for this.
11 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
12 * @author Evert Pot (http://www.rooftopsolutions.nl/)
13 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
15 class Sabre_DAV_Property_ResourceType extends Sabre_DAV_Property {
22 public $resourceType = array();
27 * @param mixed $resourceType
29 public function __construct($resourceType = array()) {
31 if ($resourceType === Sabre_DAV_Server::NODE_FILE)
32 $this->resourceType = array();
33 elseif ($resourceType === Sabre_DAV_Server::NODE_DIRECTORY)
34 $this->resourceType = array('{DAV:}collection');
35 elseif (is_array($resourceType))
36 $this->resourceType = $resourceType;
38 $this->resourceType = array($resourceType);
45 * @param Sabre_DAV_Server $server
46 * @param DOMElement $prop
49 public function serialize(Sabre_DAV_Server $server, DOMElement $prop) {
52 $rt = $this->resourceType;
54 foreach($rt as $resourceType) {
55 if (preg_match('/^{([^}]*)}(.*)$/',$resourceType,$propName)) {
57 if (isset($server->xmlNamespaces[$propName[1]])) {
58 $prop->appendChild($prop->ownerDocument->createElement($server->xmlNamespaces[$propName[1]] . ':' . $propName[2]));
60 $prop->appendChild($prop->ownerDocument->createElementNS($propName[1],'custom:' . $propName[2]));
69 * Returns the values in clark-notation
71 * For example array('{DAV:}collection')
75 public function getValue() {
77 return $this->resourceType;
82 * Checks if the principal contains a certain value
87 public function is($type) {
89 return in_array($type, $this->resourceType);
94 * Adds a resourcetype value to this property
99 public function add($type) {
101 $this->resourceType[] = $type;
102 $this->resourceType = array_unique($this->resourceType);
107 * Unserializes a DOM element into a ResourceType property.
109 * @param DOMElement $dom
110 * @return Sabre_DAV_Property_ResourceType
112 static public function unserialize(DOMElement $dom) {
115 foreach($dom->childNodes as $child) {
117 $value[] = Sabre_DAV_XMLUtil::toClarkNotation($child);
121 return new self($value);