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) 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 * @param string[] $methods 36 */ 37 function __construct(array $methods) { 38 39 $this->methods = $methods; 40 41 } 42 43 /** 44 * Returns the list of supported http methods. 45 * 46 * @return string[] 47 */ 48 function getValue() { 49 50 return $this->methods; 51 52 } 53 54 /** 55 * Returns true or false if the property contains a specific method. 56 * 57 * @param string $methodName 58 * @return bool 59 */ 60 function has($methodName) { 61 62 return in_array( 63 $methodName, 64 $this->methods 65 ); 66 67 } 68 69 /** 70 * The xmlSerialize method is called during xml writing. 71 * 72 * Use the $writer argument to write its own xml serialization. 73 * 74 * An important note: do _not_ create a parent element. Any element 75 * implementing XmlSerializable should only ever write what's considered 76 * its 'inner xml'. 77 * 78 * The parent of the current element is responsible for writing a 79 * containing element. 80 * 81 * This allows serializers to be re-used for different element names. 82 * 83 * If you are opening new elements, you must also close them again. 84 * 85 * @param Writer $writer 86 * @return void 87 */ 88 function xmlSerialize(Writer $writer) { 89 90 foreach ($this->getValue() as $val) { 91 $writer->startElement('{DAV:}supported-method'); 92 $writer->writeAttribute('name', $val); 93 $writer->endElement(); 94 } 95 96 } 97 98 /** 99 * Generate html representation for this value. 100 * 101 * The html output is 100% trusted, and no effort is being made to sanitize 102 * it. It's up to the implementor to sanitize user provided values. 103 * 104 * The output must be in UTF-8. 105 * 106 * The baseUri parameter is a url to the root of the application, and can 107 * be used to construct local links. 108 * 109 * @param HtmlOutputHelper $html 110 * @return string 111 */ 112 function toHtml(HtmlOutputHelper $html) { 113 114 return implode( 115 ', ', 116 array_map([$html, 'h'], $this->getValue()) 117 ); 118 119 } 120 121} 122