repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
39
1.84M
func_code_tokens
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
sabre-io/dav
lib/DAV/FSExt/Directory.php
Directory.getQuotaInfo
public function getQuotaInfo() { $total = disk_total_space(realpath($this->path)); $free = disk_free_space(realpath($this->path)); return [ $total - $free, $free, ]; }
php
public function getQuotaInfo() { $total = disk_total_space(realpath($this->path)); $free = disk_free_space(realpath($this->path)); return [ $total - $free, $free, ]; }
[ "public", "function", "getQuotaInfo", "(", ")", "{", "$", "total", "=", "disk_total_space", "(", "realpath", "(", "$", "this", "->", "path", ")", ")", ";", "$", "free", "=", "disk_free_space", "(", "realpath", "(", "$", "this", "->", "path", ")", ")", ";", "return", "[", "$", "total", "-", "$", "free", ",", "$", "free", ",", "]", ";", "}" ]
Returns available diskspace information. @return array
[ "Returns", "available", "diskspace", "information", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/FSExt/Directory.php#L167-L176
sabre-io/dav
lib/DAV/FSExt/Directory.php
Directory.moveInto
public function moveInto($targetName, $sourcePath, DAV\INode $sourceNode) { // We only support FSExt\Directory or FSExt\File objects, so // anything else we want to quickly reject. if (!$sourceNode instanceof self && !$sourceNode instanceof File) { return false; } // PHP allows us to access protected properties from other objects, as // long as they are defined in a class that has a shared inheritance // with the current class. return rename($sourceNode->path, $this->path.'/'.$targetName); }
php
public function moveInto($targetName, $sourcePath, DAV\INode $sourceNode) { if (!$sourceNode instanceof self && !$sourceNode instanceof File) { return false; } return rename($sourceNode->path, $this->path.'/'.$targetName); }
[ "public", "function", "moveInto", "(", "$", "targetName", ",", "$", "sourcePath", ",", "DAV", "\\", "INode", "$", "sourceNode", ")", "{", "// We only support FSExt\\Directory or FSExt\\File objects, so", "// anything else we want to quickly reject.", "if", "(", "!", "$", "sourceNode", "instanceof", "self", "&&", "!", "$", "sourceNode", "instanceof", "File", ")", "{", "return", "false", ";", "}", "// PHP allows us to access protected properties from other objects, as", "// long as they are defined in a class that has a shared inheritance", "// with the current class.", "return", "rename", "(", "$", "sourceNode", "->", "path", ",", "$", "this", "->", "path", ".", "'/'", ".", "$", "targetName", ")", ";", "}" ]
Moves a node into this collection. It is up to the implementors to: 1. Create the new resource. 2. Remove the old resource. 3. Transfer any properties or other data. Generally you should make very sure that your collection can easily move the move. If you don't, just return false, which will trigger sabre/dav to handle the move itself. If you return true from this function, the assumption is that the move was successful. @param string $targetName new local file/collection name @param string $sourcePath Full path to source node @param DAV\INode $sourceNode Source node itself @return bool
[ "Moves", "a", "node", "into", "this", "collection", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/FSExt/Directory.php#L199-L211
sabre-io/dav
lib/CalDAV/SharedCalendar.php
SharedCalendar.getACL
public function getACL() { $acl = []; switch ($this->getShareAccess()) { case SPlugin::ACCESS_NOTSHARED: case SPlugin::ACCESS_SHAREDOWNER: $acl[] = [ 'privilege' => '{DAV:}share', 'principal' => $this->calendarInfo['principaluri'], 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}share', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write', 'protected' => true, ]; // no break intentional! case SPlugin::ACCESS_READWRITE: $acl[] = [ 'privilege' => '{DAV:}write', 'principal' => $this->calendarInfo['principaluri'], 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}write', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write', 'protected' => true, ]; // no break intentional! case SPlugin::ACCESS_READ: $acl[] = [ 'privilege' => '{DAV:}write-properties', 'principal' => $this->calendarInfo['principaluri'], 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}write-properties', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write', 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}read', 'principal' => $this->calendarInfo['principaluri'], 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}read', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-read', 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}read', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write', 'protected' => true, ]; $acl[] = [ 'privilege' => '{'.Plugin::NS_CALDAV.'}read-free-busy', 'principal' => '{DAV:}authenticated', 'protected' => true, ]; break; } return $acl; }
php
public function getACL() { $acl = []; switch ($this->getShareAccess()) { case SPlugin::ACCESS_NOTSHARED: case SPlugin::ACCESS_SHAREDOWNER: $acl[] = [ 'privilege' => '{DAV:}share', 'principal' => $this->calendarInfo['principaluri'], 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}share', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write', 'protected' => true, ]; case SPlugin::ACCESS_READWRITE: $acl[] = [ 'privilege' => '{DAV:}write', 'principal' => $this->calendarInfo['principaluri'], 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}write', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write', 'protected' => true, ]; case SPlugin::ACCESS_READ: $acl[] = [ 'privilege' => '{DAV:}write-properties', 'principal' => $this->calendarInfo['principaluri'], 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}write-properties', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write', 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}read', 'principal' => $this->calendarInfo['principaluri'], 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}read', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-read', 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}read', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write', 'protected' => true, ]; $acl[] = [ 'privilege' => '{'.Plugin::NS_CALDAV.'}read-free-busy', 'principal' => '{DAV:}authenticated', 'protected' => true, ]; break; } return $acl; }
[ "public", "function", "getACL", "(", ")", "{", "$", "acl", "=", "[", "]", ";", "switch", "(", "$", "this", "->", "getShareAccess", "(", ")", ")", "{", "case", "SPlugin", "::", "ACCESS_NOTSHARED", ":", "case", "SPlugin", "::", "ACCESS_SHAREDOWNER", ":", "$", "acl", "[", "]", "=", "[", "'privilege'", "=>", "'{DAV:}share'", ",", "'principal'", "=>", "$", "this", "->", "calendarInfo", "[", "'principaluri'", "]", ",", "'protected'", "=>", "true", ",", "]", ";", "$", "acl", "[", "]", "=", "[", "'privilege'", "=>", "'{DAV:}share'", ",", "'principal'", "=>", "$", "this", "->", "calendarInfo", "[", "'principaluri'", "]", ".", "'/calendar-proxy-write'", ",", "'protected'", "=>", "true", ",", "]", ";", "// no break intentional!", "case", "SPlugin", "::", "ACCESS_READWRITE", ":", "$", "acl", "[", "]", "=", "[", "'privilege'", "=>", "'{DAV:}write'", ",", "'principal'", "=>", "$", "this", "->", "calendarInfo", "[", "'principaluri'", "]", ",", "'protected'", "=>", "true", ",", "]", ";", "$", "acl", "[", "]", "=", "[", "'privilege'", "=>", "'{DAV:}write'", ",", "'principal'", "=>", "$", "this", "->", "calendarInfo", "[", "'principaluri'", "]", ".", "'/calendar-proxy-write'", ",", "'protected'", "=>", "true", ",", "]", ";", "// no break intentional!", "case", "SPlugin", "::", "ACCESS_READ", ":", "$", "acl", "[", "]", "=", "[", "'privilege'", "=>", "'{DAV:}write-properties'", ",", "'principal'", "=>", "$", "this", "->", "calendarInfo", "[", "'principaluri'", "]", ",", "'protected'", "=>", "true", ",", "]", ";", "$", "acl", "[", "]", "=", "[", "'privilege'", "=>", "'{DAV:}write-properties'", ",", "'principal'", "=>", "$", "this", "->", "calendarInfo", "[", "'principaluri'", "]", ".", "'/calendar-proxy-write'", ",", "'protected'", "=>", "true", ",", "]", ";", "$", "acl", "[", "]", "=", "[", "'privilege'", "=>", "'{DAV:}read'", ",", "'principal'", "=>", "$", "this", "->", "calendarInfo", "[", "'principaluri'", "]", ",", "'protected'", "=>", "true", ",", "]", ";", "$", "acl", "[", "]", "=", "[", "'privilege'", "=>", "'{DAV:}read'", ",", "'principal'", "=>", "$", "this", "->", "calendarInfo", "[", "'principaluri'", "]", ".", "'/calendar-proxy-read'", ",", "'protected'", "=>", "true", ",", "]", ";", "$", "acl", "[", "]", "=", "[", "'privilege'", "=>", "'{DAV:}read'", ",", "'principal'", "=>", "$", "this", "->", "calendarInfo", "[", "'principaluri'", "]", ".", "'/calendar-proxy-write'", ",", "'protected'", "=>", "true", ",", "]", ";", "$", "acl", "[", "]", "=", "[", "'privilege'", "=>", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}read-free-busy'", ",", "'principal'", "=>", "'{DAV:}authenticated'", ",", "'protected'", "=>", "true", ",", "]", ";", "break", ";", "}", "return", "$", "acl", ";", "}" ]
Returns a list of ACE's for this node. Each ACE has the following properties: * 'privilege', a string such as {DAV:}read or {DAV:}write. These are currently the only supported privileges * 'principal', a url to the principal who owns the node * 'protected' (optional), indicating that this ACE is not allowed to be updated. @return array
[ "Returns", "a", "list", "of", "ACE", "s", "for", "this", "node", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/SharedCalendar.php#L105-L170
sabre-io/dav
lib/CalDAV/SharedCalendar.php
SharedCalendar.getChildACL
public function getChildACL() { $acl = []; switch ($this->getShareAccess()) { case SPlugin::ACCESS_NOTSHARED: case SPlugin::ACCESS_SHAREDOWNER: case SPlugin::ACCESS_READWRITE: $acl[] = [ 'privilege' => '{DAV:}write', 'principal' => $this->calendarInfo['principaluri'], 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}write', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write', 'protected' => true, ]; // no break intentional case SPlugin::ACCESS_READ: $acl[] = [ 'privilege' => '{DAV:}read', 'principal' => $this->calendarInfo['principaluri'], 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}read', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write', 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}read', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-read', 'protected' => true, ]; break; } return $acl; }
php
public function getChildACL() { $acl = []; switch ($this->getShareAccess()) { case SPlugin::ACCESS_NOTSHARED: case SPlugin::ACCESS_SHAREDOWNER: case SPlugin::ACCESS_READWRITE: $acl[] = [ 'privilege' => '{DAV:}write', 'principal' => $this->calendarInfo['principaluri'], 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}write', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write', 'protected' => true, ]; case SPlugin::ACCESS_READ: $acl[] = [ 'privilege' => '{DAV:}read', 'principal' => $this->calendarInfo['principaluri'], 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}read', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write', 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}read', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-read', 'protected' => true, ]; break; } return $acl; }
[ "public", "function", "getChildACL", "(", ")", "{", "$", "acl", "=", "[", "]", ";", "switch", "(", "$", "this", "->", "getShareAccess", "(", ")", ")", "{", "case", "SPlugin", "::", "ACCESS_NOTSHARED", ":", "case", "SPlugin", "::", "ACCESS_SHAREDOWNER", ":", "case", "SPlugin", "::", "ACCESS_READWRITE", ":", "$", "acl", "[", "]", "=", "[", "'privilege'", "=>", "'{DAV:}write'", ",", "'principal'", "=>", "$", "this", "->", "calendarInfo", "[", "'principaluri'", "]", ",", "'protected'", "=>", "true", ",", "]", ";", "$", "acl", "[", "]", "=", "[", "'privilege'", "=>", "'{DAV:}write'", ",", "'principal'", "=>", "$", "this", "->", "calendarInfo", "[", "'principaluri'", "]", ".", "'/calendar-proxy-write'", ",", "'protected'", "=>", "true", ",", "]", ";", "// no break intentional", "case", "SPlugin", "::", "ACCESS_READ", ":", "$", "acl", "[", "]", "=", "[", "'privilege'", "=>", "'{DAV:}read'", ",", "'principal'", "=>", "$", "this", "->", "calendarInfo", "[", "'principaluri'", "]", ",", "'protected'", "=>", "true", ",", "]", ";", "$", "acl", "[", "]", "=", "[", "'privilege'", "=>", "'{DAV:}read'", ",", "'principal'", "=>", "$", "this", "->", "calendarInfo", "[", "'principaluri'", "]", ".", "'/calendar-proxy-write'", ",", "'protected'", "=>", "true", ",", "]", ";", "$", "acl", "[", "]", "=", "[", "'privilege'", "=>", "'{DAV:}read'", ",", "'principal'", "=>", "$", "this", "->", "calendarInfo", "[", "'principaluri'", "]", ".", "'/calendar-proxy-read'", ",", "'protected'", "=>", "true", ",", "]", ";", "break", ";", "}", "return", "$", "acl", ";", "}" ]
This method returns the ACL's for calendar objects in this calendar. The result of this method automatically gets passed to the calendar-object nodes in the calendar. @return array
[ "This", "method", "returns", "the", "ACL", "s", "for", "calendar", "objects", "in", "this", "calendar", ".", "The", "result", "of", "this", "method", "automatically", "gets", "passed", "to", "the", "calendar", "-", "object", "nodes", "in", "the", "calendar", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/SharedCalendar.php#L179-L218
sabre-io/dav
lib/CalDAV/Xml/Filter/ParamFilter.php
ParamFilter.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { $result = [ 'name' => null, 'is-not-defined' => false, 'text-match' => null, ]; $att = $reader->parseAttributes(); $result['name'] = $att['name']; $elems = $reader->parseInnerTree(); if (is_array($elems)) { foreach ($elems as $elem) { switch ($elem['name']) { case '{'.Plugin::NS_CALDAV.'}is-not-defined': $result['is-not-defined'] = true; break; case '{'.Plugin::NS_CALDAV.'}text-match': $result['text-match'] = [ 'negate-condition' => isset($elem['attributes']['negate-condition']) && 'yes' === $elem['attributes']['negate-condition'], 'collation' => isset($elem['attributes']['collation']) ? $elem['attributes']['collation'] : 'i;ascii-casemap', 'value' => $elem['value'], ]; break; } } } return $result; }
php
public static function xmlDeserialize(Reader $reader) { $result = [ 'name' => null, 'is-not-defined' => false, 'text-match' => null, ]; $att = $reader->parseAttributes(); $result['name'] = $att['name']; $elems = $reader->parseInnerTree(); if (is_array($elems)) { foreach ($elems as $elem) { switch ($elem['name']) { case '{'.Plugin::NS_CALDAV.'}is-not-defined': $result['is-not-defined'] = true; break; case '{'.Plugin::NS_CALDAV.'}text-match': $result['text-match'] = [ 'negate-condition' => isset($elem['attributes']['negate-condition']) && 'yes' === $elem['attributes']['negate-condition'], 'collation' => isset($elem['attributes']['collation']) ? $elem['attributes']['collation'] : 'i;ascii-casemap', 'value' => $elem['value'], ]; break; } } } return $result; }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "$", "result", "=", "[", "'name'", "=>", "null", ",", "'is-not-defined'", "=>", "false", ",", "'text-match'", "=>", "null", ",", "]", ";", "$", "att", "=", "$", "reader", "->", "parseAttributes", "(", ")", ";", "$", "result", "[", "'name'", "]", "=", "$", "att", "[", "'name'", "]", ";", "$", "elems", "=", "$", "reader", "->", "parseInnerTree", "(", ")", ";", "if", "(", "is_array", "(", "$", "elems", ")", ")", "{", "foreach", "(", "$", "elems", "as", "$", "elem", ")", "{", "switch", "(", "$", "elem", "[", "'name'", "]", ")", "{", "case", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}is-not-defined'", ":", "$", "result", "[", "'is-not-defined'", "]", "=", "true", ";", "break", ";", "case", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}text-match'", ":", "$", "result", "[", "'text-match'", "]", "=", "[", "'negate-condition'", "=>", "isset", "(", "$", "elem", "[", "'attributes'", "]", "[", "'negate-condition'", "]", ")", "&&", "'yes'", "===", "$", "elem", "[", "'attributes'", "]", "[", "'negate-condition'", "]", ",", "'collation'", "=>", "isset", "(", "$", "elem", "[", "'attributes'", "]", "[", "'collation'", "]", ")", "?", "$", "elem", "[", "'attributes'", "]", "[", "'collation'", "]", ":", "'i;ascii-casemap'", ",", "'value'", "=>", "$", "elem", "[", "'value'", "]", ",", "]", ";", "break", ";", "}", "}", "}", "return", "$", "result", ";", "}" ]
The deserialize method is called during xml parsing. This method is called statically, this is because in theory this method may be used as a type of constructor, or factory method. Often you want to return an instance of the current class, but you are free to return other data as well. Important note 2: You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop. If you just want to skip parsing for this element altogether, you can just call $reader->next(); $reader->parseInnerTree() will parse the entire sub-tree, and advance to the next element. @param Reader $reader @return mixed
[ "The", "deserialize", "method", "is", "called", "during", "xml", "parsing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Xml/Filter/ParamFilter.php#L49-L80
sabre-io/dav
lib/DAV/Xml/Element/Prop.php
Prop.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { // If there's no children, we don't do anything. if ($reader->isEmptyElement) { $reader->next(); return []; } $values = []; $reader->read(); do { if (Reader::ELEMENT === $reader->nodeType) { $clark = $reader->getClark(); $values[$clark] = self::parseCurrentElement($reader)['value']; } else { $reader->read(); } } while (Reader::END_ELEMENT !== $reader->nodeType); $reader->read(); return $values; }
php
public static function xmlDeserialize(Reader $reader) { if ($reader->isEmptyElement) { $reader->next(); return []; } $values = []; $reader->read(); do { if (Reader::ELEMENT === $reader->nodeType) { $clark = $reader->getClark(); $values[$clark] = self::parseCurrentElement($reader)['value']; } else { $reader->read(); } } while (Reader::END_ELEMENT !== $reader->nodeType); $reader->read(); return $values; }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "// If there's no children, we don't do anything.", "if", "(", "$", "reader", "->", "isEmptyElement", ")", "{", "$", "reader", "->", "next", "(", ")", ";", "return", "[", "]", ";", "}", "$", "values", "=", "[", "]", ";", "$", "reader", "->", "read", "(", ")", ";", "do", "{", "if", "(", "Reader", "::", "ELEMENT", "===", "$", "reader", "->", "nodeType", ")", "{", "$", "clark", "=", "$", "reader", "->", "getClark", "(", ")", ";", "$", "values", "[", "$", "clark", "]", "=", "self", "::", "parseCurrentElement", "(", "$", "reader", ")", "[", "'value'", "]", ";", "}", "else", "{", "$", "reader", "->", "read", "(", ")", ";", "}", "}", "while", "(", "Reader", "::", "END_ELEMENT", "!==", "$", "reader", "->", "nodeType", ")", ";", "$", "reader", "->", "read", "(", ")", ";", "return", "$", "values", ";", "}" ]
The deserialize method is called during xml parsing. This method is called statically, this is because in theory this method may be used as a type of constructor, or factory method. Often you want to return an instance of the current class, but you are free to return other data as well. You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop. If you just want to skip parsing for this element altogether, you can just call $reader->next(); $reader->parseInnerTree() will parse the entire sub-tree, and advance to the next element. @param Reader $reader @return mixed
[ "The", "deserialize", "method", "is", "called", "during", "xml", "parsing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Element/Prop.php#L46-L70
sabre-io/dav
lib/DAV/Xml/Element/Prop.php
Prop.parseCurrentElement
private static function parseCurrentElement(Reader $reader) { $name = $reader->getClark(); if (array_key_exists($name, $reader->elementMap)) { $deserializer = $reader->elementMap[$name]; if (is_subclass_of($deserializer, 'Sabre\\Xml\\XmlDeserializable')) { $value = call_user_func([$deserializer, 'xmlDeserialize'], $reader); } elseif (is_callable($deserializer)) { $value = call_user_func($deserializer, $reader); } else { $type = gettype($deserializer); if ('string' === $type) { $type .= ' ('.$deserializer.')'; } elseif ('object' === $type) { $type .= ' ('.get_class($deserializer).')'; } throw new \LogicException('Could not use this type as a deserializer: '.$type); } } else { $value = Complex::xmlDeserialize($reader); } return [ 'name' => $name, 'value' => $value, ]; }
php
private static function parseCurrentElement(Reader $reader) { $name = $reader->getClark(); if (array_key_exists($name, $reader->elementMap)) { $deserializer = $reader->elementMap[$name]; if (is_subclass_of($deserializer, 'Sabre\\Xml\\XmlDeserializable')) { $value = call_user_func([$deserializer, 'xmlDeserialize'], $reader); } elseif (is_callable($deserializer)) { $value = call_user_func($deserializer, $reader); } else { $type = gettype($deserializer); if ('string' === $type) { $type .= ' ('.$deserializer.')'; } elseif ('object' === $type) { $type .= ' ('.get_class($deserializer).')'; } throw new \LogicException('Could not use this type as a deserializer: '.$type); } } else { $value = Complex::xmlDeserialize($reader); } return [ 'name' => $name, 'value' => $value, ]; }
[ "private", "static", "function", "parseCurrentElement", "(", "Reader", "$", "reader", ")", "{", "$", "name", "=", "$", "reader", "->", "getClark", "(", ")", ";", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "reader", "->", "elementMap", ")", ")", "{", "$", "deserializer", "=", "$", "reader", "->", "elementMap", "[", "$", "name", "]", ";", "if", "(", "is_subclass_of", "(", "$", "deserializer", ",", "'Sabre\\\\Xml\\\\XmlDeserializable'", ")", ")", "{", "$", "value", "=", "call_user_func", "(", "[", "$", "deserializer", ",", "'xmlDeserialize'", "]", ",", "$", "reader", ")", ";", "}", "elseif", "(", "is_callable", "(", "$", "deserializer", ")", ")", "{", "$", "value", "=", "call_user_func", "(", "$", "deserializer", ",", "$", "reader", ")", ";", "}", "else", "{", "$", "type", "=", "gettype", "(", "$", "deserializer", ")", ";", "if", "(", "'string'", "===", "$", "type", ")", "{", "$", "type", ".=", "' ('", ".", "$", "deserializer", ".", "')'", ";", "}", "elseif", "(", "'object'", "===", "$", "type", ")", "{", "$", "type", ".=", "' ('", ".", "get_class", "(", "$", "deserializer", ")", ".", "')'", ";", "}", "throw", "new", "\\", "LogicException", "(", "'Could not use this type as a deserializer: '", ".", "$", "type", ")", ";", "}", "}", "else", "{", "$", "value", "=", "Complex", "::", "xmlDeserialize", "(", "$", "reader", ")", ";", "}", "return", "[", "'name'", "=>", "$", "name", ",", "'value'", "=>", "$", "value", ",", "]", ";", "}" ]
This function behaves similar to Sabre\Xml\Reader::parseCurrentElement, but instead of creating deep xml array structures, it will turn any top-level element it doesn't recognize into either a string, or an XmlFragment class. This method returns arn array with 2 properties: * name - A clark-notation XML element name. * value - The parsed value. @param Reader $reader @return array
[ "This", "function", "behaves", "similar", "to", "Sabre", "\\", "Xml", "\\", "Reader", "::", "parseCurrentElement", "but", "instead", "of", "creating", "deep", "xml", "array", "structures", "it", "will", "turn", "any", "top", "-", "level", "element", "it", "doesn", "t", "recognize", "into", "either", "a", "string", "or", "an", "XmlFragment", "class", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Element/Prop.php#L86-L113
sabre-io/dav
lib/DAV/Browser/Plugin.php
Plugin.initialize
public function initialize(DAV\Server $server) { $this->server = $server; $this->server->on('method:GET', [$this, 'httpGetEarly'], 90); $this->server->on('method:GET', [$this, 'httpGet'], 200); $this->server->on('onHTMLActionsPanel', [$this, 'htmlActionsPanel'], 200); if ($this->enablePost) { $this->server->on('method:POST', [$this, 'httpPOST']); } }
php
public function initialize(DAV\Server $server) { $this->server = $server; $this->server->on('method:GET', [$this, 'httpGetEarly'], 90); $this->server->on('method:GET', [$this, 'httpGet'], 200); $this->server->on('onHTMLActionsPanel', [$this, 'htmlActionsPanel'], 200); if ($this->enablePost) { $this->server->on('method:POST', [$this, 'httpPOST']); } }
[ "public", "function", "initialize", "(", "DAV", "\\", "Server", "$", "server", ")", "{", "$", "this", "->", "server", "=", "$", "server", ";", "$", "this", "->", "server", "->", "on", "(", "'method:GET'", ",", "[", "$", "this", ",", "'httpGetEarly'", "]", ",", "90", ")", ";", "$", "this", "->", "server", "->", "on", "(", "'method:GET'", ",", "[", "$", "this", ",", "'httpGet'", "]", ",", "200", ")", ";", "$", "this", "->", "server", "->", "on", "(", "'onHTMLActionsPanel'", ",", "[", "$", "this", ",", "'htmlActionsPanel'", "]", ",", "200", ")", ";", "if", "(", "$", "this", "->", "enablePost", ")", "{", "$", "this", "->", "server", "->", "on", "(", "'method:POST'", ",", "[", "$", "this", ",", "'httpPOST'", "]", ")", ";", "}", "}" ]
Initializes the plugin and subscribes to events. @param DAV\Server $server
[ "Initializes", "the", "plugin", "and", "subscribes", "to", "events", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/Plugin.php#L76-L85
sabre-io/dav
lib/DAV/Browser/Plugin.php
Plugin.httpGetEarly
public function httpGetEarly(RequestInterface $request, ResponseInterface $response) { $params = $request->getQueryParameters(); if (isset($params['sabreAction']) && 'info' === $params['sabreAction']) { return $this->httpGet($request, $response); } }
php
public function httpGetEarly(RequestInterface $request, ResponseInterface $response) { $params = $request->getQueryParameters(); if (isset($params['sabreAction']) && 'info' === $params['sabreAction']) { return $this->httpGet($request, $response); } }
[ "public", "function", "httpGetEarly", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "params", "=", "$", "request", "->", "getQueryParameters", "(", ")", ";", "if", "(", "isset", "(", "$", "params", "[", "'sabreAction'", "]", ")", "&&", "'info'", "===", "$", "params", "[", "'sabreAction'", "]", ")", "{", "return", "$", "this", "->", "httpGet", "(", "$", "request", ",", "$", "response", ")", ";", "}", "}" ]
This method intercepts GET requests that have ?sabreAction=info appended to the URL. @param RequestInterface $request @param ResponseInterface $response @return bool
[ "This", "method", "intercepts", "GET", "requests", "that", "have", "?sabreAction", "=", "info", "appended", "to", "the", "URL", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/Plugin.php#L96-L102
sabre-io/dav
lib/DAV/Browser/Plugin.php
Plugin.httpGet
public function httpGet(RequestInterface $request, ResponseInterface $response) { // We're not using straight-up $_GET, because we want everything to be // unit testable. $getVars = $request->getQueryParameters(); // CSP headers $response->setHeader('Content-Security-Policy', "default-src 'none'; img-src 'self'; style-src 'self'; font-src 'self';"); $sabreAction = isset($getVars['sabreAction']) ? $getVars['sabreAction'] : null; switch ($sabreAction) { case 'asset': // Asset handling, such as images $this->serveAsset(isset($getVars['assetName']) ? $getVars['assetName'] : null); return false; default: case 'info': try { $this->server->tree->getNodeForPath($request->getPath()); } catch (DAV\Exception\NotFound $e) { // We're simply stopping when the file isn't found to not interfere // with other plugins. return; } $response->setStatus(200); $response->setHeader('Content-Type', 'text/html; charset=utf-8'); $response->setBody( $this->generateDirectoryIndex($request->getPath()) ); return false; case 'plugins': $response->setStatus(200); $response->setHeader('Content-Type', 'text/html; charset=utf-8'); $response->setBody( $this->generatePluginListing() ); return false; } }
php
public function httpGet(RequestInterface $request, ResponseInterface $response) { $getVars = $request->getQueryParameters(); $response->setHeader('Content-Security-Policy', "default-src 'none'; img-src 'self'; style-src 'self'; font-src 'self';"); $sabreAction = isset($getVars['sabreAction']) ? $getVars['sabreAction'] : null; switch ($sabreAction) { case 'asset': $this->serveAsset(isset($getVars['assetName']) ? $getVars['assetName'] : null); return false; default: case 'info': try { $this->server->tree->getNodeForPath($request->getPath()); } catch (DAV\Exception\NotFound $e) { return; } $response->setStatus(200); $response->setHeader('Content-Type', 'text/html; charset=utf-8'); $response->setBody( $this->generateDirectoryIndex($request->getPath()) ); return false; case 'plugins': $response->setStatus(200); $response->setHeader('Content-Type', 'text/html; charset=utf-8'); $response->setBody( $this->generatePluginListing() ); return false; } }
[ "public", "function", "httpGet", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "// We're not using straight-up $_GET, because we want everything to be", "// unit testable.", "$", "getVars", "=", "$", "request", "->", "getQueryParameters", "(", ")", ";", "// CSP headers", "$", "response", "->", "setHeader", "(", "'Content-Security-Policy'", ",", "\"default-src 'none'; img-src 'self'; style-src 'self'; font-src 'self';\"", ")", ";", "$", "sabreAction", "=", "isset", "(", "$", "getVars", "[", "'sabreAction'", "]", ")", "?", "$", "getVars", "[", "'sabreAction'", "]", ":", "null", ";", "switch", "(", "$", "sabreAction", ")", "{", "case", "'asset'", ":", "// Asset handling, such as images", "$", "this", "->", "serveAsset", "(", "isset", "(", "$", "getVars", "[", "'assetName'", "]", ")", "?", "$", "getVars", "[", "'assetName'", "]", ":", "null", ")", ";", "return", "false", ";", "default", ":", "case", "'info'", ":", "try", "{", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "request", "->", "getPath", "(", ")", ")", ";", "}", "catch", "(", "DAV", "\\", "Exception", "\\", "NotFound", "$", "e", ")", "{", "// We're simply stopping when the file isn't found to not interfere", "// with other plugins.", "return", ";", "}", "$", "response", "->", "setStatus", "(", "200", ")", ";", "$", "response", "->", "setHeader", "(", "'Content-Type'", ",", "'text/html; charset=utf-8'", ")", ";", "$", "response", "->", "setBody", "(", "$", "this", "->", "generateDirectoryIndex", "(", "$", "request", "->", "getPath", "(", ")", ")", ")", ";", "return", "false", ";", "case", "'plugins'", ":", "$", "response", "->", "setStatus", "(", "200", ")", ";", "$", "response", "->", "setHeader", "(", "'Content-Type'", ",", "'text/html; charset=utf-8'", ")", ";", "$", "response", "->", "setBody", "(", "$", "this", "->", "generatePluginListing", "(", ")", ")", ";", "return", "false", ";", "}", "}" ]
This method intercepts GET requests to collections and returns the html. @param RequestInterface $request @param ResponseInterface $response @return bool
[ "This", "method", "intercepts", "GET", "requests", "to", "collections", "and", "returns", "the", "html", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/Plugin.php#L112-L158
sabre-io/dav
lib/DAV/Browser/Plugin.php
Plugin.httpPOST
public function httpPOST(RequestInterface $request, ResponseInterface $response) { $contentType = $request->getHeader('Content-Type'); list($contentType) = explode(';', $contentType); if ('application/x-www-form-urlencoded' !== $contentType && 'multipart/form-data' !== $contentType) { return; } $postVars = $request->getPostData(); if (!isset($postVars['sabreAction'])) { return; } $uri = $request->getPath(); if ($this->server->emit('onBrowserPostAction', [$uri, $postVars['sabreAction'], $postVars])) { switch ($postVars['sabreAction']) { case 'mkcol': if (isset($postVars['name']) && trim($postVars['name'])) { // Using basename() because we won't allow slashes list(, $folderName) = Uri\split(trim($postVars['name'])); if (isset($postVars['resourceType'])) { $resourceType = explode(',', $postVars['resourceType']); } else { $resourceType = ['{DAV:}collection']; } $properties = []; foreach ($postVars as $varName => $varValue) { // Any _POST variable in clark notation is treated // like a property. if ('{' === $varName[0]) { // PHP will convert any dots to underscores. // This leaves us with no way to differentiate // the two. // Therefore we replace the string *DOT* with a // real dot. * is not allowed in uris so we // should be good. $varName = str_replace('*DOT*', '.', $varName); $properties[$varName] = $varValue; } } $mkCol = new MkCol( $resourceType, $properties ); $this->server->createCollection($uri.'/'.$folderName, $mkCol); } break; // @codeCoverageIgnoreStart case 'put': if ($_FILES) { $file = current($_FILES); } else { break; } list(, $newName) = Uri\split(trim($file['name'])); if (isset($postVars['name']) && trim($postVars['name'])) { $newName = trim($postVars['name']); } // Making sure we only have a 'basename' component list(, $newName) = Uri\split($newName); if (is_uploaded_file($file['tmp_name'])) { $this->server->createFile($uri.'/'.$newName, fopen($file['tmp_name'], 'r')); } break; // @codeCoverageIgnoreEnd } } $response->setHeader('Location', $request->getUrl()); $response->setStatus(302); return false; }
php
public function httpPOST(RequestInterface $request, ResponseInterface $response) { $contentType = $request->getHeader('Content-Type'); list($contentType) = explode(';', $contentType); if ('application/x-www-form-urlencoded' !== $contentType && 'multipart/form-data' !== $contentType) { return; } $postVars = $request->getPostData(); if (!isset($postVars['sabreAction'])) { return; } $uri = $request->getPath(); if ($this->server->emit('onBrowserPostAction', [$uri, $postVars['sabreAction'], $postVars])) { switch ($postVars['sabreAction']) { case 'mkcol': if (isset($postVars['name']) && trim($postVars['name'])) { list(, $folderName) = Uri\split(trim($postVars['name'])); if (isset($postVars['resourceType'])) { $resourceType = explode(',', $postVars['resourceType']); } else { $resourceType = ['{DAV:}collection']; } $properties = []; foreach ($postVars as $varName => $varValue) { if ('{' === $varName[0]) { $varName = str_replace('*DOT*', '.', $varName); $properties[$varName] = $varValue; } } $mkCol = new MkCol( $resourceType, $properties ); $this->server->createCollection($uri.'/'.$folderName, $mkCol); } break; case 'put': if ($_FILES) { $file = current($_FILES); } else { break; } list(, $newName) = Uri\split(trim($file['name'])); if (isset($postVars['name']) && trim($postVars['name'])) { $newName = trim($postVars['name']); } list(, $newName) = Uri\split($newName); if (is_uploaded_file($file['tmp_name'])) { $this->server->createFile($uri.'/'.$newName, fopen($file['tmp_name'], 'r')); } break; } } $response->setHeader('Location', $request->getUrl()); $response->setStatus(302); return false; }
[ "public", "function", "httpPOST", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "contentType", "=", "$", "request", "->", "getHeader", "(", "'Content-Type'", ")", ";", "list", "(", "$", "contentType", ")", "=", "explode", "(", "';'", ",", "$", "contentType", ")", ";", "if", "(", "'application/x-www-form-urlencoded'", "!==", "$", "contentType", "&&", "'multipart/form-data'", "!==", "$", "contentType", ")", "{", "return", ";", "}", "$", "postVars", "=", "$", "request", "->", "getPostData", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "postVars", "[", "'sabreAction'", "]", ")", ")", "{", "return", ";", "}", "$", "uri", "=", "$", "request", "->", "getPath", "(", ")", ";", "if", "(", "$", "this", "->", "server", "->", "emit", "(", "'onBrowserPostAction'", ",", "[", "$", "uri", ",", "$", "postVars", "[", "'sabreAction'", "]", ",", "$", "postVars", "]", ")", ")", "{", "switch", "(", "$", "postVars", "[", "'sabreAction'", "]", ")", "{", "case", "'mkcol'", ":", "if", "(", "isset", "(", "$", "postVars", "[", "'name'", "]", ")", "&&", "trim", "(", "$", "postVars", "[", "'name'", "]", ")", ")", "{", "// Using basename() because we won't allow slashes", "list", "(", ",", "$", "folderName", ")", "=", "Uri", "\\", "split", "(", "trim", "(", "$", "postVars", "[", "'name'", "]", ")", ")", ";", "if", "(", "isset", "(", "$", "postVars", "[", "'resourceType'", "]", ")", ")", "{", "$", "resourceType", "=", "explode", "(", "','", ",", "$", "postVars", "[", "'resourceType'", "]", ")", ";", "}", "else", "{", "$", "resourceType", "=", "[", "'{DAV:}collection'", "]", ";", "}", "$", "properties", "=", "[", "]", ";", "foreach", "(", "$", "postVars", "as", "$", "varName", "=>", "$", "varValue", ")", "{", "// Any _POST variable in clark notation is treated", "// like a property.", "if", "(", "'{'", "===", "$", "varName", "[", "0", "]", ")", "{", "// PHP will convert any dots to underscores.", "// This leaves us with no way to differentiate", "// the two.", "// Therefore we replace the string *DOT* with a", "// real dot. * is not allowed in uris so we", "// should be good.", "$", "varName", "=", "str_replace", "(", "'*DOT*'", ",", "'.'", ",", "$", "varName", ")", ";", "$", "properties", "[", "$", "varName", "]", "=", "$", "varValue", ";", "}", "}", "$", "mkCol", "=", "new", "MkCol", "(", "$", "resourceType", ",", "$", "properties", ")", ";", "$", "this", "->", "server", "->", "createCollection", "(", "$", "uri", ".", "'/'", ".", "$", "folderName", ",", "$", "mkCol", ")", ";", "}", "break", ";", "// @codeCoverageIgnoreStart", "case", "'put'", ":", "if", "(", "$", "_FILES", ")", "{", "$", "file", "=", "current", "(", "$", "_FILES", ")", ";", "}", "else", "{", "break", ";", "}", "list", "(", ",", "$", "newName", ")", "=", "Uri", "\\", "split", "(", "trim", "(", "$", "file", "[", "'name'", "]", ")", ")", ";", "if", "(", "isset", "(", "$", "postVars", "[", "'name'", "]", ")", "&&", "trim", "(", "$", "postVars", "[", "'name'", "]", ")", ")", "{", "$", "newName", "=", "trim", "(", "$", "postVars", "[", "'name'", "]", ")", ";", "}", "// Making sure we only have a 'basename' component", "list", "(", ",", "$", "newName", ")", "=", "Uri", "\\", "split", "(", "$", "newName", ")", ";", "if", "(", "is_uploaded_file", "(", "$", "file", "[", "'tmp_name'", "]", ")", ")", "{", "$", "this", "->", "server", "->", "createFile", "(", "$", "uri", ".", "'/'", ".", "$", "newName", ",", "fopen", "(", "$", "file", "[", "'tmp_name'", "]", ",", "'r'", ")", ")", ";", "}", "break", ";", "// @codeCoverageIgnoreEnd", "}", "}", "$", "response", "->", "setHeader", "(", "'Location'", ",", "$", "request", "->", "getUrl", "(", ")", ")", ";", "$", "response", "->", "setStatus", "(", "302", ")", ";", "return", "false", ";", "}" ]
Handles POST requests for tree operations. @param RequestInterface $request @param ResponseInterface $response @return bool
[ "Handles", "POST", "requests", "for", "tree", "operations", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/Plugin.php#L168-L249
sabre-io/dav
lib/DAV/Browser/Plugin.php
Plugin.generateDirectoryIndex
public function generateDirectoryIndex($path) { $html = $this->generateHeader($path ? $path : '/', $path); $node = $this->server->tree->getNodeForPath($path); if ($node instanceof DAV\ICollection) { $html .= "<section><h1>Nodes</h1>\n"; $html .= '<table class="nodeTable">'; $subNodes = $this->server->getPropertiesForChildren($path, [ '{DAV:}displayname', '{DAV:}resourcetype', '{DAV:}getcontenttype', '{DAV:}getcontentlength', '{DAV:}getlastmodified', ]); foreach ($subNodes as $subPath => $subProps) { $subNode = $this->server->tree->getNodeForPath($subPath); $fullPath = $this->server->getBaseUri().HTTP\encodePath($subPath); list(, $displayPath) = Uri\split($subPath); $subNodes[$subPath]['subNode'] = $subNode; $subNodes[$subPath]['fullPath'] = $fullPath; $subNodes[$subPath]['displayPath'] = $displayPath; } uasort($subNodes, [$this, 'compareNodes']); foreach ($subNodes as $subProps) { $type = [ 'string' => 'Unknown', 'icon' => 'cog', ]; if (isset($subProps['{DAV:}resourcetype'])) { $type = $this->mapResourceType($subProps['{DAV:}resourcetype']->getValue(), $subProps['subNode']); } $html .= '<tr>'; $html .= '<td class="nameColumn"><a href="'.$this->escapeHTML($subProps['fullPath']).'"><span class="oi" data-glyph="'.$this->escapeHTML($type['icon']).'"></span> '.$this->escapeHTML($subProps['displayPath']).'</a></td>'; $html .= '<td class="typeColumn">'.$this->escapeHTML($type['string']).'</td>'; $html .= '<td>'; if (isset($subProps['{DAV:}getcontentlength'])) { $html .= $this->escapeHTML($subProps['{DAV:}getcontentlength'].' bytes'); } $html .= '</td><td>'; if (isset($subProps['{DAV:}getlastmodified'])) { $lastMod = $subProps['{DAV:}getlastmodified']->getTime(); $html .= $this->escapeHTML($lastMod->format('F j, Y, g:i a')); } $html .= '</td><td>'; if (isset($subProps['{DAV:}displayname'])) { $html .= $this->escapeHTML($subProps['{DAV:}displayname']); } $html .= '</td>'; $buttonActions = ''; if ($subProps['subNode'] instanceof DAV\IFile) { $buttonActions = '<a href="'.$this->escapeHTML($subProps['fullPath']).'?sabreAction=info"><span class="oi" data-glyph="info"></span></a>'; } $this->server->emit('browserButtonActions', [$subProps['fullPath'], $subProps['subNode'], &$buttonActions]); $html .= '<td>'.$buttonActions.'</td>'; $html .= '</tr>'; } $html .= '</table>'; } $html .= '</section>'; $html .= '<section><h1>Properties</h1>'; $html .= '<table class="propTable">'; // Allprops request $propFind = new PropFindAll($path); $properties = $this->server->getPropertiesByNode($propFind, $node); $properties = $propFind->getResultForMultiStatus()[200]; foreach ($properties as $propName => $propValue) { if (!in_array($propName, $this->uninterestingProperties)) { $html .= $this->drawPropertyRow($propName, $propValue); } } $html .= '</table>'; $html .= '</section>'; /* Start of generating actions */ $output = ''; if ($this->enablePost) { $this->server->emit('onHTMLActionsPanel', [$node, &$output, $path]); } if ($output) { $html .= '<section><h1>Actions</h1>'; $html .= "<div class=\"actions\">\n"; $html .= $output; $html .= "</div>\n"; $html .= "</section>\n"; } $html .= $this->generateFooter(); $this->server->httpResponse->setHeader('Content-Security-Policy', "default-src 'none'; img-src 'self'; style-src 'self'; font-src 'self';"); return $html; }
php
public function generateDirectoryIndex($path) { $html = $this->generateHeader($path ? $path : '/', $path); $node = $this->server->tree->getNodeForPath($path); if ($node instanceof DAV\ICollection) { $html .= "<section><h1>Nodes</h1>\n"; $html .= '<table class="nodeTable">'; $subNodes = $this->server->getPropertiesForChildren($path, [ '{DAV:}displayname', '{DAV:}resourcetype', '{DAV:}getcontenttype', '{DAV:}getcontentlength', '{DAV:}getlastmodified', ]); foreach ($subNodes as $subPath => $subProps) { $subNode = $this->server->tree->getNodeForPath($subPath); $fullPath = $this->server->getBaseUri().HTTP\encodePath($subPath); list(, $displayPath) = Uri\split($subPath); $subNodes[$subPath]['subNode'] = $subNode; $subNodes[$subPath]['fullPath'] = $fullPath; $subNodes[$subPath]['displayPath'] = $displayPath; } uasort($subNodes, [$this, 'compareNodes']); foreach ($subNodes as $subProps) { $type = [ 'string' => 'Unknown', 'icon' => 'cog', ]; if (isset($subProps['{DAV:}resourcetype'])) { $type = $this->mapResourceType($subProps['{DAV:}resourcetype']->getValue(), $subProps['subNode']); } $html .= '<tr>'; $html .= '<td class="nameColumn"><a href="'.$this->escapeHTML($subProps['fullPath']).'"><span class="oi" data-glyph="'.$this->escapeHTML($type['icon']).'"></span> '.$this->escapeHTML($subProps['displayPath']).'</a></td>'; $html .= '<td class="typeColumn">'.$this->escapeHTML($type['string']).'</td>'; $html .= '<td>'; if (isset($subProps['{DAV:}getcontentlength'])) { $html .= $this->escapeHTML($subProps['{DAV:}getcontentlength'].' bytes'); } $html .= '</td><td>'; if (isset($subProps['{DAV:}getlastmodified'])) { $lastMod = $subProps['{DAV:}getlastmodified']->getTime(); $html .= $this->escapeHTML($lastMod->format('F j, Y, g:i a')); } $html .= '</td><td>'; if (isset($subProps['{DAV:}displayname'])) { $html .= $this->escapeHTML($subProps['{DAV:}displayname']); } $html .= '</td>'; $buttonActions = ''; if ($subProps['subNode'] instanceof DAV\IFile) { $buttonActions = '<a href="'.$this->escapeHTML($subProps['fullPath']).'?sabreAction=info"><span class="oi" data-glyph="info"></span></a>'; } $this->server->emit('browserButtonActions', [$subProps['fullPath'], $subProps['subNode'], &$buttonActions]); $html .= '<td>'.$buttonActions.'</td>'; $html .= '</tr>'; } $html .= '</table>'; } $html .= '</section>'; $html .= '<section><h1>Properties</h1>'; $html .= '<table class="propTable">'; $propFind = new PropFindAll($path); $properties = $this->server->getPropertiesByNode($propFind, $node); $properties = $propFind->getResultForMultiStatus()[200]; foreach ($properties as $propName => $propValue) { if (!in_array($propName, $this->uninterestingProperties)) { $html .= $this->drawPropertyRow($propName, $propValue); } } $html .= '</table>'; $html .= '</section>'; $output = ''; if ($this->enablePost) { $this->server->emit('onHTMLActionsPanel', [$node, &$output, $path]); } if ($output) { $html .= '<section><h1>Actions</h1>'; $html .= "<div class=\"actions\">\n"; $html .= $output; $html .= "</div>\n"; $html .= "</section>\n"; } $html .= $this->generateFooter(); $this->server->httpResponse->setHeader('Content-Security-Policy', "default-src 'none'; img-src 'self'; style-src 'self'; font-src 'self';"); return $html; }
[ "public", "function", "generateDirectoryIndex", "(", "$", "path", ")", "{", "$", "html", "=", "$", "this", "->", "generateHeader", "(", "$", "path", "?", "$", "path", ":", "'/'", ",", "$", "path", ")", ";", "$", "node", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "path", ")", ";", "if", "(", "$", "node", "instanceof", "DAV", "\\", "ICollection", ")", "{", "$", "html", ".=", "\"<section><h1>Nodes</h1>\\n\"", ";", "$", "html", ".=", "'<table class=\"nodeTable\">'", ";", "$", "subNodes", "=", "$", "this", "->", "server", "->", "getPropertiesForChildren", "(", "$", "path", ",", "[", "'{DAV:}displayname'", ",", "'{DAV:}resourcetype'", ",", "'{DAV:}getcontenttype'", ",", "'{DAV:}getcontentlength'", ",", "'{DAV:}getlastmodified'", ",", "]", ")", ";", "foreach", "(", "$", "subNodes", "as", "$", "subPath", "=>", "$", "subProps", ")", "{", "$", "subNode", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "subPath", ")", ";", "$", "fullPath", "=", "$", "this", "->", "server", "->", "getBaseUri", "(", ")", ".", "HTTP", "\\", "encodePath", "(", "$", "subPath", ")", ";", "list", "(", ",", "$", "displayPath", ")", "=", "Uri", "\\", "split", "(", "$", "subPath", ")", ";", "$", "subNodes", "[", "$", "subPath", "]", "[", "'subNode'", "]", "=", "$", "subNode", ";", "$", "subNodes", "[", "$", "subPath", "]", "[", "'fullPath'", "]", "=", "$", "fullPath", ";", "$", "subNodes", "[", "$", "subPath", "]", "[", "'displayPath'", "]", "=", "$", "displayPath", ";", "}", "uasort", "(", "$", "subNodes", ",", "[", "$", "this", ",", "'compareNodes'", "]", ")", ";", "foreach", "(", "$", "subNodes", "as", "$", "subProps", ")", "{", "$", "type", "=", "[", "'string'", "=>", "'Unknown'", ",", "'icon'", "=>", "'cog'", ",", "]", ";", "if", "(", "isset", "(", "$", "subProps", "[", "'{DAV:}resourcetype'", "]", ")", ")", "{", "$", "type", "=", "$", "this", "->", "mapResourceType", "(", "$", "subProps", "[", "'{DAV:}resourcetype'", "]", "->", "getValue", "(", ")", ",", "$", "subProps", "[", "'subNode'", "]", ")", ";", "}", "$", "html", ".=", "'<tr>'", ";", "$", "html", ".=", "'<td class=\"nameColumn\"><a href=\"'", ".", "$", "this", "->", "escapeHTML", "(", "$", "subProps", "[", "'fullPath'", "]", ")", ".", "'\"><span class=\"oi\" data-glyph=\"'", ".", "$", "this", "->", "escapeHTML", "(", "$", "type", "[", "'icon'", "]", ")", ".", "'\"></span> '", ".", "$", "this", "->", "escapeHTML", "(", "$", "subProps", "[", "'displayPath'", "]", ")", ".", "'</a></td>'", ";", "$", "html", ".=", "'<td class=\"typeColumn\">'", ".", "$", "this", "->", "escapeHTML", "(", "$", "type", "[", "'string'", "]", ")", ".", "'</td>'", ";", "$", "html", ".=", "'<td>'", ";", "if", "(", "isset", "(", "$", "subProps", "[", "'{DAV:}getcontentlength'", "]", ")", ")", "{", "$", "html", ".=", "$", "this", "->", "escapeHTML", "(", "$", "subProps", "[", "'{DAV:}getcontentlength'", "]", ".", "' bytes'", ")", ";", "}", "$", "html", ".=", "'</td><td>'", ";", "if", "(", "isset", "(", "$", "subProps", "[", "'{DAV:}getlastmodified'", "]", ")", ")", "{", "$", "lastMod", "=", "$", "subProps", "[", "'{DAV:}getlastmodified'", "]", "->", "getTime", "(", ")", ";", "$", "html", ".=", "$", "this", "->", "escapeHTML", "(", "$", "lastMod", "->", "format", "(", "'F j, Y, g:i a'", ")", ")", ";", "}", "$", "html", ".=", "'</td><td>'", ";", "if", "(", "isset", "(", "$", "subProps", "[", "'{DAV:}displayname'", "]", ")", ")", "{", "$", "html", ".=", "$", "this", "->", "escapeHTML", "(", "$", "subProps", "[", "'{DAV:}displayname'", "]", ")", ";", "}", "$", "html", ".=", "'</td>'", ";", "$", "buttonActions", "=", "''", ";", "if", "(", "$", "subProps", "[", "'subNode'", "]", "instanceof", "DAV", "\\", "IFile", ")", "{", "$", "buttonActions", "=", "'<a href=\"'", ".", "$", "this", "->", "escapeHTML", "(", "$", "subProps", "[", "'fullPath'", "]", ")", ".", "'?sabreAction=info\"><span class=\"oi\" data-glyph=\"info\"></span></a>'", ";", "}", "$", "this", "->", "server", "->", "emit", "(", "'browserButtonActions'", ",", "[", "$", "subProps", "[", "'fullPath'", "]", ",", "$", "subProps", "[", "'subNode'", "]", ",", "&", "$", "buttonActions", "]", ")", ";", "$", "html", ".=", "'<td>'", ".", "$", "buttonActions", ".", "'</td>'", ";", "$", "html", ".=", "'</tr>'", ";", "}", "$", "html", ".=", "'</table>'", ";", "}", "$", "html", ".=", "'</section>'", ";", "$", "html", ".=", "'<section><h1>Properties</h1>'", ";", "$", "html", ".=", "'<table class=\"propTable\">'", ";", "// Allprops request", "$", "propFind", "=", "new", "PropFindAll", "(", "$", "path", ")", ";", "$", "properties", "=", "$", "this", "->", "server", "->", "getPropertiesByNode", "(", "$", "propFind", ",", "$", "node", ")", ";", "$", "properties", "=", "$", "propFind", "->", "getResultForMultiStatus", "(", ")", "[", "200", "]", ";", "foreach", "(", "$", "properties", "as", "$", "propName", "=>", "$", "propValue", ")", "{", "if", "(", "!", "in_array", "(", "$", "propName", ",", "$", "this", "->", "uninterestingProperties", ")", ")", "{", "$", "html", ".=", "$", "this", "->", "drawPropertyRow", "(", "$", "propName", ",", "$", "propValue", ")", ";", "}", "}", "$", "html", ".=", "'</table>'", ";", "$", "html", ".=", "'</section>'", ";", "/* Start of generating actions */", "$", "output", "=", "''", ";", "if", "(", "$", "this", "->", "enablePost", ")", "{", "$", "this", "->", "server", "->", "emit", "(", "'onHTMLActionsPanel'", ",", "[", "$", "node", ",", "&", "$", "output", ",", "$", "path", "]", ")", ";", "}", "if", "(", "$", "output", ")", "{", "$", "html", ".=", "'<section><h1>Actions</h1>'", ";", "$", "html", ".=", "\"<div class=\\\"actions\\\">\\n\"", ";", "$", "html", ".=", "$", "output", ";", "$", "html", ".=", "\"</div>\\n\"", ";", "$", "html", ".=", "\"</section>\\n\"", ";", "}", "$", "html", ".=", "$", "this", "->", "generateFooter", "(", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setHeader", "(", "'Content-Security-Policy'", ",", "\"default-src 'none'; img-src 'self'; style-src 'self'; font-src 'self';\"", ")", ";", "return", "$", "html", ";", "}" ]
Generates the html directory index for a given url. @param string $path @return string
[ "Generates", "the", "html", "directory", "index", "for", "a", "given", "url", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/Plugin.php#L270-L377
sabre-io/dav
lib/DAV/Browser/Plugin.php
Plugin.generatePluginListing
public function generatePluginListing() { $html = $this->generateHeader('Plugins'); $html .= '<section><h1>Plugins</h1>'; $html .= '<table class="propTable">'; foreach ($this->server->getPlugins() as $plugin) { $info = $plugin->getPluginInfo(); $html .= '<tr><th>'.$info['name'].'</th>'; $html .= '<td>'.$info['description'].'</td>'; $html .= '<td>'; if (isset($info['link']) && $info['link']) { $html .= '<a href="'.$this->escapeHTML($info['link']).'"><span class="oi" data-glyph="book"></span></a>'; } $html .= '</td></tr>'; } $html .= '</table>'; $html .= '</section>'; /* Start of generating actions */ $html .= $this->generateFooter(); return $html; }
php
public function generatePluginListing() { $html = $this->generateHeader('Plugins'); $html .= '<section><h1>Plugins</h1>'; $html .= '<table class="propTable">'; foreach ($this->server->getPlugins() as $plugin) { $info = $plugin->getPluginInfo(); $html .= '<tr><th>'.$info['name'].'</th>'; $html .= '<td>'.$info['description'].'</td>'; $html .= '<td>'; if (isset($info['link']) && $info['link']) { $html .= '<a href="'.$this->escapeHTML($info['link']).'"><span class="oi" data-glyph="book"></span></a>'; } $html .= '</td></tr>'; } $html .= '</table>'; $html .= '</section>'; $html .= $this->generateFooter(); return $html; }
[ "public", "function", "generatePluginListing", "(", ")", "{", "$", "html", "=", "$", "this", "->", "generateHeader", "(", "'Plugins'", ")", ";", "$", "html", ".=", "'<section><h1>Plugins</h1>'", ";", "$", "html", ".=", "'<table class=\"propTable\">'", ";", "foreach", "(", "$", "this", "->", "server", "->", "getPlugins", "(", ")", "as", "$", "plugin", ")", "{", "$", "info", "=", "$", "plugin", "->", "getPluginInfo", "(", ")", ";", "$", "html", ".=", "'<tr><th>'", ".", "$", "info", "[", "'name'", "]", ".", "'</th>'", ";", "$", "html", ".=", "'<td>'", ".", "$", "info", "[", "'description'", "]", ".", "'</td>'", ";", "$", "html", ".=", "'<td>'", ";", "if", "(", "isset", "(", "$", "info", "[", "'link'", "]", ")", "&&", "$", "info", "[", "'link'", "]", ")", "{", "$", "html", ".=", "'<a href=\"'", ".", "$", "this", "->", "escapeHTML", "(", "$", "info", "[", "'link'", "]", ")", ".", "'\"><span class=\"oi\" data-glyph=\"book\"></span></a>'", ";", "}", "$", "html", ".=", "'</td></tr>'", ";", "}", "$", "html", ".=", "'</table>'", ";", "$", "html", ".=", "'</section>'", ";", "/* Start of generating actions */", "$", "html", ".=", "$", "this", "->", "generateFooter", "(", ")", ";", "return", "$", "html", ";", "}" ]
Generates the 'plugins' page. @return string
[ "Generates", "the", "plugins", "page", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/Plugin.php#L384-L408
sabre-io/dav
lib/DAV/Browser/Plugin.php
Plugin.generateHeader
public function generateHeader($title, $path = null) { $version = ''; if (DAV\Server::$exposeVersion) { $version = DAV\Version::VERSION; } $vars = [ 'title' => $this->escapeHTML($title), 'favicon' => $this->escapeHTML($this->getAssetUrl('favicon.ico')), 'style' => $this->escapeHTML($this->getAssetUrl('sabredav.css')), 'iconstyle' => $this->escapeHTML($this->getAssetUrl('openiconic/open-iconic.css')), 'logo' => $this->escapeHTML($this->getAssetUrl('sabredav.png')), 'baseUrl' => $this->server->getBaseUri(), ]; $html = <<<HTML <!DOCTYPE html> <html> <head> <title>$vars[title] - sabre/dav $version</title> <link rel="shortcut icon" href="$vars[favicon]" type="image/vnd.microsoft.icon" /> <link rel="stylesheet" href="$vars[style]" type="text/css" /> <link rel="stylesheet" href="$vars[iconstyle]" type="text/css" /> </head> <body> <header> <div class="logo"> <a href="$vars[baseUrl]"><img src="$vars[logo]" alt="sabre/dav" /> $vars[title]</a> </div> </header> <nav> HTML; // If the path is empty, there's no parent. if ($path) { list($parentUri) = Uri\split($path); $fullPath = $this->server->getBaseUri().HTTP\encodePath($parentUri); $html .= '<a href="'.$fullPath.'" class="btn">⇤ Go to parent</a>'; } else { $html .= '<span class="btn disabled">⇤ Go to parent</span>'; } $html .= ' <a href="?sabreAction=plugins" class="btn"><span class="oi" data-glyph="puzzle-piece"></span> Plugins</a>'; $html .= '</nav>'; return $html; }
php
public function generateHeader($title, $path = null) { $version = ''; if (DAV\Server::$exposeVersion) { $version = DAV\Version::VERSION; } $vars = [ 'title' => $this->escapeHTML($title), 'favicon' => $this->escapeHTML($this->getAssetUrl('favicon.ico')), 'style' => $this->escapeHTML($this->getAssetUrl('sabredav.css')), 'iconstyle' => $this->escapeHTML($this->getAssetUrl('openiconic/open-iconic.css')), 'logo' => $this->escapeHTML($this->getAssetUrl('sabredav.png')), 'baseUrl' => $this->server->getBaseUri(), ]; $html = <<<HTML <!DOCTYPE html> <html> <head> <title>$vars[title] - sabre/dav $version</title> <link rel="shortcut icon" href="$vars[favicon]" type="image/vnd.microsoft.icon" /> <link rel="stylesheet" href="$vars[style]" type="text/css" /> <link rel="stylesheet" href="$vars[iconstyle]" type="text/css" /> </head> <body> <header> <div class="logo"> <a href="$vars[baseUrl]"><img src="$vars[logo]" alt="sabre/dav" /> $vars[title]</a> </div> </header> <nav> HTML; if ($path) { list($parentUri) = Uri\split($path); $fullPath = $this->server->getBaseUri().HTTP\encodePath($parentUri); $html .= '<a href="'.$fullPath.'" class="btn">⇤ Go to parent</a>'; } else { $html .= '<span class="btn disabled">⇤ Go to parent</span>'; } $html .= ' <a href="?sabreAction=plugins" class="btn"><span class="oi" data-glyph="puzzle-piece"></span> Plugins</a>'; $html .= '</nav>'; return $html; }
[ "public", "function", "generateHeader", "(", "$", "title", ",", "$", "path", "=", "null", ")", "{", "$", "version", "=", "''", ";", "if", "(", "DAV", "\\", "Server", "::", "$", "exposeVersion", ")", "{", "$", "version", "=", "DAV", "\\", "Version", "::", "VERSION", ";", "}", "$", "vars", "=", "[", "'title'", "=>", "$", "this", "->", "escapeHTML", "(", "$", "title", ")", ",", "'favicon'", "=>", "$", "this", "->", "escapeHTML", "(", "$", "this", "->", "getAssetUrl", "(", "'favicon.ico'", ")", ")", ",", "'style'", "=>", "$", "this", "->", "escapeHTML", "(", "$", "this", "->", "getAssetUrl", "(", "'sabredav.css'", ")", ")", ",", "'iconstyle'", "=>", "$", "this", "->", "escapeHTML", "(", "$", "this", "->", "getAssetUrl", "(", "'openiconic/open-iconic.css'", ")", ")", ",", "'logo'", "=>", "$", "this", "->", "escapeHTML", "(", "$", "this", "->", "getAssetUrl", "(", "'sabredav.png'", ")", ")", ",", "'baseUrl'", "=>", "$", "this", "->", "server", "->", "getBaseUri", "(", ")", ",", "]", ";", "$", "html", "=", " <<<HTML\n<!DOCTYPE html>\n<html>\n<head>\n <title>$vars[title] - sabre/dav $version</title>\n <link rel=\"shortcut icon\" href=\"$vars[favicon]\" type=\"image/vnd.microsoft.icon\" />\n <link rel=\"stylesheet\" href=\"$vars[style]\" type=\"text/css\" />\n <link rel=\"stylesheet\" href=\"$vars[iconstyle]\" type=\"text/css\" />\n\n</head>\n<body>\n <header>\n <div class=\"logo\">\n <a href=\"$vars[baseUrl]\"><img src=\"$vars[logo]\" alt=\"sabre/dav\" /> $vars[title]</a>\n </div>\n </header>\n\n <nav>\nHTML", ";", "// If the path is empty, there's no parent.", "if", "(", "$", "path", ")", "{", "list", "(", "$", "parentUri", ")", "=", "Uri", "\\", "split", "(", "$", "path", ")", ";", "$", "fullPath", "=", "$", "this", "->", "server", "->", "getBaseUri", "(", ")", ".", "HTTP", "\\", "encodePath", "(", "$", "parentUri", ")", ";", "$", "html", ".=", "'<a href=\"'", ".", "$", "fullPath", ".", "'\" class=\"btn\">⇤ Go to parent</a>';", "", "}", "else", "{", "$", "html", ".=", "'<span class=\"btn disabled\">⇤ Go to parent</span>';", "", "}", "$", "html", ".=", "' <a href=\"?sabreAction=plugins\" class=\"btn\"><span class=\"oi\" data-glyph=\"puzzle-piece\"></span> Plugins</a>'", ";", "$", "html", ".=", "'</nav>'", ";", "return", "$", "html", ";", "}" ]
Generates the first block of HTML, including the <head> tag and page header. Returns footer. @param string $title @param string $path @return string
[ "Generates", "the", "first", "block", "of", "HTML", "including", "the", "<head", ">", "tag", "and", "page", "header", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/Plugin.php#L421-L471
sabre-io/dav
lib/DAV/Browser/Plugin.php
Plugin.htmlActionsPanel
public function htmlActionsPanel(DAV\INode $node, &$output, $path) { if (!$node instanceof DAV\ICollection) { return; } // We also know fairly certain that if an object is a non-extended // SimpleCollection, we won't need to show the panel either. if ('Sabre\\DAV\\SimpleCollection' === get_class($node)) { return; } $output .= <<<HTML <form method="post" action=""> <h3>Create new folder</h3> <input type="hidden" name="sabreAction" value="mkcol" /> <label>Name:</label> <input type="text" name="name" /><br /> <input type="submit" value="create" /> </form> <form method="post" action="" enctype="multipart/form-data"> <h3>Upload file</h3> <input type="hidden" name="sabreAction" value="put" /> <label>Name (optional):</label> <input type="text" name="name" /><br /> <label>File:</label> <input type="file" name="file" /><br /> <input type="submit" value="upload" /> </form> HTML; }
php
public function htmlActionsPanel(DAV\INode $node, &$output, $path) { if (!$node instanceof DAV\ICollection) { return; } if ('Sabre\\DAV\\SimpleCollection' === get_class($node)) { return; } $output .= <<<HTML <form method="post" action=""> <h3>Create new folder</h3> <input type="hidden" name="sabreAction" value="mkcol" /> <label>Name:</label> <input type="text" name="name" /><br /> <input type="submit" value="create" /> </form> <form method="post" action="" enctype="multipart/form-data"> <h3>Upload file</h3> <input type="hidden" name="sabreAction" value="put" /> <label>Name (optional):</label> <input type="text" name="name" /><br /> <label>File:</label> <input type="file" name="file" /><br /> <input type="submit" value="upload" /> </form> HTML; }
[ "public", "function", "htmlActionsPanel", "(", "DAV", "\\", "INode", "$", "node", ",", "&", "$", "output", ",", "$", "path", ")", "{", "if", "(", "!", "$", "node", "instanceof", "DAV", "\\", "ICollection", ")", "{", "return", ";", "}", "// We also know fairly certain that if an object is a non-extended", "// SimpleCollection, we won't need to show the panel either.", "if", "(", "'Sabre\\\\DAV\\\\SimpleCollection'", "===", "get_class", "(", "$", "node", ")", ")", "{", "return", ";", "}", "$", "output", ".=", " <<<HTML\n<form method=\"post\" action=\"\">\n<h3>Create new folder</h3>\n<input type=\"hidden\" name=\"sabreAction\" value=\"mkcol\" />\n<label>Name:</label> <input type=\"text\" name=\"name\" /><br />\n<input type=\"submit\" value=\"create\" />\n</form>\n<form method=\"post\" action=\"\" enctype=\"multipart/form-data\">\n<h3>Upload file</h3>\n<input type=\"hidden\" name=\"sabreAction\" value=\"put\" />\n<label>Name (optional):</label> <input type=\"text\" name=\"name\" /><br />\n<label>File:</label> <input type=\"file\" name=\"file\" /><br />\n<input type=\"submit\" value=\"upload\" />\n</form>\nHTML", ";", "}" ]
This method is used to generate the 'actions panel' output for collections. This specifically generates the interfaces for creating new files, and creating new directories. @param DAV\INode $node @param mixed $output @param string $path
[ "This", "method", "is", "used", "to", "generate", "the", "actions", "panel", "output", "for", "collections", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/Plugin.php#L505-L532
sabre-io/dav
lib/DAV/Browser/Plugin.php
Plugin.getLocalAssetPath
protected function getLocalAssetPath($assetName) { $assetDir = __DIR__.'/assets/'; $path = $assetDir.$assetName; // Making sure people aren't trying to escape from the base path. $path = str_replace('\\', '/', $path); if (false !== strpos($path, '/../') || '/..' === strrchr($path, '/')) { throw new DAV\Exception\NotFound('Path does not exist, or escaping from the base path was detected'); } $realPath = realpath($path); if ($realPath && 0 === strpos($realPath, realpath($assetDir)) && file_exists($path)) { return $path; } throw new DAV\Exception\NotFound('Path does not exist, or escaping from the base path was detected'); }
php
protected function getLocalAssetPath($assetName) { $assetDir = __DIR__.'/assets/'; $path = $assetDir.$assetName; $path = str_replace('\\', '/', $path); if (false !== strpos($path, '/../') || '/..' === strrchr($path, '/')) { throw new DAV\Exception\NotFound('Path does not exist, or escaping from the base path was detected'); } $realPath = realpath($path); if ($realPath && 0 === strpos($realPath, realpath($assetDir)) && file_exists($path)) { return $path; } throw new DAV\Exception\NotFound('Path does not exist, or escaping from the base path was detected'); }
[ "protected", "function", "getLocalAssetPath", "(", "$", "assetName", ")", "{", "$", "assetDir", "=", "__DIR__", ".", "'/assets/'", ";", "$", "path", "=", "$", "assetDir", ".", "$", "assetName", ";", "// Making sure people aren't trying to escape from the base path.", "$", "path", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "path", ")", ";", "if", "(", "false", "!==", "strpos", "(", "$", "path", ",", "'/../'", ")", "||", "'/..'", "===", "strrchr", "(", "$", "path", ",", "'/'", ")", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "NotFound", "(", "'Path does not exist, or escaping from the base path was detected'", ")", ";", "}", "$", "realPath", "=", "realpath", "(", "$", "path", ")", ";", "if", "(", "$", "realPath", "&&", "0", "===", "strpos", "(", "$", "realPath", ",", "realpath", "(", "$", "assetDir", ")", ")", "&&", "file_exists", "(", "$", "path", ")", ")", "{", "return", "$", "path", ";", "}", "throw", "new", "DAV", "\\", "Exception", "\\", "NotFound", "(", "'Path does not exist, or escaping from the base path was detected'", ")", ";", "}" ]
This method returns a local pathname to an asset. @param string $assetName @throws DAV\Exception\NotFound @return string
[ "This", "method", "returns", "a", "local", "pathname", "to", "an", "asset", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/Plugin.php#L556-L571
sabre-io/dav
lib/DAV/Browser/Plugin.php
Plugin.serveAsset
protected function serveAsset($assetName) { $assetPath = $this->getLocalAssetPath($assetName); // Rudimentary mime type detection $mime = 'application/octet-stream'; $map = [ 'ico' => 'image/vnd.microsoft.icon', 'png' => 'image/png', 'css' => 'text/css', ]; $ext = substr($assetName, strrpos($assetName, '.') + 1); if (isset($map[$ext])) { $mime = $map[$ext]; } $this->server->httpResponse->setHeader('Content-Type', $mime); $this->server->httpResponse->setHeader('Content-Length', filesize($assetPath)); $this->server->httpResponse->setHeader('Cache-Control', 'public, max-age=1209600'); $this->server->httpResponse->setStatus(200); $this->server->httpResponse->setBody(fopen($assetPath, 'r')); }
php
protected function serveAsset($assetName) { $assetPath = $this->getLocalAssetPath($assetName); $mime = 'application/octet-stream'; $map = [ 'ico' => 'image/vnd.microsoft.icon', 'png' => 'image/png', 'css' => 'text/css', ]; $ext = substr($assetName, strrpos($assetName, '.') + 1); if (isset($map[$ext])) { $mime = $map[$ext]; } $this->server->httpResponse->setHeader('Content-Type', $mime); $this->server->httpResponse->setHeader('Content-Length', filesize($assetPath)); $this->server->httpResponse->setHeader('Cache-Control', 'public, max-age=1209600'); $this->server->httpResponse->setStatus(200); $this->server->httpResponse->setBody(fopen($assetPath, 'r')); }
[ "protected", "function", "serveAsset", "(", "$", "assetName", ")", "{", "$", "assetPath", "=", "$", "this", "->", "getLocalAssetPath", "(", "$", "assetName", ")", ";", "// Rudimentary mime type detection", "$", "mime", "=", "'application/octet-stream'", ";", "$", "map", "=", "[", "'ico'", "=>", "'image/vnd.microsoft.icon'", ",", "'png'", "=>", "'image/png'", ",", "'css'", "=>", "'text/css'", ",", "]", ";", "$", "ext", "=", "substr", "(", "$", "assetName", ",", "strrpos", "(", "$", "assetName", ",", "'.'", ")", "+", "1", ")", ";", "if", "(", "isset", "(", "$", "map", "[", "$", "ext", "]", ")", ")", "{", "$", "mime", "=", "$", "map", "[", "$", "ext", "]", ";", "}", "$", "this", "->", "server", "->", "httpResponse", "->", "setHeader", "(", "'Content-Type'", ",", "$", "mime", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setHeader", "(", "'Content-Length'", ",", "filesize", "(", "$", "assetPath", ")", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setHeader", "(", "'Cache-Control'", ",", "'public, max-age=1209600'", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setStatus", "(", "200", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setBody", "(", "fopen", "(", "$", "assetPath", ",", "'r'", ")", ")", ";", "}" ]
This method reads an asset from disk and generates a full http response. @param string $assetName
[ "This", "method", "reads", "an", "asset", "from", "disk", "and", "generates", "a", "full", "http", "response", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/Plugin.php#L578-L600
sabre-io/dav
lib/DAV/Browser/Plugin.php
Plugin.compareNodes
protected function compareNodes($a, $b) { $typeA = (isset($a['{DAV:}resourcetype'])) ? (in_array('{DAV:}collection', $a['{DAV:}resourcetype']->getValue())) : false; $typeB = (isset($b['{DAV:}resourcetype'])) ? (in_array('{DAV:}collection', $b['{DAV:}resourcetype']->getValue())) : false; // If same type, sort alphabetically by filename: if ($typeA === $typeB) { return strnatcasecmp($a['displayPath'], $b['displayPath']); } return ($typeA < $typeB) ? 1 : -1; }
php
protected function compareNodes($a, $b) { $typeA = (isset($a['{DAV:}resourcetype'])) ? (in_array('{DAV:}collection', $a['{DAV:}resourcetype']->getValue())) : false; $typeB = (isset($b['{DAV:}resourcetype'])) ? (in_array('{DAV:}collection', $b['{DAV:}resourcetype']->getValue())) : false; if ($typeA === $typeB) { return strnatcasecmp($a['displayPath'], $b['displayPath']); } return ($typeA < $typeB) ? 1 : -1; }
[ "protected", "function", "compareNodes", "(", "$", "a", ",", "$", "b", ")", "{", "$", "typeA", "=", "(", "isset", "(", "$", "a", "[", "'{DAV:}resourcetype'", "]", ")", ")", "?", "(", "in_array", "(", "'{DAV:}collection'", ",", "$", "a", "[", "'{DAV:}resourcetype'", "]", "->", "getValue", "(", ")", ")", ")", ":", "false", ";", "$", "typeB", "=", "(", "isset", "(", "$", "b", "[", "'{DAV:}resourcetype'", "]", ")", ")", "?", "(", "in_array", "(", "'{DAV:}collection'", ",", "$", "b", "[", "'{DAV:}resourcetype'", "]", "->", "getValue", "(", ")", ")", ")", ":", "false", ";", "// If same type, sort alphabetically by filename:", "if", "(", "$", "typeA", "===", "$", "typeB", ")", "{", "return", "strnatcasecmp", "(", "$", "a", "[", "'displayPath'", "]", ",", "$", "b", "[", "'displayPath'", "]", ")", ";", "}", "return", "(", "$", "typeA", "<", "$", "typeB", ")", "?", "1", ":", "-", "1", ";", "}" ]
Sort helper function: compares two directory entries based on type and display name. Collections sort above other types. @param array $a @param array $b @return int
[ "Sort", "helper", "function", ":", "compares", "two", "directory", "entries", "based", "on", "type", "and", "display", "name", ".", "Collections", "sort", "above", "other", "types", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/Plugin.php#L611-L627
sabre-io/dav
lib/DAV/Browser/Plugin.php
Plugin.mapResourceType
private function mapResourceType(array $resourceTypes, $node) { if (!$resourceTypes) { if ($node instanceof DAV\IFile) { return [ 'string' => 'File', 'icon' => 'file', ]; } else { return [ 'string' => 'Unknown', 'icon' => 'cog', ]; } } $types = [ '{http://calendarserver.org/ns/}calendar-proxy-write' => [ 'string' => 'Proxy-Write', 'icon' => 'people', ], '{http://calendarserver.org/ns/}calendar-proxy-read' => [ 'string' => 'Proxy-Read', 'icon' => 'people', ], '{urn:ietf:params:xml:ns:caldav}schedule-outbox' => [ 'string' => 'Outbox', 'icon' => 'inbox', ], '{urn:ietf:params:xml:ns:caldav}schedule-inbox' => [ 'string' => 'Inbox', 'icon' => 'inbox', ], '{urn:ietf:params:xml:ns:caldav}calendar' => [ 'string' => 'Calendar', 'icon' => 'calendar', ], '{http://calendarserver.org/ns/}shared-owner' => [ 'string' => 'Shared', 'icon' => 'calendar', ], '{http://calendarserver.org/ns/}subscribed' => [ 'string' => 'Subscription', 'icon' => 'calendar', ], '{urn:ietf:params:xml:ns:carddav}directory' => [ 'string' => 'Directory', 'icon' => 'globe', ], '{urn:ietf:params:xml:ns:carddav}addressbook' => [ 'string' => 'Address book', 'icon' => 'book', ], '{DAV:}principal' => [ 'string' => 'Principal', 'icon' => 'person', ], '{DAV:}collection' => [ 'string' => 'Collection', 'icon' => 'folder', ], ]; $info = [ 'string' => [], 'icon' => 'cog', ]; foreach ($resourceTypes as $k => $resourceType) { if (isset($types[$resourceType])) { $info['string'][] = $types[$resourceType]['string']; } else { $info['string'][] = $resourceType; } } foreach ($types as $key => $resourceInfo) { if (in_array($key, $resourceTypes)) { $info['icon'] = $resourceInfo['icon']; break; } } $info['string'] = implode(', ', $info['string']); return $info; }
php
private function mapResourceType(array $resourceTypes, $node) { if (!$resourceTypes) { if ($node instanceof DAV\IFile) { return [ 'string' => 'File', 'icon' => 'file', ]; } else { return [ 'string' => 'Unknown', 'icon' => 'cog', ]; } } $types = [ '{http: 'string' => 'Proxy-Write', 'icon' => 'people', ], '{http: 'string' => 'Proxy-Read', 'icon' => 'people', ], '{urn:ietf:params:xml:ns:caldav}schedule-outbox' => [ 'string' => 'Outbox', 'icon' => 'inbox', ], '{urn:ietf:params:xml:ns:caldav}schedule-inbox' => [ 'string' => 'Inbox', 'icon' => 'inbox', ], '{urn:ietf:params:xml:ns:caldav}calendar' => [ 'string' => 'Calendar', 'icon' => 'calendar', ], '{http: 'string' => 'Shared', 'icon' => 'calendar', ], '{http: 'string' => 'Subscription', 'icon' => 'calendar', ], '{urn:ietf:params:xml:ns:carddav}directory' => [ 'string' => 'Directory', 'icon' => 'globe', ], '{urn:ietf:params:xml:ns:carddav}addressbook' => [ 'string' => 'Address book', 'icon' => 'book', ], '{DAV:}principal' => [ 'string' => 'Principal', 'icon' => 'person', ], '{DAV:}collection' => [ 'string' => 'Collection', 'icon' => 'folder', ], ]; $info = [ 'string' => [], 'icon' => 'cog', ]; foreach ($resourceTypes as $k => $resourceType) { if (isset($types[$resourceType])) { $info['string'][] = $types[$resourceType]['string']; } else { $info['string'][] = $resourceType; } } foreach ($types as $key => $resourceInfo) { if (in_array($key, $resourceTypes)) { $info['icon'] = $resourceInfo['icon']; break; } } $info['string'] = implode(', ', $info['string']); return $info; }
[ "private", "function", "mapResourceType", "(", "array", "$", "resourceTypes", ",", "$", "node", ")", "{", "if", "(", "!", "$", "resourceTypes", ")", "{", "if", "(", "$", "node", "instanceof", "DAV", "\\", "IFile", ")", "{", "return", "[", "'string'", "=>", "'File'", ",", "'icon'", "=>", "'file'", ",", "]", ";", "}", "else", "{", "return", "[", "'string'", "=>", "'Unknown'", ",", "'icon'", "=>", "'cog'", ",", "]", ";", "}", "}", "$", "types", "=", "[", "'{http://calendarserver.org/ns/}calendar-proxy-write'", "=>", "[", "'string'", "=>", "'Proxy-Write'", ",", "'icon'", "=>", "'people'", ",", "]", ",", "'{http://calendarserver.org/ns/}calendar-proxy-read'", "=>", "[", "'string'", "=>", "'Proxy-Read'", ",", "'icon'", "=>", "'people'", ",", "]", ",", "'{urn:ietf:params:xml:ns:caldav}schedule-outbox'", "=>", "[", "'string'", "=>", "'Outbox'", ",", "'icon'", "=>", "'inbox'", ",", "]", ",", "'{urn:ietf:params:xml:ns:caldav}schedule-inbox'", "=>", "[", "'string'", "=>", "'Inbox'", ",", "'icon'", "=>", "'inbox'", ",", "]", ",", "'{urn:ietf:params:xml:ns:caldav}calendar'", "=>", "[", "'string'", "=>", "'Calendar'", ",", "'icon'", "=>", "'calendar'", ",", "]", ",", "'{http://calendarserver.org/ns/}shared-owner'", "=>", "[", "'string'", "=>", "'Shared'", ",", "'icon'", "=>", "'calendar'", ",", "]", ",", "'{http://calendarserver.org/ns/}subscribed'", "=>", "[", "'string'", "=>", "'Subscription'", ",", "'icon'", "=>", "'calendar'", ",", "]", ",", "'{urn:ietf:params:xml:ns:carddav}directory'", "=>", "[", "'string'", "=>", "'Directory'", ",", "'icon'", "=>", "'globe'", ",", "]", ",", "'{urn:ietf:params:xml:ns:carddav}addressbook'", "=>", "[", "'string'", "=>", "'Address book'", ",", "'icon'", "=>", "'book'", ",", "]", ",", "'{DAV:}principal'", "=>", "[", "'string'", "=>", "'Principal'", ",", "'icon'", "=>", "'person'", ",", "]", ",", "'{DAV:}collection'", "=>", "[", "'string'", "=>", "'Collection'", ",", "'icon'", "=>", "'folder'", ",", "]", ",", "]", ";", "$", "info", "=", "[", "'string'", "=>", "[", "]", ",", "'icon'", "=>", "'cog'", ",", "]", ";", "foreach", "(", "$", "resourceTypes", "as", "$", "k", "=>", "$", "resourceType", ")", "{", "if", "(", "isset", "(", "$", "types", "[", "$", "resourceType", "]", ")", ")", "{", "$", "info", "[", "'string'", "]", "[", "]", "=", "$", "types", "[", "$", "resourceType", "]", "[", "'string'", "]", ";", "}", "else", "{", "$", "info", "[", "'string'", "]", "[", "]", "=", "$", "resourceType", ";", "}", "}", "foreach", "(", "$", "types", "as", "$", "key", "=>", "$", "resourceInfo", ")", "{", "if", "(", "in_array", "(", "$", "key", ",", "$", "resourceTypes", ")", ")", "{", "$", "info", "[", "'icon'", "]", "=", "$", "resourceInfo", "[", "'icon'", "]", ";", "break", ";", "}", "}", "$", "info", "[", "'string'", "]", "=", "implode", "(", "', '", ",", "$", "info", "[", "'string'", "]", ")", ";", "return", "$", "info", ";", "}" ]
Maps a resource type to a human-readable string and icon. @param array $resourceTypes @param DAV\INode $node @return array
[ "Maps", "a", "resource", "type", "to", "a", "human", "-", "readable", "string", "and", "icon", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/Plugin.php#L637-L720
sabre-io/dav
lib/DAV/Browser/Plugin.php
Plugin.drawPropertyRow
private function drawPropertyRow($name, $value) { $html = new HtmlOutputHelper( $this->server->getBaseUri(), $this->server->xml->namespaceMap ); return '<tr><th>'.$html->xmlName($name).'</th><td>'.$this->drawPropertyValue($html, $value).'</td></tr>'; }
php
private function drawPropertyRow($name, $value) { $html = new HtmlOutputHelper( $this->server->getBaseUri(), $this->server->xml->namespaceMap ); return '<tr><th>'.$html->xmlName($name).'</th><td>'.$this->drawPropertyValue($html, $value).'</td></tr>'; }
[ "private", "function", "drawPropertyRow", "(", "$", "name", ",", "$", "value", ")", "{", "$", "html", "=", "new", "HtmlOutputHelper", "(", "$", "this", "->", "server", "->", "getBaseUri", "(", ")", ",", "$", "this", "->", "server", "->", "xml", "->", "namespaceMap", ")", ";", "return", "'<tr><th>'", ".", "$", "html", "->", "xmlName", "(", "$", "name", ")", ".", "'</th><td>'", ".", "$", "this", "->", "drawPropertyValue", "(", "$", "html", ",", "$", "value", ")", ".", "'</td></tr>'", ";", "}" ]
Draws a table row for a property. @param string $name @param mixed $value @return string
[ "Draws", "a", "table", "row", "for", "a", "property", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/Plugin.php#L730-L738
sabre-io/dav
lib/DAV/Browser/Plugin.php
Plugin.drawPropertyValue
private function drawPropertyValue($html, $value) { if (is_scalar($value)) { return $html->h($value); } elseif ($value instanceof HtmlOutput) { return $value->toHtml($html); } elseif ($value instanceof \Sabre\Xml\XmlSerializable) { // There's no default html output for this property, we're going // to output the actual xml serialization instead. $xml = $this->server->xml->write('{DAV:}root', $value, $this->server->getBaseUri()); // removing first and last line, as they contain our root // element. $xml = explode("\n", $xml); $xml = array_slice($xml, 2, -2); return '<pre>'.$html->h(implode("\n", $xml)).'</pre>'; } else { return '<em>unknown</em>'; } }
php
private function drawPropertyValue($html, $value) { if (is_scalar($value)) { return $html->h($value); } elseif ($value instanceof HtmlOutput) { return $value->toHtml($html); } elseif ($value instanceof \Sabre\Xml\XmlSerializable) { $xml = $this->server->xml->write('{DAV:}root', $value, $this->server->getBaseUri()); $xml = explode("\n", $xml); $xml = array_slice($xml, 2, -2); return '<pre>'.$html->h(implode("\n", $xml)).'</pre>'; } else { return '<em>unknown</em>'; } }
[ "private", "function", "drawPropertyValue", "(", "$", "html", ",", "$", "value", ")", "{", "if", "(", "is_scalar", "(", "$", "value", ")", ")", "{", "return", "$", "html", "->", "h", "(", "$", "value", ")", ";", "}", "elseif", "(", "$", "value", "instanceof", "HtmlOutput", ")", "{", "return", "$", "value", "->", "toHtml", "(", "$", "html", ")", ";", "}", "elseif", "(", "$", "value", "instanceof", "\\", "Sabre", "\\", "Xml", "\\", "XmlSerializable", ")", "{", "// There's no default html output for this property, we're going", "// to output the actual xml serialization instead.", "$", "xml", "=", "$", "this", "->", "server", "->", "xml", "->", "write", "(", "'{DAV:}root'", ",", "$", "value", ",", "$", "this", "->", "server", "->", "getBaseUri", "(", ")", ")", ";", "// removing first and last line, as they contain our root", "// element.", "$", "xml", "=", "explode", "(", "\"\\n\"", ",", "$", "xml", ")", ";", "$", "xml", "=", "array_slice", "(", "$", "xml", ",", "2", ",", "-", "2", ")", ";", "return", "'<pre>'", ".", "$", "html", "->", "h", "(", "implode", "(", "\"\\n\"", ",", "$", "xml", ")", ")", ".", "'</pre>'", ";", "}", "else", "{", "return", "'<em>unknown</em>'", ";", "}", "}" ]
Draws a table row for a property. @param HtmlOutputHelper $html @param mixed $value @return string
[ "Draws", "a", "table", "row", "for", "a", "property", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/Plugin.php#L748-L767
sabre-io/dav
lib/CalDAV/Xml/Property/SupportedCalendarComponentSet.php
SupportedCalendarComponentSet.xmlSerialize
public function xmlSerialize(Writer $writer) { foreach ($this->components as $component) { $writer->startElement('{'.Plugin::NS_CALDAV.'}comp'); $writer->writeAttributes(['name' => $component]); $writer->endElement(); } }
php
public function xmlSerialize(Writer $writer) { foreach ($this->components as $component) { $writer->startElement('{'.Plugin::NS_CALDAV.'}comp'); $writer->writeAttributes(['name' => $component]); $writer->endElement(); } }
[ "public", "function", "xmlSerialize", "(", "Writer", "$", "writer", ")", "{", "foreach", "(", "$", "this", "->", "components", "as", "$", "component", ")", "{", "$", "writer", "->", "startElement", "(", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}comp'", ")", ";", "$", "writer", "->", "writeAttributes", "(", "[", "'name'", "=>", "$", "component", "]", ")", ";", "$", "writer", "->", "endElement", "(", ")", ";", "}", "}" ]
The xmlSerialize method is called during xml writing. Use the $writer argument to write its own xml serialization. An important note: do _not_ create a parent element. Any element implementing XmlSerializable should only ever write what's considered its 'inner xml'. The parent of the current element is responsible for writing a containing element. This allows serializers to be re-used for different element names. If you are opening new elements, you must also close them again. @param Writer $writer
[ "The", "xmlSerialize", "method", "is", "called", "during", "xml", "writing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Xml/Property/SupportedCalendarComponentSet.php#L75-L82
sabre-io/dav
lib/CalDAV/Xml/Property/SupportedCalendarComponentSet.php
SupportedCalendarComponentSet.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { $elems = $reader->parseInnerTree(); $components = []; foreach ((array) $elems as $elem) { if ($elem['name'] === '{'.Plugin::NS_CALDAV.'}comp') { $components[] = $elem['attributes']['name']; } } if (!$components) { throw new ParseException('supported-calendar-component-set must have at least one CALDAV:comp element'); } return new self($components); }
php
public static function xmlDeserialize(Reader $reader) { $elems = $reader->parseInnerTree(); $components = []; foreach ((array) $elems as $elem) { if ($elem['name'] === '{'.Plugin::NS_CALDAV.'}comp') { $components[] = $elem['attributes']['name']; } } if (!$components) { throw new ParseException('supported-calendar-component-set must have at least one CALDAV:comp element'); } return new self($components); }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "$", "elems", "=", "$", "reader", "->", "parseInnerTree", "(", ")", ";", "$", "components", "=", "[", "]", ";", "foreach", "(", "(", "array", ")", "$", "elems", "as", "$", "elem", ")", "{", "if", "(", "$", "elem", "[", "'name'", "]", "===", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}comp'", ")", "{", "$", "components", "[", "]", "=", "$", "elem", "[", "'attributes'", "]", "[", "'name'", "]", ";", "}", "}", "if", "(", "!", "$", "components", ")", "{", "throw", "new", "ParseException", "(", "'supported-calendar-component-set must have at least one CALDAV:comp element'", ")", ";", "}", "return", "new", "self", "(", "$", "components", ")", ";", "}" ]
The deserialize method is called during xml parsing. This method is called statically, this is because in theory this method may be used as a type of constructor, or factory method. Often you want to return an instance of the current class, but you are free to return other data as well. You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop. If you just want to skip parsing for this element altogether, you can just call $reader->next(); $reader->parseInnerTree() will parse the entire sub-tree, and advance to the next element. @param Reader $reader @return mixed
[ "The", "deserialize", "method", "is", "called", "during", "xml", "parsing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Xml/Property/SupportedCalendarComponentSet.php#L106-L123
sabre-io/dav
lib/DAV/Auth/Backend/File.php
File.loadFile
public function loadFile($filename) { foreach (file($filename, FILE_IGNORE_NEW_LINES) as $line) { if (2 !== substr_count($line, ':')) { throw new DAV\Exception('Malformed htdigest file. Every line should contain 2 colons'); } list($username, $realm, $A1) = explode(':', $line); if (!preg_match('/^[a-zA-Z0-9]{32}$/', $A1)) { throw new DAV\Exception('Malformed htdigest file. Invalid md5 hash'); } $this->users[$realm.':'.$username] = $A1; } }
php
public function loadFile($filename) { foreach (file($filename, FILE_IGNORE_NEW_LINES) as $line) { if (2 !== substr_count($line, ':')) { throw new DAV\Exception('Malformed htdigest file. Every line should contain 2 colons'); } list($username, $realm, $A1) = explode(':', $line); if (!preg_match('/^[a-zA-Z0-9]{32}$/', $A1)) { throw new DAV\Exception('Malformed htdigest file. Invalid md5 hash'); } $this->users[$realm.':'.$username] = $A1; } }
[ "public", "function", "loadFile", "(", "$", "filename", ")", "{", "foreach", "(", "file", "(", "$", "filename", ",", "FILE_IGNORE_NEW_LINES", ")", "as", "$", "line", ")", "{", "if", "(", "2", "!==", "substr_count", "(", "$", "line", ",", "':'", ")", ")", "{", "throw", "new", "DAV", "\\", "Exception", "(", "'Malformed htdigest file. Every line should contain 2 colons'", ")", ";", "}", "list", "(", "$", "username", ",", "$", "realm", ",", "$", "A1", ")", "=", "explode", "(", "':'", ",", "$", "line", ")", ";", "if", "(", "!", "preg_match", "(", "'/^[a-zA-Z0-9]{32}$/'", ",", "$", "A1", ")", ")", "{", "throw", "new", "DAV", "\\", "Exception", "(", "'Malformed htdigest file. Invalid md5 hash'", ")", ";", "}", "$", "this", "->", "users", "[", "$", "realm", ".", "':'", ".", "$", "username", "]", "=", "$", "A1", ";", "}", "}" ]
Loads an htdigest-formatted file. This method can be called multiple times if more than 1 file is used. @param string $filename
[ "Loads", "an", "htdigest", "-", "formatted", "file", ".", "This", "method", "can", "be", "called", "multiple", "times", "if", "more", "than", "1", "file", "is", "used", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Auth/Backend/File.php#L47-L60
sabre-io/dav
lib/DAV/Auth/Backend/File.php
File.getDigestHash
public function getDigestHash($realm, $username) { return isset($this->users[$realm.':'.$username]) ? $this->users[$realm.':'.$username] : false; }
php
public function getDigestHash($realm, $username) { return isset($this->users[$realm.':'.$username]) ? $this->users[$realm.':'.$username] : false; }
[ "public", "function", "getDigestHash", "(", "$", "realm", ",", "$", "username", ")", "{", "return", "isset", "(", "$", "this", "->", "users", "[", "$", "realm", ".", "':'", ".", "$", "username", "]", ")", "?", "$", "this", "->", "users", "[", "$", "realm", ".", "':'", ".", "$", "username", "]", ":", "false", ";", "}" ]
Returns a users' information. @param string $realm @param string $username @return string
[ "Returns", "a", "users", "information", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Auth/Backend/File.php#L70-L73
sabre-io/dav
lib/DAVACL/Principal.php
Principal.getAlternateUriSet
public function getAlternateUriSet() { $uris = []; if (isset($this->principalProperties['{DAV:}alternate-URI-set'])) { $uris = $this->principalProperties['{DAV:}alternate-URI-set']; } if (isset($this->principalProperties['{http://sabredav.org/ns}email-address'])) { $uris[] = 'mailto:'.$this->principalProperties['{http://sabredav.org/ns}email-address']; } return array_unique($uris); }
php
public function getAlternateUriSet() { $uris = []; if (isset($this->principalProperties['{DAV:}alternate-URI-set'])) { $uris = $this->principalProperties['{DAV:}alternate-URI-set']; } if (isset($this->principalProperties['{http: $uris[] = 'mailto:'.$this->principalProperties['{http: } return array_unique($uris); }
[ "public", "function", "getAlternateUriSet", "(", ")", "{", "$", "uris", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "principalProperties", "[", "'{DAV:}alternate-URI-set'", "]", ")", ")", "{", "$", "uris", "=", "$", "this", "->", "principalProperties", "[", "'{DAV:}alternate-URI-set'", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "principalProperties", "[", "'{http://sabredav.org/ns}email-address'", "]", ")", ")", "{", "$", "uris", "[", "]", "=", "'mailto:'", ".", "$", "this", "->", "principalProperties", "[", "'{http://sabredav.org/ns}email-address'", "]", ";", "}", "return", "array_unique", "(", "$", "uris", ")", ";", "}" ]
Returns a list of alternative urls for a principal. This can for example be an email address, or ldap url. @return array
[ "Returns", "a", "list", "of", "alternative", "urls", "for", "a", "principal", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Principal.php#L75-L87
sabre-io/dav
lib/DAVACL/Principal.php
Principal.getName
public function getName() { $uri = $this->principalProperties['uri']; list(, $name) = Uri\split($uri); return $name; }
php
public function getName() { $uri = $this->principalProperties['uri']; list(, $name) = Uri\split($uri); return $name; }
[ "public", "function", "getName", "(", ")", "{", "$", "uri", "=", "$", "this", "->", "principalProperties", "[", "'uri'", "]", ";", "list", "(", ",", "$", "name", ")", "=", "Uri", "\\", "split", "(", "$", "uri", ")", ";", "return", "$", "name", ";", "}" ]
Returns this principals name. @return string
[ "Returns", "this", "principals", "name", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Principal.php#L135-L141
sabre-io/dav
lib/DAVACL/Principal.php
Principal.getProperties
public function getProperties($requestedProperties) { $newProperties = []; foreach ($requestedProperties as $propName) { if (isset($this->principalProperties[$propName])) { $newProperties[$propName] = $this->principalProperties[$propName]; } } return $newProperties; }
php
public function getProperties($requestedProperties) { $newProperties = []; foreach ($requestedProperties as $propName) { if (isset($this->principalProperties[$propName])) { $newProperties[$propName] = $this->principalProperties[$propName]; } } return $newProperties; }
[ "public", "function", "getProperties", "(", "$", "requestedProperties", ")", "{", "$", "newProperties", "=", "[", "]", ";", "foreach", "(", "$", "requestedProperties", "as", "$", "propName", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "principalProperties", "[", "$", "propName", "]", ")", ")", "{", "$", "newProperties", "[", "$", "propName", "]", "=", "$", "this", "->", "principalProperties", "[", "$", "propName", "]", ";", "}", "}", "return", "$", "newProperties", ";", "}" ]
Returns a list of properties. @param array $requestedProperties @return array
[ "Returns", "a", "list", "of", "properties", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Principal.php#L164-L174
sabre-io/dav
lib/DAVACL/Principal.php
Principal.propPatch
public function propPatch(DAV\PropPatch $propPatch) { return $this->principalBackend->updatePrincipal( $this->principalProperties['uri'], $propPatch ); }
php
public function propPatch(DAV\PropPatch $propPatch) { return $this->principalBackend->updatePrincipal( $this->principalProperties['uri'], $propPatch ); }
[ "public", "function", "propPatch", "(", "DAV", "\\", "PropPatch", "$", "propPatch", ")", "{", "return", "$", "this", "->", "principalBackend", "->", "updatePrincipal", "(", "$", "this", "->", "principalProperties", "[", "'uri'", "]", ",", "$", "propPatch", ")", ";", "}" ]
Updates properties on this node. This method received a PropPatch object, which contains all the information about the update. To update specific properties, call the 'handle' method on this object. Read the PropPatch documentation for more information. @param DAV\PropPatch $propPatch
[ "Updates", "properties", "on", "this", "node", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Principal.php#L187-L193
sabre-io/dav
lib/CalDAV/Xml/Request/CalendarQueryReport.php
CalendarQueryReport.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { $elems = $reader->parseInnerTree([ '{urn:ietf:params:xml:ns:caldav}comp-filter' => 'Sabre\\CalDAV\\Xml\\Filter\\CompFilter', '{urn:ietf:params:xml:ns:caldav}prop-filter' => 'Sabre\\CalDAV\\Xml\\Filter\\PropFilter', '{urn:ietf:params:xml:ns:caldav}param-filter' => 'Sabre\\CalDAV\\Xml\\Filter\\ParamFilter', '{urn:ietf:params:xml:ns:caldav}calendar-data' => 'Sabre\\CalDAV\\Xml\\Filter\\CalendarData', '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', ]); $newProps = [ 'filters' => null, 'properties' => [], ]; if (!is_array($elems)) { $elems = []; } foreach ($elems as $elem) { switch ($elem['name']) { case '{DAV:}prop': $newProps['properties'] = array_keys($elem['value']); if (isset($elem['value']['{'.Plugin::NS_CALDAV.'}calendar-data'])) { $newProps += $elem['value']['{'.Plugin::NS_CALDAV.'}calendar-data']; } break; case '{'.Plugin::NS_CALDAV.'}filter': foreach ($elem['value'] as $subElem) { if ($subElem['name'] === '{'.Plugin::NS_CALDAV.'}comp-filter') { if (!is_null($newProps['filters'])) { throw new BadRequest('Only one top-level comp-filter may be defined'); } $newProps['filters'] = $subElem['value']; } } break; } } if (is_null($newProps['filters'])) { throw new BadRequest('The {'.Plugin::NS_CALDAV.'}filter element is required for this request'); } $obj = new self(); foreach ($newProps as $key => $value) { $obj->$key = $value; } return $obj; }
php
public static function xmlDeserialize(Reader $reader) { $elems = $reader->parseInnerTree([ '{urn:ietf:params:xml:ns:caldav}comp-filter' => 'Sabre\\CalDAV\\Xml\\Filter\\CompFilter', '{urn:ietf:params:xml:ns:caldav}prop-filter' => 'Sabre\\CalDAV\\Xml\\Filter\\PropFilter', '{urn:ietf:params:xml:ns:caldav}param-filter' => 'Sabre\\CalDAV\\Xml\\Filter\\ParamFilter', '{urn:ietf:params:xml:ns:caldav}calendar-data' => 'Sabre\\CalDAV\\Xml\\Filter\\CalendarData', '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', ]); $newProps = [ 'filters' => null, 'properties' => [], ]; if (!is_array($elems)) { $elems = []; } foreach ($elems as $elem) { switch ($elem['name']) { case '{DAV:}prop': $newProps['properties'] = array_keys($elem['value']); if (isset($elem['value']['{'.Plugin::NS_CALDAV.'}calendar-data'])) { $newProps += $elem['value']['{'.Plugin::NS_CALDAV.'}calendar-data']; } break; case '{'.Plugin::NS_CALDAV.'}filter': foreach ($elem['value'] as $subElem) { if ($subElem['name'] === '{'.Plugin::NS_CALDAV.'}comp-filter') { if (!is_null($newProps['filters'])) { throw new BadRequest('Only one top-level comp-filter may be defined'); } $newProps['filters'] = $subElem['value']; } } break; } } if (is_null($newProps['filters'])) { throw new BadRequest('The {'.Plugin::NS_CALDAV.'}filter element is required for this request'); } $obj = new self(); foreach ($newProps as $key => $value) { $obj->$key = $value; } return $obj; }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "$", "elems", "=", "$", "reader", "->", "parseInnerTree", "(", "[", "'{urn:ietf:params:xml:ns:caldav}comp-filter'", "=>", "'Sabre\\\\CalDAV\\\\Xml\\\\Filter\\\\CompFilter'", ",", "'{urn:ietf:params:xml:ns:caldav}prop-filter'", "=>", "'Sabre\\\\CalDAV\\\\Xml\\\\Filter\\\\PropFilter'", ",", "'{urn:ietf:params:xml:ns:caldav}param-filter'", "=>", "'Sabre\\\\CalDAV\\\\Xml\\\\Filter\\\\ParamFilter'", ",", "'{urn:ietf:params:xml:ns:caldav}calendar-data'", "=>", "'Sabre\\\\CalDAV\\\\Xml\\\\Filter\\\\CalendarData'", ",", "'{DAV:}prop'", "=>", "'Sabre\\\\Xml\\\\Element\\\\KeyValue'", ",", "]", ")", ";", "$", "newProps", "=", "[", "'filters'", "=>", "null", ",", "'properties'", "=>", "[", "]", ",", "]", ";", "if", "(", "!", "is_array", "(", "$", "elems", ")", ")", "{", "$", "elems", "=", "[", "]", ";", "}", "foreach", "(", "$", "elems", "as", "$", "elem", ")", "{", "switch", "(", "$", "elem", "[", "'name'", "]", ")", "{", "case", "'{DAV:}prop'", ":", "$", "newProps", "[", "'properties'", "]", "=", "array_keys", "(", "$", "elem", "[", "'value'", "]", ")", ";", "if", "(", "isset", "(", "$", "elem", "[", "'value'", "]", "[", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}calendar-data'", "]", ")", ")", "{", "$", "newProps", "+=", "$", "elem", "[", "'value'", "]", "[", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}calendar-data'", "]", ";", "}", "break", ";", "case", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}filter'", ":", "foreach", "(", "$", "elem", "[", "'value'", "]", "as", "$", "subElem", ")", "{", "if", "(", "$", "subElem", "[", "'name'", "]", "===", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}comp-filter'", ")", "{", "if", "(", "!", "is_null", "(", "$", "newProps", "[", "'filters'", "]", ")", ")", "{", "throw", "new", "BadRequest", "(", "'Only one top-level comp-filter may be defined'", ")", ";", "}", "$", "newProps", "[", "'filters'", "]", "=", "$", "subElem", "[", "'value'", "]", ";", "}", "}", "break", ";", "}", "}", "if", "(", "is_null", "(", "$", "newProps", "[", "'filters'", "]", ")", ")", "{", "throw", "new", "BadRequest", "(", "'The {'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}filter element is required for this request'", ")", ";", "}", "$", "obj", "=", "new", "self", "(", ")", ";", "foreach", "(", "$", "newProps", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "obj", "->", "$", "key", "=", "$", "value", ";", "}", "return", "$", "obj", ";", "}" ]
The deserialize method is called during xml parsing. This method is called statically, this is because in theory this method may be used as a type of constructor, or factory method. Often you want to return an instance of the current class, but you are free to return other data as well. You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop. If you just want to skip parsing for this element altogether, you can just call $reader->next(); $reader->parseInnerTree() will parse the entire sub-tree, and advance to the next element. @param Reader $reader @return mixed
[ "The", "deserialize", "method", "is", "called", "during", "xml", "parsing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Xml/Request/CalendarQueryReport.php#L88-L138
sabre-io/dav
lib/CalDAV/Xml/Property/SupportedCollationSet.php
SupportedCollationSet.xmlSerialize
public function xmlSerialize(Writer $writer) { $collations = [ 'i;ascii-casemap', 'i;octet', 'i;unicode-casemap', ]; foreach ($collations as $collation) { $writer->writeElement('{'.Plugin::NS_CALDAV.'}supported-collation', $collation); } }
php
public function xmlSerialize(Writer $writer) { $collations = [ 'i;ascii-casemap', 'i;octet', 'i;unicode-casemap', ]; foreach ($collations as $collation) { $writer->writeElement('{'.Plugin::NS_CALDAV.'}supported-collation', $collation); } }
[ "public", "function", "xmlSerialize", "(", "Writer", "$", "writer", ")", "{", "$", "collations", "=", "[", "'i;ascii-casemap'", ",", "'i;octet'", ",", "'i;unicode-casemap'", ",", "]", ";", "foreach", "(", "$", "collations", "as", "$", "collation", ")", "{", "$", "writer", "->", "writeElement", "(", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}supported-collation'", ",", "$", "collation", ")", ";", "}", "}" ]
The xmlSerialize method is called during xml writing. Use the $writer argument to write its own xml serialization. An important note: do _not_ create a parent element. Any element implementing XmlSerializable should only ever write what's considered its 'inner xml'. The parent of the current element is responsible for writing a containing element. This allows serializers to be re-used for different element names. If you are opening new elements, you must also close them again. @param Writer $writer
[ "The", "xmlSerialize", "method", "is", "called", "during", "xml", "writing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Xml/Property/SupportedCollationSet.php#L44-L55
sabre-io/dav
lib/CalDAV/SharingPlugin.php
SharingPlugin.initialize
public function initialize(DAV\Server $server) { $this->server = $server; if (is_null($this->server->getPlugin('sharing'))) { throw new \LogicException('The generic "sharing" plugin must be loaded before the caldav sharing plugin. Call $server->addPlugin(new \Sabre\DAV\Sharing\Plugin()); before this one.'); } array_push( $this->server->protectedProperties, '{'.Plugin::NS_CALENDARSERVER.'}invite', '{'.Plugin::NS_CALENDARSERVER.'}allowed-sharing-modes', '{'.Plugin::NS_CALENDARSERVER.'}shared-url' ); $this->server->xml->elementMap['{'.Plugin::NS_CALENDARSERVER.'}share'] = 'Sabre\\CalDAV\\Xml\\Request\\Share'; $this->server->xml->elementMap['{'.Plugin::NS_CALENDARSERVER.'}invite-reply'] = 'Sabre\\CalDAV\\Xml\\Request\\InviteReply'; $this->server->on('propFind', [$this, 'propFindEarly']); $this->server->on('propFind', [$this, 'propFindLate'], 150); $this->server->on('propPatch', [$this, 'propPatch'], 40); $this->server->on('method:POST', [$this, 'httpPost']); }
php
public function initialize(DAV\Server $server) { $this->server = $server; if (is_null($this->server->getPlugin('sharing'))) { throw new \LogicException('The generic "sharing" plugin must be loaded before the caldav sharing plugin. Call $server->addPlugin(new \Sabre\DAV\Sharing\Plugin()); before this one.'); } array_push( $this->server->protectedProperties, '{'.Plugin::NS_CALENDARSERVER.'}invite', '{'.Plugin::NS_CALENDARSERVER.'}allowed-sharing-modes', '{'.Plugin::NS_CALENDARSERVER.'}shared-url' ); $this->server->xml->elementMap['{'.Plugin::NS_CALENDARSERVER.'}share'] = 'Sabre\\CalDAV\\Xml\\Request\\Share'; $this->server->xml->elementMap['{'.Plugin::NS_CALENDARSERVER.'}invite-reply'] = 'Sabre\\CalDAV\\Xml\\Request\\InviteReply'; $this->server->on('propFind', [$this, 'propFindEarly']); $this->server->on('propFind', [$this, 'propFindLate'], 150); $this->server->on('propPatch', [$this, 'propPatch'], 40); $this->server->on('method:POST', [$this, 'httpPost']); }
[ "public", "function", "initialize", "(", "DAV", "\\", "Server", "$", "server", ")", "{", "$", "this", "->", "server", "=", "$", "server", ";", "if", "(", "is_null", "(", "$", "this", "->", "server", "->", "getPlugin", "(", "'sharing'", ")", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "'The generic \"sharing\" plugin must be loaded before the caldav sharing plugin. Call $server->addPlugin(new \\Sabre\\DAV\\Sharing\\Plugin()); before this one.'", ")", ";", "}", "array_push", "(", "$", "this", "->", "server", "->", "protectedProperties", ",", "'{'", ".", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}invite'", ",", "'{'", ".", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}allowed-sharing-modes'", ",", "'{'", ".", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}shared-url'", ")", ";", "$", "this", "->", "server", "->", "xml", "->", "elementMap", "[", "'{'", ".", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}share'", "]", "=", "'Sabre\\\\CalDAV\\\\Xml\\\\Request\\\\Share'", ";", "$", "this", "->", "server", "->", "xml", "->", "elementMap", "[", "'{'", ".", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}invite-reply'", "]", "=", "'Sabre\\\\CalDAV\\\\Xml\\\\Request\\\\InviteReply'", ";", "$", "this", "->", "server", "->", "on", "(", "'propFind'", ",", "[", "$", "this", ",", "'propFindEarly'", "]", ")", ";", "$", "this", "->", "server", "->", "on", "(", "'propFind'", ",", "[", "$", "this", ",", "'propFindLate'", "]", ",", "150", ")", ";", "$", "this", "->", "server", "->", "on", "(", "'propPatch'", ",", "[", "$", "this", ",", "'propPatch'", "]", ",", "40", ")", ";", "$", "this", "->", "server", "->", "on", "(", "'method:POST'", ",", "[", "$", "this", ",", "'httpPost'", "]", ")", ";", "}" ]
This initializes the plugin. This function is called by Sabre\DAV\Server, after addPlugin is called. This method should set up the required event subscriptions. @param DAV\Server $server
[ "This", "initializes", "the", "plugin", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/SharingPlugin.php#L73-L95
sabre-io/dav
lib/CalDAV/SharingPlugin.php
SharingPlugin.propFindEarly
public function propFindEarly(DAV\PropFind $propFind, DAV\INode $node) { if ($node instanceof ISharedCalendar) { $propFind->handle('{'.Plugin::NS_CALENDARSERVER.'}invite', function () use ($node) { return new Xml\Property\Invite( $node->getInvites() ); }); } }
php
public function propFindEarly(DAV\PropFind $propFind, DAV\INode $node) { if ($node instanceof ISharedCalendar) { $propFind->handle('{'.Plugin::NS_CALENDARSERVER.'}invite', function () use ($node) { return new Xml\Property\Invite( $node->getInvites() ); }); } }
[ "public", "function", "propFindEarly", "(", "DAV", "\\", "PropFind", "$", "propFind", ",", "DAV", "\\", "INode", "$", "node", ")", "{", "if", "(", "$", "node", "instanceof", "ISharedCalendar", ")", "{", "$", "propFind", "->", "handle", "(", "'{'", ".", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}invite'", ",", "function", "(", ")", "use", "(", "$", "node", ")", "{", "return", "new", "Xml", "\\", "Property", "\\", "Invite", "(", "$", "node", "->", "getInvites", "(", ")", ")", ";", "}", ")", ";", "}", "}" ]
This event is triggered when properties are requested for a certain node. This allows us to inject any properties early. @param DAV\PropFind $propFind @param DAV\INode $node
[ "This", "event", "is", "triggered", "when", "properties", "are", "requested", "for", "a", "certain", "node", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/SharingPlugin.php#L106-L115
sabre-io/dav
lib/CalDAV/SharingPlugin.php
SharingPlugin.propFindLate
public function propFindLate(DAV\PropFind $propFind, DAV\INode $node) { if ($node instanceof ISharedCalendar) { $shareAccess = $node->getShareAccess(); if ($rt = $propFind->get('{DAV:}resourcetype')) { switch ($shareAccess) { case \Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER: $rt->add('{'.Plugin::NS_CALENDARSERVER.'}shared-owner'); break; case \Sabre\DAV\Sharing\Plugin::ACCESS_READ: case \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE: $rt->add('{'.Plugin::NS_CALENDARSERVER.'}shared'); break; } } $propFind->handle('{'.Plugin::NS_CALENDARSERVER.'}allowed-sharing-modes', function () { return new Xml\Property\AllowedSharingModes(true, false); }); } }
php
public function propFindLate(DAV\PropFind $propFind, DAV\INode $node) { if ($node instanceof ISharedCalendar) { $shareAccess = $node->getShareAccess(); if ($rt = $propFind->get('{DAV:}resourcetype')) { switch ($shareAccess) { case \Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER: $rt->add('{'.Plugin::NS_CALENDARSERVER.'}shared-owner'); break; case \Sabre\DAV\Sharing\Plugin::ACCESS_READ: case \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE: $rt->add('{'.Plugin::NS_CALENDARSERVER.'}shared'); break; } } $propFind->handle('{'.Plugin::NS_CALENDARSERVER.'}allowed-sharing-modes', function () { return new Xml\Property\AllowedSharingModes(true, false); }); } }
[ "public", "function", "propFindLate", "(", "DAV", "\\", "PropFind", "$", "propFind", ",", "DAV", "\\", "INode", "$", "node", ")", "{", "if", "(", "$", "node", "instanceof", "ISharedCalendar", ")", "{", "$", "shareAccess", "=", "$", "node", "->", "getShareAccess", "(", ")", ";", "if", "(", "$", "rt", "=", "$", "propFind", "->", "get", "(", "'{DAV:}resourcetype'", ")", ")", "{", "switch", "(", "$", "shareAccess", ")", "{", "case", "\\", "Sabre", "\\", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "ACCESS_SHAREDOWNER", ":", "$", "rt", "->", "add", "(", "'{'", ".", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}shared-owner'", ")", ";", "break", ";", "case", "\\", "Sabre", "\\", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "ACCESS_READ", ":", "case", "\\", "Sabre", "\\", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "ACCESS_READWRITE", ":", "$", "rt", "->", "add", "(", "'{'", ".", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}shared'", ")", ";", "break", ";", "}", "}", "$", "propFind", "->", "handle", "(", "'{'", ".", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}allowed-sharing-modes'", ",", "function", "(", ")", "{", "return", "new", "Xml", "\\", "Property", "\\", "AllowedSharingModes", "(", "true", ",", "false", ")", ";", "}", ")", ";", "}", "}" ]
This method is triggered *after* all properties have been retrieved. This allows us to inject the correct resourcetype for calendars that have been shared. @param DAV\PropFind $propFind @param DAV\INode $node
[ "This", "method", "is", "triggered", "*", "after", "*", "all", "properties", "have", "been", "retrieved", ".", "This", "allows", "us", "to", "inject", "the", "correct", "resourcetype", "for", "calendars", "that", "have", "been", "shared", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/SharingPlugin.php#L125-L144
sabre-io/dav
lib/CalDAV/SharingPlugin.php
SharingPlugin.propPatch
public function propPatch($path, DAV\PropPatch $propPatch) { $node = $this->server->tree->getNodeForPath($path); if (!$node instanceof ISharedCalendar) { return; } if (\Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER === $node->getShareAccess() || \Sabre\DAV\Sharing\Plugin::ACCESS_NOTSHARED === $node->getShareAccess()) { $propPatch->handle('{DAV:}resourcetype', function ($value) use ($node) { if ($value->is('{'.Plugin::NS_CALENDARSERVER.'}shared-owner')) { return false; } $shares = $node->getInvites(); foreach ($shares as $share) { $share->access = DAV\Sharing\Plugin::ACCESS_NOACCESS; } $node->updateInvites($shares); return true; }); } }
php
public function propPatch($path, DAV\PropPatch $propPatch) { $node = $this->server->tree->getNodeForPath($path); if (!$node instanceof ISharedCalendar) { return; } if (\Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER === $node->getShareAccess() || \Sabre\DAV\Sharing\Plugin::ACCESS_NOTSHARED === $node->getShareAccess()) { $propPatch->handle('{DAV:}resourcetype', function ($value) use ($node) { if ($value->is('{'.Plugin::NS_CALENDARSERVER.'}shared-owner')) { return false; } $shares = $node->getInvites(); foreach ($shares as $share) { $share->access = DAV\Sharing\Plugin::ACCESS_NOACCESS; } $node->updateInvites($shares); return true; }); } }
[ "public", "function", "propPatch", "(", "$", "path", ",", "DAV", "\\", "PropPatch", "$", "propPatch", ")", "{", "$", "node", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "path", ")", ";", "if", "(", "!", "$", "node", "instanceof", "ISharedCalendar", ")", "{", "return", ";", "}", "if", "(", "\\", "Sabre", "\\", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "ACCESS_SHAREDOWNER", "===", "$", "node", "->", "getShareAccess", "(", ")", "||", "\\", "Sabre", "\\", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "ACCESS_NOTSHARED", "===", "$", "node", "->", "getShareAccess", "(", ")", ")", "{", "$", "propPatch", "->", "handle", "(", "'{DAV:}resourcetype'", ",", "function", "(", "$", "value", ")", "use", "(", "$", "node", ")", "{", "if", "(", "$", "value", "->", "is", "(", "'{'", ".", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}shared-owner'", ")", ")", "{", "return", "false", ";", "}", "$", "shares", "=", "$", "node", "->", "getInvites", "(", ")", ";", "foreach", "(", "$", "shares", "as", "$", "share", ")", "{", "$", "share", "->", "access", "=", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "ACCESS_NOACCESS", ";", "}", "$", "node", "->", "updateInvites", "(", "$", "shares", ")", ";", "return", "true", ";", "}", ")", ";", "}", "}" ]
This method is trigged when a user attempts to update a node's properties. A previous draft of the sharing spec stated that it was possible to use PROPPATCH to remove 'shared-owner' from the resourcetype, thus unsharing the calendar. Even though this is no longer in the current spec, we keep this around because OS X 10.7 may still make use of this feature. @param string $path @param DAV\PropPatch $propPatch
[ "This", "method", "is", "trigged", "when", "a", "user", "attempts", "to", "update", "a", "node", "s", "properties", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/SharingPlugin.php#L160-L181
sabre-io/dav
lib/CalDAV/SharingPlugin.php
SharingPlugin.httpPost
public function httpPost(RequestInterface $request, ResponseInterface $response) { $path = $request->getPath(); // Only handling xml $contentType = $request->getHeader('Content-Type'); if (null === $contentType) { return; } if (false === strpos($contentType, 'application/xml') && false === strpos($contentType, 'text/xml')) { return; } // Making sure the node exists try { $node = $this->server->tree->getNodeForPath($path); } catch (DAV\Exception\NotFound $e) { return; } $requestBody = $request->getBodyAsString(); // If this request handler could not deal with this POST request, it // will return 'null' and other plugins get a chance to handle the // request. // // However, we already requested the full body. This is a problem, // because a body can only be read once. This is why we preemptively // re-populated the request body with the existing data. $request->setBody($requestBody); $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); switch ($documentType) { // Both the DAV:share-resource and CALENDARSERVER:share requests // behave identically. case '{'.Plugin::NS_CALENDARSERVER.'}share': $sharingPlugin = $this->server->getPlugin('sharing'); $sharingPlugin->shareResource($path, $message->sharees); $response->setStatus(200); // Adding this because sending a response body may cause issues, // and I wanted some type of indicator the response was handled. $response->setHeader('X-Sabre-Status', 'everything-went-well'); // Breaking the event chain return false; // The invite-reply document is sent when the user replies to an // invitation of a calendar share. case '{'.Plugin::NS_CALENDARSERVER.'}invite-reply': // This only works on the calendar-home-root node. if (!$node instanceof CalendarHome) { return; } $this->server->transactionType = 'post-invite-reply'; // Getting ACL info $acl = $this->server->getPlugin('acl'); // If there's no ACL support, we allow everything if ($acl) { $acl->checkPrivileges($path, '{DAV:}write'); } $url = $node->shareReply( $message->href, $message->status, $message->calendarUri, $message->inReplyTo, $message->summary ); $response->setStatus(200); // Adding this because sending a response body may cause issues, // and I wanted some type of indicator the response was handled. $response->setHeader('X-Sabre-Status', 'everything-went-well'); if ($url) { $writer = $this->server->xml->getWriter(); $writer->contextUri = $request->getUrl(); $writer->openMemory(); $writer->startDocument(); $writer->startElement('{'.Plugin::NS_CALENDARSERVER.'}shared-as'); $writer->write(new LocalHref($url)); $writer->endElement(); $response->setHeader('Content-Type', 'application/xml'); $response->setBody($writer->outputMemory()); } // Breaking the event chain return false; case '{'.Plugin::NS_CALENDARSERVER.'}publish-calendar': // We can only deal with IShareableCalendar objects if (!$node instanceof ISharedCalendar) { return; } $this->server->transactionType = 'post-publish-calendar'; // Getting ACL info $acl = $this->server->getPlugin('acl'); // If there's no ACL support, we allow everything if ($acl) { $acl->checkPrivileges($path, '{DAV:}share'); } $node->setPublishStatus(true); // iCloud sends back the 202, so we will too. $response->setStatus(202); // Adding this because sending a response body may cause issues, // and I wanted some type of indicator the response was handled. $response->setHeader('X-Sabre-Status', 'everything-went-well'); // Breaking the event chain return false; case '{'.Plugin::NS_CALENDARSERVER.'}unpublish-calendar': // We can only deal with IShareableCalendar objects if (!$node instanceof ISharedCalendar) { return; } $this->server->transactionType = 'post-unpublish-calendar'; // Getting ACL info $acl = $this->server->getPlugin('acl'); // If there's no ACL support, we allow everything if ($acl) { $acl->checkPrivileges($path, '{DAV:}share'); } $node->setPublishStatus(false); $response->setStatus(200); // Adding this because sending a response body may cause issues, // and I wanted some type of indicator the response was handled. $response->setHeader('X-Sabre-Status', 'everything-went-well'); // Breaking the event chain return false; } }
php
public function httpPost(RequestInterface $request, ResponseInterface $response) { $path = $request->getPath(); $contentType = $request->getHeader('Content-Type'); if (null === $contentType) { return; } if (false === strpos($contentType, 'application/xml') && false === strpos($contentType, 'text/xml')) { return; } try { $node = $this->server->tree->getNodeForPath($path); } catch (DAV\Exception\NotFound $e) { return; } $requestBody = $request->getBodyAsString(); $request->setBody($requestBody); $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); switch ($documentType) { case '{'.Plugin::NS_CALENDARSERVER.'}share': $sharingPlugin = $this->server->getPlugin('sharing'); $sharingPlugin->shareResource($path, $message->sharees); $response->setStatus(200); $response->setHeader('X-Sabre-Status', 'everything-went-well'); return false; case '{'.Plugin::NS_CALENDARSERVER.'}invite-reply': if (!$node instanceof CalendarHome) { return; } $this->server->transactionType = 'post-invite-reply'; $acl = $this->server->getPlugin('acl'); if ($acl) { $acl->checkPrivileges($path, '{DAV:}write'); } $url = $node->shareReply( $message->href, $message->status, $message->calendarUri, $message->inReplyTo, $message->summary ); $response->setStatus(200); $response->setHeader('X-Sabre-Status', 'everything-went-well'); if ($url) { $writer = $this->server->xml->getWriter(); $writer->contextUri = $request->getUrl(); $writer->openMemory(); $writer->startDocument(); $writer->startElement('{'.Plugin::NS_CALENDARSERVER.'}shared-as'); $writer->write(new LocalHref($url)); $writer->endElement(); $response->setHeader('Content-Type', 'application/xml'); $response->setBody($writer->outputMemory()); } return false; case '{'.Plugin::NS_CALENDARSERVER.'}publish-calendar': if (!$node instanceof ISharedCalendar) { return; } $this->server->transactionType = 'post-publish-calendar'; $acl = $this->server->getPlugin('acl'); if ($acl) { $acl->checkPrivileges($path, '{DAV:}share'); } $node->setPublishStatus(true); $response->setStatus(202); $response->setHeader('X-Sabre-Status', 'everything-went-well'); return false; case '{'.Plugin::NS_CALENDARSERVER.'}unpublish-calendar': if (!$node instanceof ISharedCalendar) { return; } $this->server->transactionType = 'post-unpublish-calendar'; $acl = $this->server->getPlugin('acl'); if ($acl) { $acl->checkPrivileges($path, '{DAV:}share'); } $node->setPublishStatus(false); $response->setStatus(200); $response->setHeader('X-Sabre-Status', 'everything-went-well'); return false; } }
[ "public", "function", "httpPost", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "path", "=", "$", "request", "->", "getPath", "(", ")", ";", "// Only handling xml", "$", "contentType", "=", "$", "request", "->", "getHeader", "(", "'Content-Type'", ")", ";", "if", "(", "null", "===", "$", "contentType", ")", "{", "return", ";", "}", "if", "(", "false", "===", "strpos", "(", "$", "contentType", ",", "'application/xml'", ")", "&&", "false", "===", "strpos", "(", "$", "contentType", ",", "'text/xml'", ")", ")", "{", "return", ";", "}", "// Making sure the node exists", "try", "{", "$", "node", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "path", ")", ";", "}", "catch", "(", "DAV", "\\", "Exception", "\\", "NotFound", "$", "e", ")", "{", "return", ";", "}", "$", "requestBody", "=", "$", "request", "->", "getBodyAsString", "(", ")", ";", "// If this request handler could not deal with this POST request, it", "// will return 'null' and other plugins get a chance to handle the", "// request.", "//", "// However, we already requested the full body. This is a problem,", "// because a body can only be read once. This is why we preemptively", "// re-populated the request body with the existing data.", "$", "request", "->", "setBody", "(", "$", "requestBody", ")", ";", "$", "message", "=", "$", "this", "->", "server", "->", "xml", "->", "parse", "(", "$", "requestBody", ",", "$", "request", "->", "getUrl", "(", ")", ",", "$", "documentType", ")", ";", "switch", "(", "$", "documentType", ")", "{", "// Both the DAV:share-resource and CALENDARSERVER:share requests", "// behave identically.", "case", "'{'", ".", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}share'", ":", "$", "sharingPlugin", "=", "$", "this", "->", "server", "->", "getPlugin", "(", "'sharing'", ")", ";", "$", "sharingPlugin", "->", "shareResource", "(", "$", "path", ",", "$", "message", "->", "sharees", ")", ";", "$", "response", "->", "setStatus", "(", "200", ")", ";", "// Adding this because sending a response body may cause issues,", "// and I wanted some type of indicator the response was handled.", "$", "response", "->", "setHeader", "(", "'X-Sabre-Status'", ",", "'everything-went-well'", ")", ";", "// Breaking the event chain", "return", "false", ";", "// The invite-reply document is sent when the user replies to an", "// invitation of a calendar share.", "case", "'{'", ".", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}invite-reply'", ":", "// This only works on the calendar-home-root node.", "if", "(", "!", "$", "node", "instanceof", "CalendarHome", ")", "{", "return", ";", "}", "$", "this", "->", "server", "->", "transactionType", "=", "'post-invite-reply'", ";", "// Getting ACL info", "$", "acl", "=", "$", "this", "->", "server", "->", "getPlugin", "(", "'acl'", ")", ";", "// If there's no ACL support, we allow everything", "if", "(", "$", "acl", ")", "{", "$", "acl", "->", "checkPrivileges", "(", "$", "path", ",", "'{DAV:}write'", ")", ";", "}", "$", "url", "=", "$", "node", "->", "shareReply", "(", "$", "message", "->", "href", ",", "$", "message", "->", "status", ",", "$", "message", "->", "calendarUri", ",", "$", "message", "->", "inReplyTo", ",", "$", "message", "->", "summary", ")", ";", "$", "response", "->", "setStatus", "(", "200", ")", ";", "// Adding this because sending a response body may cause issues,", "// and I wanted some type of indicator the response was handled.", "$", "response", "->", "setHeader", "(", "'X-Sabre-Status'", ",", "'everything-went-well'", ")", ";", "if", "(", "$", "url", ")", "{", "$", "writer", "=", "$", "this", "->", "server", "->", "xml", "->", "getWriter", "(", ")", ";", "$", "writer", "->", "contextUri", "=", "$", "request", "->", "getUrl", "(", ")", ";", "$", "writer", "->", "openMemory", "(", ")", ";", "$", "writer", "->", "startDocument", "(", ")", ";", "$", "writer", "->", "startElement", "(", "'{'", ".", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}shared-as'", ")", ";", "$", "writer", "->", "write", "(", "new", "LocalHref", "(", "$", "url", ")", ")", ";", "$", "writer", "->", "endElement", "(", ")", ";", "$", "response", "->", "setHeader", "(", "'Content-Type'", ",", "'application/xml'", ")", ";", "$", "response", "->", "setBody", "(", "$", "writer", "->", "outputMemory", "(", ")", ")", ";", "}", "// Breaking the event chain", "return", "false", ";", "case", "'{'", ".", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}publish-calendar'", ":", "// We can only deal with IShareableCalendar objects", "if", "(", "!", "$", "node", "instanceof", "ISharedCalendar", ")", "{", "return", ";", "}", "$", "this", "->", "server", "->", "transactionType", "=", "'post-publish-calendar'", ";", "// Getting ACL info", "$", "acl", "=", "$", "this", "->", "server", "->", "getPlugin", "(", "'acl'", ")", ";", "// If there's no ACL support, we allow everything", "if", "(", "$", "acl", ")", "{", "$", "acl", "->", "checkPrivileges", "(", "$", "path", ",", "'{DAV:}share'", ")", ";", "}", "$", "node", "->", "setPublishStatus", "(", "true", ")", ";", "// iCloud sends back the 202, so we will too.", "$", "response", "->", "setStatus", "(", "202", ")", ";", "// Adding this because sending a response body may cause issues,", "// and I wanted some type of indicator the response was handled.", "$", "response", "->", "setHeader", "(", "'X-Sabre-Status'", ",", "'everything-went-well'", ")", ";", "// Breaking the event chain", "return", "false", ";", "case", "'{'", ".", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}unpublish-calendar'", ":", "// We can only deal with IShareableCalendar objects", "if", "(", "!", "$", "node", "instanceof", "ISharedCalendar", ")", "{", "return", ";", "}", "$", "this", "->", "server", "->", "transactionType", "=", "'post-unpublish-calendar'", ";", "// Getting ACL info", "$", "acl", "=", "$", "this", "->", "server", "->", "getPlugin", "(", "'acl'", ")", ";", "// If there's no ACL support, we allow everything", "if", "(", "$", "acl", ")", "{", "$", "acl", "->", "checkPrivileges", "(", "$", "path", ",", "'{DAV:}share'", ")", ";", "}", "$", "node", "->", "setPublishStatus", "(", "false", ")", ";", "$", "response", "->", "setStatus", "(", "200", ")", ";", "// Adding this because sending a response body may cause issues,", "// and I wanted some type of indicator the response was handled.", "$", "response", "->", "setHeader", "(", "'X-Sabre-Status'", ",", "'everything-went-well'", ")", ";", "// Breaking the event chain", "return", "false", ";", "}", "}" ]
We intercept this to handle POST requests on calendars. @param RequestInterface $request @param ResponseInterface $response @return bool|null
[ "We", "intercept", "this", "to", "handle", "POST", "requests", "on", "calendars", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/SharingPlugin.php#L191-L341
sabre-io/dav
lib/DAV/Exception/ConflictingLock.php
ConflictingLock.serialize
public function serialize(DAV\Server $server, \DOMElement $errorNode) { if ($this->lock) { $error = $errorNode->ownerDocument->createElementNS('DAV:', 'd:no-conflicting-lock'); $errorNode->appendChild($error); $error->appendChild($errorNode->ownerDocument->createElementNS('DAV:', 'd:href', $this->lock->uri)); } }
php
public function serialize(DAV\Server $server, \DOMElement $errorNode) { if ($this->lock) { $error = $errorNode->ownerDocument->createElementNS('DAV:', 'd:no-conflicting-lock'); $errorNode->appendChild($error); $error->appendChild($errorNode->ownerDocument->createElementNS('DAV:', 'd:href', $this->lock->uri)); } }
[ "public", "function", "serialize", "(", "DAV", "\\", "Server", "$", "server", ",", "\\", "DOMElement", "$", "errorNode", ")", "{", "if", "(", "$", "this", "->", "lock", ")", "{", "$", "error", "=", "$", "errorNode", "->", "ownerDocument", "->", "createElementNS", "(", "'DAV:'", ",", "'d:no-conflicting-lock'", ")", ";", "$", "errorNode", "->", "appendChild", "(", "$", "error", ")", ";", "$", "error", "->", "appendChild", "(", "$", "errorNode", "->", "ownerDocument", "->", "createElementNS", "(", "'DAV:'", ",", "'d:href'", ",", "$", "this", "->", "lock", "->", "uri", ")", ")", ";", "}", "}" ]
This method allows the exception to include additional information into the WebDAV error response. @param DAV\Server $server @param \DOMElement $errorNode
[ "This", "method", "allows", "the", "exception", "to", "include", "additional", "information", "into", "the", "WebDAV", "error", "response", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Exception/ConflictingLock.php#L27-L34
sabre-io/dav
lib/CalDAV/Xml/Filter/PropFilter.php
PropFilter.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { $result = [ 'name' => null, 'is-not-defined' => false, 'param-filters' => [], 'text-match' => null, 'time-range' => false, ]; $att = $reader->parseAttributes(); $result['name'] = $att['name']; $elems = $reader->parseInnerTree(); if (is_array($elems)) { foreach ($elems as $elem) { switch ($elem['name']) { case '{'.Plugin::NS_CALDAV.'}param-filter': $result['param-filters'][] = $elem['value']; break; case '{'.Plugin::NS_CALDAV.'}is-not-defined': $result['is-not-defined'] = true; break; case '{'.Plugin::NS_CALDAV.'}time-range': $result['time-range'] = [ 'start' => isset($elem['attributes']['start']) ? DateTimeParser::parseDateTime($elem['attributes']['start']) : null, 'end' => isset($elem['attributes']['end']) ? DateTimeParser::parseDateTime($elem['attributes']['end']) : null, ]; if ($result['time-range']['start'] && $result['time-range']['end'] && $result['time-range']['end'] <= $result['time-range']['start']) { throw new BadRequest('The end-date must be larger than the start-date'); } break; case '{'.Plugin::NS_CALDAV.'}text-match': $result['text-match'] = [ 'negate-condition' => isset($elem['attributes']['negate-condition']) && 'yes' === $elem['attributes']['negate-condition'], 'collation' => isset($elem['attributes']['collation']) ? $elem['attributes']['collation'] : 'i;ascii-casemap', 'value' => $elem['value'], ]; break; } } } return $result; }
php
public static function xmlDeserialize(Reader $reader) { $result = [ 'name' => null, 'is-not-defined' => false, 'param-filters' => [], 'text-match' => null, 'time-range' => false, ]; $att = $reader->parseAttributes(); $result['name'] = $att['name']; $elems = $reader->parseInnerTree(); if (is_array($elems)) { foreach ($elems as $elem) { switch ($elem['name']) { case '{'.Plugin::NS_CALDAV.'}param-filter': $result['param-filters'][] = $elem['value']; break; case '{'.Plugin::NS_CALDAV.'}is-not-defined': $result['is-not-defined'] = true; break; case '{'.Plugin::NS_CALDAV.'}time-range': $result['time-range'] = [ 'start' => isset($elem['attributes']['start']) ? DateTimeParser::parseDateTime($elem['attributes']['start']) : null, 'end' => isset($elem['attributes']['end']) ? DateTimeParser::parseDateTime($elem['attributes']['end']) : null, ]; if ($result['time-range']['start'] && $result['time-range']['end'] && $result['time-range']['end'] <= $result['time-range']['start']) { throw new BadRequest('The end-date must be larger than the start-date'); } break; case '{'.Plugin::NS_CALDAV.'}text-match': $result['text-match'] = [ 'negate-condition' => isset($elem['attributes']['negate-condition']) && 'yes' === $elem['attributes']['negate-condition'], 'collation' => isset($elem['attributes']['collation']) ? $elem['attributes']['collation'] : 'i;ascii-casemap', 'value' => $elem['value'], ]; break; } } } return $result; }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "$", "result", "=", "[", "'name'", "=>", "null", ",", "'is-not-defined'", "=>", "false", ",", "'param-filters'", "=>", "[", "]", ",", "'text-match'", "=>", "null", ",", "'time-range'", "=>", "false", ",", "]", ";", "$", "att", "=", "$", "reader", "->", "parseAttributes", "(", ")", ";", "$", "result", "[", "'name'", "]", "=", "$", "att", "[", "'name'", "]", ";", "$", "elems", "=", "$", "reader", "->", "parseInnerTree", "(", ")", ";", "if", "(", "is_array", "(", "$", "elems", ")", ")", "{", "foreach", "(", "$", "elems", "as", "$", "elem", ")", "{", "switch", "(", "$", "elem", "[", "'name'", "]", ")", "{", "case", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}param-filter'", ":", "$", "result", "[", "'param-filters'", "]", "[", "]", "=", "$", "elem", "[", "'value'", "]", ";", "break", ";", "case", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}is-not-defined'", ":", "$", "result", "[", "'is-not-defined'", "]", "=", "true", ";", "break", ";", "case", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}time-range'", ":", "$", "result", "[", "'time-range'", "]", "=", "[", "'start'", "=>", "isset", "(", "$", "elem", "[", "'attributes'", "]", "[", "'start'", "]", ")", "?", "DateTimeParser", "::", "parseDateTime", "(", "$", "elem", "[", "'attributes'", "]", "[", "'start'", "]", ")", ":", "null", ",", "'end'", "=>", "isset", "(", "$", "elem", "[", "'attributes'", "]", "[", "'end'", "]", ")", "?", "DateTimeParser", "::", "parseDateTime", "(", "$", "elem", "[", "'attributes'", "]", "[", "'end'", "]", ")", ":", "null", ",", "]", ";", "if", "(", "$", "result", "[", "'time-range'", "]", "[", "'start'", "]", "&&", "$", "result", "[", "'time-range'", "]", "[", "'end'", "]", "&&", "$", "result", "[", "'time-range'", "]", "[", "'end'", "]", "<=", "$", "result", "[", "'time-range'", "]", "[", "'start'", "]", ")", "{", "throw", "new", "BadRequest", "(", "'The end-date must be larger than the start-date'", ")", ";", "}", "break", ";", "case", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}text-match'", ":", "$", "result", "[", "'text-match'", "]", "=", "[", "'negate-condition'", "=>", "isset", "(", "$", "elem", "[", "'attributes'", "]", "[", "'negate-condition'", "]", ")", "&&", "'yes'", "===", "$", "elem", "[", "'attributes'", "]", "[", "'negate-condition'", "]", ",", "'collation'", "=>", "isset", "(", "$", "elem", "[", "'attributes'", "]", "[", "'collation'", "]", ")", "?", "$", "elem", "[", "'attributes'", "]", "[", "'collation'", "]", ":", "'i;ascii-casemap'", ",", "'value'", "=>", "$", "elem", "[", "'value'", "]", ",", "]", ";", "break", ";", "}", "}", "}", "return", "$", "result", ";", "}" ]
The deserialize method is called during xml parsing. This method is called statically, this is because in theory this method may be used as a type of constructor, or factory method. Often you want to return an instance of the current class, but you are free to return other data as well. You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop. If you just want to skip parsing for this element altogether, you can just call $reader->next(); $reader->parseInnerTree() will parse the entire sub-tree, and advance to the next element. @param Reader $reader @return mixed
[ "The", "deserialize", "method", "is", "called", "during", "xml", "parsing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Xml/Filter/PropFilter.php#L51-L96
sabre-io/dav
lib/CalDAV/ICSExportPlugin.php
ICSExportPlugin.httpGet
public function httpGet(RequestInterface $request, ResponseInterface $response) { $queryParams = $request->getQueryParameters(); if (!array_key_exists('export', $queryParams)) { return; } $path = $request->getPath(); $node = $this->server->getProperties($path, [ '{DAV:}resourcetype', '{DAV:}displayname', '{http://sabredav.org/ns}sync-token', '{DAV:}sync-token', '{http://apple.com/ns/ical/}calendar-color', ]); if (!isset($node['{DAV:}resourcetype']) || !$node['{DAV:}resourcetype']->is('{'.Plugin::NS_CALDAV.'}calendar')) { return; } // Marking the transactionType, for logging purposes. $this->server->transactionType = 'get-calendar-export'; $properties = $node; $start = null; $end = null; $expand = false; $componentType = false; if (isset($queryParams['start'])) { if (!ctype_digit($queryParams['start'])) { throw new BadRequest('The start= parameter must contain a unix timestamp'); } $start = DateTime::createFromFormat('U', $queryParams['start']); } if (isset($queryParams['end'])) { if (!ctype_digit($queryParams['end'])) { throw new BadRequest('The end= parameter must contain a unix timestamp'); } $end = DateTime::createFromFormat('U', $queryParams['end']); } if (isset($queryParams['expand']) && (bool) $queryParams['expand']) { if (!$start || !$end) { throw new BadRequest('If you\'d like to expand recurrences, you must specify both a start= and end= parameter.'); } $expand = true; $componentType = 'VEVENT'; } if (isset($queryParams['componentType'])) { if (!in_array($queryParams['componentType'], ['VEVENT', 'VTODO', 'VJOURNAL'])) { throw new BadRequest('You are not allowed to search for components of type: '.$queryParams['componentType'].' here'); } $componentType = $queryParams['componentType']; } $format = \Sabre\HTTP\negotiateContentType( $request->getHeader('Accept'), [ 'text/calendar', 'application/calendar+json', ] ); if (isset($queryParams['accept'])) { if ('application/calendar+json' === $queryParams['accept'] || 'jcal' === $queryParams['accept']) { $format = 'application/calendar+json'; } } if (!$format) { $format = 'text/calendar'; } $this->generateResponse($path, $start, $end, $expand, $componentType, $format, $properties, $response); // Returning false to break the event chain return false; }
php
public function httpGet(RequestInterface $request, ResponseInterface $response) { $queryParams = $request->getQueryParameters(); if (!array_key_exists('export', $queryParams)) { return; } $path = $request->getPath(); $node = $this->server->getProperties($path, [ '{DAV:}resourcetype', '{DAV:}displayname', '{http: '{DAV:}sync-token', '{http: ]); if (!isset($node['{DAV:}resourcetype']) || !$node['{DAV:}resourcetype']->is('{'.Plugin::NS_CALDAV.'}calendar')) { return; } $this->server->transactionType = 'get-calendar-export'; $properties = $node; $start = null; $end = null; $expand = false; $componentType = false; if (isset($queryParams['start'])) { if (!ctype_digit($queryParams['start'])) { throw new BadRequest('The start= parameter must contain a unix timestamp'); } $start = DateTime::createFromFormat('U', $queryParams['start']); } if (isset($queryParams['end'])) { if (!ctype_digit($queryParams['end'])) { throw new BadRequest('The end= parameter must contain a unix timestamp'); } $end = DateTime::createFromFormat('U', $queryParams['end']); } if (isset($queryParams['expand']) && (bool) $queryParams['expand']) { if (!$start || !$end) { throw new BadRequest('If you\'d like to expand recurrences, you must specify both a start= and end= parameter.'); } $expand = true; $componentType = 'VEVENT'; } if (isset($queryParams['componentType'])) { if (!in_array($queryParams['componentType'], ['VEVENT', 'VTODO', 'VJOURNAL'])) { throw new BadRequest('You are not allowed to search for components of type: '.$queryParams['componentType'].' here'); } $componentType = $queryParams['componentType']; } $format = \Sabre\HTTP\negotiateContentType( $request->getHeader('Accept'), [ 'text/calendar', 'application/calendar+json', ] ); if (isset($queryParams['accept'])) { if ('application/calendar+json' === $queryParams['accept'] || 'jcal' === $queryParams['accept']) { $format = 'application/calendar+json'; } } if (!$format) { $format = 'text/calendar'; } $this->generateResponse($path, $start, $end, $expand, $componentType, $format, $properties, $response); return false; }
[ "public", "function", "httpGet", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "queryParams", "=", "$", "request", "->", "getQueryParameters", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "'export'", ",", "$", "queryParams", ")", ")", "{", "return", ";", "}", "$", "path", "=", "$", "request", "->", "getPath", "(", ")", ";", "$", "node", "=", "$", "this", "->", "server", "->", "getProperties", "(", "$", "path", ",", "[", "'{DAV:}resourcetype'", ",", "'{DAV:}displayname'", ",", "'{http://sabredav.org/ns}sync-token'", ",", "'{DAV:}sync-token'", ",", "'{http://apple.com/ns/ical/}calendar-color'", ",", "]", ")", ";", "if", "(", "!", "isset", "(", "$", "node", "[", "'{DAV:}resourcetype'", "]", ")", "||", "!", "$", "node", "[", "'{DAV:}resourcetype'", "]", "->", "is", "(", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}calendar'", ")", ")", "{", "return", ";", "}", "// Marking the transactionType, for logging purposes.", "$", "this", "->", "server", "->", "transactionType", "=", "'get-calendar-export'", ";", "$", "properties", "=", "$", "node", ";", "$", "start", "=", "null", ";", "$", "end", "=", "null", ";", "$", "expand", "=", "false", ";", "$", "componentType", "=", "false", ";", "if", "(", "isset", "(", "$", "queryParams", "[", "'start'", "]", ")", ")", "{", "if", "(", "!", "ctype_digit", "(", "$", "queryParams", "[", "'start'", "]", ")", ")", "{", "throw", "new", "BadRequest", "(", "'The start= parameter must contain a unix timestamp'", ")", ";", "}", "$", "start", "=", "DateTime", "::", "createFromFormat", "(", "'U'", ",", "$", "queryParams", "[", "'start'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "queryParams", "[", "'end'", "]", ")", ")", "{", "if", "(", "!", "ctype_digit", "(", "$", "queryParams", "[", "'end'", "]", ")", ")", "{", "throw", "new", "BadRequest", "(", "'The end= parameter must contain a unix timestamp'", ")", ";", "}", "$", "end", "=", "DateTime", "::", "createFromFormat", "(", "'U'", ",", "$", "queryParams", "[", "'end'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "queryParams", "[", "'expand'", "]", ")", "&&", "(", "bool", ")", "$", "queryParams", "[", "'expand'", "]", ")", "{", "if", "(", "!", "$", "start", "||", "!", "$", "end", ")", "{", "throw", "new", "BadRequest", "(", "'If you\\'d like to expand recurrences, you must specify both a start= and end= parameter.'", ")", ";", "}", "$", "expand", "=", "true", ";", "$", "componentType", "=", "'VEVENT'", ";", "}", "if", "(", "isset", "(", "$", "queryParams", "[", "'componentType'", "]", ")", ")", "{", "if", "(", "!", "in_array", "(", "$", "queryParams", "[", "'componentType'", "]", ",", "[", "'VEVENT'", ",", "'VTODO'", ",", "'VJOURNAL'", "]", ")", ")", "{", "throw", "new", "BadRequest", "(", "'You are not allowed to search for components of type: '", ".", "$", "queryParams", "[", "'componentType'", "]", ".", "' here'", ")", ";", "}", "$", "componentType", "=", "$", "queryParams", "[", "'componentType'", "]", ";", "}", "$", "format", "=", "\\", "Sabre", "\\", "HTTP", "\\", "negotiateContentType", "(", "$", "request", "->", "getHeader", "(", "'Accept'", ")", ",", "[", "'text/calendar'", ",", "'application/calendar+json'", ",", "]", ")", ";", "if", "(", "isset", "(", "$", "queryParams", "[", "'accept'", "]", ")", ")", "{", "if", "(", "'application/calendar+json'", "===", "$", "queryParams", "[", "'accept'", "]", "||", "'jcal'", "===", "$", "queryParams", "[", "'accept'", "]", ")", "{", "$", "format", "=", "'application/calendar+json'", ";", "}", "}", "if", "(", "!", "$", "format", ")", "{", "$", "format", "=", "'text/calendar'", ";", "}", "$", "this", "->", "generateResponse", "(", "$", "path", ",", "$", "start", ",", "$", "end", ",", "$", "expand", ",", "$", "componentType", ",", "$", "format", ",", "$", "properties", ",", "$", "response", ")", ";", "// Returning false to break the event chain", "return", "false", ";", "}" ]
Intercepts GET requests on calendar urls ending with ?export. @param RequestInterface $request @param ResponseInterface $response @throws BadRequest @throws DAV\Exception\NotFound @throws VObject\InvalidDataException @return bool
[ "Intercepts", "GET", "requests", "on", "calendar", "urls", "ending", "with", "?export", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/ICSExportPlugin.php#L86-L162
sabre-io/dav
lib/CalDAV/ICSExportPlugin.php
ICSExportPlugin.generateResponse
protected function generateResponse($path, $start, $end, $expand, $componentType, $format, $properties, ResponseInterface $response) { $calDataProp = '{'.Plugin::NS_CALDAV.'}calendar-data'; $calendarNode = $this->server->tree->getNodeForPath($path); $blobs = []; if ($start || $end || $componentType) { // If there was a start or end filter, we need to enlist // calendarQuery for speed. $queryResult = $calendarNode->calendarQuery([ 'name' => 'VCALENDAR', 'comp-filters' => [ [ 'name' => $componentType, 'comp-filters' => [], 'prop-filters' => [], 'is-not-defined' => false, 'time-range' => [ 'start' => $start, 'end' => $end, ], ], ], 'prop-filters' => [], 'is-not-defined' => false, 'time-range' => null, ]); // queryResult is just a list of base urls. We need to prefix the // calendar path. $queryResult = array_map( function ($item) use ($path) { return $path.'/'.$item; }, $queryResult ); $nodes = $this->server->getPropertiesForMultiplePaths($queryResult, [$calDataProp]); unset($queryResult); } else { $nodes = $this->server->getPropertiesForPath($path, [$calDataProp], 1); } // Flattening the arrays foreach ($nodes as $node) { if (isset($node[200][$calDataProp])) { $blobs[$node['href']] = $node[200][$calDataProp]; } } unset($nodes); $mergedCalendar = $this->mergeObjects( $properties, $blobs ); if ($expand) { $calendarTimeZone = null; // We're expanding, and for that we need to figure out the // calendar's timezone. $tzProp = '{'.Plugin::NS_CALDAV.'}calendar-timezone'; $tzResult = $this->server->getProperties($path, [$tzProp]); if (isset($tzResult[$tzProp])) { // This property contains a VCALENDAR with a single // VTIMEZONE. $vtimezoneObj = VObject\Reader::read($tzResult[$tzProp]); $calendarTimeZone = $vtimezoneObj->VTIMEZONE->getTimeZone(); // Destroy circular references to PHP will GC the object. $vtimezoneObj->destroy(); unset($vtimezoneObj); } else { // Defaulting to UTC. $calendarTimeZone = new DateTimeZone('UTC'); } $mergedCalendar = $mergedCalendar->expand($start, $end, $calendarTimeZone); } $filenameExtension = '.ics'; switch ($format) { case 'text/calendar': $mergedCalendar = $mergedCalendar->serialize(); $filenameExtension = '.ics'; break; case 'application/calendar+json': $mergedCalendar = json_encode($mergedCalendar->jsonSerialize()); $filenameExtension = '.json'; break; } $filename = preg_replace( '/[^a-zA-Z0-9-_ ]/um', '', $calendarNode->getName() ); $filename .= '-'.date('Y-m-d').$filenameExtension; $response->setHeader('Content-Disposition', 'attachment; filename="'.$filename.'"'); $response->setHeader('Content-Type', $format); $response->setStatus(200); $response->setBody($mergedCalendar); }
php
protected function generateResponse($path, $start, $end, $expand, $componentType, $format, $properties, ResponseInterface $response) { $calDataProp = '{'.Plugin::NS_CALDAV.'}calendar-data'; $calendarNode = $this->server->tree->getNodeForPath($path); $blobs = []; if ($start || $end || $componentType) { $queryResult = $calendarNode->calendarQuery([ 'name' => 'VCALENDAR', 'comp-filters' => [ [ 'name' => $componentType, 'comp-filters' => [], 'prop-filters' => [], 'is-not-defined' => false, 'time-range' => [ 'start' => $start, 'end' => $end, ], ], ], 'prop-filters' => [], 'is-not-defined' => false, 'time-range' => null, ]); $queryResult = array_map( function ($item) use ($path) { return $path.'/'.$item; }, $queryResult ); $nodes = $this->server->getPropertiesForMultiplePaths($queryResult, [$calDataProp]); unset($queryResult); } else { $nodes = $this->server->getPropertiesForPath($path, [$calDataProp], 1); } foreach ($nodes as $node) { if (isset($node[200][$calDataProp])) { $blobs[$node['href']] = $node[200][$calDataProp]; } } unset($nodes); $mergedCalendar = $this->mergeObjects( $properties, $blobs ); if ($expand) { $calendarTimeZone = null; $tzProp = '{'.Plugin::NS_CALDAV.'}calendar-timezone'; $tzResult = $this->server->getProperties($path, [$tzProp]); if (isset($tzResult[$tzProp])) { $vtimezoneObj = VObject\Reader::read($tzResult[$tzProp]); $calendarTimeZone = $vtimezoneObj->VTIMEZONE->getTimeZone(); $vtimezoneObj->destroy(); unset($vtimezoneObj); } else { $calendarTimeZone = new DateTimeZone('UTC'); } $mergedCalendar = $mergedCalendar->expand($start, $end, $calendarTimeZone); } $filenameExtension = '.ics'; switch ($format) { case 'text/calendar': $mergedCalendar = $mergedCalendar->serialize(); $filenameExtension = '.ics'; break; case 'application/calendar+json': $mergedCalendar = json_encode($mergedCalendar->jsonSerialize()); $filenameExtension = '.json'; break; } $filename = preg_replace( '/[^a-zA-Z0-9-_ ]/um', '', $calendarNode->getName() ); $filename .= '-'.date('Y-m-d').$filenameExtension; $response->setHeader('Content-Disposition', 'attachment; filename="'.$filename.'"'); $response->setHeader('Content-Type', $format); $response->setStatus(200); $response->setBody($mergedCalendar); }
[ "protected", "function", "generateResponse", "(", "$", "path", ",", "$", "start", ",", "$", "end", ",", "$", "expand", ",", "$", "componentType", ",", "$", "format", ",", "$", "properties", ",", "ResponseInterface", "$", "response", ")", "{", "$", "calDataProp", "=", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}calendar-data'", ";", "$", "calendarNode", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "path", ")", ";", "$", "blobs", "=", "[", "]", ";", "if", "(", "$", "start", "||", "$", "end", "||", "$", "componentType", ")", "{", "// If there was a start or end filter, we need to enlist", "// calendarQuery for speed.", "$", "queryResult", "=", "$", "calendarNode", "->", "calendarQuery", "(", "[", "'name'", "=>", "'VCALENDAR'", ",", "'comp-filters'", "=>", "[", "[", "'name'", "=>", "$", "componentType", ",", "'comp-filters'", "=>", "[", "]", ",", "'prop-filters'", "=>", "[", "]", ",", "'is-not-defined'", "=>", "false", ",", "'time-range'", "=>", "[", "'start'", "=>", "$", "start", ",", "'end'", "=>", "$", "end", ",", "]", ",", "]", ",", "]", ",", "'prop-filters'", "=>", "[", "]", ",", "'is-not-defined'", "=>", "false", ",", "'time-range'", "=>", "null", ",", "]", ")", ";", "// queryResult is just a list of base urls. We need to prefix the", "// calendar path.", "$", "queryResult", "=", "array_map", "(", "function", "(", "$", "item", ")", "use", "(", "$", "path", ")", "{", "return", "$", "path", ".", "'/'", ".", "$", "item", ";", "}", ",", "$", "queryResult", ")", ";", "$", "nodes", "=", "$", "this", "->", "server", "->", "getPropertiesForMultiplePaths", "(", "$", "queryResult", ",", "[", "$", "calDataProp", "]", ")", ";", "unset", "(", "$", "queryResult", ")", ";", "}", "else", "{", "$", "nodes", "=", "$", "this", "->", "server", "->", "getPropertiesForPath", "(", "$", "path", ",", "[", "$", "calDataProp", "]", ",", "1", ")", ";", "}", "// Flattening the arrays", "foreach", "(", "$", "nodes", "as", "$", "node", ")", "{", "if", "(", "isset", "(", "$", "node", "[", "200", "]", "[", "$", "calDataProp", "]", ")", ")", "{", "$", "blobs", "[", "$", "node", "[", "'href'", "]", "]", "=", "$", "node", "[", "200", "]", "[", "$", "calDataProp", "]", ";", "}", "}", "unset", "(", "$", "nodes", ")", ";", "$", "mergedCalendar", "=", "$", "this", "->", "mergeObjects", "(", "$", "properties", ",", "$", "blobs", ")", ";", "if", "(", "$", "expand", ")", "{", "$", "calendarTimeZone", "=", "null", ";", "// We're expanding, and for that we need to figure out the", "// calendar's timezone.", "$", "tzProp", "=", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}calendar-timezone'", ";", "$", "tzResult", "=", "$", "this", "->", "server", "->", "getProperties", "(", "$", "path", ",", "[", "$", "tzProp", "]", ")", ";", "if", "(", "isset", "(", "$", "tzResult", "[", "$", "tzProp", "]", ")", ")", "{", "// This property contains a VCALENDAR with a single", "// VTIMEZONE.", "$", "vtimezoneObj", "=", "VObject", "\\", "Reader", "::", "read", "(", "$", "tzResult", "[", "$", "tzProp", "]", ")", ";", "$", "calendarTimeZone", "=", "$", "vtimezoneObj", "->", "VTIMEZONE", "->", "getTimeZone", "(", ")", ";", "// Destroy circular references to PHP will GC the object.", "$", "vtimezoneObj", "->", "destroy", "(", ")", ";", "unset", "(", "$", "vtimezoneObj", ")", ";", "}", "else", "{", "// Defaulting to UTC.", "$", "calendarTimeZone", "=", "new", "DateTimeZone", "(", "'UTC'", ")", ";", "}", "$", "mergedCalendar", "=", "$", "mergedCalendar", "->", "expand", "(", "$", "start", ",", "$", "end", ",", "$", "calendarTimeZone", ")", ";", "}", "$", "filenameExtension", "=", "'.ics'", ";", "switch", "(", "$", "format", ")", "{", "case", "'text/calendar'", ":", "$", "mergedCalendar", "=", "$", "mergedCalendar", "->", "serialize", "(", ")", ";", "$", "filenameExtension", "=", "'.ics'", ";", "break", ";", "case", "'application/calendar+json'", ":", "$", "mergedCalendar", "=", "json_encode", "(", "$", "mergedCalendar", "->", "jsonSerialize", "(", ")", ")", ";", "$", "filenameExtension", "=", "'.json'", ";", "break", ";", "}", "$", "filename", "=", "preg_replace", "(", "'/[^a-zA-Z0-9-_ ]/um'", ",", "''", ",", "$", "calendarNode", "->", "getName", "(", ")", ")", ";", "$", "filename", ".=", "'-'", ".", "date", "(", "'Y-m-d'", ")", ".", "$", "filenameExtension", ";", "$", "response", "->", "setHeader", "(", "'Content-Disposition'", ",", "'attachment; filename=\"'", ".", "$", "filename", ".", "'\"'", ")", ";", "$", "response", "->", "setHeader", "(", "'Content-Type'", ",", "$", "format", ")", ";", "$", "response", "->", "setStatus", "(", "200", ")", ";", "$", "response", "->", "setBody", "(", "$", "mergedCalendar", ")", ";", "}" ]
This method is responsible for generating the actual, full response. @param string $path @param DateTime|null $start @param DateTime|null $end @param bool $expand @param string $componentType @param string $format @param array $properties @param ResponseInterface $response @throws DAV\Exception\NotFound @throws VObject\InvalidDataException
[ "This", "method", "is", "responsible", "for", "generating", "the", "actual", "full", "response", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/ICSExportPlugin.php#L179-L281
sabre-io/dav
lib/CalDAV/ICSExportPlugin.php
ICSExportPlugin.mergeObjects
public function mergeObjects(array $properties, array $inputObjects) { $calendar = new VObject\Component\VCalendar(); $calendar->VERSION = '2.0'; if (DAV\Server::$exposeVersion) { $calendar->PRODID = '-//SabreDAV//SabreDAV '.DAV\Version::VERSION.'//EN'; } else { $calendar->PRODID = '-//SabreDAV//SabreDAV//EN'; } if (isset($properties['{DAV:}displayname'])) { $calendar->{'X-WR-CALNAME'} = $properties['{DAV:}displayname']; } if (isset($properties['{http://apple.com/ns/ical/}calendar-color'])) { $calendar->{'X-APPLE-CALENDAR-COLOR'} = $properties['{http://apple.com/ns/ical/}calendar-color']; } $collectedTimezones = []; $timezones = []; $objects = []; foreach ($inputObjects as $href => $inputObject) { $nodeComp = VObject\Reader::read($inputObject); foreach ($nodeComp->children() as $child) { switch ($child->name) { case 'VEVENT': case 'VTODO': case 'VJOURNAL': $objects[] = clone $child; break; // VTIMEZONE is special, because we need to filter out the duplicates case 'VTIMEZONE': // Naively just checking tzid. if (in_array((string) $child->TZID, $collectedTimezones)) { break; } $timezones[] = clone $child; $collectedTimezones[] = $child->TZID; break; } } // Destroy circular references to PHP will GC the object. $nodeComp->destroy(); unset($nodeComp); } foreach ($timezones as $tz) { $calendar->add($tz); } foreach ($objects as $obj) { $calendar->add($obj); } return $calendar; }
php
public function mergeObjects(array $properties, array $inputObjects) { $calendar = new VObject\Component\VCalendar(); $calendar->VERSION = '2.0'; if (DAV\Server::$exposeVersion) { $calendar->PRODID = '- } else { $calendar->PRODID = '- } if (isset($properties['{DAV:}displayname'])) { $calendar->{'X-WR-CALNAME'} = $properties['{DAV:}displayname']; } if (isset($properties['{http: $calendar->{'X-APPLE-CALENDAR-COLOR'} = $properties['{http: } $collectedTimezones = []; $timezones = []; $objects = []; foreach ($inputObjects as $href => $inputObject) { $nodeComp = VObject\Reader::read($inputObject); foreach ($nodeComp->children() as $child) { switch ($child->name) { case 'VEVENT': case 'VTODO': case 'VJOURNAL': $objects[] = clone $child; break; case 'VTIMEZONE': if (in_array((string) $child->TZID, $collectedTimezones)) { break; } $timezones[] = clone $child; $collectedTimezones[] = $child->TZID; break; } } $nodeComp->destroy(); unset($nodeComp); } foreach ($timezones as $tz) { $calendar->add($tz); } foreach ($objects as $obj) { $calendar->add($obj); } return $calendar; }
[ "public", "function", "mergeObjects", "(", "array", "$", "properties", ",", "array", "$", "inputObjects", ")", "{", "$", "calendar", "=", "new", "VObject", "\\", "Component", "\\", "VCalendar", "(", ")", ";", "$", "calendar", "->", "VERSION", "=", "'2.0'", ";", "if", "(", "DAV", "\\", "Server", "::", "$", "exposeVersion", ")", "{", "$", "calendar", "->", "PRODID", "=", "'-//SabreDAV//SabreDAV '", ".", "DAV", "\\", "Version", "::", "VERSION", ".", "'//EN'", ";", "}", "else", "{", "$", "calendar", "->", "PRODID", "=", "'-//SabreDAV//SabreDAV//EN'", ";", "}", "if", "(", "isset", "(", "$", "properties", "[", "'{DAV:}displayname'", "]", ")", ")", "{", "$", "calendar", "->", "{", "'X-WR-CALNAME'", "}", "=", "$", "properties", "[", "'{DAV:}displayname'", "]", ";", "}", "if", "(", "isset", "(", "$", "properties", "[", "'{http://apple.com/ns/ical/}calendar-color'", "]", ")", ")", "{", "$", "calendar", "->", "{", "'X-APPLE-CALENDAR-COLOR'", "}", "=", "$", "properties", "[", "'{http://apple.com/ns/ical/}calendar-color'", "]", ";", "}", "$", "collectedTimezones", "=", "[", "]", ";", "$", "timezones", "=", "[", "]", ";", "$", "objects", "=", "[", "]", ";", "foreach", "(", "$", "inputObjects", "as", "$", "href", "=>", "$", "inputObject", ")", "{", "$", "nodeComp", "=", "VObject", "\\", "Reader", "::", "read", "(", "$", "inputObject", ")", ";", "foreach", "(", "$", "nodeComp", "->", "children", "(", ")", "as", "$", "child", ")", "{", "switch", "(", "$", "child", "->", "name", ")", "{", "case", "'VEVENT'", ":", "case", "'VTODO'", ":", "case", "'VJOURNAL'", ":", "$", "objects", "[", "]", "=", "clone", "$", "child", ";", "break", ";", "// VTIMEZONE is special, because we need to filter out the duplicates", "case", "'VTIMEZONE'", ":", "// Naively just checking tzid.", "if", "(", "in_array", "(", "(", "string", ")", "$", "child", "->", "TZID", ",", "$", "collectedTimezones", ")", ")", "{", "break", ";", "}", "$", "timezones", "[", "]", "=", "clone", "$", "child", ";", "$", "collectedTimezones", "[", "]", "=", "$", "child", "->", "TZID", ";", "break", ";", "}", "}", "// Destroy circular references to PHP will GC the object.", "$", "nodeComp", "->", "destroy", "(", ")", ";", "unset", "(", "$", "nodeComp", ")", ";", "}", "foreach", "(", "$", "timezones", "as", "$", "tz", ")", "{", "$", "calendar", "->", "add", "(", "$", "tz", ")", ";", "}", "foreach", "(", "$", "objects", "as", "$", "obj", ")", "{", "$", "calendar", "->", "add", "(", "$", "obj", ")", ";", "}", "return", "$", "calendar", ";", "}" ]
Merges all calendar objects, and builds one big iCalendar blob. @param array $properties Some CalDAV properties @param array $inputObjects @return VObject\Component\VCalendar
[ "Merges", "all", "calendar", "objects", "and", "builds", "one", "big", "iCalendar", "blob", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/ICSExportPlugin.php#L291-L348
sabre-io/dav
lib/DAV/Exception/TooManyMatches.php
TooManyMatches.serialize
public function serialize(DAV\Server $server, \DOMElement $errorNode) { $error = $errorNode->ownerDocument->createElementNS('DAV:', 'd:number-of-matches-within-limits'); $errorNode->appendChild($error); }
php
public function serialize(DAV\Server $server, \DOMElement $errorNode) { $error = $errorNode->ownerDocument->createElementNS('DAV:', 'd:number-of-matches-within-limits'); $errorNode->appendChild($error); }
[ "public", "function", "serialize", "(", "DAV", "\\", "Server", "$", "server", ",", "\\", "DOMElement", "$", "errorNode", ")", "{", "$", "error", "=", "$", "errorNode", "->", "ownerDocument", "->", "createElementNS", "(", "'DAV:'", ",", "'d:number-of-matches-within-limits'", ")", ";", "$", "errorNode", "->", "appendChild", "(", "$", "error", ")", ";", "}" ]
This method allows the exception to include additional information into the WebDAV error response. @param DAV\Server $server @param \DOMElement $errorNode
[ "This", "method", "allows", "the", "exception", "to", "include", "additional", "information", "into", "the", "WebDAV", "error", "response", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Exception/TooManyMatches.php#L32-L36
sabre-io/dav
lib/DAV/Tree.php
Tree.getNodeForPath
public function getNodeForPath($path) { $path = trim($path, '/'); if (isset($this->cache[$path])) { return $this->cache[$path]; } // Is it the root node? if (!strlen($path)) { return $this->rootNode; } // Attempting to fetch its parent list($parentName, $baseName) = Uri\split($path); // If there was no parent, we must simply ask it from the root node. if ('' === $parentName) { $node = $this->rootNode->getChild($baseName); } else { // Otherwise, we recursively grab the parent and ask him/her. $parent = $this->getNodeForPath($parentName); if (!($parent instanceof ICollection)) { throw new Exception\NotFound('Could not find node at path: '.$path); } $node = $parent->getChild($baseName); } $this->cache[$path] = $node; return $node; }
php
public function getNodeForPath($path) { $path = trim($path, '/'); if (isset($this->cache[$path])) { return $this->cache[$path]; } if (!strlen($path)) { return $this->rootNode; } list($parentName, $baseName) = Uri\split($path); if ('' === $parentName) { $node = $this->rootNode->getChild($baseName); } else { $parent = $this->getNodeForPath($parentName); if (!($parent instanceof ICollection)) { throw new Exception\NotFound('Could not find node at path: '.$path); } $node = $parent->getChild($baseName); } $this->cache[$path] = $node; return $node; }
[ "public", "function", "getNodeForPath", "(", "$", "path", ")", "{", "$", "path", "=", "trim", "(", "$", "path", ",", "'/'", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "cache", "[", "$", "path", "]", ")", ")", "{", "return", "$", "this", "->", "cache", "[", "$", "path", "]", ";", "}", "// Is it the root node?", "if", "(", "!", "strlen", "(", "$", "path", ")", ")", "{", "return", "$", "this", "->", "rootNode", ";", "}", "// Attempting to fetch its parent", "list", "(", "$", "parentName", ",", "$", "baseName", ")", "=", "Uri", "\\", "split", "(", "$", "path", ")", ";", "// If there was no parent, we must simply ask it from the root node.", "if", "(", "''", "===", "$", "parentName", ")", "{", "$", "node", "=", "$", "this", "->", "rootNode", "->", "getChild", "(", "$", "baseName", ")", ";", "}", "else", "{", "// Otherwise, we recursively grab the parent and ask him/her.", "$", "parent", "=", "$", "this", "->", "getNodeForPath", "(", "$", "parentName", ")", ";", "if", "(", "!", "(", "$", "parent", "instanceof", "ICollection", ")", ")", "{", "throw", "new", "Exception", "\\", "NotFound", "(", "'Could not find node at path: '", ".", "$", "path", ")", ";", "}", "$", "node", "=", "$", "parent", "->", "getChild", "(", "$", "baseName", ")", ";", "}", "$", "this", "->", "cache", "[", "$", "path", "]", "=", "$", "node", ";", "return", "$", "node", ";", "}" ]
Returns the INode object for the requested path. @param string $path @return INode
[ "Returns", "the", "INode", "object", "for", "the", "requested", "path", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Tree.php#L55-L86
sabre-io/dav
lib/DAV/Tree.php
Tree.nodeExists
public function nodeExists($path) { try { // The root always exists if ('' === $path) { return true; } list($parent, $base) = Uri\split($path); $parentNode = $this->getNodeForPath($parent); if (!$parentNode instanceof ICollection) { return false; } return $parentNode->childExists($base); } catch (Exception\NotFound $e) { return false; } }
php
public function nodeExists($path) { try { if ('' === $path) { return true; } list($parent, $base) = Uri\split($path); $parentNode = $this->getNodeForPath($parent); if (!$parentNode instanceof ICollection) { return false; } return $parentNode->childExists($base); } catch (Exception\NotFound $e) { return false; } }
[ "public", "function", "nodeExists", "(", "$", "path", ")", "{", "try", "{", "// The root always exists", "if", "(", "''", "===", "$", "path", ")", "{", "return", "true", ";", "}", "list", "(", "$", "parent", ",", "$", "base", ")", "=", "Uri", "\\", "split", "(", "$", "path", ")", ";", "$", "parentNode", "=", "$", "this", "->", "getNodeForPath", "(", "$", "parent", ")", ";", "if", "(", "!", "$", "parentNode", "instanceof", "ICollection", ")", "{", "return", "false", ";", "}", "return", "$", "parentNode", "->", "childExists", "(", "$", "base", ")", ";", "}", "catch", "(", "Exception", "\\", "NotFound", "$", "e", ")", "{", "return", "false", ";", "}", "}" ]
This function allows you to check if a node exists. Implementors of this class should override this method to make it cheaper. @param string $path @return bool
[ "This", "function", "allows", "you", "to", "check", "if", "a", "node", "exists", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Tree.php#L98-L117
sabre-io/dav
lib/DAV/Tree.php
Tree.copy
public function copy($sourcePath, $destinationPath) { $sourceNode = $this->getNodeForPath($sourcePath); // grab the dirname and basename components list($destinationDir, $destinationName) = Uri\split($destinationPath); $destinationParent = $this->getNodeForPath($destinationDir); // Check if the target can handle the copy itself. If not, we do it ourselves. if (!$destinationParent instanceof ICopyTarget || !$destinationParent->copyInto($destinationName, $sourcePath, $sourceNode)) { $this->copyNode($sourceNode, $destinationParent, $destinationName); } $this->markDirty($destinationDir); }
php
public function copy($sourcePath, $destinationPath) { $sourceNode = $this->getNodeForPath($sourcePath); list($destinationDir, $destinationName) = Uri\split($destinationPath); $destinationParent = $this->getNodeForPath($destinationDir); if (!$destinationParent instanceof ICopyTarget || !$destinationParent->copyInto($destinationName, $sourcePath, $sourceNode)) { $this->copyNode($sourceNode, $destinationParent, $destinationName); } $this->markDirty($destinationDir); }
[ "public", "function", "copy", "(", "$", "sourcePath", ",", "$", "destinationPath", ")", "{", "$", "sourceNode", "=", "$", "this", "->", "getNodeForPath", "(", "$", "sourcePath", ")", ";", "// grab the dirname and basename components", "list", "(", "$", "destinationDir", ",", "$", "destinationName", ")", "=", "Uri", "\\", "split", "(", "$", "destinationPath", ")", ";", "$", "destinationParent", "=", "$", "this", "->", "getNodeForPath", "(", "$", "destinationDir", ")", ";", "// Check if the target can handle the copy itself. If not, we do it ourselves.", "if", "(", "!", "$", "destinationParent", "instanceof", "ICopyTarget", "||", "!", "$", "destinationParent", "->", "copyInto", "(", "$", "destinationName", ",", "$", "sourcePath", ",", "$", "sourceNode", ")", ")", "{", "$", "this", "->", "copyNode", "(", "$", "sourceNode", ",", "$", "destinationParent", ",", "$", "destinationName", ")", ";", "}", "$", "this", "->", "markDirty", "(", "$", "destinationDir", ")", ";", "}" ]
Copies a file from path to another. @param string $sourcePath The source location @param string $destinationPath The full destination path
[ "Copies", "a", "file", "from", "path", "to", "another", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Tree.php#L125-L139
sabre-io/dav
lib/DAV/Tree.php
Tree.move
public function move($sourcePath, $destinationPath) { list($sourceDir) = Uri\split($sourcePath); list($destinationDir, $destinationName) = Uri\split($destinationPath); if ($sourceDir === $destinationDir) { // If this is a 'local' rename, it means we can just trigger a rename. $sourceNode = $this->getNodeForPath($sourcePath); $sourceNode->setName($destinationName); } else { $newParentNode = $this->getNodeForPath($destinationDir); $moveSuccess = false; if ($newParentNode instanceof IMoveTarget) { // The target collection may be able to handle the move $sourceNode = $this->getNodeForPath($sourcePath); $moveSuccess = $newParentNode->moveInto($destinationName, $sourcePath, $sourceNode); } if (!$moveSuccess) { $this->copy($sourcePath, $destinationPath); $this->getNodeForPath($sourcePath)->delete(); } } $this->markDirty($sourceDir); $this->markDirty($destinationDir); }
php
public function move($sourcePath, $destinationPath) { list($sourceDir) = Uri\split($sourcePath); list($destinationDir, $destinationName) = Uri\split($destinationPath); if ($sourceDir === $destinationDir) { $sourceNode = $this->getNodeForPath($sourcePath); $sourceNode->setName($destinationName); } else { $newParentNode = $this->getNodeForPath($destinationDir); $moveSuccess = false; if ($newParentNode instanceof IMoveTarget) { $sourceNode = $this->getNodeForPath($sourcePath); $moveSuccess = $newParentNode->moveInto($destinationName, $sourcePath, $sourceNode); } if (!$moveSuccess) { $this->copy($sourcePath, $destinationPath); $this->getNodeForPath($sourcePath)->delete(); } } $this->markDirty($sourceDir); $this->markDirty($destinationDir); }
[ "public", "function", "move", "(", "$", "sourcePath", ",", "$", "destinationPath", ")", "{", "list", "(", "$", "sourceDir", ")", "=", "Uri", "\\", "split", "(", "$", "sourcePath", ")", ";", "list", "(", "$", "destinationDir", ",", "$", "destinationName", ")", "=", "Uri", "\\", "split", "(", "$", "destinationPath", ")", ";", "if", "(", "$", "sourceDir", "===", "$", "destinationDir", ")", "{", "// If this is a 'local' rename, it means we can just trigger a rename.", "$", "sourceNode", "=", "$", "this", "->", "getNodeForPath", "(", "$", "sourcePath", ")", ";", "$", "sourceNode", "->", "setName", "(", "$", "destinationName", ")", ";", "}", "else", "{", "$", "newParentNode", "=", "$", "this", "->", "getNodeForPath", "(", "$", "destinationDir", ")", ";", "$", "moveSuccess", "=", "false", ";", "if", "(", "$", "newParentNode", "instanceof", "IMoveTarget", ")", "{", "// The target collection may be able to handle the move", "$", "sourceNode", "=", "$", "this", "->", "getNodeForPath", "(", "$", "sourcePath", ")", ";", "$", "moveSuccess", "=", "$", "newParentNode", "->", "moveInto", "(", "$", "destinationName", ",", "$", "sourcePath", ",", "$", "sourceNode", ")", ";", "}", "if", "(", "!", "$", "moveSuccess", ")", "{", "$", "this", "->", "copy", "(", "$", "sourcePath", ",", "$", "destinationPath", ")", ";", "$", "this", "->", "getNodeForPath", "(", "$", "sourcePath", ")", "->", "delete", "(", ")", ";", "}", "}", "$", "this", "->", "markDirty", "(", "$", "sourceDir", ")", ";", "$", "this", "->", "markDirty", "(", "$", "destinationDir", ")", ";", "}" ]
Moves a file from one location to another. @param string $sourcePath The path to the file which should be moved @param string $destinationPath The full destination path, so not just the destination parent node @return int
[ "Moves", "a", "file", "from", "one", "location", "to", "another", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Tree.php#L149-L173
sabre-io/dav
lib/DAV/Tree.php
Tree.delete
public function delete($path) { $node = $this->getNodeForPath($path); $node->delete(); list($parent) = Uri\split($path); $this->markDirty($parent); }
php
public function delete($path) { $node = $this->getNodeForPath($path); $node->delete(); list($parent) = Uri\split($path); $this->markDirty($parent); }
[ "public", "function", "delete", "(", "$", "path", ")", "{", "$", "node", "=", "$", "this", "->", "getNodeForPath", "(", "$", "path", ")", ";", "$", "node", "->", "delete", "(", ")", ";", "list", "(", "$", "parent", ")", "=", "Uri", "\\", "split", "(", "$", "path", ")", ";", "$", "this", "->", "markDirty", "(", "$", "parent", ")", ";", "}" ]
Deletes a node from the tree. @param string $path
[ "Deletes", "a", "node", "from", "the", "tree", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Tree.php#L180-L187
sabre-io/dav
lib/DAV/Tree.php
Tree.getChildren
public function getChildren($path) { $node = $this->getNodeForPath($path); $basePath = trim($path, '/'); if ('' !== $basePath) { $basePath .= '/'; } foreach ($node->getChildren() as $child) { $this->cache[$basePath.$child->getName()] = $child; yield $child; } }
php
public function getChildren($path) { $node = $this->getNodeForPath($path); $basePath = trim($path, '/'); if ('' !== $basePath) { $basePath .= '/'; } foreach ($node->getChildren() as $child) { $this->cache[$basePath.$child->getName()] = $child; yield $child; } }
[ "public", "function", "getChildren", "(", "$", "path", ")", "{", "$", "node", "=", "$", "this", "->", "getNodeForPath", "(", "$", "path", ")", ";", "$", "basePath", "=", "trim", "(", "$", "path", ",", "'/'", ")", ";", "if", "(", "''", "!==", "$", "basePath", ")", "{", "$", "basePath", ".=", "'/'", ";", "}", "foreach", "(", "$", "node", "->", "getChildren", "(", ")", "as", "$", "child", ")", "{", "$", "this", "->", "cache", "[", "$", "basePath", ".", "$", "child", "->", "getName", "(", ")", "]", "=", "$", "child", ";", "yield", "$", "child", ";", "}", "}" ]
Returns a list of childnodes for a given path. @param string $path @return \Traversable
[ "Returns", "a", "list", "of", "childnodes", "for", "a", "given", "path", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Tree.php#L196-L208
sabre-io/dav
lib/DAV/Tree.php
Tree.markDirty
public function markDirty($path) { // We don't care enough about sub-paths // flushing the entire cache $path = trim($path, '/'); foreach ($this->cache as $nodePath => $node) { if ('' === $path || $nodePath == $path || 0 === strpos($nodePath, $path.'/')) { unset($this->cache[$nodePath]); } } }
php
public function markDirty($path) { $path = trim($path, '/'); foreach ($this->cache as $nodePath => $node) { if ('' === $path || $nodePath == $path || 0 === strpos($nodePath, $path.'/')) { unset($this->cache[$nodePath]); } } }
[ "public", "function", "markDirty", "(", "$", "path", ")", "{", "// We don't care enough about sub-paths", "// flushing the entire cache", "$", "path", "=", "trim", "(", "$", "path", ",", "'/'", ")", ";", "foreach", "(", "$", "this", "->", "cache", "as", "$", "nodePath", "=>", "$", "node", ")", "{", "if", "(", "''", "===", "$", "path", "||", "$", "nodePath", "==", "$", "path", "||", "0", "===", "strpos", "(", "$", "nodePath", ",", "$", "path", ".", "'/'", ")", ")", "{", "unset", "(", "$", "this", "->", "cache", "[", "$", "nodePath", "]", ")", ";", "}", "}", "}" ]
This method is called with every tree update. Examples of tree updates are: * node deletions * node creations * copy * move * renaming nodes If Tree classes implement a form of caching, this will allow them to make sure caches will be expired. If a path is passed, it is assumed that the entire subtree is dirty @param string $path
[ "This", "method", "is", "called", "with", "every", "tree", "update", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Tree.php#L227-L237
sabre-io/dav
lib/DAV/Tree.php
Tree.getMultipleNodes
public function getMultipleNodes($paths) { // Finding common parents $parents = []; foreach ($paths as $path) { list($parent, $node) = Uri\split($path); if (!isset($parents[$parent])) { $parents[$parent] = [$node]; } else { $parents[$parent][] = $node; } } $result = []; foreach ($parents as $parent => $children) { $parentNode = $this->getNodeForPath($parent); if ($parentNode instanceof IMultiGet) { foreach ($parentNode->getMultipleChildren($children) as $childNode) { $fullPath = $parent.'/'.$childNode->getName(); $result[$fullPath] = $childNode; $this->cache[$fullPath] = $childNode; } } else { foreach ($children as $child) { $fullPath = $parent.'/'.$child; $result[$fullPath] = $this->getNodeForPath($fullPath); } } } return $result; }
php
public function getMultipleNodes($paths) { $parents = []; foreach ($paths as $path) { list($parent, $node) = Uri\split($path); if (!isset($parents[$parent])) { $parents[$parent] = [$node]; } else { $parents[$parent][] = $node; } } $result = []; foreach ($parents as $parent => $children) { $parentNode = $this->getNodeForPath($parent); if ($parentNode instanceof IMultiGet) { foreach ($parentNode->getMultipleChildren($children) as $childNode) { $fullPath = $parent.'/'.$childNode->getName(); $result[$fullPath] = $childNode; $this->cache[$fullPath] = $childNode; } } else { foreach ($children as $child) { $fullPath = $parent.'/'.$child; $result[$fullPath] = $this->getNodeForPath($fullPath); } } } return $result; }
[ "public", "function", "getMultipleNodes", "(", "$", "paths", ")", "{", "// Finding common parents", "$", "parents", "=", "[", "]", ";", "foreach", "(", "$", "paths", "as", "$", "path", ")", "{", "list", "(", "$", "parent", ",", "$", "node", ")", "=", "Uri", "\\", "split", "(", "$", "path", ")", ";", "if", "(", "!", "isset", "(", "$", "parents", "[", "$", "parent", "]", ")", ")", "{", "$", "parents", "[", "$", "parent", "]", "=", "[", "$", "node", "]", ";", "}", "else", "{", "$", "parents", "[", "$", "parent", "]", "[", "]", "=", "$", "node", ";", "}", "}", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "parents", "as", "$", "parent", "=>", "$", "children", ")", "{", "$", "parentNode", "=", "$", "this", "->", "getNodeForPath", "(", "$", "parent", ")", ";", "if", "(", "$", "parentNode", "instanceof", "IMultiGet", ")", "{", "foreach", "(", "$", "parentNode", "->", "getMultipleChildren", "(", "$", "children", ")", "as", "$", "childNode", ")", "{", "$", "fullPath", "=", "$", "parent", ".", "'/'", ".", "$", "childNode", "->", "getName", "(", ")", ";", "$", "result", "[", "$", "fullPath", "]", "=", "$", "childNode", ";", "$", "this", "->", "cache", "[", "$", "fullPath", "]", "=", "$", "childNode", ";", "}", "}", "else", "{", "foreach", "(", "$", "children", "as", "$", "child", ")", "{", "$", "fullPath", "=", "$", "parent", ".", "'/'", ".", "$", "child", ";", "$", "result", "[", "$", "fullPath", "]", "=", "$", "this", "->", "getNodeForPath", "(", "$", "fullPath", ")", ";", "}", "}", "}", "return", "$", "result", ";", "}" ]
This method tells the tree system to pre-fetch and cache a list of children of a single parent. There are a bunch of operations in the WebDAV stack that request many children (based on uris), and sometimes fetching many at once can optimize this. This method returns an array with the found nodes. It's keys are the original paths. The result may be out of order. @param array $paths list of nodes that must be fetched @return array
[ "This", "method", "tells", "the", "tree", "system", "to", "pre", "-", "fetch", "and", "cache", "a", "list", "of", "children", "of", "a", "single", "parent", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Tree.php#L254-L286
sabre-io/dav
lib/DAV/Tree.php
Tree.copyNode
protected function copyNode(INode $source, ICollection $destinationParent, $destinationName = null) { if ('' === (string) $destinationName) { $destinationName = $source->getName(); } if ($source instanceof IFile) { $data = $source->get(); // If the body was a string, we need to convert it to a stream if (is_string($data)) { $stream = fopen('php://temp', 'r+'); fwrite($stream, $data); rewind($stream); $data = $stream; } $destinationParent->createFile($destinationName, $data); $destination = $destinationParent->getChild($destinationName); } elseif ($source instanceof ICollection) { $destinationParent->createDirectory($destinationName); $destination = $destinationParent->getChild($destinationName); foreach ($source->getChildren() as $child) { $this->copyNode($child, $destination); } } if ($source instanceof IProperties && $destination instanceof IProperties) { $props = $source->getProperties([]); $propPatch = new PropPatch($props); $destination->propPatch($propPatch); $propPatch->commit(); } }
php
protected function copyNode(INode $source, ICollection $destinationParent, $destinationName = null) { if ('' === (string) $destinationName) { $destinationName = $source->getName(); } if ($source instanceof IFile) { $data = $source->get(); if (is_string($data)) { $stream = fopen('php: fwrite($stream, $data); rewind($stream); $data = $stream; } $destinationParent->createFile($destinationName, $data); $destination = $destinationParent->getChild($destinationName); } elseif ($source instanceof ICollection) { $destinationParent->createDirectory($destinationName); $destination = $destinationParent->getChild($destinationName); foreach ($source->getChildren() as $child) { $this->copyNode($child, $destination); } } if ($source instanceof IProperties && $destination instanceof IProperties) { $props = $source->getProperties([]); $propPatch = new PropPatch($props); $destination->propPatch($propPatch); $propPatch->commit(); } }
[ "protected", "function", "copyNode", "(", "INode", "$", "source", ",", "ICollection", "$", "destinationParent", ",", "$", "destinationName", "=", "null", ")", "{", "if", "(", "''", "===", "(", "string", ")", "$", "destinationName", ")", "{", "$", "destinationName", "=", "$", "source", "->", "getName", "(", ")", ";", "}", "if", "(", "$", "source", "instanceof", "IFile", ")", "{", "$", "data", "=", "$", "source", "->", "get", "(", ")", ";", "// If the body was a string, we need to convert it to a stream", "if", "(", "is_string", "(", "$", "data", ")", ")", "{", "$", "stream", "=", "fopen", "(", "'php://temp'", ",", "'r+'", ")", ";", "fwrite", "(", "$", "stream", ",", "$", "data", ")", ";", "rewind", "(", "$", "stream", ")", ";", "$", "data", "=", "$", "stream", ";", "}", "$", "destinationParent", "->", "createFile", "(", "$", "destinationName", ",", "$", "data", ")", ";", "$", "destination", "=", "$", "destinationParent", "->", "getChild", "(", "$", "destinationName", ")", ";", "}", "elseif", "(", "$", "source", "instanceof", "ICollection", ")", "{", "$", "destinationParent", "->", "createDirectory", "(", "$", "destinationName", ")", ";", "$", "destination", "=", "$", "destinationParent", "->", "getChild", "(", "$", "destinationName", ")", ";", "foreach", "(", "$", "source", "->", "getChildren", "(", ")", "as", "$", "child", ")", "{", "$", "this", "->", "copyNode", "(", "$", "child", ",", "$", "destination", ")", ";", "}", "}", "if", "(", "$", "source", "instanceof", "IProperties", "&&", "$", "destination", "instanceof", "IProperties", ")", "{", "$", "props", "=", "$", "source", "->", "getProperties", "(", "[", "]", ")", ";", "$", "propPatch", "=", "new", "PropPatch", "(", "$", "props", ")", ";", "$", "destination", "->", "propPatch", "(", "$", "propPatch", ")", ";", "$", "propPatch", "->", "commit", "(", ")", ";", "}", "}" ]
copyNode. @param INode $source @param ICollection $destinationParent @param string $destinationName
[ "copyNode", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Tree.php#L295-L327
sabre-io/dav
lib/DAV/FSExt/File.php
File.put
public function put($data) { file_put_contents($this->path, $data); clearstatcache(true, $this->path); return $this->getETag(); }
php
public function put($data) { file_put_contents($this->path, $data); clearstatcache(true, $this->path); return $this->getETag(); }
[ "public", "function", "put", "(", "$", "data", ")", "{", "file_put_contents", "(", "$", "this", "->", "path", ",", "$", "data", ")", ";", "clearstatcache", "(", "true", ",", "$", "this", "->", "path", ")", ";", "return", "$", "this", "->", "getETag", "(", ")", ";", "}" ]
Updates the data. Data is a readable stream resource. @param resource|string $data @return string
[ "Updates", "the", "data", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/FSExt/File.php#L28-L34
sabre-io/dav
lib/DAV/FSExt/File.php
File.patch
public function patch($data, $rangeType, $offset = null) { switch ($rangeType) { case 1: $f = fopen($this->path, 'a'); break; case 2: $f = fopen($this->path, 'c'); fseek($f, $offset); break; case 3: $f = fopen($this->path, 'c'); fseek($f, $offset, SEEK_END); break; } if (is_string($data)) { fwrite($f, $data); } else { stream_copy_to_stream($data, $f); } fclose($f); clearstatcache(true, $this->path); return $this->getETag(); }
php
public function patch($data, $rangeType, $offset = null) { switch ($rangeType) { case 1: $f = fopen($this->path, 'a'); break; case 2: $f = fopen($this->path, 'c'); fseek($f, $offset); break; case 3: $f = fopen($this->path, 'c'); fseek($f, $offset, SEEK_END); break; } if (is_string($data)) { fwrite($f, $data); } else { stream_copy_to_stream($data, $f); } fclose($f); clearstatcache(true, $this->path); return $this->getETag(); }
[ "public", "function", "patch", "(", "$", "data", ",", "$", "rangeType", ",", "$", "offset", "=", "null", ")", "{", "switch", "(", "$", "rangeType", ")", "{", "case", "1", ":", "$", "f", "=", "fopen", "(", "$", "this", "->", "path", ",", "'a'", ")", ";", "break", ";", "case", "2", ":", "$", "f", "=", "fopen", "(", "$", "this", "->", "path", ",", "'c'", ")", ";", "fseek", "(", "$", "f", ",", "$", "offset", ")", ";", "break", ";", "case", "3", ":", "$", "f", "=", "fopen", "(", "$", "this", "->", "path", ",", "'c'", ")", ";", "fseek", "(", "$", "f", ",", "$", "offset", ",", "SEEK_END", ")", ";", "break", ";", "}", "if", "(", "is_string", "(", "$", "data", ")", ")", "{", "fwrite", "(", "$", "f", ",", "$", "data", ")", ";", "}", "else", "{", "stream_copy_to_stream", "(", "$", "data", ",", "$", "f", ")", ";", "}", "fclose", "(", "$", "f", ")", ";", "clearstatcache", "(", "true", ",", "$", "this", "->", "path", ")", ";", "return", "$", "this", "->", "getETag", "(", ")", ";", "}" ]
Updates the file based on a range specification. The first argument is the data, which is either a readable stream resource or a string. The second argument is the type of update we're doing. This is either: * 1. append * 2. update based on a start byte * 3. update based on an end byte ; The third argument is the start or end byte. After a successful put operation, you may choose to return an ETag. The ETAG must always be surrounded by double-quotes. These quotes must appear in the actual string you're returning. Clients may use the ETag from a PUT request to later on make sure that when they update the file, the contents haven't changed in the mean time. @param resource|string $data @param int $rangeType @param int $offset @return string|null
[ "Updates", "the", "file", "based", "on", "a", "range", "specification", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/FSExt/File.php#L64-L88
sabre-io/dav
lib/CalDAV/Plugin.php
Plugin.getHTTPMethods
public function getHTTPMethods($uri) { // The MKCALENDAR is only available on unmapped uri's, whose // parents extend IExtendedCollection list($parent, $name) = Uri\split($uri); $node = $this->server->tree->getNodeForPath($parent); if ($node instanceof DAV\IExtendedCollection) { try { $node->getChild($name); } catch (DAV\Exception\NotFound $e) { return ['MKCALENDAR']; } } return []; }
php
public function getHTTPMethods($uri) { list($parent, $name) = Uri\split($uri); $node = $this->server->tree->getNodeForPath($parent); if ($node instanceof DAV\IExtendedCollection) { try { $node->getChild($name); } catch (DAV\Exception\NotFound $e) { return ['MKCALENDAR']; } } return []; }
[ "public", "function", "getHTTPMethods", "(", "$", "uri", ")", "{", "// The MKCALENDAR is only available on unmapped uri's, whose", "// parents extend IExtendedCollection", "list", "(", "$", "parent", ",", "$", "name", ")", "=", "Uri", "\\", "split", "(", "$", "uri", ")", ";", "$", "node", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "parent", ")", ";", "if", "(", "$", "node", "instanceof", "DAV", "\\", "IExtendedCollection", ")", "{", "try", "{", "$", "node", "->", "getChild", "(", "$", "name", ")", ";", "}", "catch", "(", "DAV", "\\", "Exception", "\\", "NotFound", "$", "e", ")", "{", "return", "[", "'MKCALENDAR'", "]", ";", "}", "}", "return", "[", "]", ";", "}" ]
Use this method to tell the server this plugin defines additional HTTP methods. This method is passed a uri. It should only return HTTP methods that are available for the specified uri. @param string $uri @return array
[ "Use", "this", "method", "to", "tell", "the", "server", "this", "plugin", "defines", "additional", "HTTP", "methods", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Plugin.php#L74-L91
sabre-io/dav
lib/CalDAV/Plugin.php
Plugin.getCalendarHomeForPrincipal
public function getCalendarHomeForPrincipal($principalUrl) { // The default behavior for most sabre/dav servers is that there is a // principals root node, which contains users directly under it. // // This function assumes that there are two components in a principal // path. If there's more, we don't return a calendar home. This // excludes things like the calendar-proxy-read principal (which it // should). $parts = explode('/', trim($principalUrl, '/')); if (2 !== count($parts)) { return; } if ('principals' !== $parts[0]) { return; } return self::CALENDAR_ROOT.'/'.$parts[1]; }
php
public function getCalendarHomeForPrincipal($principalUrl) { $parts = explode('/', trim($principalUrl, '/')); if (2 !== count($parts)) { return; } if ('principals' !== $parts[0]) { return; } return self::CALENDAR_ROOT.'/'.$parts[1]; }
[ "public", "function", "getCalendarHomeForPrincipal", "(", "$", "principalUrl", ")", "{", "// The default behavior for most sabre/dav servers is that there is a", "// principals root node, which contains users directly under it.", "//", "// This function assumes that there are two components in a principal", "// path. If there's more, we don't return a calendar home. This", "// excludes things like the calendar-proxy-read principal (which it", "// should).", "$", "parts", "=", "explode", "(", "'/'", ",", "trim", "(", "$", "principalUrl", ",", "'/'", ")", ")", ";", "if", "(", "2", "!==", "count", "(", "$", "parts", ")", ")", "{", "return", ";", "}", "if", "(", "'principals'", "!==", "$", "parts", "[", "0", "]", ")", "{", "return", ";", "}", "return", "self", "::", "CALENDAR_ROOT", ".", "'/'", ".", "$", "parts", "[", "1", "]", ";", "}" ]
Returns the path to a principal's calendar home. The return url must not end with a slash. This function should return null in case a principal did not have a calendar home. @param string $principalUrl @return string
[ "Returns", "the", "path", "to", "a", "principal", "s", "calendar", "home", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Plugin.php#L104-L122
sabre-io/dav
lib/CalDAV/Plugin.php
Plugin.getSupportedReportSet
public function getSupportedReportSet($uri) { $node = $this->server->tree->getNodeForPath($uri); $reports = []; if ($node instanceof ICalendarObjectContainer || $node instanceof ICalendarObject) { $reports[] = '{'.self::NS_CALDAV.'}calendar-multiget'; $reports[] = '{'.self::NS_CALDAV.'}calendar-query'; } if ($node instanceof ICalendar) { $reports[] = '{'.self::NS_CALDAV.'}free-busy-query'; } // iCal has a bug where it assumes that sync support is enabled, only // if we say we support it on the calendar-home, even though this is // not actually the case. if ($node instanceof CalendarHome && $this->server->getPlugin('sync')) { $reports[] = '{DAV:}sync-collection'; } return $reports; }
php
public function getSupportedReportSet($uri) { $node = $this->server->tree->getNodeForPath($uri); $reports = []; if ($node instanceof ICalendarObjectContainer || $node instanceof ICalendarObject) { $reports[] = '{'.self::NS_CALDAV.'}calendar-multiget'; $reports[] = '{'.self::NS_CALDAV.'}calendar-query'; } if ($node instanceof ICalendar) { $reports[] = '{'.self::NS_CALDAV.'}free-busy-query'; } if ($node instanceof CalendarHome && $this->server->getPlugin('sync')) { $reports[] = '{DAV:}sync-collection'; } return $reports; }
[ "public", "function", "getSupportedReportSet", "(", "$", "uri", ")", "{", "$", "node", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "uri", ")", ";", "$", "reports", "=", "[", "]", ";", "if", "(", "$", "node", "instanceof", "ICalendarObjectContainer", "||", "$", "node", "instanceof", "ICalendarObject", ")", "{", "$", "reports", "[", "]", "=", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-multiget'", ";", "$", "reports", "[", "]", "=", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-query'", ";", "}", "if", "(", "$", "node", "instanceof", "ICalendar", ")", "{", "$", "reports", "[", "]", "=", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}free-busy-query'", ";", "}", "// iCal has a bug where it assumes that sync support is enabled, only", "// if we say we support it on the calendar-home, even though this is", "// not actually the case.", "if", "(", "$", "node", "instanceof", "CalendarHome", "&&", "$", "this", "->", "server", "->", "getPlugin", "(", "'sync'", ")", ")", "{", "$", "reports", "[", "]", "=", "'{DAV:}sync-collection'", ";", "}", "return", "$", "reports", ";", "}" ]
Returns a list of reports this plugin supports. This will be used in the {DAV:}supported-report-set property. Note that you still need to subscribe to the 'report' event to actually implement them @param string $uri @return array
[ "Returns", "a", "list", "of", "reports", "this", "plugin", "supports", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Plugin.php#L158-L178
sabre-io/dav
lib/CalDAV/Plugin.php
Plugin.initialize
public function initialize(DAV\Server $server) { $this->server = $server; $server->on('method:MKCALENDAR', [$this, 'httpMkCalendar']); $server->on('report', [$this, 'report']); $server->on('propFind', [$this, 'propFind']); $server->on('onHTMLActionsPanel', [$this, 'htmlActionsPanel']); $server->on('beforeCreateFile', [$this, 'beforeCreateFile']); $server->on('beforeWriteContent', [$this, 'beforeWriteContent']); $server->on('afterMethod:GET', [$this, 'httpAfterGET']); $server->on('getSupportedPrivilegeSet', [$this, 'getSupportedPrivilegeSet']); $server->xml->namespaceMap[self::NS_CALDAV] = 'cal'; $server->xml->namespaceMap[self::NS_CALENDARSERVER] = 'cs'; $server->xml->elementMap['{'.self::NS_CALDAV.'}supported-calendar-component-set'] = 'Sabre\\CalDAV\\Xml\\Property\\SupportedCalendarComponentSet'; $server->xml->elementMap['{'.self::NS_CALDAV.'}calendar-query'] = 'Sabre\\CalDAV\\Xml\\Request\\CalendarQueryReport'; $server->xml->elementMap['{'.self::NS_CALDAV.'}calendar-multiget'] = 'Sabre\\CalDAV\\Xml\\Request\\CalendarMultiGetReport'; $server->xml->elementMap['{'.self::NS_CALDAV.'}free-busy-query'] = 'Sabre\\CalDAV\\Xml\\Request\\FreeBusyQueryReport'; $server->xml->elementMap['{'.self::NS_CALDAV.'}mkcalendar'] = 'Sabre\\CalDAV\\Xml\\Request\\MkCalendar'; $server->xml->elementMap['{'.self::NS_CALDAV.'}schedule-calendar-transp'] = 'Sabre\\CalDAV\\Xml\\Property\\ScheduleCalendarTransp'; $server->xml->elementMap['{'.self::NS_CALDAV.'}supported-calendar-component-set'] = 'Sabre\\CalDAV\\Xml\\Property\\SupportedCalendarComponentSet'; $server->resourceTypeMapping['\\Sabre\\CalDAV\\ICalendar'] = '{urn:ietf:params:xml:ns:caldav}calendar'; $server->resourceTypeMapping['\\Sabre\\CalDAV\\Principal\\IProxyRead'] = '{http://calendarserver.org/ns/}calendar-proxy-read'; $server->resourceTypeMapping['\\Sabre\\CalDAV\\Principal\\IProxyWrite'] = '{http://calendarserver.org/ns/}calendar-proxy-write'; array_push($server->protectedProperties, '{'.self::NS_CALDAV.'}supported-calendar-component-set', '{'.self::NS_CALDAV.'}supported-calendar-data', '{'.self::NS_CALDAV.'}max-resource-size', '{'.self::NS_CALDAV.'}min-date-time', '{'.self::NS_CALDAV.'}max-date-time', '{'.self::NS_CALDAV.'}max-instances', '{'.self::NS_CALDAV.'}max-attendees-per-instance', '{'.self::NS_CALDAV.'}calendar-home-set', '{'.self::NS_CALDAV.'}supported-collation-set', '{'.self::NS_CALDAV.'}calendar-data', // CalendarServer extensions '{'.self::NS_CALENDARSERVER.'}getctag', '{'.self::NS_CALENDARSERVER.'}calendar-proxy-read-for', '{'.self::NS_CALENDARSERVER.'}calendar-proxy-write-for' ); if ($aclPlugin = $server->getPlugin('acl')) { $aclPlugin->principalSearchPropertySet['{'.self::NS_CALDAV.'}calendar-user-address-set'] = 'Calendar address'; } }
php
public function initialize(DAV\Server $server) { $this->server = $server; $server->on('method:MKCALENDAR', [$this, 'httpMkCalendar']); $server->on('report', [$this, 'report']); $server->on('propFind', [$this, 'propFind']); $server->on('onHTMLActionsPanel', [$this, 'htmlActionsPanel']); $server->on('beforeCreateFile', [$this, 'beforeCreateFile']); $server->on('beforeWriteContent', [$this, 'beforeWriteContent']); $server->on('afterMethod:GET', [$this, 'httpAfterGET']); $server->on('getSupportedPrivilegeSet', [$this, 'getSupportedPrivilegeSet']); $server->xml->namespaceMap[self::NS_CALDAV] = 'cal'; $server->xml->namespaceMap[self::NS_CALENDARSERVER] = 'cs'; $server->xml->elementMap['{'.self::NS_CALDAV.'}supported-calendar-component-set'] = 'Sabre\\CalDAV\\Xml\\Property\\SupportedCalendarComponentSet'; $server->xml->elementMap['{'.self::NS_CALDAV.'}calendar-query'] = 'Sabre\\CalDAV\\Xml\\Request\\CalendarQueryReport'; $server->xml->elementMap['{'.self::NS_CALDAV.'}calendar-multiget'] = 'Sabre\\CalDAV\\Xml\\Request\\CalendarMultiGetReport'; $server->xml->elementMap['{'.self::NS_CALDAV.'}free-busy-query'] = 'Sabre\\CalDAV\\Xml\\Request\\FreeBusyQueryReport'; $server->xml->elementMap['{'.self::NS_CALDAV.'}mkcalendar'] = 'Sabre\\CalDAV\\Xml\\Request\\MkCalendar'; $server->xml->elementMap['{'.self::NS_CALDAV.'}schedule-calendar-transp'] = 'Sabre\\CalDAV\\Xml\\Property\\ScheduleCalendarTransp'; $server->xml->elementMap['{'.self::NS_CALDAV.'}supported-calendar-component-set'] = 'Sabre\\CalDAV\\Xml\\Property\\SupportedCalendarComponentSet'; $server->resourceTypeMapping['\\Sabre\\CalDAV\\ICalendar'] = '{urn:ietf:params:xml:ns:caldav}calendar'; $server->resourceTypeMapping['\\Sabre\\CalDAV\\Principal\\IProxyRead'] = '{http: $server->resourceTypeMapping['\\Sabre\\CalDAV\\Principal\\IProxyWrite'] = '{http: array_push($server->protectedProperties, '{'.self::NS_CALDAV.'}supported-calendar-component-set', '{'.self::NS_CALDAV.'}supported-calendar-data', '{'.self::NS_CALDAV.'}max-resource-size', '{'.self::NS_CALDAV.'}min-date-time', '{'.self::NS_CALDAV.'}max-date-time', '{'.self::NS_CALDAV.'}max-instances', '{'.self::NS_CALDAV.'}max-attendees-per-instance', '{'.self::NS_CALDAV.'}calendar-home-set', '{'.self::NS_CALDAV.'}supported-collation-set', '{'.self::NS_CALDAV.'}calendar-data', '{'.self::NS_CALENDARSERVER.'}getctag', '{'.self::NS_CALENDARSERVER.'}calendar-proxy-read-for', '{'.self::NS_CALENDARSERVER.'}calendar-proxy-write-for' ); if ($aclPlugin = $server->getPlugin('acl')) { $aclPlugin->principalSearchPropertySet['{'.self::NS_CALDAV.'}calendar-user-address-set'] = 'Calendar address'; } }
[ "public", "function", "initialize", "(", "DAV", "\\", "Server", "$", "server", ")", "{", "$", "this", "->", "server", "=", "$", "server", ";", "$", "server", "->", "on", "(", "'method:MKCALENDAR'", ",", "[", "$", "this", ",", "'httpMkCalendar'", "]", ")", ";", "$", "server", "->", "on", "(", "'report'", ",", "[", "$", "this", ",", "'report'", "]", ")", ";", "$", "server", "->", "on", "(", "'propFind'", ",", "[", "$", "this", ",", "'propFind'", "]", ")", ";", "$", "server", "->", "on", "(", "'onHTMLActionsPanel'", ",", "[", "$", "this", ",", "'htmlActionsPanel'", "]", ")", ";", "$", "server", "->", "on", "(", "'beforeCreateFile'", ",", "[", "$", "this", ",", "'beforeCreateFile'", "]", ")", ";", "$", "server", "->", "on", "(", "'beforeWriteContent'", ",", "[", "$", "this", ",", "'beforeWriteContent'", "]", ")", ";", "$", "server", "->", "on", "(", "'afterMethod:GET'", ",", "[", "$", "this", ",", "'httpAfterGET'", "]", ")", ";", "$", "server", "->", "on", "(", "'getSupportedPrivilegeSet'", ",", "[", "$", "this", ",", "'getSupportedPrivilegeSet'", "]", ")", ";", "$", "server", "->", "xml", "->", "namespaceMap", "[", "self", "::", "NS_CALDAV", "]", "=", "'cal'", ";", "$", "server", "->", "xml", "->", "namespaceMap", "[", "self", "::", "NS_CALENDARSERVER", "]", "=", "'cs'", ";", "$", "server", "->", "xml", "->", "elementMap", "[", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}supported-calendar-component-set'", "]", "=", "'Sabre\\\\CalDAV\\\\Xml\\\\Property\\\\SupportedCalendarComponentSet'", ";", "$", "server", "->", "xml", "->", "elementMap", "[", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-query'", "]", "=", "'Sabre\\\\CalDAV\\\\Xml\\\\Request\\\\CalendarQueryReport'", ";", "$", "server", "->", "xml", "->", "elementMap", "[", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-multiget'", "]", "=", "'Sabre\\\\CalDAV\\\\Xml\\\\Request\\\\CalendarMultiGetReport'", ";", "$", "server", "->", "xml", "->", "elementMap", "[", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}free-busy-query'", "]", "=", "'Sabre\\\\CalDAV\\\\Xml\\\\Request\\\\FreeBusyQueryReport'", ";", "$", "server", "->", "xml", "->", "elementMap", "[", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}mkcalendar'", "]", "=", "'Sabre\\\\CalDAV\\\\Xml\\\\Request\\\\MkCalendar'", ";", "$", "server", "->", "xml", "->", "elementMap", "[", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}schedule-calendar-transp'", "]", "=", "'Sabre\\\\CalDAV\\\\Xml\\\\Property\\\\ScheduleCalendarTransp'", ";", "$", "server", "->", "xml", "->", "elementMap", "[", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}supported-calendar-component-set'", "]", "=", "'Sabre\\\\CalDAV\\\\Xml\\\\Property\\\\SupportedCalendarComponentSet'", ";", "$", "server", "->", "resourceTypeMapping", "[", "'\\\\Sabre\\\\CalDAV\\\\ICalendar'", "]", "=", "'{urn:ietf:params:xml:ns:caldav}calendar'", ";", "$", "server", "->", "resourceTypeMapping", "[", "'\\\\Sabre\\\\CalDAV\\\\Principal\\\\IProxyRead'", "]", "=", "'{http://calendarserver.org/ns/}calendar-proxy-read'", ";", "$", "server", "->", "resourceTypeMapping", "[", "'\\\\Sabre\\\\CalDAV\\\\Principal\\\\IProxyWrite'", "]", "=", "'{http://calendarserver.org/ns/}calendar-proxy-write'", ";", "array_push", "(", "$", "server", "->", "protectedProperties", ",", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}supported-calendar-component-set'", ",", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}supported-calendar-data'", ",", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}max-resource-size'", ",", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}min-date-time'", ",", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}max-date-time'", ",", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}max-instances'", ",", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}max-attendees-per-instance'", ",", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-home-set'", ",", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}supported-collation-set'", ",", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-data'", ",", "// CalendarServer extensions", "'{'", ".", "self", "::", "NS_CALENDARSERVER", ".", "'}getctag'", ",", "'{'", ".", "self", "::", "NS_CALENDARSERVER", ".", "'}calendar-proxy-read-for'", ",", "'{'", ".", "self", "::", "NS_CALENDARSERVER", ".", "'}calendar-proxy-write-for'", ")", ";", "if", "(", "$", "aclPlugin", "=", "$", "server", "->", "getPlugin", "(", "'acl'", ")", ")", "{", "$", "aclPlugin", "->", "principalSearchPropertySet", "[", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-user-address-set'", "]", "=", "'Calendar address'", ";", "}", "}" ]
Initializes the plugin. @param DAV\Server $server
[ "Initializes", "the", "plugin", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Plugin.php#L185-L235
sabre-io/dav
lib/CalDAV/Plugin.php
Plugin.report
public function report($reportName, $report, $path) { switch ($reportName) { case '{'.self::NS_CALDAV.'}calendar-multiget': $this->server->transactionType = 'report-calendar-multiget'; $this->calendarMultiGetReport($report); return false; case '{'.self::NS_CALDAV.'}calendar-query': $this->server->transactionType = 'report-calendar-query'; $this->calendarQueryReport($report); return false; case '{'.self::NS_CALDAV.'}free-busy-query': $this->server->transactionType = 'report-free-busy-query'; $this->freeBusyQueryReport($report); return false; } }
php
public function report($reportName, $report, $path) { switch ($reportName) { case '{'.self::NS_CALDAV.'}calendar-multiget': $this->server->transactionType = 'report-calendar-multiget'; $this->calendarMultiGetReport($report); return false; case '{'.self::NS_CALDAV.'}calendar-query': $this->server->transactionType = 'report-calendar-query'; $this->calendarQueryReport($report); return false; case '{'.self::NS_CALDAV.'}free-busy-query': $this->server->transactionType = 'report-free-busy-query'; $this->freeBusyQueryReport($report); return false; } }
[ "public", "function", "report", "(", "$", "reportName", ",", "$", "report", ",", "$", "path", ")", "{", "switch", "(", "$", "reportName", ")", "{", "case", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-multiget'", ":", "$", "this", "->", "server", "->", "transactionType", "=", "'report-calendar-multiget'", ";", "$", "this", "->", "calendarMultiGetReport", "(", "$", "report", ")", ";", "return", "false", ";", "case", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-query'", ":", "$", "this", "->", "server", "->", "transactionType", "=", "'report-calendar-query'", ";", "$", "this", "->", "calendarQueryReport", "(", "$", "report", ")", ";", "return", "false", ";", "case", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}free-busy-query'", ":", "$", "this", "->", "server", "->", "transactionType", "=", "'report-free-busy-query'", ";", "$", "this", "->", "freeBusyQueryReport", "(", "$", "report", ")", ";", "return", "false", ";", "}", "}" ]
This functions handles REPORT requests specific to CalDAV. @param string $reportName @param mixed $report @param mixed $path @return bool
[ "This", "functions", "handles", "REPORT", "requests", "specific", "to", "CalDAV", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Plugin.php#L246-L265
sabre-io/dav
lib/CalDAV/Plugin.php
Plugin.httpMkCalendar
public function httpMkCalendar(RequestInterface $request, ResponseInterface $response) { $body = $request->getBodyAsString(); $path = $request->getPath(); $properties = []; if ($body) { try { $mkcalendar = $this->server->xml->expect( '{urn:ietf:params:xml:ns:caldav}mkcalendar', $body ); } catch (\Sabre\Xml\ParseException $e) { throw new BadRequest($e->getMessage(), 0, $e); } $properties = $mkcalendar->getProperties(); } // iCal abuses MKCALENDAR since iCal 10.9.2 to create server-stored // subscriptions. Before that it used MKCOL which was the correct way // to do this. // // If the body had a {DAV:}resourcetype, it means we stumbled upon this // request, and we simply use it instead of the pre-defined list. if (isset($properties['{DAV:}resourcetype'])) { $resourceType = $properties['{DAV:}resourcetype']->getValue(); } else { $resourceType = ['{DAV:}collection', '{urn:ietf:params:xml:ns:caldav}calendar']; } $this->server->createCollection($path, new MkCol($resourceType, $properties)); $response->setStatus(201); $response->setHeader('Content-Length', 0); // This breaks the method chain. return false; }
php
public function httpMkCalendar(RequestInterface $request, ResponseInterface $response) { $body = $request->getBodyAsString(); $path = $request->getPath(); $properties = []; if ($body) { try { $mkcalendar = $this->server->xml->expect( '{urn:ietf:params:xml:ns:caldav}mkcalendar', $body ); } catch (\Sabre\Xml\ParseException $e) { throw new BadRequest($e->getMessage(), 0, $e); } $properties = $mkcalendar->getProperties(); } if (isset($properties['{DAV:}resourcetype'])) { $resourceType = $properties['{DAV:}resourcetype']->getValue(); } else { $resourceType = ['{DAV:}collection', '{urn:ietf:params:xml:ns:caldav}calendar']; } $this->server->createCollection($path, new MkCol($resourceType, $properties)); $response->setStatus(201); $response->setHeader('Content-Length', 0); return false; }
[ "public", "function", "httpMkCalendar", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "body", "=", "$", "request", "->", "getBodyAsString", "(", ")", ";", "$", "path", "=", "$", "request", "->", "getPath", "(", ")", ";", "$", "properties", "=", "[", "]", ";", "if", "(", "$", "body", ")", "{", "try", "{", "$", "mkcalendar", "=", "$", "this", "->", "server", "->", "xml", "->", "expect", "(", "'{urn:ietf:params:xml:ns:caldav}mkcalendar'", ",", "$", "body", ")", ";", "}", "catch", "(", "\\", "Sabre", "\\", "Xml", "\\", "ParseException", "$", "e", ")", "{", "throw", "new", "BadRequest", "(", "$", "e", "->", "getMessage", "(", ")", ",", "0", ",", "$", "e", ")", ";", "}", "$", "properties", "=", "$", "mkcalendar", "->", "getProperties", "(", ")", ";", "}", "// iCal abuses MKCALENDAR since iCal 10.9.2 to create server-stored", "// subscriptions. Before that it used MKCOL which was the correct way", "// to do this.", "//", "// If the body had a {DAV:}resourcetype, it means we stumbled upon this", "// request, and we simply use it instead of the pre-defined list.", "if", "(", "isset", "(", "$", "properties", "[", "'{DAV:}resourcetype'", "]", ")", ")", "{", "$", "resourceType", "=", "$", "properties", "[", "'{DAV:}resourcetype'", "]", "->", "getValue", "(", ")", ";", "}", "else", "{", "$", "resourceType", "=", "[", "'{DAV:}collection'", ",", "'{urn:ietf:params:xml:ns:caldav}calendar'", "]", ";", "}", "$", "this", "->", "server", "->", "createCollection", "(", "$", "path", ",", "new", "MkCol", "(", "$", "resourceType", ",", "$", "properties", ")", ")", ";", "$", "response", "->", "setStatus", "(", "201", ")", ";", "$", "response", "->", "setHeader", "(", "'Content-Length'", ",", "0", ")", ";", "// This breaks the method chain.", "return", "false", ";", "}" ]
This function handles the MKCALENDAR HTTP method, which creates a new calendar. @param RequestInterface $request @param ResponseInterface $response @return bool
[ "This", "function", "handles", "the", "MKCALENDAR", "HTTP", "method", "which", "creates", "a", "new", "calendar", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Plugin.php#L276-L314
sabre-io/dav
lib/CalDAV/Plugin.php
Plugin.propFind
public function propFind(DAV\PropFind $propFind, DAV\INode $node) { $ns = '{'.self::NS_CALDAV.'}'; if ($node instanceof ICalendarObjectContainer) { $propFind->handle($ns.'max-resource-size', $this->maxResourceSize); $propFind->handle($ns.'supported-calendar-data', function () { return new Xml\Property\SupportedCalendarData(); }); $propFind->handle($ns.'supported-collation-set', function () { return new Xml\Property\SupportedCollationSet(); }); } if ($node instanceof DAVACL\IPrincipal) { $principalUrl = $node->getPrincipalUrl(); $propFind->handle('{'.self::NS_CALDAV.'}calendar-home-set', function () use ($principalUrl) { $calendarHomePath = $this->getCalendarHomeForPrincipal($principalUrl); if (is_null($calendarHomePath)) { return null; } return new LocalHref($calendarHomePath.'/'); }); // The calendar-user-address-set property is basically mapped to // the {DAV:}alternate-URI-set property. $propFind->handle('{'.self::NS_CALDAV.'}calendar-user-address-set', function () use ($node) { $addresses = $node->getAlternateUriSet(); $addresses[] = $this->server->getBaseUri().$node->getPrincipalUrl().'/'; return new LocalHref($addresses); }); // For some reason somebody thought it was a good idea to add // another one of these properties. We're supporting it too. $propFind->handle('{'.self::NS_CALENDARSERVER.'}email-address-set', function () use ($node) { $addresses = $node->getAlternateUriSet(); $emails = []; foreach ($addresses as $address) { if ('mailto:' === substr($address, 0, 7)) { $emails[] = substr($address, 7); } } return new Xml\Property\EmailAddressSet($emails); }); // These two properties are shortcuts for ical to easily find // other principals this principal has access to. $propRead = '{'.self::NS_CALENDARSERVER.'}calendar-proxy-read-for'; $propWrite = '{'.self::NS_CALENDARSERVER.'}calendar-proxy-write-for'; if (404 === $propFind->getStatus($propRead) || 404 === $propFind->getStatus($propWrite)) { $aclPlugin = $this->server->getPlugin('acl'); $membership = $aclPlugin->getPrincipalMembership($propFind->getPath()); $readList = []; $writeList = []; foreach ($membership as $group) { $groupNode = $this->server->tree->getNodeForPath($group); $listItem = Uri\split($group)[0].'/'; // If the node is either ap proxy-read or proxy-write // group, we grab the parent principal and add it to the // list. if ($groupNode instanceof Principal\IProxyRead) { $readList[] = $listItem; } if ($groupNode instanceof Principal\IProxyWrite) { $writeList[] = $listItem; } } $propFind->set($propRead, new LocalHref($readList)); $propFind->set($propWrite, new LocalHref($writeList)); } } // instanceof IPrincipal if ($node instanceof ICalendarObject) { // The calendar-data property is not supposed to be a 'real' // property, but in large chunks of the spec it does act as such. // Therefore we simply expose it as a property. $propFind->handle('{'.self::NS_CALDAV.'}calendar-data', function () use ($node) { $val = $node->get(); if (is_resource($val)) { $val = stream_get_contents($val); } // Taking out \r to not screw up the xml output return str_replace("\r", '', $val); }); } }
php
public function propFind(DAV\PropFind $propFind, DAV\INode $node) { $ns = '{'.self::NS_CALDAV.'}'; if ($node instanceof ICalendarObjectContainer) { $propFind->handle($ns.'max-resource-size', $this->maxResourceSize); $propFind->handle($ns.'supported-calendar-data', function () { return new Xml\Property\SupportedCalendarData(); }); $propFind->handle($ns.'supported-collation-set', function () { return new Xml\Property\SupportedCollationSet(); }); } if ($node instanceof DAVACL\IPrincipal) { $principalUrl = $node->getPrincipalUrl(); $propFind->handle('{'.self::NS_CALDAV.'}calendar-home-set', function () use ($principalUrl) { $calendarHomePath = $this->getCalendarHomeForPrincipal($principalUrl); if (is_null($calendarHomePath)) { return null; } return new LocalHref($calendarHomePath.'/'); }); $propFind->handle('{'.self::NS_CALDAV.'}calendar-user-address-set', function () use ($node) { $addresses = $node->getAlternateUriSet(); $addresses[] = $this->server->getBaseUri().$node->getPrincipalUrl().'/'; return new LocalHref($addresses); }); $propFind->handle('{'.self::NS_CALENDARSERVER.'}email-address-set', function () use ($node) { $addresses = $node->getAlternateUriSet(); $emails = []; foreach ($addresses as $address) { if ('mailto:' === substr($address, 0, 7)) { $emails[] = substr($address, 7); } } return new Xml\Property\EmailAddressSet($emails); }); $propRead = '{'.self::NS_CALENDARSERVER.'}calendar-proxy-read-for'; $propWrite = '{'.self::NS_CALENDARSERVER.'}calendar-proxy-write-for'; if (404 === $propFind->getStatus($propRead) || 404 === $propFind->getStatus($propWrite)) { $aclPlugin = $this->server->getPlugin('acl'); $membership = $aclPlugin->getPrincipalMembership($propFind->getPath()); $readList = []; $writeList = []; foreach ($membership as $group) { $groupNode = $this->server->tree->getNodeForPath($group); $listItem = Uri\split($group)[0].'/'; if ($groupNode instanceof Principal\IProxyRead) { $readList[] = $listItem; } if ($groupNode instanceof Principal\IProxyWrite) { $writeList[] = $listItem; } } $propFind->set($propRead, new LocalHref($readList)); $propFind->set($propWrite, new LocalHref($writeList)); } } if ($node instanceof ICalendarObject) { $propFind->handle('{'.self::NS_CALDAV.'}calendar-data', function () use ($node) { $val = $node->get(); if (is_resource($val)) { $val = stream_get_contents($val); } return str_replace("\r", '', $val); }); } }
[ "public", "function", "propFind", "(", "DAV", "\\", "PropFind", "$", "propFind", ",", "DAV", "\\", "INode", "$", "node", ")", "{", "$", "ns", "=", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}'", ";", "if", "(", "$", "node", "instanceof", "ICalendarObjectContainer", ")", "{", "$", "propFind", "->", "handle", "(", "$", "ns", ".", "'max-resource-size'", ",", "$", "this", "->", "maxResourceSize", ")", ";", "$", "propFind", "->", "handle", "(", "$", "ns", ".", "'supported-calendar-data'", ",", "function", "(", ")", "{", "return", "new", "Xml", "\\", "Property", "\\", "SupportedCalendarData", "(", ")", ";", "}", ")", ";", "$", "propFind", "->", "handle", "(", "$", "ns", ".", "'supported-collation-set'", ",", "function", "(", ")", "{", "return", "new", "Xml", "\\", "Property", "\\", "SupportedCollationSet", "(", ")", ";", "}", ")", ";", "}", "if", "(", "$", "node", "instanceof", "DAVACL", "\\", "IPrincipal", ")", "{", "$", "principalUrl", "=", "$", "node", "->", "getPrincipalUrl", "(", ")", ";", "$", "propFind", "->", "handle", "(", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-home-set'", ",", "function", "(", ")", "use", "(", "$", "principalUrl", ")", "{", "$", "calendarHomePath", "=", "$", "this", "->", "getCalendarHomeForPrincipal", "(", "$", "principalUrl", ")", ";", "if", "(", "is_null", "(", "$", "calendarHomePath", ")", ")", "{", "return", "null", ";", "}", "return", "new", "LocalHref", "(", "$", "calendarHomePath", ".", "'/'", ")", ";", "}", ")", ";", "// The calendar-user-address-set property is basically mapped to", "// the {DAV:}alternate-URI-set property.", "$", "propFind", "->", "handle", "(", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-user-address-set'", ",", "function", "(", ")", "use", "(", "$", "node", ")", "{", "$", "addresses", "=", "$", "node", "->", "getAlternateUriSet", "(", ")", ";", "$", "addresses", "[", "]", "=", "$", "this", "->", "server", "->", "getBaseUri", "(", ")", ".", "$", "node", "->", "getPrincipalUrl", "(", ")", ".", "'/'", ";", "return", "new", "LocalHref", "(", "$", "addresses", ")", ";", "}", ")", ";", "// For some reason somebody thought it was a good idea to add", "// another one of these properties. We're supporting it too.", "$", "propFind", "->", "handle", "(", "'{'", ".", "self", "::", "NS_CALENDARSERVER", ".", "'}email-address-set'", ",", "function", "(", ")", "use", "(", "$", "node", ")", "{", "$", "addresses", "=", "$", "node", "->", "getAlternateUriSet", "(", ")", ";", "$", "emails", "=", "[", "]", ";", "foreach", "(", "$", "addresses", "as", "$", "address", ")", "{", "if", "(", "'mailto:'", "===", "substr", "(", "$", "address", ",", "0", ",", "7", ")", ")", "{", "$", "emails", "[", "]", "=", "substr", "(", "$", "address", ",", "7", ")", ";", "}", "}", "return", "new", "Xml", "\\", "Property", "\\", "EmailAddressSet", "(", "$", "emails", ")", ";", "}", ")", ";", "// These two properties are shortcuts for ical to easily find", "// other principals this principal has access to.", "$", "propRead", "=", "'{'", ".", "self", "::", "NS_CALENDARSERVER", ".", "'}calendar-proxy-read-for'", ";", "$", "propWrite", "=", "'{'", ".", "self", "::", "NS_CALENDARSERVER", ".", "'}calendar-proxy-write-for'", ";", "if", "(", "404", "===", "$", "propFind", "->", "getStatus", "(", "$", "propRead", ")", "||", "404", "===", "$", "propFind", "->", "getStatus", "(", "$", "propWrite", ")", ")", "{", "$", "aclPlugin", "=", "$", "this", "->", "server", "->", "getPlugin", "(", "'acl'", ")", ";", "$", "membership", "=", "$", "aclPlugin", "->", "getPrincipalMembership", "(", "$", "propFind", "->", "getPath", "(", ")", ")", ";", "$", "readList", "=", "[", "]", ";", "$", "writeList", "=", "[", "]", ";", "foreach", "(", "$", "membership", "as", "$", "group", ")", "{", "$", "groupNode", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "group", ")", ";", "$", "listItem", "=", "Uri", "\\", "split", "(", "$", "group", ")", "[", "0", "]", ".", "'/'", ";", "// If the node is either ap proxy-read or proxy-write", "// group, we grab the parent principal and add it to the", "// list.", "if", "(", "$", "groupNode", "instanceof", "Principal", "\\", "IProxyRead", ")", "{", "$", "readList", "[", "]", "=", "$", "listItem", ";", "}", "if", "(", "$", "groupNode", "instanceof", "Principal", "\\", "IProxyWrite", ")", "{", "$", "writeList", "[", "]", "=", "$", "listItem", ";", "}", "}", "$", "propFind", "->", "set", "(", "$", "propRead", ",", "new", "LocalHref", "(", "$", "readList", ")", ")", ";", "$", "propFind", "->", "set", "(", "$", "propWrite", ",", "new", "LocalHref", "(", "$", "writeList", ")", ")", ";", "}", "}", "// instanceof IPrincipal", "if", "(", "$", "node", "instanceof", "ICalendarObject", ")", "{", "// The calendar-data property is not supposed to be a 'real'", "// property, but in large chunks of the spec it does act as such.", "// Therefore we simply expose it as a property.", "$", "propFind", "->", "handle", "(", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-data'", ",", "function", "(", ")", "use", "(", "$", "node", ")", "{", "$", "val", "=", "$", "node", "->", "get", "(", ")", ";", "if", "(", "is_resource", "(", "$", "val", ")", ")", "{", "$", "val", "=", "stream_get_contents", "(", "$", "val", ")", ";", "}", "// Taking out \\r to not screw up the xml output", "return", "str_replace", "(", "\"\\r\"", ",", "''", ",", "$", "val", ")", ";", "}", ")", ";", "}", "}" ]
PropFind. This method handler is invoked before any after properties for a resource are fetched. This allows us to add in any CalDAV specific properties. @param DAV\PropFind $propFind @param DAV\INode $node
[ "PropFind", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Plugin.php#L326-L419
sabre-io/dav
lib/CalDAV/Plugin.php
Plugin.calendarMultiGetReport
public function calendarMultiGetReport($report) { $needsJson = 'application/calendar+json' === $report->contentType; $timeZones = []; $propertyList = []; $paths = array_map( [$this->server, 'calculateUri'], $report->hrefs ); foreach ($this->server->getPropertiesForMultiplePaths($paths, $report->properties) as $uri => $objProps) { if (($needsJson || $report->expand) && isset($objProps[200]['{'.self::NS_CALDAV.'}calendar-data'])) { $vObject = VObject\Reader::read($objProps[200]['{'.self::NS_CALDAV.'}calendar-data']); if ($report->expand) { // We're expanding, and for that we need to figure out the // calendar's timezone. list($calendarPath) = Uri\split($uri); if (!isset($timeZones[$calendarPath])) { // Checking the calendar-timezone property. $tzProp = '{'.self::NS_CALDAV.'}calendar-timezone'; $tzResult = $this->server->getProperties($calendarPath, [$tzProp]); if (isset($tzResult[$tzProp])) { // This property contains a VCALENDAR with a single // VTIMEZONE. $vtimezoneObj = VObject\Reader::read($tzResult[$tzProp]); $timeZone = $vtimezoneObj->VTIMEZONE->getTimeZone(); } else { // Defaulting to UTC. $timeZone = new DateTimeZone('UTC'); } $timeZones[$calendarPath] = $timeZone; } $vObject = $vObject->expand($report->expand['start'], $report->expand['end'], $timeZones[$calendarPath]); } if ($needsJson) { $objProps[200]['{'.self::NS_CALDAV.'}calendar-data'] = json_encode($vObject->jsonSerialize()); } else { $objProps[200]['{'.self::NS_CALDAV.'}calendar-data'] = $vObject->serialize(); } // Destroy circular references so PHP will garbage collect the // object. $vObject->destroy(); } $propertyList[] = $objProps; } $prefer = $this->server->getHTTPPrefer(); $this->server->httpResponse->setStatus(207); $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer'); $this->server->httpResponse->setBody($this->server->generateMultiStatus($propertyList, 'minimal' === $prefer['return'])); }
php
public function calendarMultiGetReport($report) { $needsJson = 'application/calendar+json' === $report->contentType; $timeZones = []; $propertyList = []; $paths = array_map( [$this->server, 'calculateUri'], $report->hrefs ); foreach ($this->server->getPropertiesForMultiplePaths($paths, $report->properties) as $uri => $objProps) { if (($needsJson || $report->expand) && isset($objProps[200]['{'.self::NS_CALDAV.'}calendar-data'])) { $vObject = VObject\Reader::read($objProps[200]['{'.self::NS_CALDAV.'}calendar-data']); if ($report->expand) { list($calendarPath) = Uri\split($uri); if (!isset($timeZones[$calendarPath])) { $tzProp = '{'.self::NS_CALDAV.'}calendar-timezone'; $tzResult = $this->server->getProperties($calendarPath, [$tzProp]); if (isset($tzResult[$tzProp])) { $vtimezoneObj = VObject\Reader::read($tzResult[$tzProp]); $timeZone = $vtimezoneObj->VTIMEZONE->getTimeZone(); } else { $timeZone = new DateTimeZone('UTC'); } $timeZones[$calendarPath] = $timeZone; } $vObject = $vObject->expand($report->expand['start'], $report->expand['end'], $timeZones[$calendarPath]); } if ($needsJson) { $objProps[200]['{'.self::NS_CALDAV.'}calendar-data'] = json_encode($vObject->jsonSerialize()); } else { $objProps[200]['{'.self::NS_CALDAV.'}calendar-data'] = $vObject->serialize(); } $vObject->destroy(); } $propertyList[] = $objProps; } $prefer = $this->server->getHTTPPrefer(); $this->server->httpResponse->setStatus(207); $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer'); $this->server->httpResponse->setBody($this->server->generateMultiStatus($propertyList, 'minimal' === $prefer['return'])); }
[ "public", "function", "calendarMultiGetReport", "(", "$", "report", ")", "{", "$", "needsJson", "=", "'application/calendar+json'", "===", "$", "report", "->", "contentType", ";", "$", "timeZones", "=", "[", "]", ";", "$", "propertyList", "=", "[", "]", ";", "$", "paths", "=", "array_map", "(", "[", "$", "this", "->", "server", ",", "'calculateUri'", "]", ",", "$", "report", "->", "hrefs", ")", ";", "foreach", "(", "$", "this", "->", "server", "->", "getPropertiesForMultiplePaths", "(", "$", "paths", ",", "$", "report", "->", "properties", ")", "as", "$", "uri", "=>", "$", "objProps", ")", "{", "if", "(", "(", "$", "needsJson", "||", "$", "report", "->", "expand", ")", "&&", "isset", "(", "$", "objProps", "[", "200", "]", "[", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-data'", "]", ")", ")", "{", "$", "vObject", "=", "VObject", "\\", "Reader", "::", "read", "(", "$", "objProps", "[", "200", "]", "[", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-data'", "]", ")", ";", "if", "(", "$", "report", "->", "expand", ")", "{", "// We're expanding, and for that we need to figure out the", "// calendar's timezone.", "list", "(", "$", "calendarPath", ")", "=", "Uri", "\\", "split", "(", "$", "uri", ")", ";", "if", "(", "!", "isset", "(", "$", "timeZones", "[", "$", "calendarPath", "]", ")", ")", "{", "// Checking the calendar-timezone property.", "$", "tzProp", "=", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-timezone'", ";", "$", "tzResult", "=", "$", "this", "->", "server", "->", "getProperties", "(", "$", "calendarPath", ",", "[", "$", "tzProp", "]", ")", ";", "if", "(", "isset", "(", "$", "tzResult", "[", "$", "tzProp", "]", ")", ")", "{", "// This property contains a VCALENDAR with a single", "// VTIMEZONE.", "$", "vtimezoneObj", "=", "VObject", "\\", "Reader", "::", "read", "(", "$", "tzResult", "[", "$", "tzProp", "]", ")", ";", "$", "timeZone", "=", "$", "vtimezoneObj", "->", "VTIMEZONE", "->", "getTimeZone", "(", ")", ";", "}", "else", "{", "// Defaulting to UTC.", "$", "timeZone", "=", "new", "DateTimeZone", "(", "'UTC'", ")", ";", "}", "$", "timeZones", "[", "$", "calendarPath", "]", "=", "$", "timeZone", ";", "}", "$", "vObject", "=", "$", "vObject", "->", "expand", "(", "$", "report", "->", "expand", "[", "'start'", "]", ",", "$", "report", "->", "expand", "[", "'end'", "]", ",", "$", "timeZones", "[", "$", "calendarPath", "]", ")", ";", "}", "if", "(", "$", "needsJson", ")", "{", "$", "objProps", "[", "200", "]", "[", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-data'", "]", "=", "json_encode", "(", "$", "vObject", "->", "jsonSerialize", "(", ")", ")", ";", "}", "else", "{", "$", "objProps", "[", "200", "]", "[", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-data'", "]", "=", "$", "vObject", "->", "serialize", "(", ")", ";", "}", "// Destroy circular references so PHP will garbage collect the", "// object.", "$", "vObject", "->", "destroy", "(", ")", ";", "}", "$", "propertyList", "[", "]", "=", "$", "objProps", ";", "}", "$", "prefer", "=", "$", "this", "->", "server", "->", "getHTTPPrefer", "(", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setStatus", "(", "207", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setHeader", "(", "'Content-Type'", ",", "'application/xml; charset=utf-8'", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setHeader", "(", "'Vary'", ",", "'Brief,Prefer'", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setBody", "(", "$", "this", "->", "server", "->", "generateMultiStatus", "(", "$", "propertyList", ",", "'minimal'", "===", "$", "prefer", "[", "'return'", "]", ")", ")", ";", "}" ]
This function handles the calendar-multiget REPORT. This report is used by the client to fetch the content of a series of urls. Effectively avoiding a lot of redundant requests. @param CalendarMultiGetReport $report
[ "This", "function", "handles", "the", "calendar", "-", "multiget", "REPORT", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Plugin.php#L429-L486
sabre-io/dav
lib/CalDAV/Plugin.php
Plugin.calendarQueryReport
public function calendarQueryReport($report) { $path = $this->server->getRequestUri(); $needsJson = 'application/calendar+json' === $report->contentType; $node = $this->server->tree->getNodeForPath($this->server->getRequestUri()); $depth = $this->server->getHTTPDepth(0); // The default result is an empty array $result = []; $calendarTimeZone = null; if ($report->expand) { // We're expanding, and for that we need to figure out the // calendar's timezone. $tzProp = '{'.self::NS_CALDAV.'}calendar-timezone'; $tzResult = $this->server->getProperties($path, [$tzProp]); if (isset($tzResult[$tzProp])) { // This property contains a VCALENDAR with a single // VTIMEZONE. $vtimezoneObj = VObject\Reader::read($tzResult[$tzProp]); $calendarTimeZone = $vtimezoneObj->VTIMEZONE->getTimeZone(); // Destroy circular references so PHP will garbage collect the // object. $vtimezoneObj->destroy(); } else { // Defaulting to UTC. $calendarTimeZone = new DateTimeZone('UTC'); } } // The calendarobject was requested directly. In this case we handle // this locally. if (0 == $depth && $node instanceof ICalendarObject) { $requestedCalendarData = true; $requestedProperties = $report->properties; if (!in_array('{urn:ietf:params:xml:ns:caldav}calendar-data', $requestedProperties)) { // We always retrieve calendar-data, as we need it for filtering. $requestedProperties[] = '{urn:ietf:params:xml:ns:caldav}calendar-data'; // If calendar-data wasn't explicitly requested, we need to remove // it after processing. $requestedCalendarData = false; } $properties = $this->server->getPropertiesForPath( $path, $requestedProperties, 0 ); // This array should have only 1 element, the first calendar // object. $properties = current($properties); // If there wasn't any calendar-data returned somehow, we ignore // this. if (isset($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data'])) { $validator = new CalendarQueryValidator(); $vObject = VObject\Reader::read($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']); if ($validator->validate($vObject, $report->filters)) { // If the client didn't require the calendar-data property, // we won't give it back. if (!$requestedCalendarData) { unset($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']); } else { if ($report->expand) { $vObject = $vObject->expand($report->expand['start'], $report->expand['end'], $calendarTimeZone); } if ($needsJson) { $properties[200]['{'.self::NS_CALDAV.'}calendar-data'] = json_encode($vObject->jsonSerialize()); } elseif ($report->expand) { $properties[200]['{'.self::NS_CALDAV.'}calendar-data'] = $vObject->serialize(); } } $result = [$properties]; } // Destroy circular references so PHP will garbage collect the // object. $vObject->destroy(); } } if ($node instanceof ICalendarObjectContainer && 0 === $depth) { if (0 === strpos((string) $this->server->httpRequest->getHeader('User-Agent'), 'MSFT-')) { // Microsoft clients incorrectly supplied depth as 0, when it actually // should have set depth to 1. We're implementing a workaround here // to deal with this. // // This targets at least the following clients: // Windows 10 // Windows Phone 8, 10 $depth = 1; } else { throw new BadRequest('A calendar-query REPORT on a calendar with a Depth: 0 is undefined. Set Depth to 1'); } } // If we're dealing with a calendar, the calendar itself is responsible // for the calendar-query. if ($node instanceof ICalendarObjectContainer && 1 == $depth) { $nodePaths = $node->calendarQuery($report->filters); foreach ($nodePaths as $path) { list($properties) = $this->server->getPropertiesForPath($this->server->getRequestUri().'/'.$path, $report->properties); if (($needsJson || $report->expand)) { $vObject = VObject\Reader::read($properties[200]['{'.self::NS_CALDAV.'}calendar-data']); if ($report->expand) { $vObject = $vObject->expand($report->expand['start'], $report->expand['end'], $calendarTimeZone); } if ($needsJson) { $properties[200]['{'.self::NS_CALDAV.'}calendar-data'] = json_encode($vObject->jsonSerialize()); } else { $properties[200]['{'.self::NS_CALDAV.'}calendar-data'] = $vObject->serialize(); } // Destroy circular references so PHP will garbage collect the // object. $vObject->destroy(); } $result[] = $properties; } } $prefer = $this->server->getHTTPPrefer(); $this->server->httpResponse->setStatus(207); $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer'); $this->server->httpResponse->setBody($this->server->generateMultiStatus($result, 'minimal' === $prefer['return'])); }
php
public function calendarQueryReport($report) { $path = $this->server->getRequestUri(); $needsJson = 'application/calendar+json' === $report->contentType; $node = $this->server->tree->getNodeForPath($this->server->getRequestUri()); $depth = $this->server->getHTTPDepth(0); $result = []; $calendarTimeZone = null; if ($report->expand) { $tzProp = '{'.self::NS_CALDAV.'}calendar-timezone'; $tzResult = $this->server->getProperties($path, [$tzProp]); if (isset($tzResult[$tzProp])) { $vtimezoneObj = VObject\Reader::read($tzResult[$tzProp]); $calendarTimeZone = $vtimezoneObj->VTIMEZONE->getTimeZone(); $vtimezoneObj->destroy(); } else { $calendarTimeZone = new DateTimeZone('UTC'); } } if (0 == $depth && $node instanceof ICalendarObject) { $requestedCalendarData = true; $requestedProperties = $report->properties; if (!in_array('{urn:ietf:params:xml:ns:caldav}calendar-data', $requestedProperties)) { $requestedProperties[] = '{urn:ietf:params:xml:ns:caldav}calendar-data'; $requestedCalendarData = false; } $properties = $this->server->getPropertiesForPath( $path, $requestedProperties, 0 ); $properties = current($properties); if (isset($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data'])) { $validator = new CalendarQueryValidator(); $vObject = VObject\Reader::read($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']); if ($validator->validate($vObject, $report->filters)) { if (!$requestedCalendarData) { unset($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']); } else { if ($report->expand) { $vObject = $vObject->expand($report->expand['start'], $report->expand['end'], $calendarTimeZone); } if ($needsJson) { $properties[200]['{'.self::NS_CALDAV.'}calendar-data'] = json_encode($vObject->jsonSerialize()); } elseif ($report->expand) { $properties[200]['{'.self::NS_CALDAV.'}calendar-data'] = $vObject->serialize(); } } $result = [$properties]; } $vObject->destroy(); } } if ($node instanceof ICalendarObjectContainer && 0 === $depth) { if (0 === strpos((string) $this->server->httpRequest->getHeader('User-Agent'), 'MSFT-')) { $depth = 1; } else { throw new BadRequest('A calendar-query REPORT on a calendar with a Depth: 0 is undefined. Set Depth to 1'); } } if ($node instanceof ICalendarObjectContainer && 1 == $depth) { $nodePaths = $node->calendarQuery($report->filters); foreach ($nodePaths as $path) { list($properties) = $this->server->getPropertiesForPath($this->server->getRequestUri().'/'.$path, $report->properties); if (($needsJson || $report->expand)) { $vObject = VObject\Reader::read($properties[200]['{'.self::NS_CALDAV.'}calendar-data']); if ($report->expand) { $vObject = $vObject->expand($report->expand['start'], $report->expand['end'], $calendarTimeZone); } if ($needsJson) { $properties[200]['{'.self::NS_CALDAV.'}calendar-data'] = json_encode($vObject->jsonSerialize()); } else { $properties[200]['{'.self::NS_CALDAV.'}calendar-data'] = $vObject->serialize(); } $vObject->destroy(); } $result[] = $properties; } } $prefer = $this->server->getHTTPPrefer(); $this->server->httpResponse->setStatus(207); $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); $this->server->httpResponse->setHeader('Vary', 'Brief,Prefer'); $this->server->httpResponse->setBody($this->server->generateMultiStatus($result, 'minimal' === $prefer['return'])); }
[ "public", "function", "calendarQueryReport", "(", "$", "report", ")", "{", "$", "path", "=", "$", "this", "->", "server", "->", "getRequestUri", "(", ")", ";", "$", "needsJson", "=", "'application/calendar+json'", "===", "$", "report", "->", "contentType", ";", "$", "node", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "this", "->", "server", "->", "getRequestUri", "(", ")", ")", ";", "$", "depth", "=", "$", "this", "->", "server", "->", "getHTTPDepth", "(", "0", ")", ";", "// The default result is an empty array", "$", "result", "=", "[", "]", ";", "$", "calendarTimeZone", "=", "null", ";", "if", "(", "$", "report", "->", "expand", ")", "{", "// We're expanding, and for that we need to figure out the", "// calendar's timezone.", "$", "tzProp", "=", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-timezone'", ";", "$", "tzResult", "=", "$", "this", "->", "server", "->", "getProperties", "(", "$", "path", ",", "[", "$", "tzProp", "]", ")", ";", "if", "(", "isset", "(", "$", "tzResult", "[", "$", "tzProp", "]", ")", ")", "{", "// This property contains a VCALENDAR with a single", "// VTIMEZONE.", "$", "vtimezoneObj", "=", "VObject", "\\", "Reader", "::", "read", "(", "$", "tzResult", "[", "$", "tzProp", "]", ")", ";", "$", "calendarTimeZone", "=", "$", "vtimezoneObj", "->", "VTIMEZONE", "->", "getTimeZone", "(", ")", ";", "// Destroy circular references so PHP will garbage collect the", "// object.", "$", "vtimezoneObj", "->", "destroy", "(", ")", ";", "}", "else", "{", "// Defaulting to UTC.", "$", "calendarTimeZone", "=", "new", "DateTimeZone", "(", "'UTC'", ")", ";", "}", "}", "// The calendarobject was requested directly. In this case we handle", "// this locally.", "if", "(", "0", "==", "$", "depth", "&&", "$", "node", "instanceof", "ICalendarObject", ")", "{", "$", "requestedCalendarData", "=", "true", ";", "$", "requestedProperties", "=", "$", "report", "->", "properties", ";", "if", "(", "!", "in_array", "(", "'{urn:ietf:params:xml:ns:caldav}calendar-data'", ",", "$", "requestedProperties", ")", ")", "{", "// We always retrieve calendar-data, as we need it for filtering.", "$", "requestedProperties", "[", "]", "=", "'{urn:ietf:params:xml:ns:caldav}calendar-data'", ";", "// If calendar-data wasn't explicitly requested, we need to remove", "// it after processing.", "$", "requestedCalendarData", "=", "false", ";", "}", "$", "properties", "=", "$", "this", "->", "server", "->", "getPropertiesForPath", "(", "$", "path", ",", "$", "requestedProperties", ",", "0", ")", ";", "// This array should have only 1 element, the first calendar", "// object.", "$", "properties", "=", "current", "(", "$", "properties", ")", ";", "// If there wasn't any calendar-data returned somehow, we ignore", "// this.", "if", "(", "isset", "(", "$", "properties", "[", "200", "]", "[", "'{urn:ietf:params:xml:ns:caldav}calendar-data'", "]", ")", ")", "{", "$", "validator", "=", "new", "CalendarQueryValidator", "(", ")", ";", "$", "vObject", "=", "VObject", "\\", "Reader", "::", "read", "(", "$", "properties", "[", "200", "]", "[", "'{urn:ietf:params:xml:ns:caldav}calendar-data'", "]", ")", ";", "if", "(", "$", "validator", "->", "validate", "(", "$", "vObject", ",", "$", "report", "->", "filters", ")", ")", "{", "// If the client didn't require the calendar-data property,", "// we won't give it back.", "if", "(", "!", "$", "requestedCalendarData", ")", "{", "unset", "(", "$", "properties", "[", "200", "]", "[", "'{urn:ietf:params:xml:ns:caldav}calendar-data'", "]", ")", ";", "}", "else", "{", "if", "(", "$", "report", "->", "expand", ")", "{", "$", "vObject", "=", "$", "vObject", "->", "expand", "(", "$", "report", "->", "expand", "[", "'start'", "]", ",", "$", "report", "->", "expand", "[", "'end'", "]", ",", "$", "calendarTimeZone", ")", ";", "}", "if", "(", "$", "needsJson", ")", "{", "$", "properties", "[", "200", "]", "[", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-data'", "]", "=", "json_encode", "(", "$", "vObject", "->", "jsonSerialize", "(", ")", ")", ";", "}", "elseif", "(", "$", "report", "->", "expand", ")", "{", "$", "properties", "[", "200", "]", "[", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-data'", "]", "=", "$", "vObject", "->", "serialize", "(", ")", ";", "}", "}", "$", "result", "=", "[", "$", "properties", "]", ";", "}", "// Destroy circular references so PHP will garbage collect the", "// object.", "$", "vObject", "->", "destroy", "(", ")", ";", "}", "}", "if", "(", "$", "node", "instanceof", "ICalendarObjectContainer", "&&", "0", "===", "$", "depth", ")", "{", "if", "(", "0", "===", "strpos", "(", "(", "string", ")", "$", "this", "->", "server", "->", "httpRequest", "->", "getHeader", "(", "'User-Agent'", ")", ",", "'MSFT-'", ")", ")", "{", "// Microsoft clients incorrectly supplied depth as 0, when it actually", "// should have set depth to 1. We're implementing a workaround here", "// to deal with this.", "//", "// This targets at least the following clients:", "// Windows 10", "// Windows Phone 8, 10", "$", "depth", "=", "1", ";", "}", "else", "{", "throw", "new", "BadRequest", "(", "'A calendar-query REPORT on a calendar with a Depth: 0 is undefined. Set Depth to 1'", ")", ";", "}", "}", "// If we're dealing with a calendar, the calendar itself is responsible", "// for the calendar-query.", "if", "(", "$", "node", "instanceof", "ICalendarObjectContainer", "&&", "1", "==", "$", "depth", ")", "{", "$", "nodePaths", "=", "$", "node", "->", "calendarQuery", "(", "$", "report", "->", "filters", ")", ";", "foreach", "(", "$", "nodePaths", "as", "$", "path", ")", "{", "list", "(", "$", "properties", ")", "=", "$", "this", "->", "server", "->", "getPropertiesForPath", "(", "$", "this", "->", "server", "->", "getRequestUri", "(", ")", ".", "'/'", ".", "$", "path", ",", "$", "report", "->", "properties", ")", ";", "if", "(", "(", "$", "needsJson", "||", "$", "report", "->", "expand", ")", ")", "{", "$", "vObject", "=", "VObject", "\\", "Reader", "::", "read", "(", "$", "properties", "[", "200", "]", "[", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-data'", "]", ")", ";", "if", "(", "$", "report", "->", "expand", ")", "{", "$", "vObject", "=", "$", "vObject", "->", "expand", "(", "$", "report", "->", "expand", "[", "'start'", "]", ",", "$", "report", "->", "expand", "[", "'end'", "]", ",", "$", "calendarTimeZone", ")", ";", "}", "if", "(", "$", "needsJson", ")", "{", "$", "properties", "[", "200", "]", "[", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-data'", "]", "=", "json_encode", "(", "$", "vObject", "->", "jsonSerialize", "(", ")", ")", ";", "}", "else", "{", "$", "properties", "[", "200", "]", "[", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-data'", "]", "=", "$", "vObject", "->", "serialize", "(", ")", ";", "}", "// Destroy circular references so PHP will garbage collect the", "// object.", "$", "vObject", "->", "destroy", "(", ")", ";", "}", "$", "result", "[", "]", "=", "$", "properties", ";", "}", "}", "$", "prefer", "=", "$", "this", "->", "server", "->", "getHTTPPrefer", "(", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setStatus", "(", "207", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setHeader", "(", "'Content-Type'", ",", "'application/xml; charset=utf-8'", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setHeader", "(", "'Vary'", ",", "'Brief,Prefer'", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setBody", "(", "$", "this", "->", "server", "->", "generateMultiStatus", "(", "$", "result", ",", "'minimal'", "===", "$", "prefer", "[", "'return'", "]", ")", ")", ";", "}" ]
This function handles the calendar-query REPORT. This report is used by clients to request calendar objects based on complex conditions. @param Xml\Request\CalendarQueryReport $report
[ "This", "function", "handles", "the", "calendar", "-", "query", "REPORT", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Plugin.php#L496-L635
sabre-io/dav
lib/CalDAV/Plugin.php
Plugin.freeBusyQueryReport
protected function freeBusyQueryReport(Xml\Request\FreeBusyQueryReport $report) { $uri = $this->server->getRequestUri(); $acl = $this->server->getPlugin('acl'); if ($acl) { $acl->checkPrivileges($uri, '{'.self::NS_CALDAV.'}read-free-busy'); } $calendar = $this->server->tree->getNodeForPath($uri); if (!$calendar instanceof ICalendar) { throw new DAV\Exception\NotImplemented('The free-busy-query REPORT is only implemented on calendars'); } $tzProp = '{'.self::NS_CALDAV.'}calendar-timezone'; // Figuring out the default timezone for the calendar, for floating // times. $calendarProps = $this->server->getProperties($uri, [$tzProp]); if (isset($calendarProps[$tzProp])) { $vtimezoneObj = VObject\Reader::read($calendarProps[$tzProp]); $calendarTimeZone = $vtimezoneObj->VTIMEZONE->getTimeZone(); // Destroy circular references so PHP will garbage collect the object. $vtimezoneObj->destroy(); } else { $calendarTimeZone = new DateTimeZone('UTC'); } // Doing a calendar-query first, to make sure we get the most // performance. $urls = $calendar->calendarQuery([ 'name' => 'VCALENDAR', 'comp-filters' => [ [ 'name' => 'VEVENT', 'comp-filters' => [], 'prop-filters' => [], 'is-not-defined' => false, 'time-range' => [ 'start' => $report->start, 'end' => $report->end, ], ], ], 'prop-filters' => [], 'is-not-defined' => false, 'time-range' => null, ]); $objects = array_map(function ($url) use ($calendar) { $obj = $calendar->getChild($url)->get(); return $obj; }, $urls); $generator = new VObject\FreeBusyGenerator(); $generator->setObjects($objects); $generator->setTimeRange($report->start, $report->end); $generator->setTimeZone($calendarTimeZone); $result = $generator->getResult(); $result = $result->serialize(); $this->server->httpResponse->setStatus(200); $this->server->httpResponse->setHeader('Content-Type', 'text/calendar'); $this->server->httpResponse->setHeader('Content-Length', strlen($result)); $this->server->httpResponse->setBody($result); }
php
protected function freeBusyQueryReport(Xml\Request\FreeBusyQueryReport $report) { $uri = $this->server->getRequestUri(); $acl = $this->server->getPlugin('acl'); if ($acl) { $acl->checkPrivileges($uri, '{'.self::NS_CALDAV.'}read-free-busy'); } $calendar = $this->server->tree->getNodeForPath($uri); if (!$calendar instanceof ICalendar) { throw new DAV\Exception\NotImplemented('The free-busy-query REPORT is only implemented on calendars'); } $tzProp = '{'.self::NS_CALDAV.'}calendar-timezone'; $calendarProps = $this->server->getProperties($uri, [$tzProp]); if (isset($calendarProps[$tzProp])) { $vtimezoneObj = VObject\Reader::read($calendarProps[$tzProp]); $calendarTimeZone = $vtimezoneObj->VTIMEZONE->getTimeZone(); $vtimezoneObj->destroy(); } else { $calendarTimeZone = new DateTimeZone('UTC'); } $urls = $calendar->calendarQuery([ 'name' => 'VCALENDAR', 'comp-filters' => [ [ 'name' => 'VEVENT', 'comp-filters' => [], 'prop-filters' => [], 'is-not-defined' => false, 'time-range' => [ 'start' => $report->start, 'end' => $report->end, ], ], ], 'prop-filters' => [], 'is-not-defined' => false, 'time-range' => null, ]); $objects = array_map(function ($url) use ($calendar) { $obj = $calendar->getChild($url)->get(); return $obj; }, $urls); $generator = new VObject\FreeBusyGenerator(); $generator->setObjects($objects); $generator->setTimeRange($report->start, $report->end); $generator->setTimeZone($calendarTimeZone); $result = $generator->getResult(); $result = $result->serialize(); $this->server->httpResponse->setStatus(200); $this->server->httpResponse->setHeader('Content-Type', 'text/calendar'); $this->server->httpResponse->setHeader('Content-Length', strlen($result)); $this->server->httpResponse->setBody($result); }
[ "protected", "function", "freeBusyQueryReport", "(", "Xml", "\\", "Request", "\\", "FreeBusyQueryReport", "$", "report", ")", "{", "$", "uri", "=", "$", "this", "->", "server", "->", "getRequestUri", "(", ")", ";", "$", "acl", "=", "$", "this", "->", "server", "->", "getPlugin", "(", "'acl'", ")", ";", "if", "(", "$", "acl", ")", "{", "$", "acl", "->", "checkPrivileges", "(", "$", "uri", ",", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}read-free-busy'", ")", ";", "}", "$", "calendar", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "uri", ")", ";", "if", "(", "!", "$", "calendar", "instanceof", "ICalendar", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "NotImplemented", "(", "'The free-busy-query REPORT is only implemented on calendars'", ")", ";", "}", "$", "tzProp", "=", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar-timezone'", ";", "// Figuring out the default timezone for the calendar, for floating", "// times.", "$", "calendarProps", "=", "$", "this", "->", "server", "->", "getProperties", "(", "$", "uri", ",", "[", "$", "tzProp", "]", ")", ";", "if", "(", "isset", "(", "$", "calendarProps", "[", "$", "tzProp", "]", ")", ")", "{", "$", "vtimezoneObj", "=", "VObject", "\\", "Reader", "::", "read", "(", "$", "calendarProps", "[", "$", "tzProp", "]", ")", ";", "$", "calendarTimeZone", "=", "$", "vtimezoneObj", "->", "VTIMEZONE", "->", "getTimeZone", "(", ")", ";", "// Destroy circular references so PHP will garbage collect the object.", "$", "vtimezoneObj", "->", "destroy", "(", ")", ";", "}", "else", "{", "$", "calendarTimeZone", "=", "new", "DateTimeZone", "(", "'UTC'", ")", ";", "}", "// Doing a calendar-query first, to make sure we get the most", "// performance.", "$", "urls", "=", "$", "calendar", "->", "calendarQuery", "(", "[", "'name'", "=>", "'VCALENDAR'", ",", "'comp-filters'", "=>", "[", "[", "'name'", "=>", "'VEVENT'", ",", "'comp-filters'", "=>", "[", "]", ",", "'prop-filters'", "=>", "[", "]", ",", "'is-not-defined'", "=>", "false", ",", "'time-range'", "=>", "[", "'start'", "=>", "$", "report", "->", "start", ",", "'end'", "=>", "$", "report", "->", "end", ",", "]", ",", "]", ",", "]", ",", "'prop-filters'", "=>", "[", "]", ",", "'is-not-defined'", "=>", "false", ",", "'time-range'", "=>", "null", ",", "]", ")", ";", "$", "objects", "=", "array_map", "(", "function", "(", "$", "url", ")", "use", "(", "$", "calendar", ")", "{", "$", "obj", "=", "$", "calendar", "->", "getChild", "(", "$", "url", ")", "->", "get", "(", ")", ";", "return", "$", "obj", ";", "}", ",", "$", "urls", ")", ";", "$", "generator", "=", "new", "VObject", "\\", "FreeBusyGenerator", "(", ")", ";", "$", "generator", "->", "setObjects", "(", "$", "objects", ")", ";", "$", "generator", "->", "setTimeRange", "(", "$", "report", "->", "start", ",", "$", "report", "->", "end", ")", ";", "$", "generator", "->", "setTimeZone", "(", "$", "calendarTimeZone", ")", ";", "$", "result", "=", "$", "generator", "->", "getResult", "(", ")", ";", "$", "result", "=", "$", "result", "->", "serialize", "(", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setStatus", "(", "200", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setHeader", "(", "'Content-Type'", ",", "'text/calendar'", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setHeader", "(", "'Content-Length'", ",", "strlen", "(", "$", "result", ")", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setBody", "(", "$", "result", ")", ";", "}" ]
This method is responsible for parsing the request and generating the response for the CALDAV:free-busy-query REPORT. @param Xml\Request\FreeBusyQueryReport $report
[ "This", "method", "is", "responsible", "for", "parsing", "the", "request", "and", "generating", "the", "response", "for", "the", "CALDAV", ":", "free", "-", "busy", "-", "query", "REPORT", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Plugin.php#L643-L710
sabre-io/dav
lib/CalDAV/Plugin.php
Plugin.beforeWriteContent
public function beforeWriteContent($path, DAV\IFile $node, &$data, &$modified) { if (!$node instanceof ICalendarObject) { return; } // We're onyl interested in ICalendarObject nodes that are inside of a // real calendar. This is to avoid triggering validation and scheduling // for non-calendars (such as an inbox). list($parent) = Uri\split($path); $parentNode = $this->server->tree->getNodeForPath($parent); if (!$parentNode instanceof ICalendar) { return; } $this->validateICalendar( $data, $path, $modified, $this->server->httpRequest, $this->server->httpResponse, false ); }
php
public function beforeWriteContent($path, DAV\IFile $node, &$data, &$modified) { if (!$node instanceof ICalendarObject) { return; } list($parent) = Uri\split($path); $parentNode = $this->server->tree->getNodeForPath($parent); if (!$parentNode instanceof ICalendar) { return; } $this->validateICalendar( $data, $path, $modified, $this->server->httpRequest, $this->server->httpResponse, false ); }
[ "public", "function", "beforeWriteContent", "(", "$", "path", ",", "DAV", "\\", "IFile", "$", "node", ",", "&", "$", "data", ",", "&", "$", "modified", ")", "{", "if", "(", "!", "$", "node", "instanceof", "ICalendarObject", ")", "{", "return", ";", "}", "// We're onyl interested in ICalendarObject nodes that are inside of a", "// real calendar. This is to avoid triggering validation and scheduling", "// for non-calendars (such as an inbox).", "list", "(", "$", "parent", ")", "=", "Uri", "\\", "split", "(", "$", "path", ")", ";", "$", "parentNode", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "parent", ")", ";", "if", "(", "!", "$", "parentNode", "instanceof", "ICalendar", ")", "{", "return", ";", "}", "$", "this", "->", "validateICalendar", "(", "$", "data", ",", "$", "path", ",", "$", "modified", ",", "$", "this", "->", "server", "->", "httpRequest", ",", "$", "this", "->", "server", "->", "httpResponse", ",", "false", ")", ";", "}" ]
This method is triggered before a file gets updated with new content. This plugin uses this method to ensure that CalDAV objects receive valid calendar data. @param string $path @param DAV\IFile $node @param resource $data @param bool $modified should be set to true, if this event handler changed &$data
[ "This", "method", "is", "triggered", "before", "a", "file", "gets", "updated", "with", "new", "content", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Plugin.php#L724-L748
sabre-io/dav
lib/CalDAV/Plugin.php
Plugin.beforeCreateFile
public function beforeCreateFile($path, &$data, DAV\ICollection $parentNode, &$modified) { if (!$parentNode instanceof ICalendar) { return; } $this->validateICalendar( $data, $path, $modified, $this->server->httpRequest, $this->server->httpResponse, true ); }
php
public function beforeCreateFile($path, &$data, DAV\ICollection $parentNode, &$modified) { if (!$parentNode instanceof ICalendar) { return; } $this->validateICalendar( $data, $path, $modified, $this->server->httpRequest, $this->server->httpResponse, true ); }
[ "public", "function", "beforeCreateFile", "(", "$", "path", ",", "&", "$", "data", ",", "DAV", "\\", "ICollection", "$", "parentNode", ",", "&", "$", "modified", ")", "{", "if", "(", "!", "$", "parentNode", "instanceof", "ICalendar", ")", "{", "return", ";", "}", "$", "this", "->", "validateICalendar", "(", "$", "data", ",", "$", "path", ",", "$", "modified", ",", "$", "this", "->", "server", "->", "httpRequest", ",", "$", "this", "->", "server", "->", "httpResponse", ",", "true", ")", ";", "}" ]
This method is triggered before a new file is created. This plugin uses this method to ensure that newly created calendar objects contain valid calendar data. @param string $path @param resource $data @param DAV\ICollection $parentNode @param bool $modified should be set to true, if this event handler changed &$data
[ "This", "method", "is", "triggered", "before", "a", "new", "file", "is", "created", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Plugin.php#L762-L776
sabre-io/dav
lib/CalDAV/Plugin.php
Plugin.validateICalendar
protected function validateICalendar(&$data, $path, &$modified, RequestInterface $request, ResponseInterface $response, $isNew) { // If it's a stream, we convert it to a string first. if (is_resource($data)) { $data = stream_get_contents($data); } $before = $data; try { // If the data starts with a [, we can reasonably assume we're dealing // with a jCal object. if ('[' === substr($data, 0, 1)) { $vobj = VObject\Reader::readJson($data); // Converting $data back to iCalendar, as that's what we // technically support everywhere. $data = $vobj->serialize(); $modified = true; } else { $vobj = VObject\Reader::read($data); } } catch (VObject\ParseException $e) { throw new DAV\Exception\UnsupportedMediaType('This resource only supports valid iCalendar 2.0 data. Parse error: '.$e->getMessage()); } if ('VCALENDAR' !== $vobj->name) { throw new DAV\Exception\UnsupportedMediaType('This collection can only support iCalendar objects.'); } $sCCS = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; // Get the Supported Components for the target calendar list($parentPath) = Uri\split($path); $calendarProperties = $this->server->getProperties($parentPath, [$sCCS]); if (isset($calendarProperties[$sCCS])) { $supportedComponents = $calendarProperties[$sCCS]->getValue(); } else { $supportedComponents = ['VJOURNAL', 'VTODO', 'VEVENT']; } $foundType = null; foreach ($vobj->getComponents() as $component) { switch ($component->name) { case 'VTIMEZONE': continue 2; case 'VEVENT': case 'VTODO': case 'VJOURNAL': $foundType = $component->name; break; } } if (!$foundType || !in_array($foundType, $supportedComponents)) { throw new Exception\InvalidComponentType('iCalendar objects must at least have a component of type '.implode(', ', $supportedComponents)); } $options = VObject\Node::PROFILE_CALDAV; $prefer = $this->server->getHTTPPrefer(); if ('strict' !== $prefer['handling']) { $options |= VObject\Node::REPAIR; } $messages = $vobj->validate($options); $highestLevel = 0; $warningMessage = null; // $messages contains a list of problems with the vcard, along with // their severity. foreach ($messages as $message) { if ($message['level'] > $highestLevel) { // Recording the highest reported error level. $highestLevel = $message['level']; $warningMessage = $message['message']; } switch ($message['level']) { case 1: // Level 1 means that there was a problem, but it was repaired. $modified = true; break; case 2: // Level 2 means a warning, but not critical break; case 3: // Level 3 means a critical error throw new DAV\Exception\UnsupportedMediaType('Validation error in iCalendar: '.$message['message']); } } if ($warningMessage) { $response->setHeader( 'X-Sabre-Ew-Gross', 'iCalendar validation warning: '.$warningMessage ); } // We use an extra variable to allow event handles to tell us whether // the object was modified or not. // // This helps us determine if we need to re-serialize the object. $subModified = false; $this->server->emit( 'calendarObjectChange', [ $request, $response, $vobj, $parentPath, &$subModified, $isNew, ] ); if ($modified || $subModified) { // An event handler told us that it modified the object. $data = $vobj->serialize(); // Using md5 to figure out if there was an *actual* change. if (!$modified && 0 !== strcmp($data, $before)) { $modified = true; } } // Destroy circular references so PHP will garbage collect the object. $vobj->destroy(); }
php
protected function validateICalendar(&$data, $path, &$modified, RequestInterface $request, ResponseInterface $response, $isNew) { if (is_resource($data)) { $data = stream_get_contents($data); } $before = $data; try { if ('[' === substr($data, 0, 1)) { $vobj = VObject\Reader::readJson($data); $data = $vobj->serialize(); $modified = true; } else { $vobj = VObject\Reader::read($data); } } catch (VObject\ParseException $e) { throw new DAV\Exception\UnsupportedMediaType('This resource only supports valid iCalendar 2.0 data. Parse error: '.$e->getMessage()); } if ('VCALENDAR' !== $vobj->name) { throw new DAV\Exception\UnsupportedMediaType('This collection can only support iCalendar objects.'); } $sCCS = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; list($parentPath) = Uri\split($path); $calendarProperties = $this->server->getProperties($parentPath, [$sCCS]); if (isset($calendarProperties[$sCCS])) { $supportedComponents = $calendarProperties[$sCCS]->getValue(); } else { $supportedComponents = ['VJOURNAL', 'VTODO', 'VEVENT']; } $foundType = null; foreach ($vobj->getComponents() as $component) { switch ($component->name) { case 'VTIMEZONE': continue 2; case 'VEVENT': case 'VTODO': case 'VJOURNAL': $foundType = $component->name; break; } } if (!$foundType || !in_array($foundType, $supportedComponents)) { throw new Exception\InvalidComponentType('iCalendar objects must at least have a component of type '.implode(', ', $supportedComponents)); } $options = VObject\Node::PROFILE_CALDAV; $prefer = $this->server->getHTTPPrefer(); if ('strict' !== $prefer['handling']) { $options |= VObject\Node::REPAIR; } $messages = $vobj->validate($options); $highestLevel = 0; $warningMessage = null; foreach ($messages as $message) { if ($message['level'] > $highestLevel) { $highestLevel = $message['level']; $warningMessage = $message['message']; } switch ($message['level']) { case 1: $modified = true; break; case 2: break; case 3: throw new DAV\Exception\UnsupportedMediaType('Validation error in iCalendar: '.$message['message']); } } if ($warningMessage) { $response->setHeader( 'X-Sabre-Ew-Gross', 'iCalendar validation warning: '.$warningMessage ); } $subModified = false; $this->server->emit( 'calendarObjectChange', [ $request, $response, $vobj, $parentPath, &$subModified, $isNew, ] ); if ($modified || $subModified) { $data = $vobj->serialize(); if (!$modified && 0 !== strcmp($data, $before)) { $modified = true; } } $vobj->destroy(); }
[ "protected", "function", "validateICalendar", "(", "&", "$", "data", ",", "$", "path", ",", "&", "$", "modified", ",", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ",", "$", "isNew", ")", "{", "// If it's a stream, we convert it to a string first.", "if", "(", "is_resource", "(", "$", "data", ")", ")", "{", "$", "data", "=", "stream_get_contents", "(", "$", "data", ")", ";", "}", "$", "before", "=", "$", "data", ";", "try", "{", "// If the data starts with a [, we can reasonably assume we're dealing", "// with a jCal object.", "if", "(", "'['", "===", "substr", "(", "$", "data", ",", "0", ",", "1", ")", ")", "{", "$", "vobj", "=", "VObject", "\\", "Reader", "::", "readJson", "(", "$", "data", ")", ";", "// Converting $data back to iCalendar, as that's what we", "// technically support everywhere.", "$", "data", "=", "$", "vobj", "->", "serialize", "(", ")", ";", "$", "modified", "=", "true", ";", "}", "else", "{", "$", "vobj", "=", "VObject", "\\", "Reader", "::", "read", "(", "$", "data", ")", ";", "}", "}", "catch", "(", "VObject", "\\", "ParseException", "$", "e", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "UnsupportedMediaType", "(", "'This resource only supports valid iCalendar 2.0 data. Parse error: '", ".", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "if", "(", "'VCALENDAR'", "!==", "$", "vobj", "->", "name", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "UnsupportedMediaType", "(", "'This collection can only support iCalendar objects.'", ")", ";", "}", "$", "sCCS", "=", "'{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'", ";", "// Get the Supported Components for the target calendar", "list", "(", "$", "parentPath", ")", "=", "Uri", "\\", "split", "(", "$", "path", ")", ";", "$", "calendarProperties", "=", "$", "this", "->", "server", "->", "getProperties", "(", "$", "parentPath", ",", "[", "$", "sCCS", "]", ")", ";", "if", "(", "isset", "(", "$", "calendarProperties", "[", "$", "sCCS", "]", ")", ")", "{", "$", "supportedComponents", "=", "$", "calendarProperties", "[", "$", "sCCS", "]", "->", "getValue", "(", ")", ";", "}", "else", "{", "$", "supportedComponents", "=", "[", "'VJOURNAL'", ",", "'VTODO'", ",", "'VEVENT'", "]", ";", "}", "$", "foundType", "=", "null", ";", "foreach", "(", "$", "vobj", "->", "getComponents", "(", ")", "as", "$", "component", ")", "{", "switch", "(", "$", "component", "->", "name", ")", "{", "case", "'VTIMEZONE'", ":", "continue", "2", ";", "case", "'VEVENT'", ":", "case", "'VTODO'", ":", "case", "'VJOURNAL'", ":", "$", "foundType", "=", "$", "component", "->", "name", ";", "break", ";", "}", "}", "if", "(", "!", "$", "foundType", "||", "!", "in_array", "(", "$", "foundType", ",", "$", "supportedComponents", ")", ")", "{", "throw", "new", "Exception", "\\", "InvalidComponentType", "(", "'iCalendar objects must at least have a component of type '", ".", "implode", "(", "', '", ",", "$", "supportedComponents", ")", ")", ";", "}", "$", "options", "=", "VObject", "\\", "Node", "::", "PROFILE_CALDAV", ";", "$", "prefer", "=", "$", "this", "->", "server", "->", "getHTTPPrefer", "(", ")", ";", "if", "(", "'strict'", "!==", "$", "prefer", "[", "'handling'", "]", ")", "{", "$", "options", "|=", "VObject", "\\", "Node", "::", "REPAIR", ";", "}", "$", "messages", "=", "$", "vobj", "->", "validate", "(", "$", "options", ")", ";", "$", "highestLevel", "=", "0", ";", "$", "warningMessage", "=", "null", ";", "// $messages contains a list of problems with the vcard, along with", "// their severity.", "foreach", "(", "$", "messages", "as", "$", "message", ")", "{", "if", "(", "$", "message", "[", "'level'", "]", ">", "$", "highestLevel", ")", "{", "// Recording the highest reported error level.", "$", "highestLevel", "=", "$", "message", "[", "'level'", "]", ";", "$", "warningMessage", "=", "$", "message", "[", "'message'", "]", ";", "}", "switch", "(", "$", "message", "[", "'level'", "]", ")", "{", "case", "1", ":", "// Level 1 means that there was a problem, but it was repaired.", "$", "modified", "=", "true", ";", "break", ";", "case", "2", ":", "// Level 2 means a warning, but not critical", "break", ";", "case", "3", ":", "// Level 3 means a critical error", "throw", "new", "DAV", "\\", "Exception", "\\", "UnsupportedMediaType", "(", "'Validation error in iCalendar: '", ".", "$", "message", "[", "'message'", "]", ")", ";", "}", "}", "if", "(", "$", "warningMessage", ")", "{", "$", "response", "->", "setHeader", "(", "'X-Sabre-Ew-Gross'", ",", "'iCalendar validation warning: '", ".", "$", "warningMessage", ")", ";", "}", "// We use an extra variable to allow event handles to tell us whether", "// the object was modified or not.", "//", "// This helps us determine if we need to re-serialize the object.", "$", "subModified", "=", "false", ";", "$", "this", "->", "server", "->", "emit", "(", "'calendarObjectChange'", ",", "[", "$", "request", ",", "$", "response", ",", "$", "vobj", ",", "$", "parentPath", ",", "&", "$", "subModified", ",", "$", "isNew", ",", "]", ")", ";", "if", "(", "$", "modified", "||", "$", "subModified", ")", "{", "// An event handler told us that it modified the object.", "$", "data", "=", "$", "vobj", "->", "serialize", "(", ")", ";", "// Using md5 to figure out if there was an *actual* change.", "if", "(", "!", "$", "modified", "&&", "0", "!==", "strcmp", "(", "$", "data", ",", "$", "before", ")", ")", "{", "$", "modified", "=", "true", ";", "}", "}", "// Destroy circular references so PHP will garbage collect the object.", "$", "vobj", "->", "destroy", "(", ")", ";", "}" ]
Checks if the submitted iCalendar data is in fact, valid. An exception is thrown if it's not. @param resource|string $data @param string $path @param bool $modified should be set to true, if this event handler changed &$data @param RequestInterface $request the http request @param ResponseInterface $response the http response @param bool $isNew is the item a new one, or an update
[ "Checks", "if", "the", "submitted", "iCalendar", "data", "is", "in", "fact", "valid", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Plugin.php#L791-L921
sabre-io/dav
lib/CalDAV/Plugin.php
Plugin.getSupportedPrivilegeSet
public function getSupportedPrivilegeSet(INode $node, array &$supportedPrivilegeSet) { if ($node instanceof ICalendar) { $supportedPrivilegeSet['{DAV:}read']['aggregates']['{'.self::NS_CALDAV.'}read-free-busy'] = [ 'abstract' => false, 'aggregates' => [], ]; } }
php
public function getSupportedPrivilegeSet(INode $node, array &$supportedPrivilegeSet) { if ($node instanceof ICalendar) { $supportedPrivilegeSet['{DAV:}read']['aggregates']['{'.self::NS_CALDAV.'}read-free-busy'] = [ 'abstract' => false, 'aggregates' => [], ]; } }
[ "public", "function", "getSupportedPrivilegeSet", "(", "INode", "$", "node", ",", "array", "&", "$", "supportedPrivilegeSet", ")", "{", "if", "(", "$", "node", "instanceof", "ICalendar", ")", "{", "$", "supportedPrivilegeSet", "[", "'{DAV:}read'", "]", "[", "'aggregates'", "]", "[", "'{'", ".", "self", "::", "NS_CALDAV", ".", "'}read-free-busy'", "]", "=", "[", "'abstract'", "=>", "false", ",", "'aggregates'", "=>", "[", "]", ",", "]", ";", "}", "}" ]
This method is triggered whenever a subsystem reqeuests the privileges that are supported on a particular node. @param INode $node @param array $supportedPrivilegeSet
[ "This", "method", "is", "triggered", "whenever", "a", "subsystem", "reqeuests", "the", "privileges", "that", "are", "supported", "on", "a", "particular", "node", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Plugin.php#L930-L938
sabre-io/dav
lib/CalDAV/Plugin.php
Plugin.htmlActionsPanel
public function htmlActionsPanel(DAV\INode $node, &$output) { if (!$node instanceof CalendarHome) { return; } $output .= '<tr><td colspan="2"><form method="post" action=""> <h3>Create new calendar</h3> <input type="hidden" name="sabreAction" value="mkcol" /> <input type="hidden" name="resourceType" value="{DAV:}collection,{'.self::NS_CALDAV.'}calendar" /> <label>Name (uri):</label> <input type="text" name="name" /><br /> <label>Display name:</label> <input type="text" name="{DAV:}displayname" /><br /> <input type="submit" value="create" /> </form> </td></tr>'; return false; }
php
public function htmlActionsPanel(DAV\INode $node, &$output) { if (!$node instanceof CalendarHome) { return; } $output .= '<tr><td colspan="2"><form method="post" action=""> <h3>Create new calendar</h3> <input type="hidden" name="sabreAction" value="mkcol" /> <input type="hidden" name="resourceType" value="{DAV:}collection,{'.self::NS_CALDAV.'}calendar" /> <label>Name (uri):</label> <input type="text" name="name" /><br /> <label>Display name:</label> <input type="text" name="{DAV:}displayname" /><br /> <input type="submit" value="create" /> </form> </td></tr>'; return false; }
[ "public", "function", "htmlActionsPanel", "(", "DAV", "\\", "INode", "$", "node", ",", "&", "$", "output", ")", "{", "if", "(", "!", "$", "node", "instanceof", "CalendarHome", ")", "{", "return", ";", "}", "$", "output", ".=", "'<tr><td colspan=\"2\"><form method=\"post\" action=\"\">\n <h3>Create new calendar</h3>\n <input type=\"hidden\" name=\"sabreAction\" value=\"mkcol\" />\n <input type=\"hidden\" name=\"resourceType\" value=\"{DAV:}collection,{'", ".", "self", "::", "NS_CALDAV", ".", "'}calendar\" />\n <label>Name (uri):</label> <input type=\"text\" name=\"name\" /><br />\n <label>Display name:</label> <input type=\"text\" name=\"{DAV:}displayname\" /><br />\n <input type=\"submit\" value=\"create\" />\n </form>\n </td></tr>'", ";", "return", "false", ";", "}" ]
This method is used to generate HTML output for the DAV\Browser\Plugin. This allows us to generate an interface users can use to create new calendars. @param DAV\INode $node @param string $output @return bool
[ "This", "method", "is", "used", "to", "generate", "HTML", "output", "for", "the", "DAV", "\\", "Browser", "\\", "Plugin", ".", "This", "allows", "us", "to", "generate", "an", "interface", "users", "can", "use", "to", "create", "new", "calendars", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Plugin.php#L950-L967
sabre-io/dav
lib/CalDAV/Plugin.php
Plugin.httpAfterGet
public function httpAfterGet(RequestInterface $request, ResponseInterface $response) { $contentType = $response->getHeader('Content-Type'); if (null === $contentType || false === strpos($contentType, 'text/calendar')) { return; } $result = HTTP\negotiateContentType( $request->getHeader('Accept'), ['text/calendar', 'application/calendar+json'] ); if ('application/calendar+json' !== $result) { // Do nothing return; } // Transforming. $vobj = VObject\Reader::read($response->getBody()); $jsonBody = json_encode($vobj->jsonSerialize()); $response->setBody($jsonBody); // Destroy circular references so PHP will garbage collect the object. $vobj->destroy(); $response->setHeader('Content-Type', 'application/calendar+json'); $response->setHeader('Content-Length', strlen($jsonBody)); }
php
public function httpAfterGet(RequestInterface $request, ResponseInterface $response) { $contentType = $response->getHeader('Content-Type'); if (null === $contentType || false === strpos($contentType, 'text/calendar')) { return; } $result = HTTP\negotiateContentType( $request->getHeader('Accept'), ['text/calendar', 'application/calendar+json'] ); if ('application/calendar+json' !== $result) { return; } $vobj = VObject\Reader::read($response->getBody()); $jsonBody = json_encode($vobj->jsonSerialize()); $response->setBody($jsonBody); $vobj->destroy(); $response->setHeader('Content-Type', 'application/calendar+json'); $response->setHeader('Content-Length', strlen($jsonBody)); }
[ "public", "function", "httpAfterGet", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "contentType", "=", "$", "response", "->", "getHeader", "(", "'Content-Type'", ")", ";", "if", "(", "null", "===", "$", "contentType", "||", "false", "===", "strpos", "(", "$", "contentType", ",", "'text/calendar'", ")", ")", "{", "return", ";", "}", "$", "result", "=", "HTTP", "\\", "negotiateContentType", "(", "$", "request", "->", "getHeader", "(", "'Accept'", ")", ",", "[", "'text/calendar'", ",", "'application/calendar+json'", "]", ")", ";", "if", "(", "'application/calendar+json'", "!==", "$", "result", ")", "{", "// Do nothing", "return", ";", "}", "// Transforming.", "$", "vobj", "=", "VObject", "\\", "Reader", "::", "read", "(", "$", "response", "->", "getBody", "(", ")", ")", ";", "$", "jsonBody", "=", "json_encode", "(", "$", "vobj", "->", "jsonSerialize", "(", ")", ")", ";", "$", "response", "->", "setBody", "(", "$", "jsonBody", ")", ";", "// Destroy circular references so PHP will garbage collect the object.", "$", "vobj", "->", "destroy", "(", ")", ";", "$", "response", "->", "setHeader", "(", "'Content-Type'", ",", "'application/calendar+json'", ")", ";", "$", "response", "->", "setHeader", "(", "'Content-Length'", ",", "strlen", "(", "$", "jsonBody", ")", ")", ";", "}" ]
This event is triggered after GET requests. This is used to transform data into jCal, if this was requested. @param RequestInterface $request @param ResponseInterface $response
[ "This", "event", "is", "triggered", "after", "GET", "requests", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Plugin.php#L977-L1005
sabre-io/dav
lib/DAV/Xml/Property/SupportedLock.php
SupportedLock.xmlSerialize
public function xmlSerialize(Writer $writer) { $writer->writeElement('{DAV:}lockentry', [ '{DAV:}lockscope' => ['{DAV:}exclusive' => null], '{DAV:}locktype' => ['{DAV:}write' => null], ]); $writer->writeElement('{DAV:}lockentry', [ '{DAV:}lockscope' => ['{DAV:}shared' => null], '{DAV:}locktype' => ['{DAV:}write' => null], ]); }
php
public function xmlSerialize(Writer $writer) { $writer->writeElement('{DAV:}lockentry', [ '{DAV:}lockscope' => ['{DAV:}exclusive' => null], '{DAV:}locktype' => ['{DAV:}write' => null], ]); $writer->writeElement('{DAV:}lockentry', [ '{DAV:}lockscope' => ['{DAV:}shared' => null], '{DAV:}locktype' => ['{DAV:}write' => null], ]); }
[ "public", "function", "xmlSerialize", "(", "Writer", "$", "writer", ")", "{", "$", "writer", "->", "writeElement", "(", "'{DAV:}lockentry'", ",", "[", "'{DAV:}lockscope'", "=>", "[", "'{DAV:}exclusive'", "=>", "null", "]", ",", "'{DAV:}locktype'", "=>", "[", "'{DAV:}write'", "=>", "null", "]", ",", "]", ")", ";", "$", "writer", "->", "writeElement", "(", "'{DAV:}lockentry'", ",", "[", "'{DAV:}lockscope'", "=>", "[", "'{DAV:}shared'", "=>", "null", "]", ",", "'{DAV:}locktype'", "=>", "[", "'{DAV:}write'", "=>", "null", "]", ",", "]", ")", ";", "}" ]
The xmlSerialize method is called during xml writing. Use the $writer argument to write its own xml serialization. An important note: do _not_ create a parent element. Any element implementing XmlSerializable should only ever write what's considered its 'inner xml'. The parent of the current element is responsible for writing a containing element. This allows serializers to be re-used for different element names. If you are opening new elements, you must also close them again. @param Writer $writer
[ "The", "xmlSerialize", "method", "is", "called", "during", "xml", "writing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Property/SupportedLock.php#L43-L53
sabre-io/dav
lib/CalDAV/Xml/Property/ScheduleCalendarTransp.php
ScheduleCalendarTransp.xmlSerialize
public function xmlSerialize(Writer $writer) { switch ($this->value) { case self::TRANSPARENT: $writer->writeElement('{'.Plugin::NS_CALDAV.'}transparent'); break; case self::OPAQUE: $writer->writeElement('{'.Plugin::NS_CALDAV.'}opaque'); break; } }
php
public function xmlSerialize(Writer $writer) { switch ($this->value) { case self::TRANSPARENT: $writer->writeElement('{'.Plugin::NS_CALDAV.'}transparent'); break; case self::OPAQUE: $writer->writeElement('{'.Plugin::NS_CALDAV.'}opaque'); break; } }
[ "public", "function", "xmlSerialize", "(", "Writer", "$", "writer", ")", "{", "switch", "(", "$", "this", "->", "value", ")", "{", "case", "self", "::", "TRANSPARENT", ":", "$", "writer", "->", "writeElement", "(", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}transparent'", ")", ";", "break", ";", "case", "self", "::", "OPAQUE", ":", "$", "writer", "->", "writeElement", "(", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}opaque'", ")", ";", "break", ";", "}", "}" ]
The xmlSerialize method is called during xml writing. Use the $writer argument to write its own xml serialization. An important note: do _not_ create a parent element. Any element implementing XmlSerializable should only ever write what's considered its 'inner xml'. The parent of the current element is responsible for writing a containing element. This allows serializers to be re-used for different element names. If you are opening new elements, you must also close them again. @param Writer $writer
[ "The", "xmlSerialize", "method", "is", "called", "during", "xml", "writing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Xml/Property/ScheduleCalendarTransp.php#L82-L92
sabre-io/dav
lib/CalDAV/Xml/Property/ScheduleCalendarTransp.php
ScheduleCalendarTransp.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { $elems = Deserializer\enum($reader, Plugin::NS_CALDAV); if (in_array('transparent', $elems)) { $value = self::TRANSPARENT; } else { $value = self::OPAQUE; } return new self($value); }
php
public static function xmlDeserialize(Reader $reader) { $elems = Deserializer\enum($reader, Plugin::NS_CALDAV); if (in_array('transparent', $elems)) { $value = self::TRANSPARENT; } else { $value = self::OPAQUE; } return new self($value); }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "$", "elems", "=", "Deserializer", "\\", "enum", "(", "$", "reader", ",", "Plugin", "::", "NS_CALDAV", ")", ";", "if", "(", "in_array", "(", "'transparent'", ",", "$", "elems", ")", ")", "{", "$", "value", "=", "self", "::", "TRANSPARENT", ";", "}", "else", "{", "$", "value", "=", "self", "::", "OPAQUE", ";", "}", "return", "new", "self", "(", "$", "value", ")", ";", "}" ]
The deserialize method is called during xml parsing. This method is called statically, this is because in theory this method may be used as a type of constructor, or factory method. Often you want to return an instance of the current class, but you are free to return other data as well. You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop. If you just want to skip parsing for this element altogether, you can just call $reader->next(); $reader->parseInnerTree() will parse the entire sub-tree, and advance to the next element. @param Reader $reader @return mixed
[ "The", "deserialize", "method", "is", "called", "during", "xml", "parsing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Xml/Property/ScheduleCalendarTransp.php#L116-L127
sabre-io/dav
lib/DAV/Xml/Property/LockDiscovery.php
LockDiscovery.xmlSerialize
public function xmlSerialize(Writer $writer) { foreach ($this->locks as $lock) { $writer->startElement('{DAV:}activelock'); $writer->startElement('{DAV:}lockscope'); if (LockInfo::SHARED === $lock->scope) { $writer->writeElement('{DAV:}shared'); } else { $writer->writeElement('{DAV:}exclusive'); } $writer->endElement(); // {DAV:}lockscope $writer->startElement('{DAV:}locktype'); $writer->writeElement('{DAV:}write'); $writer->endElement(); // {DAV:}locktype if (!self::$hideLockRoot) { $writer->startElement('{DAV:}lockroot'); $writer->writeElement('{DAV:}href', $writer->contextUri.$lock->uri); $writer->endElement(); // {DAV:}lockroot } $writer->writeElement('{DAV:}depth', (DAV\Server::DEPTH_INFINITY == $lock->depth ? 'infinity' : $lock->depth)); $writer->writeElement('{DAV:}timeout', (LockInfo::TIMEOUT_INFINITE === $lock->timeout ? 'Infinite' : 'Second-'.$lock->timeout)); // optional according to https://tools.ietf.org/html/rfc4918#section-6.5 if (null !== $lock->token && '' !== $lock->token) { $writer->startElement('{DAV:}locktoken'); $writer->writeElement('{DAV:}href', 'opaquelocktoken:'.$lock->token); $writer->endElement(); // {DAV:}locktoken } if ($lock->owner) { $writer->writeElement('{DAV:}owner', new XmlFragment($lock->owner)); } $writer->endElement(); // {DAV:}activelock } }
php
public function xmlSerialize(Writer $writer) { foreach ($this->locks as $lock) { $writer->startElement('{DAV:}activelock'); $writer->startElement('{DAV:}lockscope'); if (LockInfo::SHARED === $lock->scope) { $writer->writeElement('{DAV:}shared'); } else { $writer->writeElement('{DAV:}exclusive'); } $writer->endElement(); $writer->startElement('{DAV:}locktype'); $writer->writeElement('{DAV:}write'); $writer->endElement(); if (!self::$hideLockRoot) { $writer->startElement('{DAV:}lockroot'); $writer->writeElement('{DAV:}href', $writer->contextUri.$lock->uri); $writer->endElement(); } $writer->writeElement('{DAV:}depth', (DAV\Server::DEPTH_INFINITY == $lock->depth ? 'infinity' : $lock->depth)); $writer->writeElement('{DAV:}timeout', (LockInfo::TIMEOUT_INFINITE === $lock->timeout ? 'Infinite' : 'Second-'.$lock->timeout)); if (null !== $lock->token && '' !== $lock->token) { $writer->startElement('{DAV:}locktoken'); $writer->writeElement('{DAV:}href', 'opaquelocktoken:'.$lock->token); $writer->endElement(); } if ($lock->owner) { $writer->writeElement('{DAV:}owner', new XmlFragment($lock->owner)); } $writer->endElement(); } }
[ "public", "function", "xmlSerialize", "(", "Writer", "$", "writer", ")", "{", "foreach", "(", "$", "this", "->", "locks", "as", "$", "lock", ")", "{", "$", "writer", "->", "startElement", "(", "'{DAV:}activelock'", ")", ";", "$", "writer", "->", "startElement", "(", "'{DAV:}lockscope'", ")", ";", "if", "(", "LockInfo", "::", "SHARED", "===", "$", "lock", "->", "scope", ")", "{", "$", "writer", "->", "writeElement", "(", "'{DAV:}shared'", ")", ";", "}", "else", "{", "$", "writer", "->", "writeElement", "(", "'{DAV:}exclusive'", ")", ";", "}", "$", "writer", "->", "endElement", "(", ")", ";", "// {DAV:}lockscope", "$", "writer", "->", "startElement", "(", "'{DAV:}locktype'", ")", ";", "$", "writer", "->", "writeElement", "(", "'{DAV:}write'", ")", ";", "$", "writer", "->", "endElement", "(", ")", ";", "// {DAV:}locktype", "if", "(", "!", "self", "::", "$", "hideLockRoot", ")", "{", "$", "writer", "->", "startElement", "(", "'{DAV:}lockroot'", ")", ";", "$", "writer", "->", "writeElement", "(", "'{DAV:}href'", ",", "$", "writer", "->", "contextUri", ".", "$", "lock", "->", "uri", ")", ";", "$", "writer", "->", "endElement", "(", ")", ";", "// {DAV:}lockroot", "}", "$", "writer", "->", "writeElement", "(", "'{DAV:}depth'", ",", "(", "DAV", "\\", "Server", "::", "DEPTH_INFINITY", "==", "$", "lock", "->", "depth", "?", "'infinity'", ":", "$", "lock", "->", "depth", ")", ")", ";", "$", "writer", "->", "writeElement", "(", "'{DAV:}timeout'", ",", "(", "LockInfo", "::", "TIMEOUT_INFINITE", "===", "$", "lock", "->", "timeout", "?", "'Infinite'", ":", "'Second-'", ".", "$", "lock", "->", "timeout", ")", ")", ";", "// optional according to https://tools.ietf.org/html/rfc4918#section-6.5", "if", "(", "null", "!==", "$", "lock", "->", "token", "&&", "''", "!==", "$", "lock", "->", "token", ")", "{", "$", "writer", "->", "startElement", "(", "'{DAV:}locktoken'", ")", ";", "$", "writer", "->", "writeElement", "(", "'{DAV:}href'", ",", "'opaquelocktoken:'", ".", "$", "lock", "->", "token", ")", ";", "$", "writer", "->", "endElement", "(", ")", ";", "// {DAV:}locktoken", "}", "if", "(", "$", "lock", "->", "owner", ")", "{", "$", "writer", "->", "writeElement", "(", "'{DAV:}owner'", ",", "new", "XmlFragment", "(", "$", "lock", "->", "owner", ")", ")", ";", "}", "$", "writer", "->", "endElement", "(", ")", ";", "// {DAV:}activelock", "}", "}" ]
The serialize method is called during xml writing. It should use the $writer argument to encode this object into XML. Important note: it is not needed to create the parent element. The parent element is already created, and we only have to worry about attributes, child elements and text (if any). Important note 2: If you are writing any new elements, you are also responsible for closing them. @param Writer $writer
[ "The", "serialize", "method", "is", "called", "during", "xml", "writing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Property/LockDiscovery.php#L68-L106
sabre-io/dav
lib/CalDAV/Backend/AbstractBackend.php
AbstractBackend.getMultipleCalendarObjects
public function getMultipleCalendarObjects($calendarId, array $uris) { return array_map(function ($uri) use ($calendarId) { return $this->getCalendarObject($calendarId, $uri); }, $uris); }
php
public function getMultipleCalendarObjects($calendarId, array $uris) { return array_map(function ($uri) use ($calendarId) { return $this->getCalendarObject($calendarId, $uri); }, $uris); }
[ "public", "function", "getMultipleCalendarObjects", "(", "$", "calendarId", ",", "array", "$", "uris", ")", "{", "return", "array_map", "(", "function", "(", "$", "uri", ")", "use", "(", "$", "calendarId", ")", "{", "return", "$", "this", "->", "getCalendarObject", "(", "$", "calendarId", ",", "$", "uri", ")", ";", "}", ",", "$", "uris", ")", ";", "}" ]
Returns a list of calendar objects. This method should work identical to getCalendarObject, but instead return all the calendar objects in the list as an array. If the backend supports this, it may allow for some speed-ups. @param mixed $calendarId @param array $uris @return array
[ "Returns", "a", "list", "of", "calendar", "objects", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/AbstractBackend.php#L53-L58
sabre-io/dav
lib/CalDAV/Backend/AbstractBackend.php
AbstractBackend.calendarQuery
public function calendarQuery($calendarId, array $filters) { $result = []; $objects = $this->getCalendarObjects($calendarId); foreach ($objects as $object) { if ($this->validateFilterForObject($object, $filters)) { $result[] = $object['uri']; } } return $result; }
php
public function calendarQuery($calendarId, array $filters) { $result = []; $objects = $this->getCalendarObjects($calendarId); foreach ($objects as $object) { if ($this->validateFilterForObject($object, $filters)) { $result[] = $object['uri']; } } return $result; }
[ "public", "function", "calendarQuery", "(", "$", "calendarId", ",", "array", "$", "filters", ")", "{", "$", "result", "=", "[", "]", ";", "$", "objects", "=", "$", "this", "->", "getCalendarObjects", "(", "$", "calendarId", ")", ";", "foreach", "(", "$", "objects", "as", "$", "object", ")", "{", "if", "(", "$", "this", "->", "validateFilterForObject", "(", "$", "object", ",", "$", "filters", ")", ")", "{", "$", "result", "[", "]", "=", "$", "object", "[", "'uri'", "]", ";", "}", "}", "return", "$", "result", ";", "}" ]
Performs a calendar-query on the contents of this calendar. The calendar-query is defined in RFC4791 : CalDAV. Using the calendar-query it is possible for a client to request a specific set of object, based on contents of iCalendar properties, date-ranges and iCalendar component types (VTODO, VEVENT). This method should just return a list of (relative) urls that match this query. The list of filters are specified as an array. The exact array is documented by \Sabre\CalDAV\CalendarQueryParser. Note that it is extremely likely that getCalendarObject for every path returned from this method will be called almost immediately after. You may want to anticipate this to speed up these requests. This method provides a default implementation, which parses *all* the iCalendar objects in the specified calendar. This default may well be good enough for personal use, and calendars that aren't very large. But if you anticipate high usage, big calendars or high loads, you are strongly adviced to optimize certain paths. The best way to do so is override this method and to optimize specifically for 'common filters'. Requests that are extremely common are: * requests for just VEVENTS * requests for just VTODO * requests with a time-range-filter on either VEVENT or VTODO. ..and combinations of these requests. It may not be worth it to try to handle every possible situation and just rely on the (relatively easy to use) CalendarQueryValidator to handle the rest. Note that especially time-range-filters may be difficult to parse. A time-range filter specified on a VEVENT must for instance also handle recurrence rules correctly. A good example of how to interprete all these filters can also simply be found in \Sabre\CalDAV\CalendarQueryFilter. This class is as correct as possible, so it gives you a good idea on what type of stuff you need to think of. @param mixed $calendarId @param array $filters @return array
[ "Performs", "a", "calendar", "-", "query", "on", "the", "contents", "of", "this", "calendar", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/AbstractBackend.php#L110-L122
sabre-io/dav
lib/CalDAV/Backend/AbstractBackend.php
AbstractBackend.validateFilterForObject
protected function validateFilterForObject(array $object, array $filters) { // Unfortunately, setting the 'calendardata' here is optional. If // it was excluded, we actually need another call to get this as // well. if (!isset($object['calendardata'])) { $object = $this->getCalendarObject($object['calendarid'], $object['uri']); } $vObject = VObject\Reader::read($object['calendardata']); $validator = new CalDAV\CalendarQueryValidator(); $result = $validator->validate($vObject, $filters); // Destroy circular references so PHP will GC the object. $vObject->destroy(); return $result; }
php
protected function validateFilterForObject(array $object, array $filters) { if (!isset($object['calendardata'])) { $object = $this->getCalendarObject($object['calendarid'], $object['uri']); } $vObject = VObject\Reader::read($object['calendardata']); $validator = new CalDAV\CalendarQueryValidator(); $result = $validator->validate($vObject, $filters); $vObject->destroy(); return $result; }
[ "protected", "function", "validateFilterForObject", "(", "array", "$", "object", ",", "array", "$", "filters", ")", "{", "// Unfortunately, setting the 'calendardata' here is optional. If", "// it was excluded, we actually need another call to get this as", "// well.", "if", "(", "!", "isset", "(", "$", "object", "[", "'calendardata'", "]", ")", ")", "{", "$", "object", "=", "$", "this", "->", "getCalendarObject", "(", "$", "object", "[", "'calendarid'", "]", ",", "$", "object", "[", "'uri'", "]", ")", ";", "}", "$", "vObject", "=", "VObject", "\\", "Reader", "::", "read", "(", "$", "object", "[", "'calendardata'", "]", ")", ";", "$", "validator", "=", "new", "CalDAV", "\\", "CalendarQueryValidator", "(", ")", ";", "$", "result", "=", "$", "validator", "->", "validate", "(", "$", "vObject", ",", "$", "filters", ")", ";", "// Destroy circular references so PHP will GC the object.", "$", "vObject", "->", "destroy", "(", ")", ";", "return", "$", "result", ";", "}" ]
This method validates if a filter (as passed to calendarQuery) matches the given object. @param array $object @param array $filters @return bool
[ "This", "method", "validates", "if", "a", "filter", "(", "as", "passed", "to", "calendarQuery", ")", "matches", "the", "given", "object", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/AbstractBackend.php#L133-L151
sabre-io/dav
lib/CalDAV/Backend/AbstractBackend.php
AbstractBackend.getCalendarObjectByUID
public function getCalendarObjectByUID($principalUri, $uid) { // Note: this is a super slow naive implementation of this method. You // are highly recommended to optimize it, if your backend allows it. foreach ($this->getCalendarsForUser($principalUri) as $calendar) { // We must ignore calendars owned by other principals. if ($calendar['principaluri'] !== $principalUri) { continue; } // Ignore calendars that are shared. if (isset($calendar['{http://sabredav.org/ns}owner-principal']) && $calendar['{http://sabredav.org/ns}owner-principal'] !== $principalUri) { continue; } $results = $this->calendarQuery( $calendar['id'], [ 'name' => 'VCALENDAR', 'prop-filters' => [], 'comp-filters' => [ [ 'name' => 'VEVENT', 'is-not-defined' => false, 'time-range' => null, 'comp-filters' => [], 'prop-filters' => [ [ 'name' => 'UID', 'is-not-defined' => false, 'time-range' => null, 'text-match' => [ 'value' => $uid, 'negate-condition' => false, 'collation' => 'i;octet', ], 'param-filters' => [], ], ], ], ], ] ); if ($results) { // We have a match return $calendar['uri'].'/'.$results[0]; } } }
php
public function getCalendarObjectByUID($principalUri, $uid) { foreach ($this->getCalendarsForUser($principalUri) as $calendar) { if ($calendar['principaluri'] !== $principalUri) { continue; } if (isset($calendar['{http: continue; } $results = $this->calendarQuery( $calendar['id'], [ 'name' => 'VCALENDAR', 'prop-filters' => [], 'comp-filters' => [ [ 'name' => 'VEVENT', 'is-not-defined' => false, 'time-range' => null, 'comp-filters' => [], 'prop-filters' => [ [ 'name' => 'UID', 'is-not-defined' => false, 'time-range' => null, 'text-match' => [ 'value' => $uid, 'negate-condition' => false, 'collation' => 'i;octet', ], 'param-filters' => [], ], ], ], ], ] ); if ($results) { return $calendar['uri'].'/'.$results[0]; } } }
[ "public", "function", "getCalendarObjectByUID", "(", "$", "principalUri", ",", "$", "uid", ")", "{", "// Note: this is a super slow naive implementation of this method. You", "// are highly recommended to optimize it, if your backend allows it.", "foreach", "(", "$", "this", "->", "getCalendarsForUser", "(", "$", "principalUri", ")", "as", "$", "calendar", ")", "{", "// We must ignore calendars owned by other principals.", "if", "(", "$", "calendar", "[", "'principaluri'", "]", "!==", "$", "principalUri", ")", "{", "continue", ";", "}", "// Ignore calendars that are shared.", "if", "(", "isset", "(", "$", "calendar", "[", "'{http://sabredav.org/ns}owner-principal'", "]", ")", "&&", "$", "calendar", "[", "'{http://sabredav.org/ns}owner-principal'", "]", "!==", "$", "principalUri", ")", "{", "continue", ";", "}", "$", "results", "=", "$", "this", "->", "calendarQuery", "(", "$", "calendar", "[", "'id'", "]", ",", "[", "'name'", "=>", "'VCALENDAR'", ",", "'prop-filters'", "=>", "[", "]", ",", "'comp-filters'", "=>", "[", "[", "'name'", "=>", "'VEVENT'", ",", "'is-not-defined'", "=>", "false", ",", "'time-range'", "=>", "null", ",", "'comp-filters'", "=>", "[", "]", ",", "'prop-filters'", "=>", "[", "[", "'name'", "=>", "'UID'", ",", "'is-not-defined'", "=>", "false", ",", "'time-range'", "=>", "null", ",", "'text-match'", "=>", "[", "'value'", "=>", "$", "uid", ",", "'negate-condition'", "=>", "false", ",", "'collation'", "=>", "'i;octet'", ",", "]", ",", "'param-filters'", "=>", "[", "]", ",", "]", ",", "]", ",", "]", ",", "]", ",", "]", ")", ";", "if", "(", "$", "results", ")", "{", "// We have a match", "return", "$", "calendar", "[", "'uri'", "]", ".", "'/'", ".", "$", "results", "[", "0", "]", ";", "}", "}", "}" ]
Searches through all of a users calendars and calendar objects to find an object with a specific UID. This method should return the path to this object, relative to the calendar home, so this path usually only contains two parts: calendarpath/objectpath.ics If the uid is not found, return null. This method should only consider * objects that the principal owns, so any calendars owned by other principals that also appear in this collection should be ignored. @param string $principalUri @param string $uid @return string|null
[ "Searches", "through", "all", "of", "a", "users", "calendars", "and", "calendar", "objects", "to", "find", "an", "object", "with", "a", "specific", "UID", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/AbstractBackend.php#L173-L221
sabre-io/dav
lib/CalDAV/CalendarQueryValidator.php
CalendarQueryValidator.validate
public function validate(VObject\Component\VCalendar $vObject, array $filters) { // The top level object is always a component filter. // We'll parse it manually, as it's pretty simple. if ($vObject->name !== $filters['name']) { return false; } return $this->validateCompFilters($vObject, $filters['comp-filters']) && $this->validatePropFilters($vObject, $filters['prop-filters']); }
php
public function validate(VObject\Component\VCalendar $vObject, array $filters) { if ($vObject->name !== $filters['name']) { return false; } return $this->validateCompFilters($vObject, $filters['comp-filters']) && $this->validatePropFilters($vObject, $filters['prop-filters']); }
[ "public", "function", "validate", "(", "VObject", "\\", "Component", "\\", "VCalendar", "$", "vObject", ",", "array", "$", "filters", ")", "{", "// The top level object is always a component filter.", "// We'll parse it manually, as it's pretty simple.", "if", "(", "$", "vObject", "->", "name", "!==", "$", "filters", "[", "'name'", "]", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "validateCompFilters", "(", "$", "vObject", ",", "$", "filters", "[", "'comp-filters'", "]", ")", "&&", "$", "this", "->", "validatePropFilters", "(", "$", "vObject", ",", "$", "filters", "[", "'prop-filters'", "]", ")", ";", "}" ]
Verify if a list of filters applies to the calendar data object. The list of filters must be formatted as parsed by \Sabre\CalDAV\CalendarQueryParser @param VObject\Component\VCalendar $vObject @param array $filters @return bool
[ "Verify", "if", "a", "list", "of", "filters", "applies", "to", "the", "calendar", "data", "object", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/CalendarQueryValidator.php#L35-L46
sabre-io/dav
lib/CalDAV/CalendarQueryValidator.php
CalendarQueryValidator.validateCompFilters
protected function validateCompFilters(VObject\Component $parent, array $filters) { foreach ($filters as $filter) { $isDefined = isset($parent->{$filter['name']}); if ($filter['is-not-defined']) { if ($isDefined) { return false; } else { continue; } } if (!$isDefined) { return false; } if ($filter['time-range']) { foreach ($parent->{$filter['name']} as $subComponent) { if ($this->validateTimeRange($subComponent, $filter['time-range']['start'], $filter['time-range']['end'])) { continue 2; } } return false; } if (!$filter['comp-filters'] && !$filter['prop-filters']) { continue; } // If there are sub-filters, we need to find at least one component // for which the subfilters hold true. foreach ($parent->{$filter['name']} as $subComponent) { if ( $this->validateCompFilters($subComponent, $filter['comp-filters']) && $this->validatePropFilters($subComponent, $filter['prop-filters'])) { // We had a match, so this comp-filter succeeds continue 2; } } // If we got here it means there were sub-comp-filters or // sub-prop-filters and there was no match. This means this filter // needs to return false. return false; } // If we got here it means we got through all comp-filters alive so the // filters were all true. return true; }
php
protected function validateCompFilters(VObject\Component $parent, array $filters) { foreach ($filters as $filter) { $isDefined = isset($parent->{$filter['name']}); if ($filter['is-not-defined']) { if ($isDefined) { return false; } else { continue; } } if (!$isDefined) { return false; } if ($filter['time-range']) { foreach ($parent->{$filter['name']} as $subComponent) { if ($this->validateTimeRange($subComponent, $filter['time-range']['start'], $filter['time-range']['end'])) { continue 2; } } return false; } if (!$filter['comp-filters'] && !$filter['prop-filters']) { continue; } foreach ($parent->{$filter['name']} as $subComponent) { if ( $this->validateCompFilters($subComponent, $filter['comp-filters']) && $this->validatePropFilters($subComponent, $filter['prop-filters'])) { continue 2; } } return false; } return true; }
[ "protected", "function", "validateCompFilters", "(", "VObject", "\\", "Component", "$", "parent", ",", "array", "$", "filters", ")", "{", "foreach", "(", "$", "filters", "as", "$", "filter", ")", "{", "$", "isDefined", "=", "isset", "(", "$", "parent", "->", "{", "$", "filter", "[", "'name'", "]", "}", ")", ";", "if", "(", "$", "filter", "[", "'is-not-defined'", "]", ")", "{", "if", "(", "$", "isDefined", ")", "{", "return", "false", ";", "}", "else", "{", "continue", ";", "}", "}", "if", "(", "!", "$", "isDefined", ")", "{", "return", "false", ";", "}", "if", "(", "$", "filter", "[", "'time-range'", "]", ")", "{", "foreach", "(", "$", "parent", "->", "{", "$", "filter", "[", "'name'", "]", "}", "as", "$", "subComponent", ")", "{", "if", "(", "$", "this", "->", "validateTimeRange", "(", "$", "subComponent", ",", "$", "filter", "[", "'time-range'", "]", "[", "'start'", "]", ",", "$", "filter", "[", "'time-range'", "]", "[", "'end'", "]", ")", ")", "{", "continue", "2", ";", "}", "}", "return", "false", ";", "}", "if", "(", "!", "$", "filter", "[", "'comp-filters'", "]", "&&", "!", "$", "filter", "[", "'prop-filters'", "]", ")", "{", "continue", ";", "}", "// If there are sub-filters, we need to find at least one component", "// for which the subfilters hold true.", "foreach", "(", "$", "parent", "->", "{", "$", "filter", "[", "'name'", "]", "}", "as", "$", "subComponent", ")", "{", "if", "(", "$", "this", "->", "validateCompFilters", "(", "$", "subComponent", ",", "$", "filter", "[", "'comp-filters'", "]", ")", "&&", "$", "this", "->", "validatePropFilters", "(", "$", "subComponent", ",", "$", "filter", "[", "'prop-filters'", "]", ")", ")", "{", "// We had a match, so this comp-filter succeeds", "continue", "2", ";", "}", "}", "// If we got here it means there were sub-comp-filters or", "// sub-prop-filters and there was no match. This means this filter", "// needs to return false.", "return", "false", ";", "}", "// If we got here it means we got through all comp-filters alive so the", "// filters were all true.", "return", "true", ";", "}" ]
This method checks the validity of comp-filters. A list of comp-filters needs to be specified. Also the parent of the component we're checking should be specified, not the component to check itself. @param VObject\Component $parent @param array $filters @return bool
[ "This", "method", "checks", "the", "validity", "of", "comp", "-", "filters", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/CalendarQueryValidator.php#L60-L110
sabre-io/dav
lib/CalDAV/CalendarQueryValidator.php
CalendarQueryValidator.validateParamFilters
protected function validateParamFilters(VObject\Property $parent, array $filters) { foreach ($filters as $filter) { $isDefined = isset($parent[$filter['name']]); if ($filter['is-not-defined']) { if ($isDefined) { return false; } else { continue; } } if (!$isDefined) { return false; } if (!$filter['text-match']) { continue; } // If there are sub-filters, we need to find at least one parameter // for which the subfilters hold true. foreach ($parent[$filter['name']]->getParts() as $paramPart) { if ($this->validateTextMatch($paramPart, $filter['text-match'])) { // We had a match, so this param-filter succeeds continue 2; } } // If we got here it means there was a text-match filter and there // were no matches. This means the filter needs to return false. return false; } // If we got here it means we got through all param-filters alive so the // filters were all true. return true; }
php
protected function validateParamFilters(VObject\Property $parent, array $filters) { foreach ($filters as $filter) { $isDefined = isset($parent[$filter['name']]); if ($filter['is-not-defined']) { if ($isDefined) { return false; } else { continue; } } if (!$isDefined) { return false; } if (!$filter['text-match']) { continue; } foreach ($parent[$filter['name']]->getParts() as $paramPart) { if ($this->validateTextMatch($paramPart, $filter['text-match'])) { continue 2; } } return false; } return true; }
[ "protected", "function", "validateParamFilters", "(", "VObject", "\\", "Property", "$", "parent", ",", "array", "$", "filters", ")", "{", "foreach", "(", "$", "filters", "as", "$", "filter", ")", "{", "$", "isDefined", "=", "isset", "(", "$", "parent", "[", "$", "filter", "[", "'name'", "]", "]", ")", ";", "if", "(", "$", "filter", "[", "'is-not-defined'", "]", ")", "{", "if", "(", "$", "isDefined", ")", "{", "return", "false", ";", "}", "else", "{", "continue", ";", "}", "}", "if", "(", "!", "$", "isDefined", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "filter", "[", "'text-match'", "]", ")", "{", "continue", ";", "}", "// If there are sub-filters, we need to find at least one parameter", "// for which the subfilters hold true.", "foreach", "(", "$", "parent", "[", "$", "filter", "[", "'name'", "]", "]", "->", "getParts", "(", ")", "as", "$", "paramPart", ")", "{", "if", "(", "$", "this", "->", "validateTextMatch", "(", "$", "paramPart", ",", "$", "filter", "[", "'text-match'", "]", ")", ")", "{", "// We had a match, so this param-filter succeeds", "continue", "2", ";", "}", "}", "// If we got here it means there was a text-match filter and there", "// were no matches. This means the filter needs to return false.", "return", "false", ";", "}", "// If we got here it means we got through all param-filters alive so the", "// filters were all true.", "return", "true", ";", "}" ]
This method checks the validity of param-filters. A list of param-filters needs to be specified. Also the parent of the parameter we're checking should be specified, not the parameter to check itself. @param VObject\Property $parent @param array $filters @return bool
[ "This", "method", "checks", "the", "validity", "of", "param", "-", "filters", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/CalendarQueryValidator.php#L189-L226
sabre-io/dav
lib/CalDAV/CalendarQueryValidator.php
CalendarQueryValidator.validateTextMatch
protected function validateTextMatch($check, array $textMatch) { if ($check instanceof VObject\Node) { $check = $check->getValue(); } $isMatching = \Sabre\DAV\StringUtil::textMatch($check, $textMatch['value'], $textMatch['collation']); return $textMatch['negate-condition'] xor $isMatching; }
php
protected function validateTextMatch($check, array $textMatch) { if ($check instanceof VObject\Node) { $check = $check->getValue(); } $isMatching = \Sabre\DAV\StringUtil::textMatch($check, $textMatch['value'], $textMatch['collation']); return $textMatch['negate-condition'] xor $isMatching; }
[ "protected", "function", "validateTextMatch", "(", "$", "check", ",", "array", "$", "textMatch", ")", "{", "if", "(", "$", "check", "instanceof", "VObject", "\\", "Node", ")", "{", "$", "check", "=", "$", "check", "->", "getValue", "(", ")", ";", "}", "$", "isMatching", "=", "\\", "Sabre", "\\", "DAV", "\\", "StringUtil", "::", "textMatch", "(", "$", "check", ",", "$", "textMatch", "[", "'value'", "]", ",", "$", "textMatch", "[", "'collation'", "]", ")", ";", "return", "$", "textMatch", "[", "'negate-condition'", "]", "xor", "$", "isMatching", ";", "}" ]
This method checks the validity of a text-match. A single text-match should be specified as well as the specific property or parameter we need to validate. @param VObject\Node|string $check value to check against @param array $textMatch @return bool
[ "This", "method", "checks", "the", "validity", "of", "a", "text", "-", "match", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/CalendarQueryValidator.php#L239-L248
sabre-io/dav
lib/CalDAV/CalendarQueryValidator.php
CalendarQueryValidator.validateTimeRange
protected function validateTimeRange(VObject\Node $component, $start, $end) { if (is_null($start)) { $start = new DateTime('1900-01-01'); } if (is_null($end)) { $end = new DateTime('3000-01-01'); } switch ($component->name) { case 'VEVENT': case 'VTODO': case 'VJOURNAL': return $component->isInTimeRange($start, $end); case 'VALARM': // If the valarm is wrapped in a recurring event, we need to // expand the recursions, and validate each. // // Our datamodel doesn't easily allow us to do this straight // in the VALARM component code, so this is a hack, and an // expensive one too. if ('VEVENT' === $component->parent->name && $component->parent->RRULE) { // Fire up the iterator! $it = new VObject\Recur\EventIterator($component->parent->parent, (string) $component->parent->UID); while ($it->valid()) { $expandedEvent = $it->getEventObject(); // We need to check from these expanded alarms, which // one is the first to trigger. Based on this, we can // determine if we can 'give up' expanding events. $firstAlarm = null; if (null !== $expandedEvent->VALARM) { foreach ($expandedEvent->VALARM as $expandedAlarm) { $effectiveTrigger = $expandedAlarm->getEffectiveTriggerTime(); if ($expandedAlarm->isInTimeRange($start, $end)) { return true; } if ('DATE-TIME' === (string) $expandedAlarm->TRIGGER['VALUE']) { // This is an alarm with a non-relative trigger // time, likely created by a buggy client. The // implication is that every alarm in this // recurring event trigger at the exact same // time. It doesn't make sense to traverse // further. } else { // We store the first alarm as a means to // figure out when we can stop traversing. if (!$firstAlarm || $effectiveTrigger < $firstAlarm) { $firstAlarm = $effectiveTrigger; } } } } if (is_null($firstAlarm)) { // No alarm was found. // // Or technically: No alarm that will change for // every instance of the recurrence was found, // which means we can assume there was no match. return false; } if ($firstAlarm > $end) { return false; } $it->next(); } return false; } else { return $component->isInTimeRange($start, $end); } // no break case 'VFREEBUSY': throw new \Sabre\DAV\Exception\NotImplemented('time-range filters are currently not supported on '.$component->name.' components'); case 'COMPLETED': case 'CREATED': case 'DTEND': case 'DTSTAMP': case 'DTSTART': case 'DUE': case 'LAST-MODIFIED': return $start <= $component->getDateTime() && $end >= $component->getDateTime(); default: throw new \Sabre\DAV\Exception\BadRequest('You cannot create a time-range filter on a '.$component->name.' component'); } }
php
protected function validateTimeRange(VObject\Node $component, $start, $end) { if (is_null($start)) { $start = new DateTime('1900-01-01'); } if (is_null($end)) { $end = new DateTime('3000-01-01'); } switch ($component->name) { case 'VEVENT': case 'VTODO': case 'VJOURNAL': return $component->isInTimeRange($start, $end); case 'VALARM': if ('VEVENT' === $component->parent->name && $component->parent->RRULE) { $it = new VObject\Recur\EventIterator($component->parent->parent, (string) $component->parent->UID); while ($it->valid()) { $expandedEvent = $it->getEventObject(); $firstAlarm = null; if (null !== $expandedEvent->VALARM) { foreach ($expandedEvent->VALARM as $expandedAlarm) { $effectiveTrigger = $expandedAlarm->getEffectiveTriggerTime(); if ($expandedAlarm->isInTimeRange($start, $end)) { return true; } if ('DATE-TIME' === (string) $expandedAlarm->TRIGGER['VALUE']) { } else { if (!$firstAlarm || $effectiveTrigger < $firstAlarm) { $firstAlarm = $effectiveTrigger; } } } } if (is_null($firstAlarm)) { return false; } if ($firstAlarm > $end) { return false; } $it->next(); } return false; } else { return $component->isInTimeRange($start, $end); } case 'VFREEBUSY': throw new \Sabre\DAV\Exception\NotImplemented('time-range filters are currently not supported on '.$component->name.' components'); case 'COMPLETED': case 'CREATED': case 'DTEND': case 'DTSTAMP': case 'DTSTART': case 'DUE': case 'LAST-MODIFIED': return $start <= $component->getDateTime() && $end >= $component->getDateTime(); default: throw new \Sabre\DAV\Exception\BadRequest('You cannot create a time-range filter on a '.$component->name.' component'); } }
[ "protected", "function", "validateTimeRange", "(", "VObject", "\\", "Node", "$", "component", ",", "$", "start", ",", "$", "end", ")", "{", "if", "(", "is_null", "(", "$", "start", ")", ")", "{", "$", "start", "=", "new", "DateTime", "(", "'1900-01-01'", ")", ";", "}", "if", "(", "is_null", "(", "$", "end", ")", ")", "{", "$", "end", "=", "new", "DateTime", "(", "'3000-01-01'", ")", ";", "}", "switch", "(", "$", "component", "->", "name", ")", "{", "case", "'VEVENT'", ":", "case", "'VTODO'", ":", "case", "'VJOURNAL'", ":", "return", "$", "component", "->", "isInTimeRange", "(", "$", "start", ",", "$", "end", ")", ";", "case", "'VALARM'", ":", "// If the valarm is wrapped in a recurring event, we need to", "// expand the recursions, and validate each.", "//", "// Our datamodel doesn't easily allow us to do this straight", "// in the VALARM component code, so this is a hack, and an", "// expensive one too.", "if", "(", "'VEVENT'", "===", "$", "component", "->", "parent", "->", "name", "&&", "$", "component", "->", "parent", "->", "RRULE", ")", "{", "// Fire up the iterator!", "$", "it", "=", "new", "VObject", "\\", "Recur", "\\", "EventIterator", "(", "$", "component", "->", "parent", "->", "parent", ",", "(", "string", ")", "$", "component", "->", "parent", "->", "UID", ")", ";", "while", "(", "$", "it", "->", "valid", "(", ")", ")", "{", "$", "expandedEvent", "=", "$", "it", "->", "getEventObject", "(", ")", ";", "// We need to check from these expanded alarms, which", "// one is the first to trigger. Based on this, we can", "// determine if we can 'give up' expanding events.", "$", "firstAlarm", "=", "null", ";", "if", "(", "null", "!==", "$", "expandedEvent", "->", "VALARM", ")", "{", "foreach", "(", "$", "expandedEvent", "->", "VALARM", "as", "$", "expandedAlarm", ")", "{", "$", "effectiveTrigger", "=", "$", "expandedAlarm", "->", "getEffectiveTriggerTime", "(", ")", ";", "if", "(", "$", "expandedAlarm", "->", "isInTimeRange", "(", "$", "start", ",", "$", "end", ")", ")", "{", "return", "true", ";", "}", "if", "(", "'DATE-TIME'", "===", "(", "string", ")", "$", "expandedAlarm", "->", "TRIGGER", "[", "'VALUE'", "]", ")", "{", "// This is an alarm with a non-relative trigger", "// time, likely created by a buggy client. The", "// implication is that every alarm in this", "// recurring event trigger at the exact same", "// time. It doesn't make sense to traverse", "// further.", "}", "else", "{", "// We store the first alarm as a means to", "// figure out when we can stop traversing.", "if", "(", "!", "$", "firstAlarm", "||", "$", "effectiveTrigger", "<", "$", "firstAlarm", ")", "{", "$", "firstAlarm", "=", "$", "effectiveTrigger", ";", "}", "}", "}", "}", "if", "(", "is_null", "(", "$", "firstAlarm", ")", ")", "{", "// No alarm was found.", "//", "// Or technically: No alarm that will change for", "// every instance of the recurrence was found,", "// which means we can assume there was no match.", "return", "false", ";", "}", "if", "(", "$", "firstAlarm", ">", "$", "end", ")", "{", "return", "false", ";", "}", "$", "it", "->", "next", "(", ")", ";", "}", "return", "false", ";", "}", "else", "{", "return", "$", "component", "->", "isInTimeRange", "(", "$", "start", ",", "$", "end", ")", ";", "}", "// no break", "case", "'VFREEBUSY'", ":", "throw", "new", "\\", "Sabre", "\\", "DAV", "\\", "Exception", "\\", "NotImplemented", "(", "'time-range filters are currently not supported on '", ".", "$", "component", "->", "name", ".", "' components'", ")", ";", "case", "'COMPLETED'", ":", "case", "'CREATED'", ":", "case", "'DTEND'", ":", "case", "'DTSTAMP'", ":", "case", "'DTSTART'", ":", "case", "'DUE'", ":", "case", "'LAST-MODIFIED'", ":", "return", "$", "start", "<=", "$", "component", "->", "getDateTime", "(", ")", "&&", "$", "end", ">=", "$", "component", "->", "getDateTime", "(", ")", ";", "default", ":", "throw", "new", "\\", "Sabre", "\\", "DAV", "\\", "Exception", "\\", "BadRequest", "(", "'You cannot create a time-range filter on a '", ".", "$", "component", "->", "name", ".", "' component'", ")", ";", "}", "}" ]
Validates if a component matches the given time range. This is all based on the rules specified in rfc4791, which are quite complex. @param VObject\Node $component @param DateTime $start @param DateTime $end @return bool
[ "Validates", "if", "a", "component", "matches", "the", "given", "time", "range", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/CalendarQueryValidator.php#L262-L353
sabre-io/dav
lib/DAV/Browser/GuessContentType.php
GuessContentType.propFind
public function propFind(PropFind $propFind, INode $node) { $propFind->handle('{DAV:}getcontenttype', function () use ($propFind) { list(, $fileName) = Uri\split($propFind->getPath()); return $this->getContentType($fileName); }); }
php
public function propFind(PropFind $propFind, INode $node) { $propFind->handle('{DAV:}getcontenttype', function () use ($propFind) { list(, $fileName) = Uri\split($propFind->getPath()); return $this->getContentType($fileName); }); }
[ "public", "function", "propFind", "(", "PropFind", "$", "propFind", ",", "INode", "$", "node", ")", "{", "$", "propFind", "->", "handle", "(", "'{DAV:}getcontenttype'", ",", "function", "(", ")", "use", "(", "$", "propFind", ")", "{", "list", "(", ",", "$", "fileName", ")", "=", "Uri", "\\", "split", "(", "$", "propFind", "->", "getPath", "(", ")", ")", ";", "return", "$", "this", "->", "getContentType", "(", "$", "fileName", ")", ";", "}", ")", ";", "}" ]
Our PROPFIND handler. Here we set a contenttype, if the node didn't already have one. @param PropFind $propFind @param INode $node
[ "Our", "PROPFIND", "handler", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/GuessContentType.php#L70-L77
sabre-io/dav
lib/DAV/Browser/GuessContentType.php
GuessContentType.getContentType
protected function getContentType($fileName) { // Just grabbing the extension $extension = strtolower(substr($fileName, strrpos($fileName, '.') + 1)); if (isset($this->extensionMap[$extension])) { return $this->extensionMap[$extension]; } return 'application/octet-stream'; }
php
protected function getContentType($fileName) { $extension = strtolower(substr($fileName, strrpos($fileName, '.') + 1)); if (isset($this->extensionMap[$extension])) { return $this->extensionMap[$extension]; } return 'application/octet-stream'; }
[ "protected", "function", "getContentType", "(", "$", "fileName", ")", "{", "// Just grabbing the extension", "$", "extension", "=", "strtolower", "(", "substr", "(", "$", "fileName", ",", "strrpos", "(", "$", "fileName", ",", "'.'", ")", "+", "1", ")", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "extensionMap", "[", "$", "extension", "]", ")", ")", "{", "return", "$", "this", "->", "extensionMap", "[", "$", "extension", "]", ";", "}", "return", "'application/octet-stream'", ";", "}" ]
Simple method to return the contenttype. @param string $fileName @return string
[ "Simple", "method", "to", "return", "the", "contenttype", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/GuessContentType.php#L86-L95
sabre-io/dav
lib/CardDAV/Backend/AbstractBackend.php
AbstractBackend.getMultipleCards
public function getMultipleCards($addressBookId, array $uris) { return array_map(function ($uri) use ($addressBookId) { return $this->getCard($addressBookId, $uri); }, $uris); }
php
public function getMultipleCards($addressBookId, array $uris) { return array_map(function ($uri) use ($addressBookId) { return $this->getCard($addressBookId, $uri); }, $uris); }
[ "public", "function", "getMultipleCards", "(", "$", "addressBookId", ",", "array", "$", "uris", ")", "{", "return", "array_map", "(", "function", "(", "$", "uri", ")", "use", "(", "$", "addressBookId", ")", "{", "return", "$", "this", "->", "getCard", "(", "$", "addressBookId", ",", "$", "uri", ")", ";", "}", ",", "$", "uris", ")", ";", "}" ]
Returns a list of cards. This method should work identical to getCard, but instead return all the cards in the list as an array. If the backend supports this, it may allow for some speed-ups. @param mixed $addressBookId @param array $uris @return array
[ "Returns", "a", "list", "of", "cards", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/AbstractBackend.php#L33-L38
sabre-io/dav
lib/DAVACL/Xml/Property/Principal.php
Principal.xmlSerialize
public function xmlSerialize(Writer $writer) { switch ($this->type) { case self::UNAUTHENTICATED: $writer->writeElement('{DAV:}unauthenticated'); break; case self::AUTHENTICATED: $writer->writeElement('{DAV:}authenticated'); break; case self::HREF: parent::xmlSerialize($writer); break; case self::ALL: $writer->writeElement('{DAV:}all'); break; } }
php
public function xmlSerialize(Writer $writer) { switch ($this->type) { case self::UNAUTHENTICATED: $writer->writeElement('{DAV:}unauthenticated'); break; case self::AUTHENTICATED: $writer->writeElement('{DAV:}authenticated'); break; case self::HREF: parent::xmlSerialize($writer); break; case self::ALL: $writer->writeElement('{DAV:}all'); break; } }
[ "public", "function", "xmlSerialize", "(", "Writer", "$", "writer", ")", "{", "switch", "(", "$", "this", "->", "type", ")", "{", "case", "self", "::", "UNAUTHENTICATED", ":", "$", "writer", "->", "writeElement", "(", "'{DAV:}unauthenticated'", ")", ";", "break", ";", "case", "self", "::", "AUTHENTICATED", ":", "$", "writer", "->", "writeElement", "(", "'{DAV:}authenticated'", ")", ";", "break", ";", "case", "self", "::", "HREF", ":", "parent", "::", "xmlSerialize", "(", "$", "writer", ")", ";", "break", ";", "case", "self", "::", "ALL", ":", "$", "writer", "->", "writeElement", "(", "'{DAV:}all'", ")", ";", "break", ";", "}", "}" ]
The xmlSerialize method is called during xml writing. Use the $writer argument to write its own xml serialization. An important note: do _not_ create a parent element. Any element implementing XmlSerializable should only ever write what's considered its 'inner xml'. The parent of the current element is responsible for writing a containing element. This allows serializers to be re-used for different element names. If you are opening new elements, you must also close them again. @param Writer $writer
[ "The", "xmlSerialize", "method", "is", "called", "during", "xml", "writing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Xml/Property/Principal.php#L104-L120
sabre-io/dav
lib/DAVACL/Xml/Property/Principal.php
Principal.toHtml
public function toHtml(HtmlOutputHelper $html) { switch ($this->type) { case self::UNAUTHENTICATED: return '<em>unauthenticated</em>'; case self::AUTHENTICATED: return '<em>authenticated</em>'; case self::HREF: return parent::toHtml($html); case self::ALL: return '<em>all</em>'; } }
php
public function toHtml(HtmlOutputHelper $html) { switch ($this->type) { case self::UNAUTHENTICATED: return '<em>unauthenticated</em>'; case self::AUTHENTICATED: return '<em>authenticated</em>'; case self::HREF: return parent::toHtml($html); case self::ALL: return '<em>all</em>'; } }
[ "public", "function", "toHtml", "(", "HtmlOutputHelper", "$", "html", ")", "{", "switch", "(", "$", "this", "->", "type", ")", "{", "case", "self", "::", "UNAUTHENTICATED", ":", "return", "'<em>unauthenticated</em>'", ";", "case", "self", "::", "AUTHENTICATED", ":", "return", "'<em>authenticated</em>'", ";", "case", "self", "::", "HREF", ":", "return", "parent", "::", "toHtml", "(", "$", "html", ")", ";", "case", "self", "::", "ALL", ":", "return", "'<em>all</em>'", ";", "}", "}" ]
Generate html representation for this value. The html output is 100% trusted, and no effort is being made to sanitize it. It's up to the implementor to sanitize user provided values. The output must be in UTF-8. The baseUri parameter is a url to the root of the application, and can be used to construct local links. @param HtmlOutputHelper $html @return string
[ "Generate", "html", "representation", "for", "this", "value", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Xml/Property/Principal.php#L137-L149
sabre-io/dav
lib/DAVACL/Xml/Property/Principal.php
Principal.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { $tree = $reader->parseInnerTree()[0]; switch ($tree['name']) { case '{DAV:}unauthenticated': return new self(self::UNAUTHENTICATED); case '{DAV:}authenticated': return new self(self::AUTHENTICATED); case '{DAV:}href': return new self(self::HREF, $tree['value']); case '{DAV:}all': return new self(self::ALL); default: throw new BadRequest('Unknown or unsupported principal type: '.$tree['name']); } }
php
public static function xmlDeserialize(Reader $reader) { $tree = $reader->parseInnerTree()[0]; switch ($tree['name']) { case '{DAV:}unauthenticated': return new self(self::UNAUTHENTICATED); case '{DAV:}authenticated': return new self(self::AUTHENTICATED); case '{DAV:}href': return new self(self::HREF, $tree['value']); case '{DAV:}all': return new self(self::ALL); default: throw new BadRequest('Unknown or unsupported principal type: '.$tree['name']); } }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "$", "tree", "=", "$", "reader", "->", "parseInnerTree", "(", ")", "[", "0", "]", ";", "switch", "(", "$", "tree", "[", "'name'", "]", ")", "{", "case", "'{DAV:}unauthenticated'", ":", "return", "new", "self", "(", "self", "::", "UNAUTHENTICATED", ")", ";", "case", "'{DAV:}authenticated'", ":", "return", "new", "self", "(", "self", "::", "AUTHENTICATED", ")", ";", "case", "'{DAV:}href'", ":", "return", "new", "self", "(", "self", "::", "HREF", ",", "$", "tree", "[", "'value'", "]", ")", ";", "case", "'{DAV:}all'", ":", "return", "new", "self", "(", "self", "::", "ALL", ")", ";", "default", ":", "throw", "new", "BadRequest", "(", "'Unknown or unsupported principal type: '", ".", "$", "tree", "[", "'name'", "]", ")", ";", "}", "}" ]
The deserialize method is called during xml parsing. This method is called staticly, this is because in theory this method may be used as a type of constructor, or factory method. Often you want to return an instance of the current class, but you are free to return other data as well. Important note 2: You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop. If you just want to skip parsing for this element altogether, you can just call $reader->next(); $reader->parseInnerTree() will parse the entire sub-tree, and advance to the next element. @param Reader $reader @return mixed
[ "The", "deserialize", "method", "is", "called", "during", "xml", "parsing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Xml/Property/Principal.php#L173-L189
sabre-io/dav
lib/CalDAV/Xml/Request/CalendarMultiGetReport.php
CalendarMultiGetReport.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { $elems = $reader->parseInnerTree([ '{urn:ietf:params:xml:ns:caldav}calendar-data' => 'Sabre\\CalDAV\\Xml\\Filter\\CalendarData', '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', ]); $newProps = [ 'hrefs' => [], 'properties' => [], ]; foreach ($elems as $elem) { switch ($elem['name']) { case '{DAV:}prop': $newProps['properties'] = array_keys($elem['value']); if (isset($elem['value']['{'.Plugin::NS_CALDAV.'}calendar-data'])) { $newProps += $elem['value']['{'.Plugin::NS_CALDAV.'}calendar-data']; } break; case '{DAV:}href': $newProps['hrefs'][] = Uri\resolve($reader->contextUri, $elem['value']); break; } } $obj = new self(); foreach ($newProps as $key => $value) { $obj->$key = $value; } return $obj; }
php
public static function xmlDeserialize(Reader $reader) { $elems = $reader->parseInnerTree([ '{urn:ietf:params:xml:ns:caldav}calendar-data' => 'Sabre\\CalDAV\\Xml\\Filter\\CalendarData', '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', ]); $newProps = [ 'hrefs' => [], 'properties' => [], ]; foreach ($elems as $elem) { switch ($elem['name']) { case '{DAV:}prop': $newProps['properties'] = array_keys($elem['value']); if (isset($elem['value']['{'.Plugin::NS_CALDAV.'}calendar-data'])) { $newProps += $elem['value']['{'.Plugin::NS_CALDAV.'}calendar-data']; } break; case '{DAV:}href': $newProps['hrefs'][] = Uri\resolve($reader->contextUri, $elem['value']); break; } } $obj = new self(); foreach ($newProps as $key => $value) { $obj->$key = $value; } return $obj; }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "$", "elems", "=", "$", "reader", "->", "parseInnerTree", "(", "[", "'{urn:ietf:params:xml:ns:caldav}calendar-data'", "=>", "'Sabre\\\\CalDAV\\\\Xml\\\\Filter\\\\CalendarData'", ",", "'{DAV:}prop'", "=>", "'Sabre\\\\Xml\\\\Element\\\\KeyValue'", ",", "]", ")", ";", "$", "newProps", "=", "[", "'hrefs'", "=>", "[", "]", ",", "'properties'", "=>", "[", "]", ",", "]", ";", "foreach", "(", "$", "elems", "as", "$", "elem", ")", "{", "switch", "(", "$", "elem", "[", "'name'", "]", ")", "{", "case", "'{DAV:}prop'", ":", "$", "newProps", "[", "'properties'", "]", "=", "array_keys", "(", "$", "elem", "[", "'value'", "]", ")", ";", "if", "(", "isset", "(", "$", "elem", "[", "'value'", "]", "[", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}calendar-data'", "]", ")", ")", "{", "$", "newProps", "+=", "$", "elem", "[", "'value'", "]", "[", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}calendar-data'", "]", ";", "}", "break", ";", "case", "'{DAV:}href'", ":", "$", "newProps", "[", "'hrefs'", "]", "[", "]", "=", "Uri", "\\", "resolve", "(", "$", "reader", "->", "contextUri", ",", "$", "elem", "[", "'value'", "]", ")", ";", "break", ";", "}", "}", "$", "obj", "=", "new", "self", "(", ")", ";", "foreach", "(", "$", "newProps", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "obj", "->", "$", "key", "=", "$", "value", ";", "}", "return", "$", "obj", ";", "}" ]
The deserialize method is called during xml parsing. This method is called statically, this is because in theory this method may be used as a type of constructor, or factory method. Often you want to return an instance of the current class, but you are free to return other data as well. You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop. If you just want to skip parsing for this element altogether, you can just call $reader->next(); $reader->parseInnerTree() will parse the entire sub-tree, and advance to the next element. @param Reader $reader @return mixed
[ "The", "deserialize", "method", "is", "called", "during", "xml", "parsing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Xml/Request/CalendarMultiGetReport.php#L88-L120
sabre-io/dav
lib/DAVACL/Xml/Request/AclPrincipalPropSetReport.php
AclPrincipalPropSetReport.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { $reader->pushContext(); $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Deserializer\enum'; $elems = Deserializer\keyValue( $reader, 'DAV:' ); $reader->popContext(); $report = new self(); if (!empty($elems['prop'])) { $report->properties = $elems['prop']; } return $report; }
php
public static function xmlDeserialize(Reader $reader) { $reader->pushContext(); $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Deserializer\enum'; $elems = Deserializer\keyValue( $reader, 'DAV:' ); $reader->popContext(); $report = new self(); if (!empty($elems['prop'])) { $report->properties = $elems['prop']; } return $report; }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "$", "reader", "->", "pushContext", "(", ")", ";", "$", "reader", "->", "elementMap", "[", "'{DAV:}prop'", "]", "=", "'Sabre\\Xml\\Deserializer\\enum'", ";", "$", "elems", "=", "Deserializer", "\\", "keyValue", "(", "$", "reader", ",", "'DAV:'", ")", ";", "$", "reader", "->", "popContext", "(", ")", ";", "$", "report", "=", "new", "self", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "elems", "[", "'prop'", "]", ")", ")", "{", "$", "report", "->", "properties", "=", "$", "elems", "[", "'prop'", "]", ";", "}", "return", "$", "report", ";", "}" ]
The deserialize method is called during xml parsing. This method is called statically, this is because in theory this method may be used as a type of constructor, or factory method. Often you want to return an instance of the current class, but you are free to return other data as well. You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop. If you just want to skip parsing for this element altogether, you can just call $reader->next(); $reader->parseInnerTree() will parse the entire sub-tree, and advance to the next element. @param Reader $reader @return mixed
[ "The", "deserialize", "method", "is", "called", "during", "xml", "parsing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Xml/Request/AclPrincipalPropSetReport.php#L48-L67
sabre-io/dav
lib/DAV/Locks/Backend/PDO.php
PDO.getLocks
public function getLocks($uri, $returnChildLocks) { // NOTE: the following 10 lines or so could be easily replaced by // pure sql. MySQL's non-standard string concatenation prevents us // from doing this though. $query = 'SELECT owner, token, timeout, created, scope, depth, uri FROM '.$this->tableName.' WHERE (created > (? - timeout)) AND ((uri = ?)'; $params = [time(), $uri]; // We need to check locks for every part in the uri. $uriParts = explode('/', $uri); // We already covered the last part of the uri array_pop($uriParts); $currentPath = ''; foreach ($uriParts as $part) { if ($currentPath) { $currentPath .= '/'; } $currentPath .= $part; $query .= ' OR (depth!=0 AND uri = ?)'; $params[] = $currentPath; } if ($returnChildLocks) { $query .= ' OR (uri LIKE ?)'; $params[] = $uri.'/%'; } $query .= ')'; $stmt = $this->pdo->prepare($query); $stmt->execute($params); $result = $stmt->fetchAll(); $lockList = []; foreach ($result as $row) { $lockInfo = new LockInfo(); $lockInfo->owner = $row['owner']; $lockInfo->token = $row['token']; $lockInfo->timeout = $row['timeout']; $lockInfo->created = $row['created']; $lockInfo->scope = $row['scope']; $lockInfo->depth = $row['depth']; $lockInfo->uri = $row['uri']; $lockList[] = $lockInfo; } return $lockList; }
php
public function getLocks($uri, $returnChildLocks) { $query = 'SELECT owner, token, timeout, created, scope, depth, uri FROM '.$this->tableName.' WHERE (created > (? - timeout)) AND ((uri = ?)'; $params = [time(), $uri]; $uriParts = explode('/', $uri); array_pop($uriParts); $currentPath = ''; foreach ($uriParts as $part) { if ($currentPath) { $currentPath .= '/'; } $currentPath .= $part; $query .= ' OR (depth!=0 AND uri = ?)'; $params[] = $currentPath; } if ($returnChildLocks) { $query .= ' OR (uri LIKE ?)'; $params[] = $uri.'/%'; } $query .= ')'; $stmt = $this->pdo->prepare($query); $stmt->execute($params); $result = $stmt->fetchAll(); $lockList = []; foreach ($result as $row) { $lockInfo = new LockInfo(); $lockInfo->owner = $row['owner']; $lockInfo->token = $row['token']; $lockInfo->timeout = $row['timeout']; $lockInfo->created = $row['created']; $lockInfo->scope = $row['scope']; $lockInfo->depth = $row['depth']; $lockInfo->uri = $row['uri']; $lockList[] = $lockInfo; } return $lockList; }
[ "public", "function", "getLocks", "(", "$", "uri", ",", "$", "returnChildLocks", ")", "{", "// NOTE: the following 10 lines or so could be easily replaced by", "// pure sql. MySQL's non-standard string concatenation prevents us", "// from doing this though.", "$", "query", "=", "'SELECT owner, token, timeout, created, scope, depth, uri FROM '", ".", "$", "this", "->", "tableName", ".", "' WHERE (created > (? - timeout)) AND ((uri = ?)'", ";", "$", "params", "=", "[", "time", "(", ")", ",", "$", "uri", "]", ";", "// We need to check locks for every part in the uri.", "$", "uriParts", "=", "explode", "(", "'/'", ",", "$", "uri", ")", ";", "// We already covered the last part of the uri", "array_pop", "(", "$", "uriParts", ")", ";", "$", "currentPath", "=", "''", ";", "foreach", "(", "$", "uriParts", "as", "$", "part", ")", "{", "if", "(", "$", "currentPath", ")", "{", "$", "currentPath", ".=", "'/'", ";", "}", "$", "currentPath", ".=", "$", "part", ";", "$", "query", ".=", "' OR (depth!=0 AND uri = ?)'", ";", "$", "params", "[", "]", "=", "$", "currentPath", ";", "}", "if", "(", "$", "returnChildLocks", ")", "{", "$", "query", ".=", "' OR (uri LIKE ?)'", ";", "$", "params", "[", "]", "=", "$", "uri", ".", "'/%'", ";", "}", "$", "query", ".=", "')'", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "$", "query", ")", ";", "$", "stmt", "->", "execute", "(", "$", "params", ")", ";", "$", "result", "=", "$", "stmt", "->", "fetchAll", "(", ")", ";", "$", "lockList", "=", "[", "]", ";", "foreach", "(", "$", "result", "as", "$", "row", ")", "{", "$", "lockInfo", "=", "new", "LockInfo", "(", ")", ";", "$", "lockInfo", "->", "owner", "=", "$", "row", "[", "'owner'", "]", ";", "$", "lockInfo", "->", "token", "=", "$", "row", "[", "'token'", "]", ";", "$", "lockInfo", "->", "timeout", "=", "$", "row", "[", "'timeout'", "]", ";", "$", "lockInfo", "->", "created", "=", "$", "row", "[", "'created'", "]", ";", "$", "lockInfo", "->", "scope", "=", "$", "row", "[", "'scope'", "]", ";", "$", "lockInfo", "->", "depth", "=", "$", "row", "[", "'depth'", "]", ";", "$", "lockInfo", "->", "uri", "=", "$", "row", "[", "'uri'", "]", ";", "$", "lockList", "[", "]", "=", "$", "lockInfo", ";", "}", "return", "$", "lockList", ";", "}" ]
Returns a list of Sabre\DAV\Locks\LockInfo objects. This method should return all the locks for a particular uri, including locks that might be set on a parent uri. If returnChildLocks is set to true, this method should also look for any locks in the subtree of the uri for locks. @param string $uri @param bool $returnChildLocks @return array
[ "Returns", "a", "list", "of", "Sabre", "\\", "DAV", "\\", "Locks", "\\", "LockInfo", "objects", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Backend/PDO.php#L59-L109
sabre-io/dav
lib/DAV/Locks/Backend/PDO.php
PDO.lock
public function lock($uri, LockInfo $lockInfo) { // We're making the lock timeout 30 minutes $lockInfo->timeout = 30 * 60; $lockInfo->created = time(); $lockInfo->uri = $uri; $locks = $this->getLocks($uri, false); $exists = false; foreach ($locks as $lock) { if ($lock->token == $lockInfo->token) { $exists = true; } } if ($exists) { $stmt = $this->pdo->prepare('UPDATE '.$this->tableName.' SET owner = ?, timeout = ?, scope = ?, depth = ?, uri = ?, created = ? WHERE token = ?'); $stmt->execute([ $lockInfo->owner, $lockInfo->timeout, $lockInfo->scope, $lockInfo->depth, $uri, $lockInfo->created, $lockInfo->token, ]); } else { $stmt = $this->pdo->prepare('INSERT INTO '.$this->tableName.' (owner,timeout,scope,depth,uri,created,token) VALUES (?,?,?,?,?,?,?)'); $stmt->execute([ $lockInfo->owner, $lockInfo->timeout, $lockInfo->scope, $lockInfo->depth, $uri, $lockInfo->created, $lockInfo->token, ]); } return true; }
php
public function lock($uri, LockInfo $lockInfo) { $lockInfo->timeout = 30 * 60; $lockInfo->created = time(); $lockInfo->uri = $uri; $locks = $this->getLocks($uri, false); $exists = false; foreach ($locks as $lock) { if ($lock->token == $lockInfo->token) { $exists = true; } } if ($exists) { $stmt = $this->pdo->prepare('UPDATE '.$this->tableName.' SET owner = ?, timeout = ?, scope = ?, depth = ?, uri = ?, created = ? WHERE token = ?'); $stmt->execute([ $lockInfo->owner, $lockInfo->timeout, $lockInfo->scope, $lockInfo->depth, $uri, $lockInfo->created, $lockInfo->token, ]); } else { $stmt = $this->pdo->prepare('INSERT INTO '.$this->tableName.' (owner,timeout,scope,depth,uri,created,token) VALUES (?,?,?,?,?,?,?)'); $stmt->execute([ $lockInfo->owner, $lockInfo->timeout, $lockInfo->scope, $lockInfo->depth, $uri, $lockInfo->created, $lockInfo->token, ]); } return true; }
[ "public", "function", "lock", "(", "$", "uri", ",", "LockInfo", "$", "lockInfo", ")", "{", "// We're making the lock timeout 30 minutes", "$", "lockInfo", "->", "timeout", "=", "30", "*", "60", ";", "$", "lockInfo", "->", "created", "=", "time", "(", ")", ";", "$", "lockInfo", "->", "uri", "=", "$", "uri", ";", "$", "locks", "=", "$", "this", "->", "getLocks", "(", "$", "uri", ",", "false", ")", ";", "$", "exists", "=", "false", ";", "foreach", "(", "$", "locks", "as", "$", "lock", ")", "{", "if", "(", "$", "lock", "->", "token", "==", "$", "lockInfo", "->", "token", ")", "{", "$", "exists", "=", "true", ";", "}", "}", "if", "(", "$", "exists", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'UPDATE '", ".", "$", "this", "->", "tableName", ".", "' SET owner = ?, timeout = ?, scope = ?, depth = ?, uri = ?, created = ? WHERE token = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "lockInfo", "->", "owner", ",", "$", "lockInfo", "->", "timeout", ",", "$", "lockInfo", "->", "scope", ",", "$", "lockInfo", "->", "depth", ",", "$", "uri", ",", "$", "lockInfo", "->", "created", ",", "$", "lockInfo", "->", "token", ",", "]", ")", ";", "}", "else", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'INSERT INTO '", ".", "$", "this", "->", "tableName", ".", "' (owner,timeout,scope,depth,uri,created,token) VALUES (?,?,?,?,?,?,?)'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "lockInfo", "->", "owner", ",", "$", "lockInfo", "->", "timeout", ",", "$", "lockInfo", "->", "scope", ",", "$", "lockInfo", "->", "depth", ",", "$", "uri", ",", "$", "lockInfo", "->", "created", ",", "$", "lockInfo", "->", "token", ",", "]", ")", ";", "}", "return", "true", ";", "}" ]
Locks a uri. @param string $uri @param LockInfo $lockInfo @return bool
[ "Locks", "a", "uri", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Backend/PDO.php#L119-L159
sabre-io/dav
lib/DAV/Locks/Backend/PDO.php
PDO.unlock
public function unlock($uri, LockInfo $lockInfo) { $stmt = $this->pdo->prepare('DELETE FROM '.$this->tableName.' WHERE uri = ? AND token = ?'); $stmt->execute([$uri, $lockInfo->token]); return 1 === $stmt->rowCount(); }
php
public function unlock($uri, LockInfo $lockInfo) { $stmt = $this->pdo->prepare('DELETE FROM '.$this->tableName.' WHERE uri = ? AND token = ?'); $stmt->execute([$uri, $lockInfo->token]); return 1 === $stmt->rowCount(); }
[ "public", "function", "unlock", "(", "$", "uri", ",", "LockInfo", "$", "lockInfo", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'DELETE FROM '", ".", "$", "this", "->", "tableName", ".", "' WHERE uri = ? AND token = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "uri", ",", "$", "lockInfo", "->", "token", "]", ")", ";", "return", "1", "===", "$", "stmt", "->", "rowCount", "(", ")", ";", "}" ]
Removes a lock from a uri. @param string $uri @param LockInfo $lockInfo @return bool
[ "Removes", "a", "lock", "from", "a", "uri", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Backend/PDO.php#L169-L175
sabre-io/dav
lib/CardDAV/Xml/Filter/AddressData.php
AddressData.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { $result = [ 'contentType' => $reader->getAttribute('content-type') ?: 'text/vcard', 'version' => $reader->getAttribute('version') ?: '3.0', ]; $elems = (array) $reader->parseInnerTree(); $elems = array_filter($elems, function ($element) { return '{urn:ietf:params:xml:ns:carddav}prop' === $element['name'] && isset($element['attributes']['name']); }); $result['addressDataProperties'] = array_map(function ($element) { return $element['attributes']['name']; }, $elems); return $result; }
php
public static function xmlDeserialize(Reader $reader) { $result = [ 'contentType' => $reader->getAttribute('content-type') ?: 'text/vcard', 'version' => $reader->getAttribute('version') ?: '3.0', ]; $elems = (array) $reader->parseInnerTree(); $elems = array_filter($elems, function ($element) { return '{urn:ietf:params:xml:ns:carddav}prop' === $element['name'] && isset($element['attributes']['name']); }); $result['addressDataProperties'] = array_map(function ($element) { return $element['attributes']['name']; }, $elems); return $result; }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "$", "result", "=", "[", "'contentType'", "=>", "$", "reader", "->", "getAttribute", "(", "'content-type'", ")", "?", ":", "'text/vcard'", ",", "'version'", "=>", "$", "reader", "->", "getAttribute", "(", "'version'", ")", "?", ":", "'3.0'", ",", "]", ";", "$", "elems", "=", "(", "array", ")", "$", "reader", "->", "parseInnerTree", "(", ")", ";", "$", "elems", "=", "array_filter", "(", "$", "elems", ",", "function", "(", "$", "element", ")", "{", "return", "'{urn:ietf:params:xml:ns:carddav}prop'", "===", "$", "element", "[", "'name'", "]", "&&", "isset", "(", "$", "element", "[", "'attributes'", "]", "[", "'name'", "]", ")", ";", "}", ")", ";", "$", "result", "[", "'addressDataProperties'", "]", "=", "array_map", "(", "function", "(", "$", "element", ")", "{", "return", "$", "element", "[", "'attributes'", "]", "[", "'name'", "]", ";", "}", ",", "$", "elems", ")", ";", "return", "$", "result", ";", "}" ]
The deserialize method is called during xml parsing. This method is called statically, this is because in theory this method may be used as a type of constructor, or factory method. Often you want to return an instance of the current class, but you are free to return other data as well. You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop. If you just want to skip parsing for this element altogether, you can just call $reader->next(); $reader->parseInnerTree() will parse the entire sub-tree, and advance to the next element. @param Reader $reader @return mixed
[ "The", "deserialize", "method", "is", "called", "during", "xml", "parsing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Xml/Filter/AddressData.php#L50-L67
sabre-io/dav
lib/DAV/Xml/Request/PropPatch.php
PropPatch.xmlSerialize
public function xmlSerialize(Writer $writer) { foreach ($this->properties as $propertyName => $propertyValue) { if (is_null($propertyValue)) { $writer->startElement('{DAV:}remove'); $writer->write(['{DAV:}prop' => [$propertyName => $propertyValue]]); $writer->endElement(); } else { $writer->startElement('{DAV:}set'); $writer->write(['{DAV:}prop' => [$propertyName => $propertyValue]]); $writer->endElement(); } } }
php
public function xmlSerialize(Writer $writer) { foreach ($this->properties as $propertyName => $propertyValue) { if (is_null($propertyValue)) { $writer->startElement('{DAV:}remove'); $writer->write(['{DAV:}prop' => [$propertyName => $propertyValue]]); $writer->endElement(); } else { $writer->startElement('{DAV:}set'); $writer->write(['{DAV:}prop' => [$propertyName => $propertyValue]]); $writer->endElement(); } } }
[ "public", "function", "xmlSerialize", "(", "Writer", "$", "writer", ")", "{", "foreach", "(", "$", "this", "->", "properties", "as", "$", "propertyName", "=>", "$", "propertyValue", ")", "{", "if", "(", "is_null", "(", "$", "propertyValue", ")", ")", "{", "$", "writer", "->", "startElement", "(", "'{DAV:}remove'", ")", ";", "$", "writer", "->", "write", "(", "[", "'{DAV:}prop'", "=>", "[", "$", "propertyName", "=>", "$", "propertyValue", "]", "]", ")", ";", "$", "writer", "->", "endElement", "(", ")", ";", "}", "else", "{", "$", "writer", "->", "startElement", "(", "'{DAV:}set'", ")", ";", "$", "writer", "->", "write", "(", "[", "'{DAV:}prop'", "=>", "[", "$", "propertyName", "=>", "$", "propertyValue", "]", "]", ")", ";", "$", "writer", "->", "endElement", "(", ")", ";", "}", "}", "}" ]
The xmlSerialize method is called during xml writing. Use the $writer argument to write its own xml serialization. An important note: do _not_ create a parent element. Any element implementing XmlSerializable should only ever write what's considered its 'inner xml'. The parent of the current element is responsible for writing a containing element. This allows serializers to be re-used for different element names. If you are opening new elements, you must also close them again. @param Writer $writer
[ "The", "xmlSerialize", "method", "is", "called", "during", "xml", "writing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Request/PropPatch.php#L51-L64
sabre-io/dav
lib/DAV/Xml/Request/PropPatch.php
PropPatch.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { $self = new self(); $elementMap = $reader->elementMap; $elementMap['{DAV:}prop'] = 'Sabre\DAV\Xml\Element\Prop'; $elementMap['{DAV:}set'] = 'Sabre\Xml\Element\KeyValue'; $elementMap['{DAV:}remove'] = 'Sabre\Xml\Element\KeyValue'; $elems = $reader->parseInnerTree($elementMap); foreach ($elems as $elem) { if ('{DAV:}set' === $elem['name']) { $self->properties = array_merge($self->properties, $elem['value']['{DAV:}prop']); } if ('{DAV:}remove' === $elem['name']) { // Ensuring there are no values. foreach ($elem['value']['{DAV:}prop'] as $remove => $value) { $self->properties[$remove] = null; } } } return $self; }
php
public static function xmlDeserialize(Reader $reader) { $self = new self(); $elementMap = $reader->elementMap; $elementMap['{DAV:}prop'] = 'Sabre\DAV\Xml\Element\Prop'; $elementMap['{DAV:}set'] = 'Sabre\Xml\Element\KeyValue'; $elementMap['{DAV:}remove'] = 'Sabre\Xml\Element\KeyValue'; $elems = $reader->parseInnerTree($elementMap); foreach ($elems as $elem) { if ('{DAV:}set' === $elem['name']) { $self->properties = array_merge($self->properties, $elem['value']['{DAV:}prop']); } if ('{DAV:}remove' === $elem['name']) { foreach ($elem['value']['{DAV:}prop'] as $remove => $value) { $self->properties[$remove] = null; } } } return $self; }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "$", "self", "=", "new", "self", "(", ")", ";", "$", "elementMap", "=", "$", "reader", "->", "elementMap", ";", "$", "elementMap", "[", "'{DAV:}prop'", "]", "=", "'Sabre\\DAV\\Xml\\Element\\Prop'", ";", "$", "elementMap", "[", "'{DAV:}set'", "]", "=", "'Sabre\\Xml\\Element\\KeyValue'", ";", "$", "elementMap", "[", "'{DAV:}remove'", "]", "=", "'Sabre\\Xml\\Element\\KeyValue'", ";", "$", "elems", "=", "$", "reader", "->", "parseInnerTree", "(", "$", "elementMap", ")", ";", "foreach", "(", "$", "elems", "as", "$", "elem", ")", "{", "if", "(", "'{DAV:}set'", "===", "$", "elem", "[", "'name'", "]", ")", "{", "$", "self", "->", "properties", "=", "array_merge", "(", "$", "self", "->", "properties", ",", "$", "elem", "[", "'value'", "]", "[", "'{DAV:}prop'", "]", ")", ";", "}", "if", "(", "'{DAV:}remove'", "===", "$", "elem", "[", "'name'", "]", ")", "{", "// Ensuring there are no values.", "foreach", "(", "$", "elem", "[", "'value'", "]", "[", "'{DAV:}prop'", "]", "as", "$", "remove", "=>", "$", "value", ")", "{", "$", "self", "->", "properties", "[", "$", "remove", "]", "=", "null", ";", "}", "}", "}", "return", "$", "self", ";", "}" ]
The deserialize method is called during xml parsing. This method is called statically, this is because in theory this method may be used as a type of constructor, or factory method. Often you want to return an instance of the current class, but you are free to return other data as well. You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop. If you just want to skip parsing for this element altogether, you can just call $reader->next(); $reader->parseInnerTree() will parse the entire sub-tree, and advance to the next element. @param Reader $reader @return mixed
[ "The", "deserialize", "method", "is", "called", "during", "xml", "parsing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Request/PropPatch.php#L88-L112
sabre-io/dav
lib/DAV/Auth/Backend/PDO.php
PDO.getDigestHash
public function getDigestHash($realm, $username) { $stmt = $this->pdo->prepare('SELECT digesta1 FROM '.$this->tableName.' WHERE username = ?'); $stmt->execute([$username]); return $stmt->fetchColumn() ?: null; }
php
public function getDigestHash($realm, $username) { $stmt = $this->pdo->prepare('SELECT digesta1 FROM '.$this->tableName.' WHERE username = ?'); $stmt->execute([$username]); return $stmt->fetchColumn() ?: null; }
[ "public", "function", "getDigestHash", "(", "$", "realm", ",", "$", "username", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'SELECT digesta1 FROM '", ".", "$", "this", "->", "tableName", ".", "' WHERE username = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "username", "]", ")", ";", "return", "$", "stmt", "->", "fetchColumn", "(", ")", "?", ":", "null", ";", "}" ]
Returns the digest hash for a user. @param string $realm @param string $username @return string|null
[ "Returns", "the", "digest", "hash", "for", "a", "user", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Auth/Backend/PDO.php#L50-L56
sabre-io/dav
lib/DAV/PropPatch.php
PropPatch.handle
public function handle($properties, callable $callback) { $usedProperties = []; foreach ((array) $properties as $propertyName) { if (array_key_exists($propertyName, $this->mutations) && !isset($this->result[$propertyName])) { $usedProperties[] = $propertyName; // HTTP Accepted $this->result[$propertyName] = 202; } } // Only registering if there's any unhandled properties. if (!$usedProperties) { return; } $this->propertyUpdateCallbacks[] = [ // If the original argument to this method was a string, we need // to also make sure that it stays that way, so the commit function // knows how to format the arguments to the callback. is_string($properties) ? $properties : $usedProperties, $callback, ]; }
php
public function handle($properties, callable $callback) { $usedProperties = []; foreach ((array) $properties as $propertyName) { if (array_key_exists($propertyName, $this->mutations) && !isset($this->result[$propertyName])) { $usedProperties[] = $propertyName; $this->result[$propertyName] = 202; } } if (!$usedProperties) { return; } $this->propertyUpdateCallbacks[] = [ is_string($properties) ? $properties : $usedProperties, $callback, ]; }
[ "public", "function", "handle", "(", "$", "properties", ",", "callable", "$", "callback", ")", "{", "$", "usedProperties", "=", "[", "]", ";", "foreach", "(", "(", "array", ")", "$", "properties", "as", "$", "propertyName", ")", "{", "if", "(", "array_key_exists", "(", "$", "propertyName", ",", "$", "this", "->", "mutations", ")", "&&", "!", "isset", "(", "$", "this", "->", "result", "[", "$", "propertyName", "]", ")", ")", "{", "$", "usedProperties", "[", "]", "=", "$", "propertyName", ";", "// HTTP Accepted", "$", "this", "->", "result", "[", "$", "propertyName", "]", "=", "202", ";", "}", "}", "// Only registering if there's any unhandled properties.", "if", "(", "!", "$", "usedProperties", ")", "{", "return", ";", "}", "$", "this", "->", "propertyUpdateCallbacks", "[", "]", "=", "[", "// If the original argument to this method was a string, we need", "// to also make sure that it stays that way, so the commit function", "// knows how to format the arguments to the callback.", "is_string", "(", "$", "properties", ")", "?", "$", "properties", ":", "$", "usedProperties", ",", "$", "callback", ",", "]", ";", "}" ]
Call this function if you wish to handle updating certain properties. For instance, your class may be responsible for handling updates for the {DAV:}displayname property. In that case, call this method with the first argument "{DAV:}displayname" and a second argument that's a method that does the actual updating. It's possible to specify more than one property as an array. The callback must return a boolean or an it. If the result is true, the operation was considered successful. If it's false, it's consided failed. If the result is an integer, we'll use that integer as the http status code associated with the operation. @param string|string[] $properties @param callable $callback
[ "Call", "this", "function", "if", "you", "wish", "to", "handle", "updating", "certain", "properties", ".", "For", "instance", "your", "class", "may", "be", "responsible", "for", "handling", "updates", "for", "the", "{", "DAV", ":", "}", "displayname", "property", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PropPatch.php#L87-L109
sabre-io/dav
lib/DAV/PropPatch.php
PropPatch.handleRemaining
public function handleRemaining(callable $callback) { $properties = $this->getRemainingMutations(); if (!$properties) { // Nothing to do, don't register callback return; } foreach ($properties as $propertyName) { // HTTP Accepted $this->result[$propertyName] = 202; $this->propertyUpdateCallbacks[] = [ $properties, $callback, ]; } }
php
public function handleRemaining(callable $callback) { $properties = $this->getRemainingMutations(); if (!$properties) { return; } foreach ($properties as $propertyName) { $this->result[$propertyName] = 202; $this->propertyUpdateCallbacks[] = [ $properties, $callback, ]; } }
[ "public", "function", "handleRemaining", "(", "callable", "$", "callback", ")", "{", "$", "properties", "=", "$", "this", "->", "getRemainingMutations", "(", ")", ";", "if", "(", "!", "$", "properties", ")", "{", "// Nothing to do, don't register callback", "return", ";", "}", "foreach", "(", "$", "properties", "as", "$", "propertyName", ")", "{", "// HTTP Accepted", "$", "this", "->", "result", "[", "$", "propertyName", "]", "=", "202", ";", "$", "this", "->", "propertyUpdateCallbacks", "[", "]", "=", "[", "$", "properties", ",", "$", "callback", ",", "]", ";", "}", "}" ]
Call this function if you wish to handle _all_ properties that haven't been handled by anything else yet. Note that you effectively claim with this that you promise to process _all_ properties that are coming in. @param callable $callback
[ "Call", "this", "function", "if", "you", "wish", "to", "handle", "_all_", "properties", "that", "haven", "t", "been", "handled", "by", "anything", "else", "yet", ".", "Note", "that", "you", "effectively", "claim", "with", "this", "that", "you", "promise", "to", "process", "_all_", "properties", "that", "are", "coming", "in", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PropPatch.php#L118-L135
sabre-io/dav
lib/DAV/PropPatch.php
PropPatch.setResultCode
public function setResultCode($properties, $resultCode) { foreach ((array) $properties as $propertyName) { $this->result[$propertyName] = $resultCode; } if ($resultCode >= 400) { $this->failed = true; } }
php
public function setResultCode($properties, $resultCode) { foreach ((array) $properties as $propertyName) { $this->result[$propertyName] = $resultCode; } if ($resultCode >= 400) { $this->failed = true; } }
[ "public", "function", "setResultCode", "(", "$", "properties", ",", "$", "resultCode", ")", "{", "foreach", "(", "(", "array", ")", "$", "properties", "as", "$", "propertyName", ")", "{", "$", "this", "->", "result", "[", "$", "propertyName", "]", "=", "$", "resultCode", ";", "}", "if", "(", "$", "resultCode", ">=", "400", ")", "{", "$", "this", "->", "failed", "=", "true", ";", "}", "}" ]
Sets the result code for one or more properties. @param string|string[] $properties @param int $resultCode
[ "Sets", "the", "result", "code", "for", "one", "or", "more", "properties", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PropPatch.php#L143-L152