1<?php 2 3namespace Sabre\DAV\Xml\Property; 4 5use Sabre\DAV\Browser\HtmlOutput; 6use Sabre\DAV\Browser\HtmlOutputHelper; 7use Sabre\Xml\Element; 8use Sabre\Xml\Reader; 9 10/** 11 * {DAV:}resourcetype property 12 * 13 * This class represents the {DAV:}resourcetype property, as defined in: 14 * 15 * https://tools.ietf.org/html/rfc4918#section-15.9 16 * 17 * @copyright Copyright (C) fruux GmbH (https://fruux.com/) 18 * @author Evert Pot (http://evertpot.com/) 19 * @license http://sabre.io/license/ Modified BSD License 20 */ 21class ResourceType extends Element\Elements implements HtmlOutput { 22 23 /** 24 * Constructor 25 * 26 * You can either pass null (for no resourcetype), a string (for a single 27 * resourcetype) or an array (for multiple). 28 * 29 * The resourcetype must be specified in clark-notation 30 * 31 * @param array|string|null $resourceTypes 32 */ 33 function __construct($resourceTypes = null) { 34 35 parent::__construct((array)$resourceTypes); 36 37 } 38 39 /** 40 * Returns the values in clark-notation 41 * 42 * For example array('{DAV:}collection') 43 * 44 * @return array 45 */ 46 function getValue() { 47 48 return $this->value; 49 50 } 51 52 /** 53 * Checks if the principal contains a certain value 54 * 55 * @param string $type 56 * @return bool 57 */ 58 function is($type) { 59 60 return in_array($type, $this->value); 61 62 } 63 64 /** 65 * Adds a resourcetype value to this property 66 * 67 * @param string $type 68 * @return void 69 */ 70 function add($type) { 71 72 $this->value[] = $type; 73 $this->value = array_unique($this->value); 74 75 } 76 77 /** 78 * The deserialize method is called during xml parsing. 79 * 80 * This method is called statically, this is because in theory this method 81 * may be used as a type of constructor, or factory method. 82 * 83 * Often you want to return an instance of the current class, but you are 84 * free to return other data as well. 85 * 86 * Important note 2: You are responsible for advancing the reader to the 87 * next element. Not doing anything will result in a never-ending loop. 88 * 89 * If you just want to skip parsing for this element altogether, you can 90 * just call $reader->next(); 91 * 92 * $reader->parseInnerTree() will parse the entire sub-tree, and advance to 93 * the next element. 94 * 95 * @param Reader $reader 96 * @return mixed 97 */ 98 static function xmlDeserialize(Reader $reader) { 99 100 return 101 new self(parent::xmlDeserialize($reader)); 102 103 } 104 105 /** 106 * Generate html representation for this value. 107 * 108 * The html output is 100% trusted, and no effort is being made to sanitize 109 * it. It's up to the implementor to sanitize user provided values. 110 * 111 * The output must be in UTF-8. 112 * 113 * The baseUri parameter is a url to the root of the application, and can 114 * be used to construct local links. 115 * 116 * @param HtmlOutputHelper $html 117 * @return string 118 */ 119 function toHtml(HtmlOutputHelper $html) { 120 121 return implode( 122 ', ', 123 array_map([$html, 'xmlName'], $this->getValue()) 124 ); 125 126 } 127 128} 129