1<?php 2 3namespace Sabre\DAV\Xml\Property; 4 5use Sabre\DAV\Browser\HtmlOutput; 6use Sabre\DAV\Browser\HtmlOutputHelper; 7use Sabre\Xml\Writer; 8use Sabre\Xml\XmlSerializable; 9 10/** 11 * supported-method-set property. 12 * 13 * This property is defined in RFC3253, but since it's 14 * so common in other webdav-related specs, it is part of the core server. 15 * 16 * This property is defined here: 17 * http://tools.ietf.org/html/rfc3253#section-3.1.3 18 * 19 * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/). 20 * @author Evert Pot (http://evertpot.com/) 21 * @license http://sabre.io/license/ Modified BSD License 22 */ 23class SupportedMethodSet implements XmlSerializable, HtmlOutput { 24 25 /** 26 * List of methods 27 * 28 * @var string[] 29 */ 30 protected $methods = []; 31 32 /** 33 * Creates the property 34 * 35 * Any reports passed in the constructor 36 * should be valid report-types in clark-notation. 37 * 38 * Either a string or an array of strings must be passed. 39 * 40 * @param string|string[] $methods 41 */ 42 function __construct($methods = null) { 43 44 $this->methods = (array)$methods; 45 46 } 47 48 /** 49 * Returns the list of supported http methods. 50 * 51 * @return string[] 52 */ 53 function getValue() { 54 55 return $this->methods; 56 57 } 58 59 /** 60 * Returns true or false if the property contains a specific method. 61 * 62 * @param string $methodName 63 * @return bool 64 */ 65 function has($methodName) { 66 67 return in_array( 68 $methodName, 69 $this->methods 70 ); 71 72 } 73 74 /** 75 * The xmlSerialize metod is called during xml writing. 76 * 77 * Use the $writer argument to write its own xml serialization. 78 * 79 * An important note: do _not_ create a parent element. Any element 80 * implementing XmlSerializble should only ever write what's considered 81 * its 'inner xml'. 82 * 83 * The parent of the current element is responsible for writing a 84 * containing element. 85 * 86 * This allows serializers to be re-used for different element names. 87 * 88 * If you are opening new elements, you must also close them again. 89 * 90 * @param Writer $writer 91 * @return void 92 */ 93 function xmlSerialize(Writer $writer) { 94 95 foreach ($this->getValue() as $val) { 96 $writer->startElement('{DAV:}supported-method'); 97 $writer->writeAttribute('name', $val); 98 $writer->endElement(); 99 } 100 101 } 102 103 /** 104 * Generate html representation for this value. 105 * 106 * The html output is 100% trusted, and no effort is being made to sanitize 107 * it. It's up to the implementor to sanitize user provided values. 108 * 109 * The output must be in UTF-8. 110 * 111 * The baseUri parameter is a url to the root of the application, and can 112 * be used to construct local links. 113 * 114 * @param HtmlOutputHelper $html 115 * @return string 116 */ 117 function toHtml(HtmlOutputHelper $html) { 118 119 return implode( 120 ', ', 121 array_map([$html, 'h'], $this->getValue()) 122 ); 123 124 } 125 126} 127