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/PropPatch.php
PropPatch.getRemainingMutations
public function getRemainingMutations() { $remaining = []; foreach ($this->mutations as $propertyName => $propValue) { if (!isset($this->result[$propertyName])) { $remaining[] = $propertyName; } } return $remaining; }
php
public function getRemainingMutations() { $remaining = []; foreach ($this->mutations as $propertyName => $propValue) { if (!isset($this->result[$propertyName])) { $remaining[] = $propertyName; } } return $remaining; }
[ "public", "function", "getRemainingMutations", "(", ")", "{", "$", "remaining", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "mutations", "as", "$", "propertyName", "=>", "$", "propValue", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "result", "[", "$", "propertyName", "]", ")", ")", "{", "$", "remaining", "[", "]", "=", "$", "propertyName", ";", "}", "}", "return", "$", "remaining", ";", "}" ]
Returns the list of properties that don't have a result code yet. This method returns a list of property names, but not its values. @return string[]
[ "Returns", "the", "list", "of", "properties", "that", "don", "t", "have", "a", "result", "code", "yet", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PropPatch.php#L174-L184
sabre-io/dav
lib/DAV/PropPatch.php
PropPatch.commit
public function commit() { // First we validate if every property has a handler foreach ($this->mutations as $propertyName => $value) { if (!isset($this->result[$propertyName])) { $this->failed = true; $this->result[$propertyName] = 403; } } foreach ($this->propertyUpdateCallbacks as $callbackInfo) { if ($this->failed) { break; } if (is_string($callbackInfo[0])) { $this->doCallbackSingleProp($callbackInfo[0], $callbackInfo[1]); } else { $this->doCallbackMultiProp($callbackInfo[0], $callbackInfo[1]); } } /* * If anywhere in this operation updating a property failed, we must * update all other properties accordingly. */ if ($this->failed) { foreach ($this->result as $propertyName => $status) { if (202 === $status) { // Failed dependency $this->result[$propertyName] = 424; } } } return !$this->failed; }
php
public function commit() { foreach ($this->mutations as $propertyName => $value) { if (!isset($this->result[$propertyName])) { $this->failed = true; $this->result[$propertyName] = 403; } } foreach ($this->propertyUpdateCallbacks as $callbackInfo) { if ($this->failed) { break; } if (is_string($callbackInfo[0])) { $this->doCallbackSingleProp($callbackInfo[0], $callbackInfo[1]); } else { $this->doCallbackMultiProp($callbackInfo[0], $callbackInfo[1]); } } if ($this->failed) { foreach ($this->result as $propertyName => $status) { if (202 === $status) { $this->result[$propertyName] = 424; } } } return !$this->failed; }
[ "public", "function", "commit", "(", ")", "{", "// First we validate if every property has a handler", "foreach", "(", "$", "this", "->", "mutations", "as", "$", "propertyName", "=>", "$", "value", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "result", "[", "$", "propertyName", "]", ")", ")", "{", "$", "this", "->", "failed", "=", "true", ";", "$", "this", "->", "result", "[", "$", "propertyName", "]", "=", "403", ";", "}", "}", "foreach", "(", "$", "this", "->", "propertyUpdateCallbacks", "as", "$", "callbackInfo", ")", "{", "if", "(", "$", "this", "->", "failed", ")", "{", "break", ";", "}", "if", "(", "is_string", "(", "$", "callbackInfo", "[", "0", "]", ")", ")", "{", "$", "this", "->", "doCallbackSingleProp", "(", "$", "callbackInfo", "[", "0", "]", ",", "$", "callbackInfo", "[", "1", "]", ")", ";", "}", "else", "{", "$", "this", "->", "doCallbackMultiProp", "(", "$", "callbackInfo", "[", "0", "]", ",", "$", "callbackInfo", "[", "1", "]", ")", ";", "}", "}", "/*\n * If anywhere in this operation updating a property failed, we must\n * update all other properties accordingly.\n */", "if", "(", "$", "this", "->", "failed", ")", "{", "foreach", "(", "$", "this", "->", "result", "as", "$", "propertyName", "=>", "$", "status", ")", "{", "if", "(", "202", "===", "$", "status", ")", "{", "// Failed dependency", "$", "this", "->", "result", "[", "$", "propertyName", "]", "=", "424", ";", "}", "}", "}", "return", "!", "$", "this", "->", "failed", ";", "}" ]
Performs the actual update, and calls all callbacks. This method returns true or false depending on if the operation was successful. @return bool
[ "Performs", "the", "actual", "update", "and", "calls", "all", "callbacks", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PropPatch.php#L213-L248
sabre-io/dav
lib/DAV/PropPatch.php
PropPatch.doCallBackSingleProp
private function doCallBackSingleProp($propertyName, callable $callback) { $result = $callback($this->mutations[$propertyName]); if (is_bool($result)) { if ($result) { if (is_null($this->mutations[$propertyName])) { // Delete $result = 204; } else { // Update $result = 200; } } else { // Fail $result = 403; } } if (!is_int($result)) { throw new UnexpectedValueException('A callback sent to handle() did not return an int or a bool'); } $this->result[$propertyName] = $result; if ($result >= 400) { $this->failed = true; } }
php
private function doCallBackSingleProp($propertyName, callable $callback) { $result = $callback($this->mutations[$propertyName]); if (is_bool($result)) { if ($result) { if (is_null($this->mutations[$propertyName])) { $result = 204; } else { $result = 200; } } else { $result = 403; } } if (!is_int($result)) { throw new UnexpectedValueException('A callback sent to handle() did not return an int or a bool'); } $this->result[$propertyName] = $result; if ($result >= 400) { $this->failed = true; } }
[ "private", "function", "doCallBackSingleProp", "(", "$", "propertyName", ",", "callable", "$", "callback", ")", "{", "$", "result", "=", "$", "callback", "(", "$", "this", "->", "mutations", "[", "$", "propertyName", "]", ")", ";", "if", "(", "is_bool", "(", "$", "result", ")", ")", "{", "if", "(", "$", "result", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "mutations", "[", "$", "propertyName", "]", ")", ")", "{", "// Delete", "$", "result", "=", "204", ";", "}", "else", "{", "// Update", "$", "result", "=", "200", ";", "}", "}", "else", "{", "// Fail", "$", "result", "=", "403", ";", "}", "}", "if", "(", "!", "is_int", "(", "$", "result", ")", ")", "{", "throw", "new", "UnexpectedValueException", "(", "'A callback sent to handle() did not return an int or a bool'", ")", ";", "}", "$", "this", "->", "result", "[", "$", "propertyName", "]", "=", "$", "result", ";", "if", "(", "$", "result", ">=", "400", ")", "{", "$", "this", "->", "failed", "=", "true", ";", "}", "}" ]
Executes a property callback with the single-property syntax. @param string $propertyName @param callable $callback
[ "Executes", "a", "property", "callback", "with", "the", "single", "-", "property", "syntax", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PropPatch.php#L256-L280
sabre-io/dav
lib/DAV/PropPatch.php
PropPatch.doCallBackMultiProp
private function doCallBackMultiProp(array $propertyList, callable $callback) { $argument = []; foreach ($propertyList as $propertyName) { $argument[$propertyName] = $this->mutations[$propertyName]; } $result = $callback($argument); if (is_array($result)) { foreach ($propertyList as $propertyName) { if (!isset($result[$propertyName])) { $resultCode = 500; } else { $resultCode = $result[$propertyName]; } if ($resultCode >= 400) { $this->failed = true; } $this->result[$propertyName] = $resultCode; } } elseif (true === $result) { // Success foreach ($argument as $propertyName => $propertyValue) { $this->result[$propertyName] = is_null($propertyValue) ? 204 : 200; } } elseif (false === $result) { // Fail :( $this->failed = true; foreach ($propertyList as $propertyName) { $this->result[$propertyName] = 403; } } else { throw new UnexpectedValueException('A callback sent to handle() did not return an array or a bool'); } }
php
private function doCallBackMultiProp(array $propertyList, callable $callback) { $argument = []; foreach ($propertyList as $propertyName) { $argument[$propertyName] = $this->mutations[$propertyName]; } $result = $callback($argument); if (is_array($result)) { foreach ($propertyList as $propertyName) { if (!isset($result[$propertyName])) { $resultCode = 500; } else { $resultCode = $result[$propertyName]; } if ($resultCode >= 400) { $this->failed = true; } $this->result[$propertyName] = $resultCode; } } elseif (true === $result) { foreach ($argument as $propertyName => $propertyValue) { $this->result[$propertyName] = is_null($propertyValue) ? 204 : 200; } } elseif (false === $result) { $this->failed = true; foreach ($propertyList as $propertyName) { $this->result[$propertyName] = 403; } } else { throw new UnexpectedValueException('A callback sent to handle() did not return an array or a bool'); } }
[ "private", "function", "doCallBackMultiProp", "(", "array", "$", "propertyList", ",", "callable", "$", "callback", ")", "{", "$", "argument", "=", "[", "]", ";", "foreach", "(", "$", "propertyList", "as", "$", "propertyName", ")", "{", "$", "argument", "[", "$", "propertyName", "]", "=", "$", "this", "->", "mutations", "[", "$", "propertyName", "]", ";", "}", "$", "result", "=", "$", "callback", "(", "$", "argument", ")", ";", "if", "(", "is_array", "(", "$", "result", ")", ")", "{", "foreach", "(", "$", "propertyList", "as", "$", "propertyName", ")", "{", "if", "(", "!", "isset", "(", "$", "result", "[", "$", "propertyName", "]", ")", ")", "{", "$", "resultCode", "=", "500", ";", "}", "else", "{", "$", "resultCode", "=", "$", "result", "[", "$", "propertyName", "]", ";", "}", "if", "(", "$", "resultCode", ">=", "400", ")", "{", "$", "this", "->", "failed", "=", "true", ";", "}", "$", "this", "->", "result", "[", "$", "propertyName", "]", "=", "$", "resultCode", ";", "}", "}", "elseif", "(", "true", "===", "$", "result", ")", "{", "// Success", "foreach", "(", "$", "argument", "as", "$", "propertyName", "=>", "$", "propertyValue", ")", "{", "$", "this", "->", "result", "[", "$", "propertyName", "]", "=", "is_null", "(", "$", "propertyValue", ")", "?", "204", ":", "200", ";", "}", "}", "elseif", "(", "false", "===", "$", "result", ")", "{", "// Fail :(", "$", "this", "->", "failed", "=", "true", ";", "foreach", "(", "$", "propertyList", "as", "$", "propertyName", ")", "{", "$", "this", "->", "result", "[", "$", "propertyName", "]", "=", "403", ";", "}", "}", "else", "{", "throw", "new", "UnexpectedValueException", "(", "'A callback sent to handle() did not return an array or a bool'", ")", ";", "}", "}" ]
Executes a property callback with the multi-property syntax. @param array $propertyList @param callable $callback
[ "Executes", "a", "property", "callback", "with", "the", "multi", "-", "property", "syntax", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PropPatch.php#L288-L323
sabre-io/dav
lib/DAV/Browser/HtmlOutputHelper.php
HtmlOutputHelper.link
public function link($url, $label = null) { $url = $this->h($this->fullUrl($url)); return '<a href="'.$url.'">'.($label ? $this->h($label) : $url).'</a>'; }
php
public function link($url, $label = null) { $url = $this->h($this->fullUrl($url)); return '<a href="'.$url.'">'.($label ? $this->h($label) : $url).'</a>'; }
[ "public", "function", "link", "(", "$", "url", ",", "$", "label", "=", "null", ")", "{", "$", "url", "=", "$", "this", "->", "h", "(", "$", "this", "->", "fullUrl", "(", "$", "url", ")", ")", ";", "return", "'<a href=\"'", ".", "$", "url", ".", "'\">'", ".", "(", "$", "label", "?", "$", "this", "->", "h", "(", "$", "label", ")", ":", "$", "url", ")", ".", "'</a>'", ";", "}" ]
Generates a full <a>-tag. Url is automatically expanded. If label is not specified, we re-use the url. @param string $url @param string $label @return string
[ "Generates", "a", "full", "<a", ">", "-", "tag", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/HtmlOutputHelper.php#L93-L98
sabre-io/dav
lib/DAV/Browser/HtmlOutputHelper.php
HtmlOutputHelper.xmlName
public function xmlName($element) { list($ns, $localName) = XmlService::parseClarkNotation($element); if (isset($this->namespaceMap[$ns])) { $propName = $this->namespaceMap[$ns].':'.$localName; } else { $propName = $element; } return '<span title="'.$this->h($element).'">'.$this->h($propName).'</span>'; }
php
public function xmlName($element) { list($ns, $localName) = XmlService::parseClarkNotation($element); if (isset($this->namespaceMap[$ns])) { $propName = $this->namespaceMap[$ns].':'.$localName; } else { $propName = $element; } return '<span title="'.$this->h($element).'">'.$this->h($propName).'</span>'; }
[ "public", "function", "xmlName", "(", "$", "element", ")", "{", "list", "(", "$", "ns", ",", "$", "localName", ")", "=", "XmlService", "::", "parseClarkNotation", "(", "$", "element", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "namespaceMap", "[", "$", "ns", "]", ")", ")", "{", "$", "propName", "=", "$", "this", "->", "namespaceMap", "[", "$", "ns", "]", ".", "':'", ".", "$", "localName", ";", "}", "else", "{", "$", "propName", "=", "$", "element", ";", "}", "return", "'<span title=\"'", ".", "$", "this", "->", "h", "(", "$", "element", ")", ".", "'\">'", ".", "$", "this", "->", "h", "(", "$", "propName", ")", ".", "'</span>'", ";", "}" ]
This method takes an xml element in clark-notation, and turns it into a shortened version with a prefix, if it was a known namespace. @param string $element @return string
[ "This", "method", "takes", "an", "xml", "element", "in", "clark", "-", "notation", "and", "turns", "it", "into", "a", "shortened", "version", "with", "a", "prefix", "if", "it", "was", "a", "known", "namespace", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/HtmlOutputHelper.php#L108-L118
sabre-io/dav
lib/DAV/FS/Directory.php
Directory.createFile
public function createFile($name, $data = null) { $newPath = $this->path.'/'.$name; file_put_contents($newPath, $data); clearstatcache(true, $newPath); }
php
public function createFile($name, $data = null) { $newPath = $this->path.'/'.$name; file_put_contents($newPath, $data); clearstatcache(true, $newPath); }
[ "public", "function", "createFile", "(", "$", "name", ",", "$", "data", "=", "null", ")", "{", "$", "newPath", "=", "$", "this", "->", "path", ".", "'/'", ".", "$", "name", ";", "file_put_contents", "(", "$", "newPath", ",", "$", "data", ")", ";", "clearstatcache", "(", "true", ",", "$", "newPath", ")", ";", "}" ]
Creates a new file in the directory. Data will either be supplied as a stream resource, or in certain cases as a string. Keep in mind that you may have to support either. After successful creation of the file, you may choose to return the ETag of the new file here. The returned ETag must be surrounded by double-quotes (The quotes should be part of the actual string). If you cannot accurately determine the ETag, you should not return it. If you don't store the file exactly as-is (you're transforming it somehow) you should also not return an ETag. This means that if a subsequent GET to this new file does not exactly return the same contents of what was submitted here, you are strongly recommended to omit the ETag. @param string $name Name of the file @param resource|string $data Initial payload @return string|null
[ "Creates", "a", "new", "file", "in", "the", "directory", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/FS/Directory.php#L43-L48
sabre-io/dav
lib/DAV/FS/Directory.php
Directory.createDirectory
public function createDirectory($name) { $newPath = $this->path.'/'.$name; mkdir($newPath); clearstatcache(true, $newPath); }
php
public function createDirectory($name) { $newPath = $this->path.'/'.$name; mkdir($newPath); clearstatcache(true, $newPath); }
[ "public", "function", "createDirectory", "(", "$", "name", ")", "{", "$", "newPath", "=", "$", "this", "->", "path", ".", "'/'", ".", "$", "name", ";", "mkdir", "(", "$", "newPath", ")", ";", "clearstatcache", "(", "true", ",", "$", "newPath", ")", ";", "}" ]
Creates a new subdirectory. @param string $name
[ "Creates", "a", "new", "subdirectory", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/FS/Directory.php#L55-L60
sabre-io/dav
lib/DAV/FS/Directory.php
Directory.getQuotaInfo
public function getQuotaInfo() { $absolute = realpath($this->path); return [ disk_total_space($absolute) - disk_free_space($absolute), disk_free_space($absolute), ]; }
php
public function getQuotaInfo() { $absolute = realpath($this->path); return [ disk_total_space($absolute) - disk_free_space($absolute), disk_free_space($absolute), ]; }
[ "public", "function", "getQuotaInfo", "(", ")", "{", "$", "absolute", "=", "realpath", "(", "$", "this", "->", "path", ")", ";", "return", "[", "disk_total_space", "(", "$", "absolute", ")", "-", "disk_free_space", "(", "$", "absolute", ")", ",", "disk_free_space", "(", "$", "absolute", ")", ",", "]", ";", "}" ]
Returns available diskspace information. @return array
[ "Returns", "available", "diskspace", "information", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/FS/Directory.php#L138-L146
sabre-io/dav
lib/DAVACL/Xml/Property/SupportedPrivilegeSet.php
SupportedPrivilegeSet.toHtml
public function toHtml(HtmlOutputHelper $html) { $traverse = function ($privName, $priv) use (&$traverse, $html) { echo '<li>'; echo $html->xmlName($privName); if (isset($priv['abstract']) && $priv['abstract']) { echo ' <i>(abstract)</i>'; } if (isset($priv['description'])) { echo ' '.$html->h($priv['description']); } if (isset($priv['aggregates'])) { echo "\n<ul>\n"; foreach ($priv['aggregates'] as $subPrivName => $subPriv) { $traverse($subPrivName, $subPriv); } echo '</ul>'; } echo "</li>\n"; }; ob_start(); echo '<ul class="tree">'; $traverse('{DAV:}all', ['aggregates' => $this->getValue()]); echo "</ul>\n"; return ob_get_clean(); }
php
public function toHtml(HtmlOutputHelper $html) { $traverse = function ($privName, $priv) use (&$traverse, $html) { echo '<li>'; echo $html->xmlName($privName); if (isset($priv['abstract']) && $priv['abstract']) { echo ' <i>(abstract)</i>'; } if (isset($priv['description'])) { echo ' '.$html->h($priv['description']); } if (isset($priv['aggregates'])) { echo "\n<ul>\n"; foreach ($priv['aggregates'] as $subPrivName => $subPriv) { $traverse($subPrivName, $subPriv); } echo '</ul>'; } echo "</li>\n"; }; ob_start(); echo '<ul class="tree">'; $traverse('{DAV:}all', ['aggregates' => $this->getValue()]); echo "</ul>\n"; return ob_get_clean(); }
[ "public", "function", "toHtml", "(", "HtmlOutputHelper", "$", "html", ")", "{", "$", "traverse", "=", "function", "(", "$", "privName", ",", "$", "priv", ")", "use", "(", "&", "$", "traverse", ",", "$", "html", ")", "{", "echo", "'<li>'", ";", "echo", "$", "html", "->", "xmlName", "(", "$", "privName", ")", ";", "if", "(", "isset", "(", "$", "priv", "[", "'abstract'", "]", ")", "&&", "$", "priv", "[", "'abstract'", "]", ")", "{", "echo", "' <i>(abstract)</i>'", ";", "}", "if", "(", "isset", "(", "$", "priv", "[", "'description'", "]", ")", ")", "{", "echo", "' '", ".", "$", "html", "->", "h", "(", "$", "priv", "[", "'description'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "priv", "[", "'aggregates'", "]", ")", ")", "{", "echo", "\"\\n<ul>\\n\"", ";", "foreach", "(", "$", "priv", "[", "'aggregates'", "]", "as", "$", "subPrivName", "=>", "$", "subPriv", ")", "{", "$", "traverse", "(", "$", "subPrivName", ",", "$", "subPriv", ")", ";", "}", "echo", "'</ul>'", ";", "}", "echo", "\"</li>\\n\"", ";", "}", ";", "ob_start", "(", ")", ";", "echo", "'<ul class=\"tree\">'", ";", "$", "traverse", "(", "'{DAV:}all'", ",", "[", "'aggregates'", "=>", "$", "this", "->", "getValue", "(", ")", "]", ")", ";", "echo", "\"</ul>\\n\"", ";", "return", "ob_get_clean", "(", ")", ";", "}" ]
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/SupportedPrivilegeSet.php#L93-L120
sabre-io/dav
lib/DAVACL/Xml/Property/SupportedPrivilegeSet.php
SupportedPrivilegeSet.serializePriv
private function serializePriv(Writer $writer, $privName, $privilege) { $writer->startElement('{DAV:}supported-privilege'); $writer->startElement('{DAV:}privilege'); $writer->writeElement($privName); $writer->endElement(); // privilege if (!empty($privilege['abstract'])) { $writer->writeElement('{DAV:}abstract'); } if (!empty($privilege['description'])) { $writer->writeElement('{DAV:}description', $privilege['description']); } if (isset($privilege['aggregates'])) { foreach ($privilege['aggregates'] as $subPrivName => $subPrivilege) { $this->serializePriv($writer, $subPrivName, $subPrivilege); } } $writer->endElement(); // supported-privilege }
php
private function serializePriv(Writer $writer, $privName, $privilege) { $writer->startElement('{DAV:}supported-privilege'); $writer->startElement('{DAV:}privilege'); $writer->writeElement($privName); $writer->endElement(); if (!empty($privilege['abstract'])) { $writer->writeElement('{DAV:}abstract'); } if (!empty($privilege['description'])) { $writer->writeElement('{DAV:}description', $privilege['description']); } if (isset($privilege['aggregates'])) { foreach ($privilege['aggregates'] as $subPrivName => $subPrivilege) { $this->serializePriv($writer, $subPrivName, $subPrivilege); } } $writer->endElement(); }
[ "private", "function", "serializePriv", "(", "Writer", "$", "writer", ",", "$", "privName", ",", "$", "privilege", ")", "{", "$", "writer", "->", "startElement", "(", "'{DAV:}supported-privilege'", ")", ";", "$", "writer", "->", "startElement", "(", "'{DAV:}privilege'", ")", ";", "$", "writer", "->", "writeElement", "(", "$", "privName", ")", ";", "$", "writer", "->", "endElement", "(", ")", ";", "// privilege", "if", "(", "!", "empty", "(", "$", "privilege", "[", "'abstract'", "]", ")", ")", "{", "$", "writer", "->", "writeElement", "(", "'{DAV:}abstract'", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "privilege", "[", "'description'", "]", ")", ")", "{", "$", "writer", "->", "writeElement", "(", "'{DAV:}description'", ",", "$", "privilege", "[", "'description'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "privilege", "[", "'aggregates'", "]", ")", ")", "{", "foreach", "(", "$", "privilege", "[", "'aggregates'", "]", "as", "$", "subPrivName", "=>", "$", "subPrivilege", ")", "{", "$", "this", "->", "serializePriv", "(", "$", "writer", ",", "$", "subPrivName", ",", "$", "subPrivilege", ")", ";", "}", "}", "$", "writer", "->", "endElement", "(", ")", ";", "// supported-privilege", "}" ]
Serializes a property. This is a recursive function. @param Writer $writer @param string $privName @param array $privilege
[ "Serializes", "a", "property", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Xml/Property/SupportedPrivilegeSet.php#L131-L152
sabre-io/dav
lib/CardDAV/Card.php
Card.get
public function get() { // Pre-populating 'carddata' is optional. If we don't yet have it // already, we fetch it from the backend. if (!isset($this->cardData['carddata'])) { $this->cardData = $this->carddavBackend->getCard($this->addressBookInfo['id'], $this->cardData['uri']); } return $this->cardData['carddata']; }
php
public function get() { if (!isset($this->cardData['carddata'])) { $this->cardData = $this->carddavBackend->getCard($this->addressBookInfo['id'], $this->cardData['uri']); } return $this->cardData['carddata']; }
[ "public", "function", "get", "(", ")", "{", "// Pre-populating 'carddata' is optional. If we don't yet have it", "// already, we fetch it from the backend.", "if", "(", "!", "isset", "(", "$", "this", "->", "cardData", "[", "'carddata'", "]", ")", ")", "{", "$", "this", "->", "cardData", "=", "$", "this", "->", "carddavBackend", "->", "getCard", "(", "$", "this", "->", "addressBookInfo", "[", "'id'", "]", ",", "$", "this", "->", "cardData", "[", "'uri'", "]", ")", ";", "}", "return", "$", "this", "->", "cardData", "[", "'carddata'", "]", ";", "}" ]
Returns the VCard-formatted object. @return string
[ "Returns", "the", "VCard", "-", "formatted", "object", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Card.php#L71-L80
sabre-io/dav
lib/CardDAV/Card.php
Card.put
public function put($cardData) { if (is_resource($cardData)) { $cardData = stream_get_contents($cardData); } // Converting to UTF-8, if needed $cardData = DAV\StringUtil::ensureUTF8($cardData); $etag = $this->carddavBackend->updateCard($this->addressBookInfo['id'], $this->cardData['uri'], $cardData); $this->cardData['carddata'] = $cardData; $this->cardData['etag'] = $etag; return $etag; }
php
public function put($cardData) { if (is_resource($cardData)) { $cardData = stream_get_contents($cardData); } $cardData = DAV\StringUtil::ensureUTF8($cardData); $etag = $this->carddavBackend->updateCard($this->addressBookInfo['id'], $this->cardData['uri'], $cardData); $this->cardData['carddata'] = $cardData; $this->cardData['etag'] = $etag; return $etag; }
[ "public", "function", "put", "(", "$", "cardData", ")", "{", "if", "(", "is_resource", "(", "$", "cardData", ")", ")", "{", "$", "cardData", "=", "stream_get_contents", "(", "$", "cardData", ")", ";", "}", "// Converting to UTF-8, if needed", "$", "cardData", "=", "DAV", "\\", "StringUtil", "::", "ensureUTF8", "(", "$", "cardData", ")", ";", "$", "etag", "=", "$", "this", "->", "carddavBackend", "->", "updateCard", "(", "$", "this", "->", "addressBookInfo", "[", "'id'", "]", ",", "$", "this", "->", "cardData", "[", "'uri'", "]", ",", "$", "cardData", ")", ";", "$", "this", "->", "cardData", "[", "'carddata'", "]", "=", "$", "cardData", ";", "$", "this", "->", "cardData", "[", "'etag'", "]", "=", "$", "etag", ";", "return", "$", "etag", ";", "}" ]
Updates the VCard-formatted object. @param string $cardData @return string|null
[ "Updates", "the", "VCard", "-", "formatted", "object", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Card.php#L89-L103
sabre-io/dav
lib/CardDAV/Card.php
Card.getETag
public function getETag() { if (isset($this->cardData['etag'])) { return $this->cardData['etag']; } else { $data = $this->get(); if (is_string($data)) { return '"'.md5($data).'"'; } else { // We refuse to calculate the md5 if it's a stream. return null; } } }
php
public function getETag() { if (isset($this->cardData['etag'])) { return $this->cardData['etag']; } else { $data = $this->get(); if (is_string($data)) { return '"'.md5($data).'"'; } else { return null; } } }
[ "public", "function", "getETag", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "cardData", "[", "'etag'", "]", ")", ")", "{", "return", "$", "this", "->", "cardData", "[", "'etag'", "]", ";", "}", "else", "{", "$", "data", "=", "$", "this", "->", "get", "(", ")", ";", "if", "(", "is_string", "(", "$", "data", ")", ")", "{", "return", "'\"'", ".", "md5", "(", "$", "data", ")", ".", "'\"'", ";", "}", "else", "{", "// We refuse to calculate the md5 if it's a stream.", "return", "null", ";", "}", "}", "}" ]
Returns an ETag for this object. @return string
[ "Returns", "an", "ETag", "for", "this", "object", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Card.php#L128-L141
sabre-io/dav
lib/DAVACL/Xml/Request/PrincipalPropertySearchReport.php
PrincipalPropertySearchReport.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { $self = new self(); $foundSearchProp = false; $self->test = 'allof'; if ('anyof' === $reader->getAttribute('test')) { $self->test = 'anyof'; } $elemMap = [ '{DAV:}property-search' => 'Sabre\\Xml\\Element\\KeyValue', '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', ]; foreach ($reader->parseInnerTree($elemMap) as $elem) { switch ($elem['name']) { case '{DAV:}prop': $self->properties = array_keys($elem['value']); break; case '{DAV:}property-search': $foundSearchProp = true; // This property has two sub-elements: // {DAV:}prop - The property to be searched on. This may // also be more than one // {DAV:}match - The value to match with if (!isset($elem['value']['{DAV:}prop']) || !isset($elem['value']['{DAV:}match'])) { throw new BadRequest('The {DAV:}property-search element must contain one {DAV:}match and one {DAV:}prop element'); } foreach ($elem['value']['{DAV:}prop'] as $propName => $discard) { $self->searchProperties[$propName] = $elem['value']['{DAV:}match']; } break; case '{DAV:}apply-to-principal-collection-set': $self->applyToPrincipalCollectionSet = true; break; } } if (!$foundSearchProp) { throw new BadRequest('The {DAV:}principal-property-search report must contain at least 1 {DAV:}property-search element'); } return $self; }
php
public static function xmlDeserialize(Reader $reader) { $self = new self(); $foundSearchProp = false; $self->test = 'allof'; if ('anyof' === $reader->getAttribute('test')) { $self->test = 'anyof'; } $elemMap = [ '{DAV:}property-search' => 'Sabre\\Xml\\Element\\KeyValue', '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', ]; foreach ($reader->parseInnerTree($elemMap) as $elem) { switch ($elem['name']) { case '{DAV:}prop': $self->properties = array_keys($elem['value']); break; case '{DAV:}property-search': $foundSearchProp = true; if (!isset($elem['value']['{DAV:}prop']) || !isset($elem['value']['{DAV:}match'])) { throw new BadRequest('The {DAV:}property-search element must contain one {DAV:}match and one {DAV:}prop element'); } foreach ($elem['value']['{DAV:}prop'] as $propName => $discard) { $self->searchProperties[$propName] = $elem['value']['{DAV:}match']; } break; case '{DAV:}apply-to-principal-collection-set': $self->applyToPrincipalCollectionSet = true; break; } } if (!$foundSearchProp) { throw new BadRequest('The {DAV:}principal-property-search report must contain at least 1 {DAV:}property-search element'); } return $self; }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "$", "self", "=", "new", "self", "(", ")", ";", "$", "foundSearchProp", "=", "false", ";", "$", "self", "->", "test", "=", "'allof'", ";", "if", "(", "'anyof'", "===", "$", "reader", "->", "getAttribute", "(", "'test'", ")", ")", "{", "$", "self", "->", "test", "=", "'anyof'", ";", "}", "$", "elemMap", "=", "[", "'{DAV:}property-search'", "=>", "'Sabre\\\\Xml\\\\Element\\\\KeyValue'", ",", "'{DAV:}prop'", "=>", "'Sabre\\\\Xml\\\\Element\\\\KeyValue'", ",", "]", ";", "foreach", "(", "$", "reader", "->", "parseInnerTree", "(", "$", "elemMap", ")", "as", "$", "elem", ")", "{", "switch", "(", "$", "elem", "[", "'name'", "]", ")", "{", "case", "'{DAV:}prop'", ":", "$", "self", "->", "properties", "=", "array_keys", "(", "$", "elem", "[", "'value'", "]", ")", ";", "break", ";", "case", "'{DAV:}property-search'", ":", "$", "foundSearchProp", "=", "true", ";", "// This property has two sub-elements:", "// {DAV:}prop - The property to be searched on. This may", "// also be more than one", "// {DAV:}match - The value to match with", "if", "(", "!", "isset", "(", "$", "elem", "[", "'value'", "]", "[", "'{DAV:}prop'", "]", ")", "||", "!", "isset", "(", "$", "elem", "[", "'value'", "]", "[", "'{DAV:}match'", "]", ")", ")", "{", "throw", "new", "BadRequest", "(", "'The {DAV:}property-search element must contain one {DAV:}match and one {DAV:}prop element'", ")", ";", "}", "foreach", "(", "$", "elem", "[", "'value'", "]", "[", "'{DAV:}prop'", "]", "as", "$", "propName", "=>", "$", "discard", ")", "{", "$", "self", "->", "searchProperties", "[", "$", "propName", "]", "=", "$", "elem", "[", "'value'", "]", "[", "'{DAV:}match'", "]", ";", "}", "break", ";", "case", "'{DAV:}apply-to-principal-collection-set'", ":", "$", "self", "->", "applyToPrincipalCollectionSet", "=", "true", ";", "break", ";", "}", "}", "if", "(", "!", "$", "foundSearchProp", ")", "{", "throw", "new", "BadRequest", "(", "'The {DAV:}principal-property-search report must contain at least 1 {DAV:}property-search element'", ")", ";", "}", "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/DAVACL/Xml/Request/PrincipalPropertySearchReport.php#L80-L123
sabre-io/dav
lib/CalDAV/Xml/Notification/InviteReply.php
InviteReply.xmlSerializeFull
public function xmlSerializeFull(Writer $writer) { $cs = '{'.CalDAV\Plugin::NS_CALENDARSERVER.'}'; $this->dtStamp->setTimezone(new \DateTimeZone('GMT')); $writer->writeElement($cs.'dtstamp', $this->dtStamp->format('Ymd\\THis\\Z')); $writer->startElement($cs.'invite-reply'); $writer->writeElement($cs.'uid', $this->id); $writer->writeElement($cs.'in-reply-to', $this->inReplyTo); $writer->writeElement('{DAV:}href', $this->href); switch ($this->type) { case DAV\Sharing\Plugin::INVITE_ACCEPTED: $writer->writeElement($cs.'invite-accepted'); break; case DAV\Sharing\Plugin::INVITE_DECLINED: $writer->writeElement($cs.'invite-declined'); break; } $writer->writeElement($cs.'hosturl', [ '{DAV:}href' => $writer->contextUri.$this->hostUrl, ]); if ($this->summary) { $writer->writeElement($cs.'summary', $this->summary); } $writer->endElement(); // invite-reply }
php
public function xmlSerializeFull(Writer $writer) { $cs = '{'.CalDAV\Plugin::NS_CALENDARSERVER.'}'; $this->dtStamp->setTimezone(new \DateTimeZone('GMT')); $writer->writeElement($cs.'dtstamp', $this->dtStamp->format('Ymd\\THis\\Z')); $writer->startElement($cs.'invite-reply'); $writer->writeElement($cs.'uid', $this->id); $writer->writeElement($cs.'in-reply-to', $this->inReplyTo); $writer->writeElement('{DAV:}href', $this->href); switch ($this->type) { case DAV\Sharing\Plugin::INVITE_ACCEPTED: $writer->writeElement($cs.'invite-accepted'); break; case DAV\Sharing\Plugin::INVITE_DECLINED: $writer->writeElement($cs.'invite-declined'); break; } $writer->writeElement($cs.'hosturl', [ '{DAV:}href' => $writer->contextUri.$this->hostUrl, ]); if ($this->summary) { $writer->writeElement($cs.'summary', $this->summary); } $writer->endElement(); }
[ "public", "function", "xmlSerializeFull", "(", "Writer", "$", "writer", ")", "{", "$", "cs", "=", "'{'", ".", "CalDAV", "\\", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}'", ";", "$", "this", "->", "dtStamp", "->", "setTimezone", "(", "new", "\\", "DateTimeZone", "(", "'GMT'", ")", ")", ";", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'dtstamp'", ",", "$", "this", "->", "dtStamp", "->", "format", "(", "'Ymd\\\\THis\\\\Z'", ")", ")", ";", "$", "writer", "->", "startElement", "(", "$", "cs", ".", "'invite-reply'", ")", ";", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'uid'", ",", "$", "this", "->", "id", ")", ";", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'in-reply-to'", ",", "$", "this", "->", "inReplyTo", ")", ";", "$", "writer", "->", "writeElement", "(", "'{DAV:}href'", ",", "$", "this", "->", "href", ")", ";", "switch", "(", "$", "this", "->", "type", ")", "{", "case", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "INVITE_ACCEPTED", ":", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'invite-accepted'", ")", ";", "break", ";", "case", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "INVITE_DECLINED", ":", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'invite-declined'", ")", ";", "break", ";", "}", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'hosturl'", ",", "[", "'{DAV:}href'", "=>", "$", "writer", "->", "contextUri", ".", "$", "this", "->", "hostUrl", ",", "]", ")", ";", "if", "(", "$", "this", "->", "summary", ")", "{", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'summary'", ",", "$", "this", "->", "summary", ")", ";", "}", "$", "writer", "->", "endElement", "(", ")", ";", "// invite-reply", "}" ]
This method serializes the entire notification, as it is used in the response body. @param Writer $writer
[ "This", "method", "serializes", "the", "entire", "notification", "as", "it", "is", "used", "in", "the", "response", "body", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Xml/Notification/InviteReply.php#L149-L179
sabre-io/dav
lib/DAV/Auth/Plugin.php
Plugin.beforeMethod
public function beforeMethod(RequestInterface $request, ResponseInterface $response) { if ($this->currentPrincipal) { // We already have authentication information. This means that the // event has already fired earlier, and is now likely fired for a // sub-request. // // We don't want to authenticate users twice, so we simply don't do // anything here. See Issue #700 for additional reasoning. // // This is not a perfect solution, but will be fixed once the // "currently authenticated principal" is information that's not // not associated with the plugin, but rather per-request. // // See issue #580 for more information about that. return; } $authResult = $this->check($request, $response); if ($authResult[0]) { // Auth was successful $this->currentPrincipal = $authResult[1]; $this->loginFailedReasons = null; return; } // If we got here, it means that no authentication backend was // successful in authenticating the user. $this->currentPrincipal = null; $this->loginFailedReasons = $authResult[1]; if ($this->autoRequireLogin) { $this->challenge($request, $response); throw new NotAuthenticated(implode(', ', $authResult[1])); } }
php
public function beforeMethod(RequestInterface $request, ResponseInterface $response) { if ($this->currentPrincipal) { return; } $authResult = $this->check($request, $response); if ($authResult[0]) { $this->currentPrincipal = $authResult[1]; $this->loginFailedReasons = null; return; } $this->currentPrincipal = null; $this->loginFailedReasons = $authResult[1]; if ($this->autoRequireLogin) { $this->challenge($request, $response); throw new NotAuthenticated(implode(', ', $authResult[1])); } }
[ "public", "function", "beforeMethod", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "if", "(", "$", "this", "->", "currentPrincipal", ")", "{", "// We already have authentication information. This means that the", "// event has already fired earlier, and is now likely fired for a", "// sub-request.", "//", "// We don't want to authenticate users twice, so we simply don't do", "// anything here. See Issue #700 for additional reasoning.", "//", "// This is not a perfect solution, but will be fixed once the", "// \"currently authenticated principal\" is information that's not", "// not associated with the plugin, but rather per-request.", "//", "// See issue #580 for more information about that.", "return", ";", "}", "$", "authResult", "=", "$", "this", "->", "check", "(", "$", "request", ",", "$", "response", ")", ";", "if", "(", "$", "authResult", "[", "0", "]", ")", "{", "// Auth was successful", "$", "this", "->", "currentPrincipal", "=", "$", "authResult", "[", "1", "]", ";", "$", "this", "->", "loginFailedReasons", "=", "null", ";", "return", ";", "}", "// If we got here, it means that no authentication backend was", "// successful in authenticating the user.", "$", "this", "->", "currentPrincipal", "=", "null", ";", "$", "this", "->", "loginFailedReasons", "=", "$", "authResult", "[", "1", "]", ";", "if", "(", "$", "this", "->", "autoRequireLogin", ")", "{", "$", "this", "->", "challenge", "(", "$", "request", ",", "$", "response", ")", ";", "throw", "new", "NotAuthenticated", "(", "implode", "(", "', '", ",", "$", "authResult", "[", "1", "]", ")", ")", ";", "}", "}" ]
This method is called before any HTTP method and forces users to be authenticated. @param RequestInterface $request @param ResponseInterface $response @return bool
[ "This", "method", "is", "called", "before", "any", "HTTP", "method", "and", "forces", "users", "to", "be", "authenticated", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Auth/Plugin.php#L126-L163
sabre-io/dav
lib/DAV/Auth/Plugin.php
Plugin.check
public function check(RequestInterface $request, ResponseInterface $response) { if (!$this->backends) { throw new \Sabre\DAV\Exception('No authentication backends were configured on this server.'); } $reasons = []; foreach ($this->backends as $backend) { $result = $backend->check( $request, $response ); if (!is_array($result) || 2 !== count($result) || !is_bool($result[0]) || !is_string($result[1])) { throw new \Sabre\DAV\Exception('The authentication backend did not return a correct value from the check() method.'); } if ($result[0]) { $this->currentPrincipal = $result[1]; // Exit early return [true, $result[1]]; } $reasons[] = $result[1]; } return [false, $reasons]; }
php
public function check(RequestInterface $request, ResponseInterface $response) { if (!$this->backends) { throw new \Sabre\DAV\Exception('No authentication backends were configured on this server.'); } $reasons = []; foreach ($this->backends as $backend) { $result = $backend->check( $request, $response ); if (!is_array($result) || 2 !== count($result) || !is_bool($result[0]) || !is_string($result[1])) { throw new \Sabre\DAV\Exception('The authentication backend did not return a correct value from the check() method.'); } if ($result[0]) { $this->currentPrincipal = $result[1]; return [true, $result[1]]; } $reasons[] = $result[1]; } return [false, $reasons]; }
[ "public", "function", "check", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "if", "(", "!", "$", "this", "->", "backends", ")", "{", "throw", "new", "\\", "Sabre", "\\", "DAV", "\\", "Exception", "(", "'No authentication backends were configured on this server.'", ")", ";", "}", "$", "reasons", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "backends", "as", "$", "backend", ")", "{", "$", "result", "=", "$", "backend", "->", "check", "(", "$", "request", ",", "$", "response", ")", ";", "if", "(", "!", "is_array", "(", "$", "result", ")", "||", "2", "!==", "count", "(", "$", "result", ")", "||", "!", "is_bool", "(", "$", "result", "[", "0", "]", ")", "||", "!", "is_string", "(", "$", "result", "[", "1", "]", ")", ")", "{", "throw", "new", "\\", "Sabre", "\\", "DAV", "\\", "Exception", "(", "'The authentication backend did not return a correct value from the check() method.'", ")", ";", "}", "if", "(", "$", "result", "[", "0", "]", ")", "{", "$", "this", "->", "currentPrincipal", "=", "$", "result", "[", "1", "]", ";", "// Exit early", "return", "[", "true", ",", "$", "result", "[", "1", "]", "]", ";", "}", "$", "reasons", "[", "]", "=", "$", "result", "[", "1", "]", ";", "}", "return", "[", "false", ",", "$", "reasons", "]", ";", "}" ]
Checks authentication credentials, and logs the user in if possible. This method returns an array. The first item in the array is a boolean indicating if login was successful. If login was successful, the second item in the array will contain the current principal url/path of the logged in user. If login was not successful, the second item in the array will contain a an array with strings. The strings are a list of reasons why login was unsuccessful. For every auth backend there will be one reason, so usually there's just one. @param RequestInterface $request @param ResponseInterface $response @return array
[ "Checks", "authentication", "credentials", "and", "logs", "the", "user", "in", "if", "possible", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Auth/Plugin.php#L184-L209
sabre-io/dav
lib/DAV/Auth/Plugin.php
Plugin.challenge
public function challenge(RequestInterface $request, ResponseInterface $response) { foreach ($this->backends as $backend) { $backend->challenge($request, $response); } }
php
public function challenge(RequestInterface $request, ResponseInterface $response) { foreach ($this->backends as $backend) { $backend->challenge($request, $response); } }
[ "public", "function", "challenge", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "foreach", "(", "$", "this", "->", "backends", "as", "$", "backend", ")", "{", "$", "backend", "->", "challenge", "(", "$", "request", ",", "$", "response", ")", ";", "}", "}" ]
This method sends authentication challenges to the user. This method will for example cause a HTTP Basic backend to set a WWW-Authorization header, indicating to the client that it should authenticate. @param RequestInterface $request @param ResponseInterface $response @return array
[ "This", "method", "sends", "authentication", "challenges", "to", "the", "user", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Auth/Plugin.php#L223-L228
sabre-io/dav
lib/DAVACL/Xml/Request/PrincipalMatchReport.php
PrincipalMatchReport.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { $reader->pushContext(); $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Deserializer\enum'; $elems = Deserializer\keyValue( $reader, 'DAV:' ); $reader->popContext(); $principalMatch = new self(); if (array_key_exists('self', $elems)) { $principalMatch->type = self::SELF; } if (array_key_exists('principal-property', $elems)) { $principalMatch->type = self::PRINCIPAL_PROPERTY; $principalMatch->principalProperty = $elems['principal-property'][0]['name']; } if (!empty($elems['prop'])) { $principalMatch->properties = $elems['prop']; } return $principalMatch; }
php
public static function xmlDeserialize(Reader $reader) { $reader->pushContext(); $reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Deserializer\enum'; $elems = Deserializer\keyValue( $reader, 'DAV:' ); $reader->popContext(); $principalMatch = new self(); if (array_key_exists('self', $elems)) { $principalMatch->type = self::SELF; } if (array_key_exists('principal-property', $elems)) { $principalMatch->type = self::PRINCIPAL_PROPERTY; $principalMatch->principalProperty = $elems['principal-property'][0]['name']; } if (!empty($elems['prop'])) { $principalMatch->properties = $elems['prop']; } return $principalMatch; }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "$", "reader", "->", "pushContext", "(", ")", ";", "$", "reader", "->", "elementMap", "[", "'{DAV:}prop'", "]", "=", "'Sabre\\Xml\\Deserializer\\enum'", ";", "$", "elems", "=", "Deserializer", "\\", "keyValue", "(", "$", "reader", ",", "'DAV:'", ")", ";", "$", "reader", "->", "popContext", "(", ")", ";", "$", "principalMatch", "=", "new", "self", "(", ")", ";", "if", "(", "array_key_exists", "(", "'self'", ",", "$", "elems", ")", ")", "{", "$", "principalMatch", "->", "type", "=", "self", "::", "SELF", ";", "}", "if", "(", "array_key_exists", "(", "'principal-property'", ",", "$", "elems", ")", ")", "{", "$", "principalMatch", "->", "type", "=", "self", "::", "PRINCIPAL_PROPERTY", ";", "$", "principalMatch", "->", "principalProperty", "=", "$", "elems", "[", "'principal-property'", "]", "[", "0", "]", "[", "'name'", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "elems", "[", "'prop'", "]", ")", ")", "{", "$", "principalMatch", "->", "properties", "=", "$", "elems", "[", "'prop'", "]", ";", "}", "return", "$", "principalMatch", ";", "}" ]
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/PrincipalMatchReport.php#L79-L107
sabre-io/dav
lib/CardDAV/AddressBookHome.php
AddressBookHome.getChild
public function getChild($name) { foreach ($this->getChildren() as $child) { if ($name == $child->getName()) { return $child; } } throw new DAV\Exception\NotFound('Addressbook with name \''.$name.'\' could not be found'); }
php
public function getChild($name) { foreach ($this->getChildren() as $child) { if ($name == $child->getName()) { return $child; } } throw new DAV\Exception\NotFound('Addressbook with name \''.$name.'\' could not be found'); }
[ "public", "function", "getChild", "(", "$", "name", ")", "{", "foreach", "(", "$", "this", "->", "getChildren", "(", ")", "as", "$", "child", ")", "{", "if", "(", "$", "name", "==", "$", "child", "->", "getName", "(", ")", ")", "{", "return", "$", "child", ";", "}", "}", "throw", "new", "DAV", "\\", "Exception", "\\", "NotFound", "(", "'Addressbook with name \\''", ".", "$", "name", ".", "'\\' could not be found'", ")", ";", "}" ]
Returns a single addressbook, by name. @param string $name @todo needs optimizing @return AddressBook
[ "Returns", "a", "single", "addressbook", "by", "name", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/AddressBookHome.php#L125-L133
sabre-io/dav
lib/CardDAV/AddressBookHome.php
AddressBookHome.getChildren
public function getChildren() { $addressbooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); $objs = []; foreach ($addressbooks as $addressbook) { $objs[] = new AddressBook($this->carddavBackend, $addressbook); } return $objs; }
php
public function getChildren() { $addressbooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri); $objs = []; foreach ($addressbooks as $addressbook) { $objs[] = new AddressBook($this->carddavBackend, $addressbook); } return $objs; }
[ "public", "function", "getChildren", "(", ")", "{", "$", "addressbooks", "=", "$", "this", "->", "carddavBackend", "->", "getAddressBooksForUser", "(", "$", "this", "->", "principalUri", ")", ";", "$", "objs", "=", "[", "]", ";", "foreach", "(", "$", "addressbooks", "as", "$", "addressbook", ")", "{", "$", "objs", "[", "]", "=", "new", "AddressBook", "(", "$", "this", "->", "carddavBackend", ",", "$", "addressbook", ")", ";", "}", "return", "$", "objs", ";", "}" ]
Returns a list of addressbooks. @return array
[ "Returns", "a", "list", "of", "addressbooks", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/AddressBookHome.php#L140-L149
sabre-io/dav
lib/CardDAV/AddressBookHome.php
AddressBookHome.createExtendedCollection
public function createExtendedCollection($name, MkCol $mkCol) { if (!$mkCol->hasResourceType('{'.Plugin::NS_CARDDAV.'}addressbook')) { throw new DAV\Exception\InvalidResourceType('Unknown resourceType for this collection'); } $properties = $mkCol->getRemainingValues(); $mkCol->setRemainingResultCode(201); $this->carddavBackend->createAddressBook($this->principalUri, $name, $properties); }
php
public function createExtendedCollection($name, MkCol $mkCol) { if (!$mkCol->hasResourceType('{'.Plugin::NS_CARDDAV.'}addressbook')) { throw new DAV\Exception\InvalidResourceType('Unknown resourceType for this collection'); } $properties = $mkCol->getRemainingValues(); $mkCol->setRemainingResultCode(201); $this->carddavBackend->createAddressBook($this->principalUri, $name, $properties); }
[ "public", "function", "createExtendedCollection", "(", "$", "name", ",", "MkCol", "$", "mkCol", ")", "{", "if", "(", "!", "$", "mkCol", "->", "hasResourceType", "(", "'{'", ".", "Plugin", "::", "NS_CARDDAV", ".", "'}addressbook'", ")", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "InvalidResourceType", "(", "'Unknown resourceType for this collection'", ")", ";", "}", "$", "properties", "=", "$", "mkCol", "->", "getRemainingValues", "(", ")", ";", "$", "mkCol", "->", "setRemainingResultCode", "(", "201", ")", ";", "$", "this", "->", "carddavBackend", "->", "createAddressBook", "(", "$", "this", "->", "principalUri", ",", "$", "name", ",", "$", "properties", ")", ";", "}" ]
Creates a new address book. @param string $name @param MkCol $mkCol @throws DAV\Exception\InvalidResourceType
[ "Creates", "a", "new", "address", "book", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/AddressBookHome.php#L159-L167
sabre-io/dav
lib/CalDAV/Notifications/Plugin.php
Plugin.initialize
public function initialize(Server $server) { $this->server = $server; $server->on('method:GET', [$this, 'httpGet'], 90); $server->on('propFind', [$this, 'propFind']); $server->xml->namespaceMap[self::NS_CALENDARSERVER] = 'cs'; $server->resourceTypeMapping['\\Sabre\\CalDAV\\Notifications\\ICollection'] = '{'.self::NS_CALENDARSERVER.'}notification'; array_push($server->protectedProperties, '{'.self::NS_CALENDARSERVER.'}notification-URL', '{'.self::NS_CALENDARSERVER.'}notificationtype' ); }
php
public function initialize(Server $server) { $this->server = $server; $server->on('method:GET', [$this, 'httpGet'], 90); $server->on('propFind', [$this, 'propFind']); $server->xml->namespaceMap[self::NS_CALENDARSERVER] = 'cs'; $server->resourceTypeMapping['\\Sabre\\CalDAV\\Notifications\\ICollection'] = '{'.self::NS_CALENDARSERVER.'}notification'; array_push($server->protectedProperties, '{'.self::NS_CALENDARSERVER.'}notification-URL', '{'.self::NS_CALENDARSERVER.'}notificationtype' ); }
[ "public", "function", "initialize", "(", "Server", "$", "server", ")", "{", "$", "this", "->", "server", "=", "$", "server", ";", "$", "server", "->", "on", "(", "'method:GET'", ",", "[", "$", "this", ",", "'httpGet'", "]", ",", "90", ")", ";", "$", "server", "->", "on", "(", "'propFind'", ",", "[", "$", "this", ",", "'propFind'", "]", ")", ";", "$", "server", "->", "xml", "->", "namespaceMap", "[", "self", "::", "NS_CALENDARSERVER", "]", "=", "'cs'", ";", "$", "server", "->", "resourceTypeMapping", "[", "'\\\\Sabre\\\\CalDAV\\\\Notifications\\\\ICollection'", "]", "=", "'{'", ".", "self", "::", "NS_CALENDARSERVER", ".", "'}notification'", ";", "array_push", "(", "$", "server", "->", "protectedProperties", ",", "'{'", ".", "self", "::", "NS_CALENDARSERVER", ".", "'}notification-URL'", ",", "'{'", ".", "self", "::", "NS_CALENDARSERVER", ".", "'}notificationtype'", ")", ";", "}" ]
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 Server $server
[ "This", "initializes", "the", "plugin", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Notifications/Plugin.php#L66-L79
sabre-io/dav
lib/CalDAV/Notifications/Plugin.php
Plugin.propFind
public function propFind(PropFind $propFind, BaseINode $node) { $caldavPlugin = $this->server->getPlugin('caldav'); if ($node instanceof DAVACL\IPrincipal) { $principalUrl = $node->getPrincipalUrl(); // notification-URL property $propFind->handle('{'.self::NS_CALENDARSERVER.'}notification-URL', function () use ($principalUrl, $caldavPlugin) { $notificationPath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl).'/notifications/'; return new DAV\Xml\Property\Href($notificationPath); }); } if ($node instanceof INode) { $propFind->handle( '{'.self::NS_CALENDARSERVER.'}notificationtype', [$node, 'getNotificationType'] ); } }
php
public function propFind(PropFind $propFind, BaseINode $node) { $caldavPlugin = $this->server->getPlugin('caldav'); if ($node instanceof DAVACL\IPrincipal) { $principalUrl = $node->getPrincipalUrl(); $propFind->handle('{'.self::NS_CALENDARSERVER.'}notification-URL', function () use ($principalUrl, $caldavPlugin) { $notificationPath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl).'/notifications/'; return new DAV\Xml\Property\Href($notificationPath); }); } if ($node instanceof INode) { $propFind->handle( '{'.self::NS_CALENDARSERVER.'}notificationtype', [$node, 'getNotificationType'] ); } }
[ "public", "function", "propFind", "(", "PropFind", "$", "propFind", ",", "BaseINode", "$", "node", ")", "{", "$", "caldavPlugin", "=", "$", "this", "->", "server", "->", "getPlugin", "(", "'caldav'", ")", ";", "if", "(", "$", "node", "instanceof", "DAVACL", "\\", "IPrincipal", ")", "{", "$", "principalUrl", "=", "$", "node", "->", "getPrincipalUrl", "(", ")", ";", "// notification-URL property", "$", "propFind", "->", "handle", "(", "'{'", ".", "self", "::", "NS_CALENDARSERVER", ".", "'}notification-URL'", ",", "function", "(", ")", "use", "(", "$", "principalUrl", ",", "$", "caldavPlugin", ")", "{", "$", "notificationPath", "=", "$", "caldavPlugin", "->", "getCalendarHomeForPrincipal", "(", "$", "principalUrl", ")", ".", "'/notifications/'", ";", "return", "new", "DAV", "\\", "Xml", "\\", "Property", "\\", "Href", "(", "$", "notificationPath", ")", ";", "}", ")", ";", "}", "if", "(", "$", "node", "instanceof", "INode", ")", "{", "$", "propFind", "->", "handle", "(", "'{'", ".", "self", "::", "NS_CALENDARSERVER", ".", "'}notificationtype'", ",", "[", "$", "node", ",", "'getNotificationType'", "]", ")", ";", "}", "}" ]
PropFind. @param PropFind $propFind @param BaseINode $node
[ "PropFind", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Notifications/Plugin.php#L87-L108
sabre-io/dav
lib/CalDAV/Notifications/Plugin.php
Plugin.httpGet
public function httpGet(RequestInterface $request, ResponseInterface $response) { $path = $request->getPath(); try { $node = $this->server->tree->getNodeForPath($path); } catch (DAV\Exception\NotFound $e) { return; } if (!$node instanceof INode) { return; } $writer = $this->server->xml->getWriter(); $writer->contextUri = $this->server->getBaseUri(); $writer->openMemory(); $writer->startDocument('1.0', 'UTF-8'); $writer->startElement('{http://calendarserver.org/ns/}notification'); $node->getNotificationType()->xmlSerializeFull($writer); $writer->endElement(); $response->setHeader('Content-Type', 'application/xml'); $response->setHeader('ETag', $node->getETag()); $response->setStatus(200); $response->setBody($writer->outputMemory()); // Return false to break the event chain. return false; }
php
public function httpGet(RequestInterface $request, ResponseInterface $response) { $path = $request->getPath(); try { $node = $this->server->tree->getNodeForPath($path); } catch (DAV\Exception\NotFound $e) { return; } if (!$node instanceof INode) { return; } $writer = $this->server->xml->getWriter(); $writer->contextUri = $this->server->getBaseUri(); $writer->openMemory(); $writer->startDocument('1.0', 'UTF-8'); $writer->startElement('{http: $node->getNotificationType()->xmlSerializeFull($writer); $writer->endElement(); $response->setHeader('Content-Type', 'application/xml'); $response->setHeader('ETag', $node->getETag()); $response->setStatus(200); $response->setBody($writer->outputMemory()); return false; }
[ "public", "function", "httpGet", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "path", "=", "$", "request", "->", "getPath", "(", ")", ";", "try", "{", "$", "node", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "path", ")", ";", "}", "catch", "(", "DAV", "\\", "Exception", "\\", "NotFound", "$", "e", ")", "{", "return", ";", "}", "if", "(", "!", "$", "node", "instanceof", "INode", ")", "{", "return", ";", "}", "$", "writer", "=", "$", "this", "->", "server", "->", "xml", "->", "getWriter", "(", ")", ";", "$", "writer", "->", "contextUri", "=", "$", "this", "->", "server", "->", "getBaseUri", "(", ")", ";", "$", "writer", "->", "openMemory", "(", ")", ";", "$", "writer", "->", "startDocument", "(", "'1.0'", ",", "'UTF-8'", ")", ";", "$", "writer", "->", "startElement", "(", "'{http://calendarserver.org/ns/}notification'", ")", ";", "$", "node", "->", "getNotificationType", "(", ")", "->", "xmlSerializeFull", "(", "$", "writer", ")", ";", "$", "writer", "->", "endElement", "(", ")", ";", "$", "response", "->", "setHeader", "(", "'Content-Type'", ",", "'application/xml'", ")", ";", "$", "response", "->", "setHeader", "(", "'ETag'", ",", "$", "node", "->", "getETag", "(", ")", ")", ";", "$", "response", "->", "setStatus", "(", "200", ")", ";", "$", "response", "->", "setBody", "(", "$", "writer", "->", "outputMemory", "(", ")", ")", ";", "// Return false to break the event chain.", "return", "false", ";", "}" ]
This event is triggered before the usual GET request handler. We use this to intercept GET calls to notification nodes, and return the proper response. @param RequestInterface $request @param ResponseInterface $response
[ "This", "event", "is", "triggered", "before", "the", "usual", "GET", "request", "handler", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Notifications/Plugin.php#L119-L148
sabre-io/dav
lib/CardDAV/Xml/Property/SupportedAddressData.php
SupportedAddressData.xmlSerialize
public function xmlSerialize(Writer $writer) { foreach ($this->supportedData as $supported) { $writer->startElement('{'.Plugin::NS_CARDDAV.'}address-data-type'); $writer->writeAttributes([ 'content-type' => $supported['contentType'], 'version' => $supported['version'], ]); $writer->endElement(); // address-data-type } }
php
public function xmlSerialize(Writer $writer) { foreach ($this->supportedData as $supported) { $writer->startElement('{'.Plugin::NS_CARDDAV.'}address-data-type'); $writer->writeAttributes([ 'content-type' => $supported['contentType'], 'version' => $supported['version'], ]); $writer->endElement(); } }
[ "public", "function", "xmlSerialize", "(", "Writer", "$", "writer", ")", "{", "foreach", "(", "$", "this", "->", "supportedData", "as", "$", "supported", ")", "{", "$", "writer", "->", "startElement", "(", "'{'", ".", "Plugin", "::", "NS_CARDDAV", ".", "'}address-data-type'", ")", ";", "$", "writer", "->", "writeAttributes", "(", "[", "'content-type'", "=>", "$", "supported", "[", "'contentType'", "]", ",", "'version'", "=>", "$", "supported", "[", "'version'", "]", ",", "]", ")", ";", "$", "writer", "->", "endElement", "(", ")", ";", "// address-data-type", "}", "}" ]
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/CardDAV/Xml/Property/SupportedAddressData.php#L70-L80
sabre-io/dav
lib/CardDAV/Plugin.php
Plugin.initialize
public function initialize(DAV\Server $server) { /* Events */ $server->on('propFind', [$this, 'propFindEarly']); $server->on('propFind', [$this, 'propFindLate'], 150); $server->on('report', [$this, 'report']); $server->on('onHTMLActionsPanel', [$this, 'htmlActionsPanel']); $server->on('beforeWriteContent', [$this, 'beforeWriteContent']); $server->on('beforeCreateFile', [$this, 'beforeCreateFile']); $server->on('afterMethod:GET', [$this, 'httpAfterGet']); $server->xml->namespaceMap[self::NS_CARDDAV] = 'card'; $server->xml->elementMap['{'.self::NS_CARDDAV.'}addressbook-query'] = 'Sabre\\CardDAV\\Xml\\Request\\AddressBookQueryReport'; $server->xml->elementMap['{'.self::NS_CARDDAV.'}addressbook-multiget'] = 'Sabre\\CardDAV\\Xml\\Request\\AddressBookMultiGetReport'; /* Mapping Interfaces to {DAV:}resourcetype values */ $server->resourceTypeMapping['Sabre\\CardDAV\\IAddressBook'] = '{'.self::NS_CARDDAV.'}addressbook'; $server->resourceTypeMapping['Sabre\\CardDAV\\IDirectory'] = '{'.self::NS_CARDDAV.'}directory'; /* Adding properties that may never be changed */ $server->protectedProperties[] = '{'.self::NS_CARDDAV.'}supported-address-data'; $server->protectedProperties[] = '{'.self::NS_CARDDAV.'}max-resource-size'; $server->protectedProperties[] = '{'.self::NS_CARDDAV.'}addressbook-home-set'; $server->protectedProperties[] = '{'.self::NS_CARDDAV.'}supported-collation-set'; $server->xml->elementMap['{http://calendarserver.org/ns/}me-card'] = 'Sabre\\DAV\\Xml\\Property\\Href'; $this->server = $server; }
php
public function initialize(DAV\Server $server) { $server->on('propFind', [$this, 'propFindEarly']); $server->on('propFind', [$this, 'propFindLate'], 150); $server->on('report', [$this, 'report']); $server->on('onHTMLActionsPanel', [$this, 'htmlActionsPanel']); $server->on('beforeWriteContent', [$this, 'beforeWriteContent']); $server->on('beforeCreateFile', [$this, 'beforeCreateFile']); $server->on('afterMethod:GET', [$this, 'httpAfterGet']); $server->xml->namespaceMap[self::NS_CARDDAV] = 'card'; $server->xml->elementMap['{'.self::NS_CARDDAV.'}addressbook-query'] = 'Sabre\\CardDAV\\Xml\\Request\\AddressBookQueryReport'; $server->xml->elementMap['{'.self::NS_CARDDAV.'}addressbook-multiget'] = 'Sabre\\CardDAV\\Xml\\Request\\AddressBookMultiGetReport'; $server->resourceTypeMapping['Sabre\\CardDAV\\IAddressBook'] = '{'.self::NS_CARDDAV.'}addressbook'; $server->resourceTypeMapping['Sabre\\CardDAV\\IDirectory'] = '{'.self::NS_CARDDAV.'}directory'; $server->protectedProperties[] = '{'.self::NS_CARDDAV.'}supported-address-data'; $server->protectedProperties[] = '{'.self::NS_CARDDAV.'}max-resource-size'; $server->protectedProperties[] = '{'.self::NS_CARDDAV.'}addressbook-home-set'; $server->protectedProperties[] = '{'.self::NS_CARDDAV.'}supported-collation-set'; $server->xml->elementMap['{http: $this->server = $server; }
[ "public", "function", "initialize", "(", "DAV", "\\", "Server", "$", "server", ")", "{", "/* Events */", "$", "server", "->", "on", "(", "'propFind'", ",", "[", "$", "this", ",", "'propFindEarly'", "]", ")", ";", "$", "server", "->", "on", "(", "'propFind'", ",", "[", "$", "this", ",", "'propFindLate'", "]", ",", "150", ")", ";", "$", "server", "->", "on", "(", "'report'", ",", "[", "$", "this", ",", "'report'", "]", ")", ";", "$", "server", "->", "on", "(", "'onHTMLActionsPanel'", ",", "[", "$", "this", ",", "'htmlActionsPanel'", "]", ")", ";", "$", "server", "->", "on", "(", "'beforeWriteContent'", ",", "[", "$", "this", ",", "'beforeWriteContent'", "]", ")", ";", "$", "server", "->", "on", "(", "'beforeCreateFile'", ",", "[", "$", "this", ",", "'beforeCreateFile'", "]", ")", ";", "$", "server", "->", "on", "(", "'afterMethod:GET'", ",", "[", "$", "this", ",", "'httpAfterGet'", "]", ")", ";", "$", "server", "->", "xml", "->", "namespaceMap", "[", "self", "::", "NS_CARDDAV", "]", "=", "'card'", ";", "$", "server", "->", "xml", "->", "elementMap", "[", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}addressbook-query'", "]", "=", "'Sabre\\\\CardDAV\\\\Xml\\\\Request\\\\AddressBookQueryReport'", ";", "$", "server", "->", "xml", "->", "elementMap", "[", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}addressbook-multiget'", "]", "=", "'Sabre\\\\CardDAV\\\\Xml\\\\Request\\\\AddressBookMultiGetReport'", ";", "/* Mapping Interfaces to {DAV:}resourcetype values */", "$", "server", "->", "resourceTypeMapping", "[", "'Sabre\\\\CardDAV\\\\IAddressBook'", "]", "=", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}addressbook'", ";", "$", "server", "->", "resourceTypeMapping", "[", "'Sabre\\\\CardDAV\\\\IDirectory'", "]", "=", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}directory'", ";", "/* Adding properties that may never be changed */", "$", "server", "->", "protectedProperties", "[", "]", "=", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}supported-address-data'", ";", "$", "server", "->", "protectedProperties", "[", "]", "=", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}max-resource-size'", ";", "$", "server", "->", "protectedProperties", "[", "]", "=", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}addressbook-home-set'", ";", "$", "server", "->", "protectedProperties", "[", "]", "=", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}supported-collation-set'", ";", "$", "server", "->", "xml", "->", "elementMap", "[", "'{http://calendarserver.org/ns/}me-card'", "]", "=", "'Sabre\\\\DAV\\\\Xml\\\\Property\\\\Href'", ";", "$", "this", "->", "server", "=", "$", "server", ";", "}" ]
Initializes the plugin. @param DAV\Server $server
[ "Initializes", "the", "plugin", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Plugin.php#L65-L94
sabre-io/dav
lib/CardDAV/Plugin.php
Plugin.getSupportedReportSet
public function getSupportedReportSet($uri) { $node = $this->server->tree->getNodeForPath($uri); if ($node instanceof IAddressBook || $node instanceof ICard) { return [ '{'.self::NS_CARDDAV.'}addressbook-multiget', '{'.self::NS_CARDDAV.'}addressbook-query', ]; } return []; }
php
public function getSupportedReportSet($uri) { $node = $this->server->tree->getNodeForPath($uri); if ($node instanceof IAddressBook || $node instanceof ICard) { return [ '{'.self::NS_CARDDAV.'}addressbook-multiget', '{'.self::NS_CARDDAV.'}addressbook-query', ]; } return []; }
[ "public", "function", "getSupportedReportSet", "(", "$", "uri", ")", "{", "$", "node", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "uri", ")", ";", "if", "(", "$", "node", "instanceof", "IAddressBook", "||", "$", "node", "instanceof", "ICard", ")", "{", "return", "[", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}addressbook-multiget'", ",", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}addressbook-query'", ",", "]", ";", "}", "return", "[", "]", ";", "}" ]
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/CardDAV/Plugin.php#L119-L130
sabre-io/dav
lib/CardDAV/Plugin.php
Plugin.propFindEarly
public function propFindEarly(DAV\PropFind $propFind, DAV\INode $node) { $ns = '{'.self::NS_CARDDAV.'}'; if ($node instanceof IAddressBook) { $propFind->handle($ns.'max-resource-size', $this->maxResourceSize); $propFind->handle($ns.'supported-address-data', function () { return new Xml\Property\SupportedAddressData(); }); $propFind->handle($ns.'supported-collation-set', function () { return new Xml\Property\SupportedCollationSet(); }); } if ($node instanceof DAVACL\IPrincipal) { $path = $propFind->getPath(); $propFind->handle('{'.self::NS_CARDDAV.'}addressbook-home-set', function () use ($path) { return new LocalHref($this->getAddressBookHomeForPrincipal($path).'/'); }); if ($this->directories) { $propFind->handle('{'.self::NS_CARDDAV.'}directory-gateway', function () { return new LocalHref($this->directories); }); } } if ($node instanceof ICard) { // The address-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_CARDDAV.'}address-data', function () use ($node) { $val = $node->get(); if (is_resource($val)) { $val = stream_get_contents($val); } return $val; }); } }
php
public function propFindEarly(DAV\PropFind $propFind, DAV\INode $node) { $ns = '{'.self::NS_CARDDAV.'}'; if ($node instanceof IAddressBook) { $propFind->handle($ns.'max-resource-size', $this->maxResourceSize); $propFind->handle($ns.'supported-address-data', function () { return new Xml\Property\SupportedAddressData(); }); $propFind->handle($ns.'supported-collation-set', function () { return new Xml\Property\SupportedCollationSet(); }); } if ($node instanceof DAVACL\IPrincipal) { $path = $propFind->getPath(); $propFind->handle('{'.self::NS_CARDDAV.'}addressbook-home-set', function () use ($path) { return new LocalHref($this->getAddressBookHomeForPrincipal($path).'/'); }); if ($this->directories) { $propFind->handle('{'.self::NS_CARDDAV.'}directory-gateway', function () { return new LocalHref($this->directories); }); } } if ($node instanceof ICard) { $propFind->handle('{'.self::NS_CARDDAV.'}address-data', function () use ($node) { $val = $node->get(); if (is_resource($val)) { $val = stream_get_contents($val); } return $val; }); } }
[ "public", "function", "propFindEarly", "(", "DAV", "\\", "PropFind", "$", "propFind", ",", "DAV", "\\", "INode", "$", "node", ")", "{", "$", "ns", "=", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}'", ";", "if", "(", "$", "node", "instanceof", "IAddressBook", ")", "{", "$", "propFind", "->", "handle", "(", "$", "ns", ".", "'max-resource-size'", ",", "$", "this", "->", "maxResourceSize", ")", ";", "$", "propFind", "->", "handle", "(", "$", "ns", ".", "'supported-address-data'", ",", "function", "(", ")", "{", "return", "new", "Xml", "\\", "Property", "\\", "SupportedAddressData", "(", ")", ";", "}", ")", ";", "$", "propFind", "->", "handle", "(", "$", "ns", ".", "'supported-collation-set'", ",", "function", "(", ")", "{", "return", "new", "Xml", "\\", "Property", "\\", "SupportedCollationSet", "(", ")", ";", "}", ")", ";", "}", "if", "(", "$", "node", "instanceof", "DAVACL", "\\", "IPrincipal", ")", "{", "$", "path", "=", "$", "propFind", "->", "getPath", "(", ")", ";", "$", "propFind", "->", "handle", "(", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}addressbook-home-set'", ",", "function", "(", ")", "use", "(", "$", "path", ")", "{", "return", "new", "LocalHref", "(", "$", "this", "->", "getAddressBookHomeForPrincipal", "(", "$", "path", ")", ".", "'/'", ")", ";", "}", ")", ";", "if", "(", "$", "this", "->", "directories", ")", "{", "$", "propFind", "->", "handle", "(", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}directory-gateway'", ",", "function", "(", ")", "{", "return", "new", "LocalHref", "(", "$", "this", "->", "directories", ")", ";", "}", ")", ";", "}", "}", "if", "(", "$", "node", "instanceof", "ICard", ")", "{", "// The address-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_CARDDAV", ".", "'}address-data'", ",", "function", "(", ")", "use", "(", "$", "node", ")", "{", "$", "val", "=", "$", "node", "->", "get", "(", ")", ";", "if", "(", "is_resource", "(", "$", "val", ")", ")", "{", "$", "val", "=", "stream_get_contents", "(", "$", "val", ")", ";", "}", "return", "$", "val", ";", "}", ")", ";", "}", "}" ]
Adds all CardDAV-specific properties. @param DAV\PropFind $propFind @param DAV\INode $node
[ "Adds", "all", "CardDAV", "-", "specific", "properties", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Plugin.php#L138-L178
sabre-io/dav
lib/CardDAV/Plugin.php
Plugin.report
public function report($reportName, $dom, $path) { switch ($reportName) { case '{'.self::NS_CARDDAV.'}addressbook-multiget': $this->server->transactionType = 'report-addressbook-multiget'; $this->addressbookMultiGetReport($dom); return false; case '{'.self::NS_CARDDAV.'}addressbook-query': $this->server->transactionType = 'report-addressbook-query'; $this->addressBookQueryReport($dom); return false; default: return; } }
php
public function report($reportName, $dom, $path) { switch ($reportName) { case '{'.self::NS_CARDDAV.'}addressbook-multiget': $this->server->transactionType = 'report-addressbook-multiget'; $this->addressbookMultiGetReport($dom); return false; case '{'.self::NS_CARDDAV.'}addressbook-query': $this->server->transactionType = 'report-addressbook-query'; $this->addressBookQueryReport($dom); return false; default: return; } }
[ "public", "function", "report", "(", "$", "reportName", ",", "$", "dom", ",", "$", "path", ")", "{", "switch", "(", "$", "reportName", ")", "{", "case", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}addressbook-multiget'", ":", "$", "this", "->", "server", "->", "transactionType", "=", "'report-addressbook-multiget'", ";", "$", "this", "->", "addressbookMultiGetReport", "(", "$", "dom", ")", ";", "return", "false", ";", "case", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}addressbook-query'", ":", "$", "this", "->", "server", "->", "transactionType", "=", "'report-addressbook-query'", ";", "$", "this", "->", "addressBookQueryReport", "(", "$", "dom", ")", ";", "return", "false", ";", "default", ":", "return", ";", "}", "}" ]
This functions handles REPORT requests specific to CardDAV. @param string $reportName @param \DOMNode $dom @param mixed $path @return bool
[ "This", "functions", "handles", "REPORT", "requests", "specific", "to", "CardDAV", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Plugin.php#L189-L205
sabre-io/dav
lib/CardDAV/Plugin.php
Plugin.getAddressbookHomeForPrincipal
protected function getAddressbookHomeForPrincipal($principal) { list(, $principalId) = Uri\split($principal); return self::ADDRESSBOOK_ROOT.'/'.$principalId; }
php
protected function getAddressbookHomeForPrincipal($principal) { list(, $principalId) = Uri\split($principal); return self::ADDRESSBOOK_ROOT.'/'.$principalId; }
[ "protected", "function", "getAddressbookHomeForPrincipal", "(", "$", "principal", ")", "{", "list", "(", ",", "$", "principalId", ")", "=", "Uri", "\\", "split", "(", "$", "principal", ")", ";", "return", "self", "::", "ADDRESSBOOK_ROOT", ".", "'/'", ".", "$", "principalId", ";", "}" ]
Returns the addressbook home for a given principal. @param string $principal @return string
[ "Returns", "the", "addressbook", "home", "for", "a", "given", "principal", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Plugin.php#L214-L219
sabre-io/dav
lib/CardDAV/Plugin.php
Plugin.addressbookMultiGetReport
public function addressbookMultiGetReport($report) { $contentType = $report->contentType; $version = $report->version; if ($version) { $contentType .= '; version='.$version; } $vcardType = $this->negotiateVCard( $contentType ); $propertyList = []; $paths = array_map( [$this->server, 'calculateUri'], $report->hrefs ); foreach ($this->server->getPropertiesForMultiplePaths($paths, $report->properties) as $props) { if (isset($props['200']['{'.self::NS_CARDDAV.'}address-data'])) { $props['200']['{'.self::NS_CARDDAV.'}address-data'] = $this->convertVCard( $props[200]['{'.self::NS_CARDDAV.'}address-data'], $vcardType ); } $propertyList[] = $props; } $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 addressbookMultiGetReport($report) { $contentType = $report->contentType; $version = $report->version; if ($version) { $contentType .= '; version='.$version; } $vcardType = $this->negotiateVCard( $contentType ); $propertyList = []; $paths = array_map( [$this->server, 'calculateUri'], $report->hrefs ); foreach ($this->server->getPropertiesForMultiplePaths($paths, $report->properties) as $props) { if (isset($props['200']['{'.self::NS_CARDDAV.'}address-data'])) { $props['200']['{'.self::NS_CARDDAV.'}address-data'] = $this->convertVCard( $props[200]['{'.self::NS_CARDDAV.'}address-data'], $vcardType ); } $propertyList[] = $props; } $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", "addressbookMultiGetReport", "(", "$", "report", ")", "{", "$", "contentType", "=", "$", "report", "->", "contentType", ";", "$", "version", "=", "$", "report", "->", "version", ";", "if", "(", "$", "version", ")", "{", "$", "contentType", ".=", "'; version='", ".", "$", "version", ";", "}", "$", "vcardType", "=", "$", "this", "->", "negotiateVCard", "(", "$", "contentType", ")", ";", "$", "propertyList", "=", "[", "]", ";", "$", "paths", "=", "array_map", "(", "[", "$", "this", "->", "server", ",", "'calculateUri'", "]", ",", "$", "report", "->", "hrefs", ")", ";", "foreach", "(", "$", "this", "->", "server", "->", "getPropertiesForMultiplePaths", "(", "$", "paths", ",", "$", "report", "->", "properties", ")", "as", "$", "props", ")", "{", "if", "(", "isset", "(", "$", "props", "[", "'200'", "]", "[", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}address-data'", "]", ")", ")", "{", "$", "props", "[", "'200'", "]", "[", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}address-data'", "]", "=", "$", "this", "->", "convertVCard", "(", "$", "props", "[", "200", "]", "[", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}address-data'", "]", ",", "$", "vcardType", ")", ";", "}", "$", "propertyList", "[", "]", "=", "$", "props", ";", "}", "$", "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 addressbook-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 Xml\Request\AddressBookMultiGetReport $report
[ "This", "function", "handles", "the", "addressbook", "-", "multiget", "REPORT", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Plugin.php#L229-L262
sabre-io/dav
lib/CardDAV/Plugin.php
Plugin.beforeWriteContent
public function beforeWriteContent($path, DAV\IFile $node, &$data, &$modified) { if (!$node instanceof ICard) { return; } $this->validateVCard($data, $modified); }
php
public function beforeWriteContent($path, DAV\IFile $node, &$data, &$modified) { if (!$node instanceof ICard) { return; } $this->validateVCard($data, $modified); }
[ "public", "function", "beforeWriteContent", "(", "$", "path", ",", "DAV", "\\", "IFile", "$", "node", ",", "&", "$", "data", ",", "&", "$", "modified", ")", "{", "if", "(", "!", "$", "node", "instanceof", "ICard", ")", "{", "return", ";", "}", "$", "this", "->", "validateVCard", "(", "$", "data", ",", "$", "modified", ")", ";", "}" ]
This method is triggered before a file gets updated with new content. This plugin uses this method to ensure that Card nodes receive valid vcard 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/CardDAV/Plugin.php#L276-L283
sabre-io/dav
lib/CardDAV/Plugin.php
Plugin.beforeCreateFile
public function beforeCreateFile($path, &$data, DAV\ICollection $parentNode, &$modified) { if (!$parentNode instanceof IAddressBook) { return; } $this->validateVCard($data, $modified); }
php
public function beforeCreateFile($path, &$data, DAV\ICollection $parentNode, &$modified) { if (!$parentNode instanceof IAddressBook) { return; } $this->validateVCard($data, $modified); }
[ "public", "function", "beforeCreateFile", "(", "$", "path", ",", "&", "$", "data", ",", "DAV", "\\", "ICollection", "$", "parentNode", ",", "&", "$", "modified", ")", "{", "if", "(", "!", "$", "parentNode", "instanceof", "IAddressBook", ")", "{", "return", ";", "}", "$", "this", "->", "validateVCard", "(", "$", "data", ",", "$", "modified", ")", ";", "}" ]
This method is triggered before a new file is created. This plugin uses this method to ensure that Card nodes receive valid vcard 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/CardDAV/Plugin.php#L297-L304
sabre-io/dav
lib/CardDAV/Plugin.php
Plugin.validateVCard
protected function validateVCard(&$data, &$modified) { // 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 vCard or jCard data. Parse error: '.$e->getMessage()); } if ('VCARD' !== $vobj->name) { throw new DAV\Exception\UnsupportedMediaType('This collection can only support vcard objects.'); } $options = VObject\Node::PROFILE_CARDDAV; $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 vCard: '.$message['message']); } } if ($warningMessage) { $this->server->httpResponse->setHeader( 'X-Sabre-Ew-Gross', 'vCard validation warning: '.$warningMessage ); // Re-serializing object. $data = $vobj->serialize(); if (!$modified && 0 !== strcmp($data, $before)) { // This ensures that the system does not send an ETag back. $modified = true; } } // Destroy circular references to PHP will GC the object. $vobj->destroy(); }
php
protected function validateVCard(&$data, &$modified) { 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 vCard or jCard data. Parse error: '.$e->getMessage()); } if ('VCARD' !== $vobj->name) { throw new DAV\Exception\UnsupportedMediaType('This collection can only support vcard objects.'); } $options = VObject\Node::PROFILE_CARDDAV; $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 vCard: '.$message['message']); } } if ($warningMessage) { $this->server->httpResponse->setHeader( 'X-Sabre-Ew-Gross', 'vCard validation warning: '.$warningMessage ); $data = $vobj->serialize(); if (!$modified && 0 !== strcmp($data, $before)) { $modified = true; } } $vobj->destroy(); }
[ "protected", "function", "validateVCard", "(", "&", "$", "data", ",", "&", "$", "modified", ")", "{", "// 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 vCard or jCard data. Parse error: '", ".", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "if", "(", "'VCARD'", "!==", "$", "vobj", "->", "name", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "UnsupportedMediaType", "(", "'This collection can only support vcard objects.'", ")", ";", "}", "$", "options", "=", "VObject", "\\", "Node", "::", "PROFILE_CARDDAV", ";", "$", "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 vCard: '", ".", "$", "message", "[", "'message'", "]", ")", ";", "}", "}", "if", "(", "$", "warningMessage", ")", "{", "$", "this", "->", "server", "->", "httpResponse", "->", "setHeader", "(", "'X-Sabre-Ew-Gross'", ",", "'vCard validation warning: '", ".", "$", "warningMessage", ")", ";", "// Re-serializing object.", "$", "data", "=", "$", "vobj", "->", "serialize", "(", ")", ";", "if", "(", "!", "$", "modified", "&&", "0", "!==", "strcmp", "(", "$", "data", ",", "$", "before", ")", ")", "{", "// This ensures that the system does not send an ETag back.", "$", "modified", "=", "true", ";", "}", "}", "// Destroy circular references to PHP will GC 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 bool $modified should be set to true, if this event handler changed &$data
[ "Checks", "if", "the", "submitted", "iCalendar", "data", "is", "in", "fact", "valid", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Plugin.php#L315-L395
sabre-io/dav
lib/CardDAV/Plugin.php
Plugin.addressbookQueryReport
protected function addressbookQueryReport($report) { $depth = $this->server->getHTTPDepth(0); if (0 == $depth) { $candidateNodes = [ $this->server->tree->getNodeForPath($this->server->getRequestUri()), ]; if (!$candidateNodes[0] instanceof ICard) { throw new ReportNotSupported('The addressbook-query report is not supported on this url with Depth: 0'); } } else { $candidateNodes = $this->server->tree->getChildren($this->server->getRequestUri()); } $contentType = $report->contentType; if ($report->version) { $contentType .= '; version='.$report->version; } $vcardType = $this->negotiateVCard( $contentType ); $validNodes = []; foreach ($candidateNodes as $node) { if (!$node instanceof ICard) { continue; } $blob = $node->get(); if (is_resource($blob)) { $blob = stream_get_contents($blob); } if (!$this->validateFilters($blob, $report->filters, $report->test)) { continue; } $validNodes[] = $node; if ($report->limit && $report->limit <= count($validNodes)) { // We hit the maximum number of items, we can stop now. break; } } $result = []; foreach ($validNodes as $validNode) { if (0 == $depth) { $href = $this->server->getRequestUri(); } else { $href = $this->server->getRequestUri().'/'.$validNode->getName(); } list($props) = $this->server->getPropertiesForPath($href, $report->properties, 0); if (isset($props[200]['{'.self::NS_CARDDAV.'}address-data'])) { $props[200]['{'.self::NS_CARDDAV.'}address-data'] = $this->convertVCard( $props[200]['{'.self::NS_CARDDAV.'}address-data'], $vcardType, $report->addressDataProperties ); } $result[] = $props; } $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
protected function addressbookQueryReport($report) { $depth = $this->server->getHTTPDepth(0); if (0 == $depth) { $candidateNodes = [ $this->server->tree->getNodeForPath($this->server->getRequestUri()), ]; if (!$candidateNodes[0] instanceof ICard) { throw new ReportNotSupported('The addressbook-query report is not supported on this url with Depth: 0'); } } else { $candidateNodes = $this->server->tree->getChildren($this->server->getRequestUri()); } $contentType = $report->contentType; if ($report->version) { $contentType .= '; version='.$report->version; } $vcardType = $this->negotiateVCard( $contentType ); $validNodes = []; foreach ($candidateNodes as $node) { if (!$node instanceof ICard) { continue; } $blob = $node->get(); if (is_resource($blob)) { $blob = stream_get_contents($blob); } if (!$this->validateFilters($blob, $report->filters, $report->test)) { continue; } $validNodes[] = $node; if ($report->limit && $report->limit <= count($validNodes)) { break; } } $result = []; foreach ($validNodes as $validNode) { if (0 == $depth) { $href = $this->server->getRequestUri(); } else { $href = $this->server->getRequestUri().'/'.$validNode->getName(); } list($props) = $this->server->getPropertiesForPath($href, $report->properties, 0); if (isset($props[200]['{'.self::NS_CARDDAV.'}address-data'])) { $props[200]['{'.self::NS_CARDDAV.'}address-data'] = $this->convertVCard( $props[200]['{'.self::NS_CARDDAV.'}address-data'], $vcardType, $report->addressDataProperties ); } $result[] = $props; } $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'])); }
[ "protected", "function", "addressbookQueryReport", "(", "$", "report", ")", "{", "$", "depth", "=", "$", "this", "->", "server", "->", "getHTTPDepth", "(", "0", ")", ";", "if", "(", "0", "==", "$", "depth", ")", "{", "$", "candidateNodes", "=", "[", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "this", "->", "server", "->", "getRequestUri", "(", ")", ")", ",", "]", ";", "if", "(", "!", "$", "candidateNodes", "[", "0", "]", "instanceof", "ICard", ")", "{", "throw", "new", "ReportNotSupported", "(", "'The addressbook-query report is not supported on this url with Depth: 0'", ")", ";", "}", "}", "else", "{", "$", "candidateNodes", "=", "$", "this", "->", "server", "->", "tree", "->", "getChildren", "(", "$", "this", "->", "server", "->", "getRequestUri", "(", ")", ")", ";", "}", "$", "contentType", "=", "$", "report", "->", "contentType", ";", "if", "(", "$", "report", "->", "version", ")", "{", "$", "contentType", ".=", "'; version='", ".", "$", "report", "->", "version", ";", "}", "$", "vcardType", "=", "$", "this", "->", "negotiateVCard", "(", "$", "contentType", ")", ";", "$", "validNodes", "=", "[", "]", ";", "foreach", "(", "$", "candidateNodes", "as", "$", "node", ")", "{", "if", "(", "!", "$", "node", "instanceof", "ICard", ")", "{", "continue", ";", "}", "$", "blob", "=", "$", "node", "->", "get", "(", ")", ";", "if", "(", "is_resource", "(", "$", "blob", ")", ")", "{", "$", "blob", "=", "stream_get_contents", "(", "$", "blob", ")", ";", "}", "if", "(", "!", "$", "this", "->", "validateFilters", "(", "$", "blob", ",", "$", "report", "->", "filters", ",", "$", "report", "->", "test", ")", ")", "{", "continue", ";", "}", "$", "validNodes", "[", "]", "=", "$", "node", ";", "if", "(", "$", "report", "->", "limit", "&&", "$", "report", "->", "limit", "<=", "count", "(", "$", "validNodes", ")", ")", "{", "// We hit the maximum number of items, we can stop now.", "break", ";", "}", "}", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "validNodes", "as", "$", "validNode", ")", "{", "if", "(", "0", "==", "$", "depth", ")", "{", "$", "href", "=", "$", "this", "->", "server", "->", "getRequestUri", "(", ")", ";", "}", "else", "{", "$", "href", "=", "$", "this", "->", "server", "->", "getRequestUri", "(", ")", ".", "'/'", ".", "$", "validNode", "->", "getName", "(", ")", ";", "}", "list", "(", "$", "props", ")", "=", "$", "this", "->", "server", "->", "getPropertiesForPath", "(", "$", "href", ",", "$", "report", "->", "properties", ",", "0", ")", ";", "if", "(", "isset", "(", "$", "props", "[", "200", "]", "[", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}address-data'", "]", ")", ")", "{", "$", "props", "[", "200", "]", "[", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}address-data'", "]", "=", "$", "this", "->", "convertVCard", "(", "$", "props", "[", "200", "]", "[", "'{'", ".", "self", "::", "NS_CARDDAV", ".", "'}address-data'", "]", ",", "$", "vcardType", ",", "$", "report", "->", "addressDataProperties", ")", ";", "}", "$", "result", "[", "]", "=", "$", "props", ";", "}", "$", "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 addressbook-query REPORT. This report is used by the client to filter an addressbook based on a complex query. @param Xml\Request\AddressBookQueryReport $report
[ "This", "function", "handles", "the", "addressbook", "-", "query", "REPORT", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Plugin.php#L405-L478
sabre-io/dav
lib/CardDAV/Plugin.php
Plugin.validateFilters
public function validateFilters($vcardData, array $filters, $test) { if (!$filters) { return true; } $vcard = VObject\Reader::read($vcardData); foreach ($filters as $filter) { $isDefined = isset($vcard->{$filter['name']}); if ($filter['is-not-defined']) { if ($isDefined) { $success = false; } else { $success = true; } } elseif ((!$filter['param-filters'] && !$filter['text-matches']) || !$isDefined) { // We only need to check for existence $success = $isDefined; } else { $vProperties = $vcard->select($filter['name']); $results = []; if ($filter['param-filters']) { $results[] = $this->validateParamFilters($vProperties, $filter['param-filters'], $filter['test']); } if ($filter['text-matches']) { $texts = []; foreach ($vProperties as $vProperty) { $texts[] = $vProperty->getValue(); } $results[] = $this->validateTextMatches($texts, $filter['text-matches'], $filter['test']); } if (1 === count($results)) { $success = $results[0]; } else { if ('anyof' === $filter['test']) { $success = $results[0] || $results[1]; } else { $success = $results[0] && $results[1]; } } } // else // There are two conditions where we can already determine whether // or not this filter succeeds. if ('anyof' === $test && $success) { // Destroy circular references to PHP will GC the object. $vcard->destroy(); return true; } if ('allof' === $test && !$success) { // Destroy circular references to PHP will GC the object. $vcard->destroy(); return false; } } // foreach // Destroy circular references to PHP will GC the object. $vcard->destroy(); // If we got all the way here, it means we haven't been able to // determine early if the test failed or not. // // This implies for 'anyof' that the test failed, and for 'allof' that // we succeeded. Sounds weird, but makes sense. return 'allof' === $test; }
php
public function validateFilters($vcardData, array $filters, $test) { if (!$filters) { return true; } $vcard = VObject\Reader::read($vcardData); foreach ($filters as $filter) { $isDefined = isset($vcard->{$filter['name']}); if ($filter['is-not-defined']) { if ($isDefined) { $success = false; } else { $success = true; } } elseif ((!$filter['param-filters'] && !$filter['text-matches']) || !$isDefined) { $success = $isDefined; } else { $vProperties = $vcard->select($filter['name']); $results = []; if ($filter['param-filters']) { $results[] = $this->validateParamFilters($vProperties, $filter['param-filters'], $filter['test']); } if ($filter['text-matches']) { $texts = []; foreach ($vProperties as $vProperty) { $texts[] = $vProperty->getValue(); } $results[] = $this->validateTextMatches($texts, $filter['text-matches'], $filter['test']); } if (1 === count($results)) { $success = $results[0]; } else { if ('anyof' === $filter['test']) { $success = $results[0] || $results[1]; } else { $success = $results[0] && $results[1]; } } } if ('anyof' === $test && $success) { $vcard->destroy(); return true; } if ('allof' === $test && !$success) { $vcard->destroy(); return false; } } $vcard->destroy(); return 'allof' === $test; }
[ "public", "function", "validateFilters", "(", "$", "vcardData", ",", "array", "$", "filters", ",", "$", "test", ")", "{", "if", "(", "!", "$", "filters", ")", "{", "return", "true", ";", "}", "$", "vcard", "=", "VObject", "\\", "Reader", "::", "read", "(", "$", "vcardData", ")", ";", "foreach", "(", "$", "filters", "as", "$", "filter", ")", "{", "$", "isDefined", "=", "isset", "(", "$", "vcard", "->", "{", "$", "filter", "[", "'name'", "]", "}", ")", ";", "if", "(", "$", "filter", "[", "'is-not-defined'", "]", ")", "{", "if", "(", "$", "isDefined", ")", "{", "$", "success", "=", "false", ";", "}", "else", "{", "$", "success", "=", "true", ";", "}", "}", "elseif", "(", "(", "!", "$", "filter", "[", "'param-filters'", "]", "&&", "!", "$", "filter", "[", "'text-matches'", "]", ")", "||", "!", "$", "isDefined", ")", "{", "// We only need to check for existence", "$", "success", "=", "$", "isDefined", ";", "}", "else", "{", "$", "vProperties", "=", "$", "vcard", "->", "select", "(", "$", "filter", "[", "'name'", "]", ")", ";", "$", "results", "=", "[", "]", ";", "if", "(", "$", "filter", "[", "'param-filters'", "]", ")", "{", "$", "results", "[", "]", "=", "$", "this", "->", "validateParamFilters", "(", "$", "vProperties", ",", "$", "filter", "[", "'param-filters'", "]", ",", "$", "filter", "[", "'test'", "]", ")", ";", "}", "if", "(", "$", "filter", "[", "'text-matches'", "]", ")", "{", "$", "texts", "=", "[", "]", ";", "foreach", "(", "$", "vProperties", "as", "$", "vProperty", ")", "{", "$", "texts", "[", "]", "=", "$", "vProperty", "->", "getValue", "(", ")", ";", "}", "$", "results", "[", "]", "=", "$", "this", "->", "validateTextMatches", "(", "$", "texts", ",", "$", "filter", "[", "'text-matches'", "]", ",", "$", "filter", "[", "'test'", "]", ")", ";", "}", "if", "(", "1", "===", "count", "(", "$", "results", ")", ")", "{", "$", "success", "=", "$", "results", "[", "0", "]", ";", "}", "else", "{", "if", "(", "'anyof'", "===", "$", "filter", "[", "'test'", "]", ")", "{", "$", "success", "=", "$", "results", "[", "0", "]", "||", "$", "results", "[", "1", "]", ";", "}", "else", "{", "$", "success", "=", "$", "results", "[", "0", "]", "&&", "$", "results", "[", "1", "]", ";", "}", "}", "}", "// else", "// There are two conditions where we can already determine whether", "// or not this filter succeeds.", "if", "(", "'anyof'", "===", "$", "test", "&&", "$", "success", ")", "{", "// Destroy circular references to PHP will GC the object.", "$", "vcard", "->", "destroy", "(", ")", ";", "return", "true", ";", "}", "if", "(", "'allof'", "===", "$", "test", "&&", "!", "$", "success", ")", "{", "// Destroy circular references to PHP will GC the object.", "$", "vcard", "->", "destroy", "(", ")", ";", "return", "false", ";", "}", "}", "// foreach", "// Destroy circular references to PHP will GC the object.", "$", "vcard", "->", "destroy", "(", ")", ";", "// If we got all the way here, it means we haven't been able to", "// determine early if the test failed or not.", "//", "// This implies for 'anyof' that the test failed, and for 'allof' that", "// we succeeded. Sounds weird, but makes sense.", "return", "'allof'", "===", "$", "test", ";", "}" ]
Validates if a vcard makes it throught a list of filters. @param string $vcardData @param array $filters @param string $test anyof or allof (which means OR or AND) @return bool
[ "Validates", "if", "a", "vcard", "makes", "it", "throught", "a", "list", "of", "filters", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Plugin.php#L489-L559
sabre-io/dav
lib/CardDAV/Plugin.php
Plugin.validateParamFilters
protected function validateParamFilters(array $vProperties, array $filters, $test) { foreach ($filters as $filter) { $isDefined = false; foreach ($vProperties as $vProperty) { $isDefined = isset($vProperty[$filter['name']]); if ($isDefined) { break; } } if ($filter['is-not-defined']) { if ($isDefined) { $success = false; } else { $success = true; } // If there's no text-match, we can just check for existence } elseif (!$filter['text-match'] || !$isDefined) { $success = $isDefined; } else { $success = false; foreach ($vProperties as $vProperty) { // If we got all the way here, we'll need to validate the // text-match filter. $success = DAV\StringUtil::textMatch($vProperty[$filter['name']]->getValue(), $filter['text-match']['value'], $filter['text-match']['collation'], $filter['text-match']['match-type']); if ($success) { break; } } if ($filter['text-match']['negate-condition']) { $success = !$success; } } // else // There are two conditions where we can already determine whether // or not this filter succeeds. if ('anyof' === $test && $success) { return true; } if ('allof' === $test && !$success) { return false; } } // If we got all the way here, it means we haven't been able to // determine early if the test failed or not. // // This implies for 'anyof' that the test failed, and for 'allof' that // we succeeded. Sounds weird, but makes sense. return 'allof' === $test; }
php
protected function validateParamFilters(array $vProperties, array $filters, $test) { foreach ($filters as $filter) { $isDefined = false; foreach ($vProperties as $vProperty) { $isDefined = isset($vProperty[$filter['name']]); if ($isDefined) { break; } } if ($filter['is-not-defined']) { if ($isDefined) { $success = false; } else { $success = true; } } elseif (!$filter['text-match'] || !$isDefined) { $success = $isDefined; } else { $success = false; foreach ($vProperties as $vProperty) { $success = DAV\StringUtil::textMatch($vProperty[$filter['name']]->getValue(), $filter['text-match']['value'], $filter['text-match']['collation'], $filter['text-match']['match-type']); if ($success) { break; } } if ($filter['text-match']['negate-condition']) { $success = !$success; } } if ('anyof' === $test && $success) { return true; } if ('allof' === $test && !$success) { return false; } } return 'allof' === $test; }
[ "protected", "function", "validateParamFilters", "(", "array", "$", "vProperties", ",", "array", "$", "filters", ",", "$", "test", ")", "{", "foreach", "(", "$", "filters", "as", "$", "filter", ")", "{", "$", "isDefined", "=", "false", ";", "foreach", "(", "$", "vProperties", "as", "$", "vProperty", ")", "{", "$", "isDefined", "=", "isset", "(", "$", "vProperty", "[", "$", "filter", "[", "'name'", "]", "]", ")", ";", "if", "(", "$", "isDefined", ")", "{", "break", ";", "}", "}", "if", "(", "$", "filter", "[", "'is-not-defined'", "]", ")", "{", "if", "(", "$", "isDefined", ")", "{", "$", "success", "=", "false", ";", "}", "else", "{", "$", "success", "=", "true", ";", "}", "// If there's no text-match, we can just check for existence", "}", "elseif", "(", "!", "$", "filter", "[", "'text-match'", "]", "||", "!", "$", "isDefined", ")", "{", "$", "success", "=", "$", "isDefined", ";", "}", "else", "{", "$", "success", "=", "false", ";", "foreach", "(", "$", "vProperties", "as", "$", "vProperty", ")", "{", "// If we got all the way here, we'll need to validate the", "// text-match filter.", "$", "success", "=", "DAV", "\\", "StringUtil", "::", "textMatch", "(", "$", "vProperty", "[", "$", "filter", "[", "'name'", "]", "]", "->", "getValue", "(", ")", ",", "$", "filter", "[", "'text-match'", "]", "[", "'value'", "]", ",", "$", "filter", "[", "'text-match'", "]", "[", "'collation'", "]", ",", "$", "filter", "[", "'text-match'", "]", "[", "'match-type'", "]", ")", ";", "if", "(", "$", "success", ")", "{", "break", ";", "}", "}", "if", "(", "$", "filter", "[", "'text-match'", "]", "[", "'negate-condition'", "]", ")", "{", "$", "success", "=", "!", "$", "success", ";", "}", "}", "// else", "// There are two conditions where we can already determine whether", "// or not this filter succeeds.", "if", "(", "'anyof'", "===", "$", "test", "&&", "$", "success", ")", "{", "return", "true", ";", "}", "if", "(", "'allof'", "===", "$", "test", "&&", "!", "$", "success", ")", "{", "return", "false", ";", "}", "}", "// If we got all the way here, it means we haven't been able to", "// determine early if the test failed or not.", "//", "// This implies for 'anyof' that the test failed, and for 'allof' that", "// we succeeded. Sounds weird, but makes sense.", "return", "'allof'", "===", "$", "test", ";", "}" ]
Validates if a param-filter can be applied to a specific property. @todo currently we're only validating the first parameter of the passed property. Any subsequence parameters with the same name are ignored. @param array $vProperties @param array $filters @param string $test @return bool
[ "Validates", "if", "a", "param", "-", "filter", "can", "be", "applied", "to", "a", "specific", "property", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Plugin.php#L574-L626
sabre-io/dav
lib/CardDAV/Plugin.php
Plugin.validateTextMatches
protected function validateTextMatches(array $texts, array $filters, $test) { foreach ($filters as $filter) { $success = false; foreach ($texts as $haystack) { $success = DAV\StringUtil::textMatch($haystack, $filter['value'], $filter['collation'], $filter['match-type']); // Breaking on the first match if ($success) { break; } } if ($filter['negate-condition']) { $success = !$success; } if ($success && 'anyof' === $test) { return true; } if (!$success && 'allof' == $test) { return false; } } // If we got all the way here, it means we haven't been able to // determine early if the test failed or not. // // This implies for 'anyof' that the test failed, and for 'allof' that // we succeeded. Sounds weird, but makes sense. return 'allof' === $test; }
php
protected function validateTextMatches(array $texts, array $filters, $test) { foreach ($filters as $filter) { $success = false; foreach ($texts as $haystack) { $success = DAV\StringUtil::textMatch($haystack, $filter['value'], $filter['collation'], $filter['match-type']); if ($success) { break; } } if ($filter['negate-condition']) { $success = !$success; } if ($success && 'anyof' === $test) { return true; } if (!$success && 'allof' == $test) { return false; } } return 'allof' === $test; }
[ "protected", "function", "validateTextMatches", "(", "array", "$", "texts", ",", "array", "$", "filters", ",", "$", "test", ")", "{", "foreach", "(", "$", "filters", "as", "$", "filter", ")", "{", "$", "success", "=", "false", ";", "foreach", "(", "$", "texts", "as", "$", "haystack", ")", "{", "$", "success", "=", "DAV", "\\", "StringUtil", "::", "textMatch", "(", "$", "haystack", ",", "$", "filter", "[", "'value'", "]", ",", "$", "filter", "[", "'collation'", "]", ",", "$", "filter", "[", "'match-type'", "]", ")", ";", "// Breaking on the first match", "if", "(", "$", "success", ")", "{", "break", ";", "}", "}", "if", "(", "$", "filter", "[", "'negate-condition'", "]", ")", "{", "$", "success", "=", "!", "$", "success", ";", "}", "if", "(", "$", "success", "&&", "'anyof'", "===", "$", "test", ")", "{", "return", "true", ";", "}", "if", "(", "!", "$", "success", "&&", "'allof'", "==", "$", "test", ")", "{", "return", "false", ";", "}", "}", "// If we got all the way here, it means we haven't been able to", "// determine early if the test failed or not.", "//", "// This implies for 'anyof' that the test failed, and for 'allof' that", "// we succeeded. Sounds weird, but makes sense.", "return", "'allof'", "===", "$", "test", ";", "}" ]
Validates if a text-filter can be applied to a specific property. @param array $texts @param array $filters @param string $test @return bool
[ "Validates", "if", "a", "text", "-", "filter", "can", "be", "applied", "to", "a", "specific", "property", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Plugin.php#L637-L668
sabre-io/dav
lib/CardDAV/Plugin.php
Plugin.propFindLate
public function propFindLate(DAV\PropFind $propFind, DAV\INode $node) { // If the request was made using the SOGO connector, we must rewrite // the content-type property. By default SabreDAV will send back // text/x-vcard; charset=utf-8, but for SOGO we must strip that last // part. if (false === strpos((string) $this->server->httpRequest->getHeader('User-Agent'), 'Thunderbird')) { return; } $contentType = $propFind->get('{DAV:}getcontenttype'); list($part) = explode(';', $contentType); if ('text/x-vcard' === $part || 'text/vcard' === $part) { $propFind->set('{DAV:}getcontenttype', 'text/x-vcard'); } }
php
public function propFindLate(DAV\PropFind $propFind, DAV\INode $node) { if (false === strpos((string) $this->server->httpRequest->getHeader('User-Agent'), 'Thunderbird')) { return; } $contentType = $propFind->get('{DAV:}getcontenttype'); list($part) = explode(';', $contentType); if ('text/x-vcard' === $part || 'text/vcard' === $part) { $propFind->set('{DAV:}getcontenttype', 'text/x-vcard'); } }
[ "public", "function", "propFindLate", "(", "DAV", "\\", "PropFind", "$", "propFind", ",", "DAV", "\\", "INode", "$", "node", ")", "{", "// If the request was made using the SOGO connector, we must rewrite", "// the content-type property. By default SabreDAV will send back", "// text/x-vcard; charset=utf-8, but for SOGO we must strip that last", "// part.", "if", "(", "false", "===", "strpos", "(", "(", "string", ")", "$", "this", "->", "server", "->", "httpRequest", "->", "getHeader", "(", "'User-Agent'", ")", ",", "'Thunderbird'", ")", ")", "{", "return", ";", "}", "$", "contentType", "=", "$", "propFind", "->", "get", "(", "'{DAV:}getcontenttype'", ")", ";", "list", "(", "$", "part", ")", "=", "explode", "(", "';'", ",", "$", "contentType", ")", ";", "if", "(", "'text/x-vcard'", "===", "$", "part", "||", "'text/vcard'", "===", "$", "part", ")", "{", "$", "propFind", "->", "set", "(", "'{DAV:}getcontenttype'", ",", "'text/x-vcard'", ")", ";", "}", "}" ]
This event is triggered when fetching properties. This event is scheduled late in the process, after most work for propfind has been done. @param DAV\PropFind $propFind @param DAV\INode $node
[ "This", "event", "is", "triggered", "when", "fetching", "properties", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Plugin.php#L679-L693
sabre-io/dav
lib/CardDAV/Plugin.php
Plugin.htmlActionsPanel
public function htmlActionsPanel(DAV\INode $node, &$output) { if (!$node instanceof AddressBookHome) { return; } $output .= '<tr><td colspan="2"><form method="post" action=""> <h3>Create new address book</h3> <input type="hidden" name="sabreAction" value="mkcol" /> <input type="hidden" name="resourceType" value="{DAV:}collection,{'.self::NS_CARDDAV.'}addressbook" /> <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 AddressBookHome) { return; } $output .= '<tr><td colspan="2"><form method="post" action=""> <h3>Create new address book</h3> <input type="hidden" name="sabreAction" value="mkcol" /> <input type="hidden" name="resourceType" value="{DAV:}collection,{'.self::NS_CARDDAV.'}addressbook" /> <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", "AddressBookHome", ")", "{", "return", ";", "}", "$", "output", ".=", "'<tr><td colspan=\"2\"><form method=\"post\" action=\"\">\n <h3>Create new address book</h3>\n <input type=\"hidden\" name=\"sabreAction\" value=\"mkcol\" />\n <input type=\"hidden\" name=\"resourceType\" value=\"{DAV:}collection,{'", ".", "self", "::", "NS_CARDDAV", ".", "'}addressbook\" />\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 Sabre\DAV\Browser\Plugin. This allows us to generate an interface users can use to create new addressbooks. @param DAV\INode $node @param string $output @return bool
[ "This", "method", "is", "used", "to", "generate", "HTML", "output", "for", "the", "Sabre", "\\", "DAV", "\\", "Browser", "\\", "Plugin", ".", "This", "allows", "us", "to", "generate", "an", "interface", "users", "can", "use", "to", "create", "new", "addressbooks", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Plugin.php#L705-L722
sabre-io/dav
lib/CardDAV/Plugin.php
Plugin.httpAfterGet
public function httpAfterGet(RequestInterface $request, ResponseInterface $response) { $contentType = $response->getHeader('Content-Type'); if (null === $contentType || false === strpos($contentType, 'text/vcard')) { return; } $target = $this->negotiateVCard($request->getHeader('Accept'), $mimeType); $newBody = $this->convertVCard( $response->getBody(), $target ); $response->setBody($newBody); $response->setHeader('Content-Type', $mimeType.'; charset=utf-8'); $response->setHeader('Content-Length', strlen($newBody)); }
php
public function httpAfterGet(RequestInterface $request, ResponseInterface $response) { $contentType = $response->getHeader('Content-Type'); if (null === $contentType || false === strpos($contentType, 'text/vcard')) { return; } $target = $this->negotiateVCard($request->getHeader('Accept'), $mimeType); $newBody = $this->convertVCard( $response->getBody(), $target ); $response->setBody($newBody); $response->setHeader('Content-Type', $mimeType.'; charset=utf-8'); $response->setHeader('Content-Length', strlen($newBody)); }
[ "public", "function", "httpAfterGet", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "contentType", "=", "$", "response", "->", "getHeader", "(", "'Content-Type'", ")", ";", "if", "(", "null", "===", "$", "contentType", "||", "false", "===", "strpos", "(", "$", "contentType", ",", "'text/vcard'", ")", ")", "{", "return", ";", "}", "$", "target", "=", "$", "this", "->", "negotiateVCard", "(", "$", "request", "->", "getHeader", "(", "'Accept'", ")", ",", "$", "mimeType", ")", ";", "$", "newBody", "=", "$", "this", "->", "convertVCard", "(", "$", "response", "->", "getBody", "(", ")", ",", "$", "target", ")", ";", "$", "response", "->", "setBody", "(", "$", "newBody", ")", ";", "$", "response", "->", "setHeader", "(", "'Content-Type'", ",", "$", "mimeType", ".", "'; charset=utf-8'", ")", ";", "$", "response", "->", "setHeader", "(", "'Content-Length'", ",", "strlen", "(", "$", "newBody", ")", ")", ";", "}" ]
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/CardDAV/Plugin.php#L732-L749
sabre-io/dav
lib/CardDAV/Plugin.php
Plugin.negotiateVCard
protected function negotiateVCard($input, &$mimeType = null) { $result = HTTP\negotiateContentType( $input, [ // Most often used mime-type. Version 3 'text/x-vcard', // The correct standard mime-type. Defaults to version 3 as // well. 'text/vcard', // vCard 4 'text/vcard; version=4.0', // vCard 3 'text/vcard; version=3.0', // jCard 'application/vcard+json', ] ); $mimeType = $result; switch ($result) { default: case 'text/x-vcard': case 'text/vcard': case 'text/vcard; version=3.0': $mimeType = 'text/vcard'; return 'vcard3'; case 'text/vcard; version=4.0': return 'vcard4'; case 'application/vcard+json': return 'jcard'; // @codeCoverageIgnoreStart } // @codeCoverageIgnoreEnd }
php
protected function negotiateVCard($input, &$mimeType = null) { $result = HTTP\negotiateContentType( $input, [ 'text/x-vcard', 'text/vcard', 'text/vcard; version=4.0', 'text/vcard; version=3.0', 'application/vcard+json', ] ); $mimeType = $result; switch ($result) { default: case 'text/x-vcard': case 'text/vcard': case 'text/vcard; version=3.0': $mimeType = 'text/vcard'; return 'vcard3'; case 'text/vcard; version=4.0': return 'vcard4'; case 'application/vcard+json': return 'jcard'; } }
[ "protected", "function", "negotiateVCard", "(", "$", "input", ",", "&", "$", "mimeType", "=", "null", ")", "{", "$", "result", "=", "HTTP", "\\", "negotiateContentType", "(", "$", "input", ",", "[", "// Most often used mime-type. Version 3", "'text/x-vcard'", ",", "// The correct standard mime-type. Defaults to version 3 as", "// well.", "'text/vcard'", ",", "// vCard 4", "'text/vcard; version=4.0'", ",", "// vCard 3", "'text/vcard; version=3.0'", ",", "// jCard", "'application/vcard+json'", ",", "]", ")", ";", "$", "mimeType", "=", "$", "result", ";", "switch", "(", "$", "result", ")", "{", "default", ":", "case", "'text/x-vcard'", ":", "case", "'text/vcard'", ":", "case", "'text/vcard; version=3.0'", ":", "$", "mimeType", "=", "'text/vcard'", ";", "return", "'vcard3'", ";", "case", "'text/vcard; version=4.0'", ":", "return", "'vcard4'", ";", "case", "'application/vcard+json'", ":", "return", "'jcard'", ";", "// @codeCoverageIgnoreStart", "}", "// @codeCoverageIgnoreEnd", "}" ]
This helper function performs the content-type negotiation for vcards. It will return one of the following strings: 1. vcard3 2. vcard4 3. jcard It defaults to vcard3. @param string $input @param string $mimeType @return string
[ "This", "helper", "function", "performs", "the", "content", "-", "type", "negotiation", "for", "vcards", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Plugin.php#L766-L802
sabre-io/dav
lib/CardDAV/Plugin.php
Plugin.convertVCard
protected function convertVCard($data, $target, array $propertiesFilter = null) { if (is_resource($data)) { $data = stream_get_contents($data); } $input = VObject\Reader::read($data); if (!empty($propertiesFilter)) { $propertiesFilter = array_merge(['UID', 'VERSION', 'FN'], $propertiesFilter); $keys = array_unique(array_map(function ($child) { return $child->name; }, $input->children())); $keys = array_diff($keys, $propertiesFilter); foreach ($keys as $key) { unset($input->$key); } $data = $input->serialize(); } $output = null; try { switch ($target) { default: case 'vcard3': if (VObject\Document::VCARD30 === $input->getDocumentType()) { // Do nothing return $data; } $output = $input->convert(VObject\Document::VCARD30); return $output->serialize(); case 'vcard4': if (VObject\Document::VCARD40 === $input->getDocumentType()) { // Do nothing return $data; } $output = $input->convert(VObject\Document::VCARD40); return $output->serialize(); case 'jcard': $output = $input->convert(VObject\Document::VCARD40); return json_encode($output); } } finally { // Destroy circular references to PHP will GC the object. $input->destroy(); if (!is_null($output)) { $output->destroy(); } } }
php
protected function convertVCard($data, $target, array $propertiesFilter = null) { if (is_resource($data)) { $data = stream_get_contents($data); } $input = VObject\Reader::read($data); if (!empty($propertiesFilter)) { $propertiesFilter = array_merge(['UID', 'VERSION', 'FN'], $propertiesFilter); $keys = array_unique(array_map(function ($child) { return $child->name; }, $input->children())); $keys = array_diff($keys, $propertiesFilter); foreach ($keys as $key) { unset($input->$key); } $data = $input->serialize(); } $output = null; try { switch ($target) { default: case 'vcard3': if (VObject\Document::VCARD30 === $input->getDocumentType()) { return $data; } $output = $input->convert(VObject\Document::VCARD30); return $output->serialize(); case 'vcard4': if (VObject\Document::VCARD40 === $input->getDocumentType()) { return $data; } $output = $input->convert(VObject\Document::VCARD40); return $output->serialize(); case 'jcard': $output = $input->convert(VObject\Document::VCARD40); return json_encode($output); } } finally { $input->destroy(); if (!is_null($output)) { $output->destroy(); } } }
[ "protected", "function", "convertVCard", "(", "$", "data", ",", "$", "target", ",", "array", "$", "propertiesFilter", "=", "null", ")", "{", "if", "(", "is_resource", "(", "$", "data", ")", ")", "{", "$", "data", "=", "stream_get_contents", "(", "$", "data", ")", ";", "}", "$", "input", "=", "VObject", "\\", "Reader", "::", "read", "(", "$", "data", ")", ";", "if", "(", "!", "empty", "(", "$", "propertiesFilter", ")", ")", "{", "$", "propertiesFilter", "=", "array_merge", "(", "[", "'UID'", ",", "'VERSION'", ",", "'FN'", "]", ",", "$", "propertiesFilter", ")", ";", "$", "keys", "=", "array_unique", "(", "array_map", "(", "function", "(", "$", "child", ")", "{", "return", "$", "child", "->", "name", ";", "}", ",", "$", "input", "->", "children", "(", ")", ")", ")", ";", "$", "keys", "=", "array_diff", "(", "$", "keys", ",", "$", "propertiesFilter", ")", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "unset", "(", "$", "input", "->", "$", "key", ")", ";", "}", "$", "data", "=", "$", "input", "->", "serialize", "(", ")", ";", "}", "$", "output", "=", "null", ";", "try", "{", "switch", "(", "$", "target", ")", "{", "default", ":", "case", "'vcard3'", ":", "if", "(", "VObject", "\\", "Document", "::", "VCARD30", "===", "$", "input", "->", "getDocumentType", "(", ")", ")", "{", "// Do nothing", "return", "$", "data", ";", "}", "$", "output", "=", "$", "input", "->", "convert", "(", "VObject", "\\", "Document", "::", "VCARD30", ")", ";", "return", "$", "output", "->", "serialize", "(", ")", ";", "case", "'vcard4'", ":", "if", "(", "VObject", "\\", "Document", "::", "VCARD40", "===", "$", "input", "->", "getDocumentType", "(", ")", ")", "{", "// Do nothing", "return", "$", "data", ";", "}", "$", "output", "=", "$", "input", "->", "convert", "(", "VObject", "\\", "Document", "::", "VCARD40", ")", ";", "return", "$", "output", "->", "serialize", "(", ")", ";", "case", "'jcard'", ":", "$", "output", "=", "$", "input", "->", "convert", "(", "VObject", "\\", "Document", "::", "VCARD40", ")", ";", "return", "json_encode", "(", "$", "output", ")", ";", "}", "}", "finally", "{", "// Destroy circular references to PHP will GC the object.", "$", "input", "->", "destroy", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "output", ")", ")", "{", "$", "output", "->", "destroy", "(", ")", ";", "}", "}", "}" ]
Converts a vcard blob to a different version, or jcard. @param string|resource $data @param string $target @param array $propertiesFilter @return string
[ "Converts", "a", "vcard", "blob", "to", "a", "different", "version", "or", "jcard", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Plugin.php#L813-L862
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.checkPrivileges
public function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) { if (!is_array($privileges)) { $privileges = [$privileges]; } $acl = $this->getCurrentUserPrivilegeSet($uri); $failed = []; foreach ($privileges as $priv) { if (!in_array($priv, $acl)) { $failed[] = $priv; } } if ($failed) { if ($this->allowUnauthenticatedAccess && is_null($this->getCurrentUserPrincipal())) { // We are not authenticated. Kicking in the Auth plugin. $authPlugin = $this->server->getPlugin('auth'); $reasons = $authPlugin->getLoginFailedReasons(); $authPlugin->challenge( $this->server->httpRequest, $this->server->httpResponse ); throw new notAuthenticated(implode(', ', $reasons).'. Login was needed for privilege: '.implode(', ', $failed).' on '.$uri); } if ($throwExceptions) { throw new NeedPrivileges($uri, $failed); } else { return false; } } return true; }
php
public function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) { if (!is_array($privileges)) { $privileges = [$privileges]; } $acl = $this->getCurrentUserPrivilegeSet($uri); $failed = []; foreach ($privileges as $priv) { if (!in_array($priv, $acl)) { $failed[] = $priv; } } if ($failed) { if ($this->allowUnauthenticatedAccess && is_null($this->getCurrentUserPrincipal())) { $authPlugin = $this->server->getPlugin('auth'); $reasons = $authPlugin->getLoginFailedReasons(); $authPlugin->challenge( $this->server->httpRequest, $this->server->httpResponse ); throw new notAuthenticated(implode(', ', $reasons).'. Login was needed for privilege: '.implode(', ', $failed).' on '.$uri); } if ($throwExceptions) { throw new NeedPrivileges($uri, $failed); } else { return false; } } return true; }
[ "public", "function", "checkPrivileges", "(", "$", "uri", ",", "$", "privileges", ",", "$", "recursion", "=", "self", "::", "R_PARENT", ",", "$", "throwExceptions", "=", "true", ")", "{", "if", "(", "!", "is_array", "(", "$", "privileges", ")", ")", "{", "$", "privileges", "=", "[", "$", "privileges", "]", ";", "}", "$", "acl", "=", "$", "this", "->", "getCurrentUserPrivilegeSet", "(", "$", "uri", ")", ";", "$", "failed", "=", "[", "]", ";", "foreach", "(", "$", "privileges", "as", "$", "priv", ")", "{", "if", "(", "!", "in_array", "(", "$", "priv", ",", "$", "acl", ")", ")", "{", "$", "failed", "[", "]", "=", "$", "priv", ";", "}", "}", "if", "(", "$", "failed", ")", "{", "if", "(", "$", "this", "->", "allowUnauthenticatedAccess", "&&", "is_null", "(", "$", "this", "->", "getCurrentUserPrincipal", "(", ")", ")", ")", "{", "// We are not authenticated. Kicking in the Auth plugin.", "$", "authPlugin", "=", "$", "this", "->", "server", "->", "getPlugin", "(", "'auth'", ")", ";", "$", "reasons", "=", "$", "authPlugin", "->", "getLoginFailedReasons", "(", ")", ";", "$", "authPlugin", "->", "challenge", "(", "$", "this", "->", "server", "->", "httpRequest", ",", "$", "this", "->", "server", "->", "httpResponse", ")", ";", "throw", "new", "notAuthenticated", "(", "implode", "(", "', '", ",", "$", "reasons", ")", ".", "'. Login was needed for privilege: '", ".", "implode", "(", "', '", ",", "$", "failed", ")", ".", "' on '", ".", "$", "uri", ")", ";", "}", "if", "(", "$", "throwExceptions", ")", "{", "throw", "new", "NeedPrivileges", "(", "$", "uri", ",", "$", "failed", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Checks if the current user has the specified privilege(s). You can specify a single privilege, or a list of privileges. This method will throw an exception if the privilege is not available and return true otherwise. @param string $uri @param array|string $privileges @param int $recursion @param bool $throwExceptions if set to false, this method won't throw exceptions @throws NeedPrivileges @throws NotAuthenticated @return bool
[ "Checks", "if", "the", "current", "user", "has", "the", "specified", "privilege", "(", "s", ")", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L193-L227
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.getCurrentUserPrincipals
public function getCurrentUserPrincipals() { $currentUser = $this->getCurrentUserPrincipal(); if (is_null($currentUser)) { return []; } return array_merge( [$currentUser], $this->getPrincipalMembership($currentUser) ); }
php
public function getCurrentUserPrincipals() { $currentUser = $this->getCurrentUserPrincipal(); if (is_null($currentUser)) { return []; } return array_merge( [$currentUser], $this->getPrincipalMembership($currentUser) ); }
[ "public", "function", "getCurrentUserPrincipals", "(", ")", "{", "$", "currentUser", "=", "$", "this", "->", "getCurrentUserPrincipal", "(", ")", ";", "if", "(", "is_null", "(", "$", "currentUser", ")", ")", "{", "return", "[", "]", ";", "}", "return", "array_merge", "(", "[", "$", "currentUser", "]", ",", "$", "this", "->", "getPrincipalMembership", "(", "$", "currentUser", ")", ")", ";", "}" ]
Returns a list of principals that's associated to the current user, either directly or through group membership. @return array
[ "Returns", "a", "list", "of", "principals", "that", "s", "associated", "to", "the", "current", "user", "either", "directly", "or", "through", "group", "membership", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L254-L266
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.getPrincipalMembership
public function getPrincipalMembership($mainPrincipal) { // First check our cache if (isset($this->principalMembershipCache[$mainPrincipal])) { return $this->principalMembershipCache[$mainPrincipal]; } $check = [$mainPrincipal]; $principals = []; while (count($check)) { $principal = array_shift($check); $node = $this->server->tree->getNodeForPath($principal); if ($node instanceof IPrincipal) { foreach ($node->getGroupMembership() as $groupMember) { if (!in_array($groupMember, $principals)) { $check[] = $groupMember; $principals[] = $groupMember; } } } } // Store the result in the cache $this->principalMembershipCache[$mainPrincipal] = $principals; return $principals; }
php
public function getPrincipalMembership($mainPrincipal) { if (isset($this->principalMembershipCache[$mainPrincipal])) { return $this->principalMembershipCache[$mainPrincipal]; } $check = [$mainPrincipal]; $principals = []; while (count($check)) { $principal = array_shift($check); $node = $this->server->tree->getNodeForPath($principal); if ($node instanceof IPrincipal) { foreach ($node->getGroupMembership() as $groupMember) { if (!in_array($groupMember, $principals)) { $check[] = $groupMember; $principals[] = $groupMember; } } } } $this->principalMembershipCache[$mainPrincipal] = $principals; return $principals; }
[ "public", "function", "getPrincipalMembership", "(", "$", "mainPrincipal", ")", "{", "// First check our cache", "if", "(", "isset", "(", "$", "this", "->", "principalMembershipCache", "[", "$", "mainPrincipal", "]", ")", ")", "{", "return", "$", "this", "->", "principalMembershipCache", "[", "$", "mainPrincipal", "]", ";", "}", "$", "check", "=", "[", "$", "mainPrincipal", "]", ";", "$", "principals", "=", "[", "]", ";", "while", "(", "count", "(", "$", "check", ")", ")", "{", "$", "principal", "=", "array_shift", "(", "$", "check", ")", ";", "$", "node", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "principal", ")", ";", "if", "(", "$", "node", "instanceof", "IPrincipal", ")", "{", "foreach", "(", "$", "node", "->", "getGroupMembership", "(", ")", "as", "$", "groupMember", ")", "{", "if", "(", "!", "in_array", "(", "$", "groupMember", ",", "$", "principals", ")", ")", "{", "$", "check", "[", "]", "=", "$", "groupMember", ";", "$", "principals", "[", "]", "=", "$", "groupMember", ";", "}", "}", "}", "}", "// Store the result in the cache", "$", "this", "->", "principalMembershipCache", "[", "$", "mainPrincipal", "]", "=", "$", "principals", ";", "return", "$", "principals", ";", "}" ]
Returns all the principal groups the specified principal is a member of. @param string $mainPrincipal @return array
[ "Returns", "all", "the", "principal", "groups", "the", "specified", "principal", "is", "a", "member", "of", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L324-L352
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.principalMatchesPrincipal
public function principalMatchesPrincipal($checkPrincipal, $currentPrincipal = null) { if (is_null($currentPrincipal)) { $currentPrincipal = $this->getCurrentUserPrincipal(); } if ($currentPrincipal === $checkPrincipal) { return true; } if (is_null($currentPrincipal)) { return false; } return in_array( $checkPrincipal, $this->getPrincipalMembership($currentPrincipal) ); }
php
public function principalMatchesPrincipal($checkPrincipal, $currentPrincipal = null) { if (is_null($currentPrincipal)) { $currentPrincipal = $this->getCurrentUserPrincipal(); } if ($currentPrincipal === $checkPrincipal) { return true; } if (is_null($currentPrincipal)) { return false; } return in_array( $checkPrincipal, $this->getPrincipalMembership($currentPrincipal) ); }
[ "public", "function", "principalMatchesPrincipal", "(", "$", "checkPrincipal", ",", "$", "currentPrincipal", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "currentPrincipal", ")", ")", "{", "$", "currentPrincipal", "=", "$", "this", "->", "getCurrentUserPrincipal", "(", ")", ";", "}", "if", "(", "$", "currentPrincipal", "===", "$", "checkPrincipal", ")", "{", "return", "true", ";", "}", "if", "(", "is_null", "(", "$", "currentPrincipal", ")", ")", "{", "return", "false", ";", "}", "return", "in_array", "(", "$", "checkPrincipal", ",", "$", "this", "->", "getPrincipalMembership", "(", "$", "currentPrincipal", ")", ")", ";", "}" ]
Find out of a principal equals another principal. This is a quick way to find out whether a principal URI is part of a group, or any subgroups. The first argument is the principal URI you want to check against. For example the principal group, and the second argument is the principal of which you want to find out of it is the same as the first principal, or in a member of the first principal's group or subgroups. So the arguments are not interchangeable. If principal A is in group B, passing 'B', 'A' will yield true, but 'A', 'B' is false. If the second argument is not passed, we will use the current user principal. @param string $checkPrincipal @param string $currentPrincipal @return bool
[ "Find", "out", "of", "a", "principal", "equals", "another", "principal", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L376-L392
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.getSupportedPrivilegeSet
public function getSupportedPrivilegeSet($node) { if (is_string($node)) { $node = $this->server->tree->getNodeForPath($node); } $supportedPrivileges = null; if ($node instanceof IACL) { $supportedPrivileges = $node->getSupportedPrivilegeSet(); } if (is_null($supportedPrivileges)) { // Default $supportedPrivileges = [ '{DAV:}read' => [ 'abstract' => false, 'aggregates' => [ '{DAV:}read-acl' => [ 'abstract' => false, 'aggregates' => [], ], '{DAV:}read-current-user-privilege-set' => [ 'abstract' => false, 'aggregates' => [], ], ], ], '{DAV:}write' => [ 'abstract' => false, 'aggregates' => [ '{DAV:}write-properties' => [ 'abstract' => false, 'aggregates' => [], ], '{DAV:}write-content' => [ 'abstract' => false, 'aggregates' => [], ], '{DAV:}unlock' => [ 'abstract' => false, 'aggregates' => [], ], ], ], ]; if ($node instanceof DAV\ICollection) { $supportedPrivileges['{DAV:}write']['aggregates']['{DAV:}bind'] = [ 'abstract' => false, 'aggregates' => [], ]; $supportedPrivileges['{DAV:}write']['aggregates']['{DAV:}unbind'] = [ 'abstract' => false, 'aggregates' => [], ]; } if ($node instanceof IACL) { $supportedPrivileges['{DAV:}write']['aggregates']['{DAV:}write-acl'] = [ 'abstract' => false, 'aggregates' => [], ]; } } $this->server->emit( 'getSupportedPrivilegeSet', [$node, &$supportedPrivileges] ); return $supportedPrivileges; }
php
public function getSupportedPrivilegeSet($node) { if (is_string($node)) { $node = $this->server->tree->getNodeForPath($node); } $supportedPrivileges = null; if ($node instanceof IACL) { $supportedPrivileges = $node->getSupportedPrivilegeSet(); } if (is_null($supportedPrivileges)) { $supportedPrivileges = [ '{DAV:}read' => [ 'abstract' => false, 'aggregates' => [ '{DAV:}read-acl' => [ 'abstract' => false, 'aggregates' => [], ], '{DAV:}read-current-user-privilege-set' => [ 'abstract' => false, 'aggregates' => [], ], ], ], '{DAV:}write' => [ 'abstract' => false, 'aggregates' => [ '{DAV:}write-properties' => [ 'abstract' => false, 'aggregates' => [], ], '{DAV:}write-content' => [ 'abstract' => false, 'aggregates' => [], ], '{DAV:}unlock' => [ 'abstract' => false, 'aggregates' => [], ], ], ], ]; if ($node instanceof DAV\ICollection) { $supportedPrivileges['{DAV:}write']['aggregates']['{DAV:}bind'] = [ 'abstract' => false, 'aggregates' => [], ]; $supportedPrivileges['{DAV:}write']['aggregates']['{DAV:}unbind'] = [ 'abstract' => false, 'aggregates' => [], ]; } if ($node instanceof IACL) { $supportedPrivileges['{DAV:}write']['aggregates']['{DAV:}write-acl'] = [ 'abstract' => false, 'aggregates' => [], ]; } } $this->server->emit( 'getSupportedPrivilegeSet', [$node, &$supportedPrivileges] ); return $supportedPrivileges; }
[ "public", "function", "getSupportedPrivilegeSet", "(", "$", "node", ")", "{", "if", "(", "is_string", "(", "$", "node", ")", ")", "{", "$", "node", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "node", ")", ";", "}", "$", "supportedPrivileges", "=", "null", ";", "if", "(", "$", "node", "instanceof", "IACL", ")", "{", "$", "supportedPrivileges", "=", "$", "node", "->", "getSupportedPrivilegeSet", "(", ")", ";", "}", "if", "(", "is_null", "(", "$", "supportedPrivileges", ")", ")", "{", "// Default", "$", "supportedPrivileges", "=", "[", "'{DAV:}read'", "=>", "[", "'abstract'", "=>", "false", ",", "'aggregates'", "=>", "[", "'{DAV:}read-acl'", "=>", "[", "'abstract'", "=>", "false", ",", "'aggregates'", "=>", "[", "]", ",", "]", ",", "'{DAV:}read-current-user-privilege-set'", "=>", "[", "'abstract'", "=>", "false", ",", "'aggregates'", "=>", "[", "]", ",", "]", ",", "]", ",", "]", ",", "'{DAV:}write'", "=>", "[", "'abstract'", "=>", "false", ",", "'aggregates'", "=>", "[", "'{DAV:}write-properties'", "=>", "[", "'abstract'", "=>", "false", ",", "'aggregates'", "=>", "[", "]", ",", "]", ",", "'{DAV:}write-content'", "=>", "[", "'abstract'", "=>", "false", ",", "'aggregates'", "=>", "[", "]", ",", "]", ",", "'{DAV:}unlock'", "=>", "[", "'abstract'", "=>", "false", ",", "'aggregates'", "=>", "[", "]", ",", "]", ",", "]", ",", "]", ",", "]", ";", "if", "(", "$", "node", "instanceof", "DAV", "\\", "ICollection", ")", "{", "$", "supportedPrivileges", "[", "'{DAV:}write'", "]", "[", "'aggregates'", "]", "[", "'{DAV:}bind'", "]", "=", "[", "'abstract'", "=>", "false", ",", "'aggregates'", "=>", "[", "]", ",", "]", ";", "$", "supportedPrivileges", "[", "'{DAV:}write'", "]", "[", "'aggregates'", "]", "[", "'{DAV:}unbind'", "]", "=", "[", "'abstract'", "=>", "false", ",", "'aggregates'", "=>", "[", "]", ",", "]", ";", "}", "if", "(", "$", "node", "instanceof", "IACL", ")", "{", "$", "supportedPrivileges", "[", "'{DAV:}write'", "]", "[", "'aggregates'", "]", "[", "'{DAV:}write-acl'", "]", "=", "[", "'abstract'", "=>", "false", ",", "'aggregates'", "=>", "[", "]", ",", "]", ";", "}", "}", "$", "this", "->", "server", "->", "emit", "(", "'getSupportedPrivilegeSet'", ",", "[", "$", "node", ",", "&", "$", "supportedPrivileges", "]", ")", ";", "return", "$", "supportedPrivileges", ";", "}" ]
Returns a tree of supported privileges for a resource. The returned array structure should be in this form: [ [ 'privilege' => '{DAV:}read', 'abstract' => false, 'aggregates' => [] ] ] Privileges can be nested using "aggregates". Doing so means that if you assign someone the aggregating privilege, all the sub-privileges will automatically be granted. Marking a privilege as abstract means that the privilege cannot be directly assigned, but must be assigned via the parent privilege. So a more complex version might look like this: [ [ 'privilege' => '{DAV:}read', 'abstract' => false, 'aggregates' => [ [ 'privilege' => '{DAV:}read-acl', 'abstract' => false, 'aggregates' => [], ] ] ] ] @param string|INode $node @return array
[ "Returns", "a", "tree", "of", "supported", "privileges", "for", "a", "resource", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L434-L503
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.getFlatPrivilegeSet
final public function getFlatPrivilegeSet($node) { $privs = [ 'abstract' => false, 'aggregates' => $this->getSupportedPrivilegeSet($node), ]; $fpsTraverse = null; $fpsTraverse = function ($privName, $privInfo, $concrete, &$flat) use (&$fpsTraverse) { $myPriv = [ 'privilege' => $privName, 'abstract' => isset($privInfo['abstract']) && $privInfo['abstract'], 'aggregates' => [], 'concrete' => isset($privInfo['abstract']) && $privInfo['abstract'] ? $concrete : $privName, ]; if (isset($privInfo['aggregates'])) { foreach ($privInfo['aggregates'] as $subPrivName => $subPrivInfo) { $myPriv['aggregates'][] = $subPrivName; } } $flat[$privName] = $myPriv; if (isset($privInfo['aggregates'])) { foreach ($privInfo['aggregates'] as $subPrivName => $subPrivInfo) { $fpsTraverse($subPrivName, $subPrivInfo, $myPriv['concrete'], $flat); } } }; $flat = []; $fpsTraverse('{DAV:}all', $privs, null, $flat); return $flat; }
php
final public function getFlatPrivilegeSet($node) { $privs = [ 'abstract' => false, 'aggregates' => $this->getSupportedPrivilegeSet($node), ]; $fpsTraverse = null; $fpsTraverse = function ($privName, $privInfo, $concrete, &$flat) use (&$fpsTraverse) { $myPriv = [ 'privilege' => $privName, 'abstract' => isset($privInfo['abstract']) && $privInfo['abstract'], 'aggregates' => [], 'concrete' => isset($privInfo['abstract']) && $privInfo['abstract'] ? $concrete : $privName, ]; if (isset($privInfo['aggregates'])) { foreach ($privInfo['aggregates'] as $subPrivName => $subPrivInfo) { $myPriv['aggregates'][] = $subPrivName; } } $flat[$privName] = $myPriv; if (isset($privInfo['aggregates'])) { foreach ($privInfo['aggregates'] as $subPrivName => $subPrivInfo) { $fpsTraverse($subPrivName, $subPrivInfo, $myPriv['concrete'], $flat); } } }; $flat = []; $fpsTraverse('{DAV:}all', $privs, null, $flat); return $flat; }
[ "final", "public", "function", "getFlatPrivilegeSet", "(", "$", "node", ")", "{", "$", "privs", "=", "[", "'abstract'", "=>", "false", ",", "'aggregates'", "=>", "$", "this", "->", "getSupportedPrivilegeSet", "(", "$", "node", ")", ",", "]", ";", "$", "fpsTraverse", "=", "null", ";", "$", "fpsTraverse", "=", "function", "(", "$", "privName", ",", "$", "privInfo", ",", "$", "concrete", ",", "&", "$", "flat", ")", "use", "(", "&", "$", "fpsTraverse", ")", "{", "$", "myPriv", "=", "[", "'privilege'", "=>", "$", "privName", ",", "'abstract'", "=>", "isset", "(", "$", "privInfo", "[", "'abstract'", "]", ")", "&&", "$", "privInfo", "[", "'abstract'", "]", ",", "'aggregates'", "=>", "[", "]", ",", "'concrete'", "=>", "isset", "(", "$", "privInfo", "[", "'abstract'", "]", ")", "&&", "$", "privInfo", "[", "'abstract'", "]", "?", "$", "concrete", ":", "$", "privName", ",", "]", ";", "if", "(", "isset", "(", "$", "privInfo", "[", "'aggregates'", "]", ")", ")", "{", "foreach", "(", "$", "privInfo", "[", "'aggregates'", "]", "as", "$", "subPrivName", "=>", "$", "subPrivInfo", ")", "{", "$", "myPriv", "[", "'aggregates'", "]", "[", "]", "=", "$", "subPrivName", ";", "}", "}", "$", "flat", "[", "$", "privName", "]", "=", "$", "myPriv", ";", "if", "(", "isset", "(", "$", "privInfo", "[", "'aggregates'", "]", ")", ")", "{", "foreach", "(", "$", "privInfo", "[", "'aggregates'", "]", "as", "$", "subPrivName", "=>", "$", "subPrivInfo", ")", "{", "$", "fpsTraverse", "(", "$", "subPrivName", ",", "$", "subPrivInfo", ",", "$", "myPriv", "[", "'concrete'", "]", ",", "$", "flat", ")", ";", "}", "}", "}", ";", "$", "flat", "=", "[", "]", ";", "$", "fpsTraverse", "(", "'{DAV:}all'", ",", "$", "privs", ",", "null", ",", "$", "flat", ")", ";", "return", "$", "flat", ";", "}" ]
Returns the supported privilege set as a flat list. This is much easier to parse. The returned list will be index by privilege name. The value is a struct containing the following properties: - aggregates - abstract - concrete @param string|INode $node @return array
[ "Returns", "the", "supported", "privilege", "set", "as", "a", "flat", "list", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L520-L555
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.getAcl
public function getAcl($node) { if (is_string($node)) { $node = $this->server->tree->getNodeForPath($node); } if (!$node instanceof IACL) { return $this->getDefaultAcl(); } $acl = $node->getACL(); foreach ($this->adminPrincipals as $adminPrincipal) { $acl[] = [ 'principal' => $adminPrincipal, 'privilege' => '{DAV:}all', 'protected' => true, ]; } return $acl; }
php
public function getAcl($node) { if (is_string($node)) { $node = $this->server->tree->getNodeForPath($node); } if (!$node instanceof IACL) { return $this->getDefaultAcl(); } $acl = $node->getACL(); foreach ($this->adminPrincipals as $adminPrincipal) { $acl[] = [ 'principal' => $adminPrincipal, 'privilege' => '{DAV:}all', 'protected' => true, ]; } return $acl; }
[ "public", "function", "getAcl", "(", "$", "node", ")", "{", "if", "(", "is_string", "(", "$", "node", ")", ")", "{", "$", "node", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "node", ")", ";", "}", "if", "(", "!", "$", "node", "instanceof", "IACL", ")", "{", "return", "$", "this", "->", "getDefaultAcl", "(", ")", ";", "}", "$", "acl", "=", "$", "node", "->", "getACL", "(", ")", ";", "foreach", "(", "$", "this", "->", "adminPrincipals", "as", "$", "adminPrincipal", ")", "{", "$", "acl", "[", "]", "=", "[", "'principal'", "=>", "$", "adminPrincipal", ",", "'privilege'", "=>", "'{DAV:}all'", ",", "'protected'", "=>", "true", ",", "]", ";", "}", "return", "$", "acl", ";", "}" ]
Returns the full ACL list. Either a uri or a INode may be passed. null will be returned if the node doesn't support ACLs. @param string|DAV\INode $node @return array
[ "Returns", "the", "full", "ACL", "list", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L568-L586
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.getCurrentUserPrivilegeSet
public function getCurrentUserPrivilegeSet($node) { if (is_string($node)) { $node = $this->server->tree->getNodeForPath($node); } $acl = $this->getACL($node); $collected = []; $isAuthenticated = null !== $this->getCurrentUserPrincipal(); foreach ($acl as $ace) { $principal = $ace['principal']; switch ($principal) { case '{DAV:}owner': $owner = $node->getOwner(); if ($owner && $this->principalMatchesPrincipal($owner)) { $collected[] = $ace; } break; // 'all' matches for every user case '{DAV:}all': $collected[] = $ace; break; case '{DAV:}authenticated': // Authenticated users only if ($isAuthenticated) { $collected[] = $ace; } break; case '{DAV:}unauthenticated': // Unauthenticated users only if (!$isAuthenticated) { $collected[] = $ace; } break; default: if ($this->principalMatchesPrincipal($ace['principal'])) { $collected[] = $ace; } break; } } // Now we deduct all aggregated privileges. $flat = $this->getFlatPrivilegeSet($node); $collected2 = []; while (count($collected)) { $current = array_pop($collected); $collected2[] = $current['privilege']; if (!isset($flat[$current['privilege']])) { // Ignoring privileges that are not in the supported-privileges list. $this->server->getLogger()->debug('A node has the "'.$current['privilege'].'" in its ACL list, but this privilege was not reported in the supportedPrivilegeSet list. This will be ignored.'); continue; } foreach ($flat[$current['privilege']]['aggregates'] as $subPriv) { $collected2[] = $subPriv; $collected[] = $flat[$subPriv]; } } return array_values(array_unique($collected2)); }
php
public function getCurrentUserPrivilegeSet($node) { if (is_string($node)) { $node = $this->server->tree->getNodeForPath($node); } $acl = $this->getACL($node); $collected = []; $isAuthenticated = null !== $this->getCurrentUserPrincipal(); foreach ($acl as $ace) { $principal = $ace['principal']; switch ($principal) { case '{DAV:}owner': $owner = $node->getOwner(); if ($owner && $this->principalMatchesPrincipal($owner)) { $collected[] = $ace; } break; case '{DAV:}all': $collected[] = $ace; break; case '{DAV:}authenticated': if ($isAuthenticated) { $collected[] = $ace; } break; case '{DAV:}unauthenticated': if (!$isAuthenticated) { $collected[] = $ace; } break; default: if ($this->principalMatchesPrincipal($ace['principal'])) { $collected[] = $ace; } break; } } $flat = $this->getFlatPrivilegeSet($node); $collected2 = []; while (count($collected)) { $current = array_pop($collected); $collected2[] = $current['privilege']; if (!isset($flat[$current['privilege']])) { $this->server->getLogger()->debug('A node has the "'.$current['privilege'].'" in its ACL list, but this privilege was not reported in the supportedPrivilegeSet list. This will be ignored.'); continue; } foreach ($flat[$current['privilege']]['aggregates'] as $subPriv) { $collected2[] = $subPriv; $collected[] = $flat[$subPriv]; } } return array_values(array_unique($collected2)); }
[ "public", "function", "getCurrentUserPrivilegeSet", "(", "$", "node", ")", "{", "if", "(", "is_string", "(", "$", "node", ")", ")", "{", "$", "node", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "node", ")", ";", "}", "$", "acl", "=", "$", "this", "->", "getACL", "(", "$", "node", ")", ";", "$", "collected", "=", "[", "]", ";", "$", "isAuthenticated", "=", "null", "!==", "$", "this", "->", "getCurrentUserPrincipal", "(", ")", ";", "foreach", "(", "$", "acl", "as", "$", "ace", ")", "{", "$", "principal", "=", "$", "ace", "[", "'principal'", "]", ";", "switch", "(", "$", "principal", ")", "{", "case", "'{DAV:}owner'", ":", "$", "owner", "=", "$", "node", "->", "getOwner", "(", ")", ";", "if", "(", "$", "owner", "&&", "$", "this", "->", "principalMatchesPrincipal", "(", "$", "owner", ")", ")", "{", "$", "collected", "[", "]", "=", "$", "ace", ";", "}", "break", ";", "// 'all' matches for every user", "case", "'{DAV:}all'", ":", "$", "collected", "[", "]", "=", "$", "ace", ";", "break", ";", "case", "'{DAV:}authenticated'", ":", "// Authenticated users only", "if", "(", "$", "isAuthenticated", ")", "{", "$", "collected", "[", "]", "=", "$", "ace", ";", "}", "break", ";", "case", "'{DAV:}unauthenticated'", ":", "// Unauthenticated users only", "if", "(", "!", "$", "isAuthenticated", ")", "{", "$", "collected", "[", "]", "=", "$", "ace", ";", "}", "break", ";", "default", ":", "if", "(", "$", "this", "->", "principalMatchesPrincipal", "(", "$", "ace", "[", "'principal'", "]", ")", ")", "{", "$", "collected", "[", "]", "=", "$", "ace", ";", "}", "break", ";", "}", "}", "// Now we deduct all aggregated privileges.", "$", "flat", "=", "$", "this", "->", "getFlatPrivilegeSet", "(", "$", "node", ")", ";", "$", "collected2", "=", "[", "]", ";", "while", "(", "count", "(", "$", "collected", ")", ")", "{", "$", "current", "=", "array_pop", "(", "$", "collected", ")", ";", "$", "collected2", "[", "]", "=", "$", "current", "[", "'privilege'", "]", ";", "if", "(", "!", "isset", "(", "$", "flat", "[", "$", "current", "[", "'privilege'", "]", "]", ")", ")", "{", "// Ignoring privileges that are not in the supported-privileges list.", "$", "this", "->", "server", "->", "getLogger", "(", ")", "->", "debug", "(", "'A node has the \"'", ".", "$", "current", "[", "'privilege'", "]", ".", "'\" in its ACL list, but this privilege was not reported in the supportedPrivilegeSet list. This will be ignored.'", ")", ";", "continue", ";", "}", "foreach", "(", "$", "flat", "[", "$", "current", "[", "'privilege'", "]", "]", "[", "'aggregates'", "]", "as", "$", "subPriv", ")", "{", "$", "collected2", "[", "]", "=", "$", "subPriv", ";", "$", "collected", "[", "]", "=", "$", "flat", "[", "$", "subPriv", "]", ";", "}", "}", "return", "array_values", "(", "array_unique", "(", "$", "collected2", ")", ")", ";", "}" ]
Returns a list of privileges the current user has on a particular node. Either a uri or a DAV\INode may be passed. null will be returned if the node doesn't support ACLs. @param string|DAV\INode $node @return array
[ "Returns", "a", "list", "of", "privileges", "the", "current", "user", "has", "on", "a", "particular", "node", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L600-L670
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.getPrincipalByUri
public function getPrincipalByUri($uri) { $result = null; $collections = $this->principalCollectionSet; foreach ($collections as $collection) { try { $principalCollection = $this->server->tree->getNodeForPath($collection); } catch (NotFound $e) { // Ignore and move on continue; } if (!$principalCollection instanceof IPrincipalCollection) { // Not a principal collection, we're simply going to ignore // this. continue; } $result = $principalCollection->findByUri($uri); if ($result) { return $result; } } }
php
public function getPrincipalByUri($uri) { $result = null; $collections = $this->principalCollectionSet; foreach ($collections as $collection) { try { $principalCollection = $this->server->tree->getNodeForPath($collection); } catch (NotFound $e) { continue; } if (!$principalCollection instanceof IPrincipalCollection) { continue; } $result = $principalCollection->findByUri($uri); if ($result) { return $result; } } }
[ "public", "function", "getPrincipalByUri", "(", "$", "uri", ")", "{", "$", "result", "=", "null", ";", "$", "collections", "=", "$", "this", "->", "principalCollectionSet", ";", "foreach", "(", "$", "collections", "as", "$", "collection", ")", "{", "try", "{", "$", "principalCollection", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "collection", ")", ";", "}", "catch", "(", "NotFound", "$", "e", ")", "{", "// Ignore and move on", "continue", ";", "}", "if", "(", "!", "$", "principalCollection", "instanceof", "IPrincipalCollection", ")", "{", "// Not a principal collection, we're simply going to ignore", "// this.", "continue", ";", "}", "$", "result", "=", "$", "principalCollection", "->", "findByUri", "(", "$", "uri", ")", ";", "if", "(", "$", "result", ")", "{", "return", "$", "result", ";", "}", "}", "}" ]
Returns a principal based on its uri. Returns null if the principal could not be found. @param string $uri @return string|null
[ "Returns", "a", "principal", "based", "on", "its", "uri", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L681-L704
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.principalSearch
public function principalSearch(array $searchProperties, array $requestedProperties, $collectionUri = null, $test = 'allof') { if (!is_null($collectionUri)) { $uris = [$collectionUri]; } else { $uris = $this->principalCollectionSet; } $lookupResults = []; foreach ($uris as $uri) { $principalCollection = $this->server->tree->getNodeForPath($uri); if (!$principalCollection instanceof IPrincipalCollection) { // Not a principal collection, we're simply going to ignore // this. continue; } $results = $principalCollection->searchPrincipals($searchProperties, $test); foreach ($results as $result) { $lookupResults[] = rtrim($uri, '/').'/'.$result; } } $matches = []; foreach ($lookupResults as $lookupResult) { list($matches[]) = $this->server->getPropertiesForPath($lookupResult, $requestedProperties, 0); } return $matches; }
php
public function principalSearch(array $searchProperties, array $requestedProperties, $collectionUri = null, $test = 'allof') { if (!is_null($collectionUri)) { $uris = [$collectionUri]; } else { $uris = $this->principalCollectionSet; } $lookupResults = []; foreach ($uris as $uri) { $principalCollection = $this->server->tree->getNodeForPath($uri); if (!$principalCollection instanceof IPrincipalCollection) { continue; } $results = $principalCollection->searchPrincipals($searchProperties, $test); foreach ($results as $result) { $lookupResults[] = rtrim($uri, '/').'/'.$result; } } $matches = []; foreach ($lookupResults as $lookupResult) { list($matches[]) = $this->server->getPropertiesForPath($lookupResult, $requestedProperties, 0); } return $matches; }
[ "public", "function", "principalSearch", "(", "array", "$", "searchProperties", ",", "array", "$", "requestedProperties", ",", "$", "collectionUri", "=", "null", ",", "$", "test", "=", "'allof'", ")", "{", "if", "(", "!", "is_null", "(", "$", "collectionUri", ")", ")", "{", "$", "uris", "=", "[", "$", "collectionUri", "]", ";", "}", "else", "{", "$", "uris", "=", "$", "this", "->", "principalCollectionSet", ";", "}", "$", "lookupResults", "=", "[", "]", ";", "foreach", "(", "$", "uris", "as", "$", "uri", ")", "{", "$", "principalCollection", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "uri", ")", ";", "if", "(", "!", "$", "principalCollection", "instanceof", "IPrincipalCollection", ")", "{", "// Not a principal collection, we're simply going to ignore", "// this.", "continue", ";", "}", "$", "results", "=", "$", "principalCollection", "->", "searchPrincipals", "(", "$", "searchProperties", ",", "$", "test", ")", ";", "foreach", "(", "$", "results", "as", "$", "result", ")", "{", "$", "lookupResults", "[", "]", "=", "rtrim", "(", "$", "uri", ",", "'/'", ")", ".", "'/'", ".", "$", "result", ";", "}", "}", "$", "matches", "=", "[", "]", ";", "foreach", "(", "$", "lookupResults", "as", "$", "lookupResult", ")", "{", "list", "(", "$", "matches", "[", "]", ")", "=", "$", "this", "->", "server", "->", "getPropertiesForPath", "(", "$", "lookupResult", ",", "$", "requestedProperties", ",", "0", ")", ";", "}", "return", "$", "matches", ";", "}" ]
Principal property search. This method can search for principals matching certain values in properties. This method will return a list of properties for the matched properties. @param array $searchProperties The properties to search on. This is a key-value list. The keys are property names, and the values the strings to match them on. @param array $requestedProperties this is the list of properties to return for every match @param string $collectionUri the principal collection to search on. If this is ommitted, the standard principal collection-set will be used @param string $test "allof" to use AND to search the properties. 'anyof' for OR. @return array This method returns an array structure similar to Sabre\DAV\Server::getPropertiesForPath. Returned properties are index by a HTTP status code.
[ "Principal", "property", "search", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L730-L760
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.initialize
public function initialize(DAV\Server $server) { if ($this->allowUnauthenticatedAccess) { $authPlugin = $server->getPlugin('auth'); if (!$authPlugin) { throw new \Exception('The Auth plugin must be loaded before the ACL plugin if you want to allow unauthenticated access.'); } $authPlugin->autoRequireLogin = false; } $this->server = $server; $server->on('propFind', [$this, 'propFind'], 20); $server->on('beforeMethod:*', [$this, 'beforeMethod'], 20); $server->on('beforeBind', [$this, 'beforeBind'], 20); $server->on('beforeUnbind', [$this, 'beforeUnbind'], 20); $server->on('propPatch', [$this, 'propPatch']); $server->on('beforeUnlock', [$this, 'beforeUnlock'], 20); $server->on('report', [$this, 'report']); $server->on('method:ACL', [$this, 'httpAcl']); $server->on('onHTMLActionsPanel', [$this, 'htmlActionsPanel']); $server->on('getPrincipalByUri', function ($principal, &$uri) { $uri = $this->getPrincipalByUri($principal); // Break event chain if ($uri) { return false; } }); array_push($server->protectedProperties, '{DAV:}alternate-URI-set', '{DAV:}principal-URL', '{DAV:}group-membership', '{DAV:}principal-collection-set', '{DAV:}current-user-principal', '{DAV:}supported-privilege-set', '{DAV:}current-user-privilege-set', '{DAV:}acl', '{DAV:}acl-restrictions', '{DAV:}inherited-acl-set', '{DAV:}owner', '{DAV:}group' ); // Automatically mapping nodes implementing IPrincipal to the // {DAV:}principal resourcetype. $server->resourceTypeMapping['Sabre\\DAVACL\\IPrincipal'] = '{DAV:}principal'; // Mapping the group-member-set property to the HrefList property // class. $server->xml->elementMap['{DAV:}group-member-set'] = 'Sabre\\DAV\\Xml\\Property\\Href'; $server->xml->elementMap['{DAV:}acl'] = 'Sabre\\DAVACL\\Xml\\Property\\Acl'; $server->xml->elementMap['{DAV:}acl-principal-prop-set'] = 'Sabre\\DAVACL\\Xml\\Request\\AclPrincipalPropSetReport'; $server->xml->elementMap['{DAV:}expand-property'] = 'Sabre\\DAVACL\\Xml\\Request\\ExpandPropertyReport'; $server->xml->elementMap['{DAV:}principal-property-search'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalPropertySearchReport'; $server->xml->elementMap['{DAV:}principal-search-property-set'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalSearchPropertySetReport'; $server->xml->elementMap['{DAV:}principal-match'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalMatchReport'; }
php
public function initialize(DAV\Server $server) { if ($this->allowUnauthenticatedAccess) { $authPlugin = $server->getPlugin('auth'); if (!$authPlugin) { throw new \Exception('The Auth plugin must be loaded before the ACL plugin if you want to allow unauthenticated access.'); } $authPlugin->autoRequireLogin = false; } $this->server = $server; $server->on('propFind', [$this, 'propFind'], 20); $server->on('beforeMethod:*', [$this, 'beforeMethod'], 20); $server->on('beforeBind', [$this, 'beforeBind'], 20); $server->on('beforeUnbind', [$this, 'beforeUnbind'], 20); $server->on('propPatch', [$this, 'propPatch']); $server->on('beforeUnlock', [$this, 'beforeUnlock'], 20); $server->on('report', [$this, 'report']); $server->on('method:ACL', [$this, 'httpAcl']); $server->on('onHTMLActionsPanel', [$this, 'htmlActionsPanel']); $server->on('getPrincipalByUri', function ($principal, &$uri) { $uri = $this->getPrincipalByUri($principal); if ($uri) { return false; } }); array_push($server->protectedProperties, '{DAV:}alternate-URI-set', '{DAV:}principal-URL', '{DAV:}group-membership', '{DAV:}principal-collection-set', '{DAV:}current-user-principal', '{DAV:}supported-privilege-set', '{DAV:}current-user-privilege-set', '{DAV:}acl', '{DAV:}acl-restrictions', '{DAV:}inherited-acl-set', '{DAV:}owner', '{DAV:}group' ); $server->resourceTypeMapping['Sabre\\DAVACL\\IPrincipal'] = '{DAV:}principal'; $server->xml->elementMap['{DAV:}group-member-set'] = 'Sabre\\DAV\\Xml\\Property\\Href'; $server->xml->elementMap['{DAV:}acl'] = 'Sabre\\DAVACL\\Xml\\Property\\Acl'; $server->xml->elementMap['{DAV:}acl-principal-prop-set'] = 'Sabre\\DAVACL\\Xml\\Request\\AclPrincipalPropSetReport'; $server->xml->elementMap['{DAV:}expand-property'] = 'Sabre\\DAVACL\\Xml\\Request\\ExpandPropertyReport'; $server->xml->elementMap['{DAV:}principal-property-search'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalPropertySearchReport'; $server->xml->elementMap['{DAV:}principal-search-property-set'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalSearchPropertySetReport'; $server->xml->elementMap['{DAV:}principal-match'] = 'Sabre\\DAVACL\\Xml\\Request\\PrincipalMatchReport'; }
[ "public", "function", "initialize", "(", "DAV", "\\", "Server", "$", "server", ")", "{", "if", "(", "$", "this", "->", "allowUnauthenticatedAccess", ")", "{", "$", "authPlugin", "=", "$", "server", "->", "getPlugin", "(", "'auth'", ")", ";", "if", "(", "!", "$", "authPlugin", ")", "{", "throw", "new", "\\", "Exception", "(", "'The Auth plugin must be loaded before the ACL plugin if you want to allow unauthenticated access.'", ")", ";", "}", "$", "authPlugin", "->", "autoRequireLogin", "=", "false", ";", "}", "$", "this", "->", "server", "=", "$", "server", ";", "$", "server", "->", "on", "(", "'propFind'", ",", "[", "$", "this", ",", "'propFind'", "]", ",", "20", ")", ";", "$", "server", "->", "on", "(", "'beforeMethod:*'", ",", "[", "$", "this", ",", "'beforeMethod'", "]", ",", "20", ")", ";", "$", "server", "->", "on", "(", "'beforeBind'", ",", "[", "$", "this", ",", "'beforeBind'", "]", ",", "20", ")", ";", "$", "server", "->", "on", "(", "'beforeUnbind'", ",", "[", "$", "this", ",", "'beforeUnbind'", "]", ",", "20", ")", ";", "$", "server", "->", "on", "(", "'propPatch'", ",", "[", "$", "this", ",", "'propPatch'", "]", ")", ";", "$", "server", "->", "on", "(", "'beforeUnlock'", ",", "[", "$", "this", ",", "'beforeUnlock'", "]", ",", "20", ")", ";", "$", "server", "->", "on", "(", "'report'", ",", "[", "$", "this", ",", "'report'", "]", ")", ";", "$", "server", "->", "on", "(", "'method:ACL'", ",", "[", "$", "this", ",", "'httpAcl'", "]", ")", ";", "$", "server", "->", "on", "(", "'onHTMLActionsPanel'", ",", "[", "$", "this", ",", "'htmlActionsPanel'", "]", ")", ";", "$", "server", "->", "on", "(", "'getPrincipalByUri'", ",", "function", "(", "$", "principal", ",", "&", "$", "uri", ")", "{", "$", "uri", "=", "$", "this", "->", "getPrincipalByUri", "(", "$", "principal", ")", ";", "// Break event chain", "if", "(", "$", "uri", ")", "{", "return", "false", ";", "}", "}", ")", ";", "array_push", "(", "$", "server", "->", "protectedProperties", ",", "'{DAV:}alternate-URI-set'", ",", "'{DAV:}principal-URL'", ",", "'{DAV:}group-membership'", ",", "'{DAV:}principal-collection-set'", ",", "'{DAV:}current-user-principal'", ",", "'{DAV:}supported-privilege-set'", ",", "'{DAV:}current-user-privilege-set'", ",", "'{DAV:}acl'", ",", "'{DAV:}acl-restrictions'", ",", "'{DAV:}inherited-acl-set'", ",", "'{DAV:}owner'", ",", "'{DAV:}group'", ")", ";", "// Automatically mapping nodes implementing IPrincipal to the", "// {DAV:}principal resourcetype.", "$", "server", "->", "resourceTypeMapping", "[", "'Sabre\\\\DAVACL\\\\IPrincipal'", "]", "=", "'{DAV:}principal'", ";", "// Mapping the group-member-set property to the HrefList property", "// class.", "$", "server", "->", "xml", "->", "elementMap", "[", "'{DAV:}group-member-set'", "]", "=", "'Sabre\\\\DAV\\\\Xml\\\\Property\\\\Href'", ";", "$", "server", "->", "xml", "->", "elementMap", "[", "'{DAV:}acl'", "]", "=", "'Sabre\\\\DAVACL\\\\Xml\\\\Property\\\\Acl'", ";", "$", "server", "->", "xml", "->", "elementMap", "[", "'{DAV:}acl-principal-prop-set'", "]", "=", "'Sabre\\\\DAVACL\\\\Xml\\\\Request\\\\AclPrincipalPropSetReport'", ";", "$", "server", "->", "xml", "->", "elementMap", "[", "'{DAV:}expand-property'", "]", "=", "'Sabre\\\\DAVACL\\\\Xml\\\\Request\\\\ExpandPropertyReport'", ";", "$", "server", "->", "xml", "->", "elementMap", "[", "'{DAV:}principal-property-search'", "]", "=", "'Sabre\\\\DAVACL\\\\Xml\\\\Request\\\\PrincipalPropertySearchReport'", ";", "$", "server", "->", "xml", "->", "elementMap", "[", "'{DAV:}principal-search-property-set'", "]", "=", "'Sabre\\\\DAVACL\\\\Xml\\\\Request\\\\PrincipalSearchPropertySetReport'", ";", "$", "server", "->", "xml", "->", "elementMap", "[", "'{DAV:}principal-match'", "]", "=", "'Sabre\\\\DAVACL\\\\Xml\\\\Request\\\\PrincipalMatchReport'", ";", "}" ]
Sets up the plugin. This method is automatically called by the server class. @param DAV\Server $server
[ "Sets", "up", "the", "plugin", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L769-L826
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.beforeMethod
public function beforeMethod(RequestInterface $request, ResponseInterface $response) { $method = $request->getMethod(); $path = $request->getPath(); $exists = $this->server->tree->nodeExists($path); // If the node doesn't exists, none of these checks apply if (!$exists) { return; } switch ($method) { case 'GET': case 'HEAD': case 'OPTIONS': // For these 3 we only need to know if the node is readable. $this->checkPrivileges($path, '{DAV:}read'); break; case 'PUT': case 'LOCK': // This method requires the write-content priv if the node // already exists, and bind on the parent if the node is being // created. // The bind privilege is handled in the beforeBind event. $this->checkPrivileges($path, '{DAV:}write-content'); break; case 'UNLOCK': // Unlock is always allowed at the moment. break; case 'PROPPATCH': $this->checkPrivileges($path, '{DAV:}write-properties'); break; case 'ACL': $this->checkPrivileges($path, '{DAV:}write-acl'); break; case 'COPY': case 'MOVE': // Copy requires read privileges on the entire source tree. // If the target exists write-content normally needs to be // checked, however, we're deleting the node beforehand and // creating a new one after, so this is handled by the // beforeUnbind event. // // The creation of the new node is handled by the beforeBind // event. // // If MOVE is used beforeUnbind will also be used to check if // the sourcenode can be deleted. $this->checkPrivileges($path, '{DAV:}read', self::R_RECURSIVE); break; } }
php
public function beforeMethod(RequestInterface $request, ResponseInterface $response) { $method = $request->getMethod(); $path = $request->getPath(); $exists = $this->server->tree->nodeExists($path); if (!$exists) { return; } switch ($method) { case 'GET': case 'HEAD': case 'OPTIONS': $this->checkPrivileges($path, '{DAV:}read'); break; case 'PUT': case 'LOCK': $this->checkPrivileges($path, '{DAV:}write-content'); break; case 'UNLOCK': break; case 'PROPPATCH': $this->checkPrivileges($path, '{DAV:}write-properties'); break; case 'ACL': $this->checkPrivileges($path, '{DAV:}write-acl'); break; case 'COPY': case 'MOVE': $this->checkPrivileges($path, '{DAV:}read', self::R_RECURSIVE); break; } }
[ "public", "function", "beforeMethod", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "method", "=", "$", "request", "->", "getMethod", "(", ")", ";", "$", "path", "=", "$", "request", "->", "getPath", "(", ")", ";", "$", "exists", "=", "$", "this", "->", "server", "->", "tree", "->", "nodeExists", "(", "$", "path", ")", ";", "// If the node doesn't exists, none of these checks apply", "if", "(", "!", "$", "exists", ")", "{", "return", ";", "}", "switch", "(", "$", "method", ")", "{", "case", "'GET'", ":", "case", "'HEAD'", ":", "case", "'OPTIONS'", ":", "// For these 3 we only need to know if the node is readable.", "$", "this", "->", "checkPrivileges", "(", "$", "path", ",", "'{DAV:}read'", ")", ";", "break", ";", "case", "'PUT'", ":", "case", "'LOCK'", ":", "// This method requires the write-content priv if the node", "// already exists, and bind on the parent if the node is being", "// created.", "// The bind privilege is handled in the beforeBind event.", "$", "this", "->", "checkPrivileges", "(", "$", "path", ",", "'{DAV:}write-content'", ")", ";", "break", ";", "case", "'UNLOCK'", ":", "// Unlock is always allowed at the moment.", "break", ";", "case", "'PROPPATCH'", ":", "$", "this", "->", "checkPrivileges", "(", "$", "path", ",", "'{DAV:}write-properties'", ")", ";", "break", ";", "case", "'ACL'", ":", "$", "this", "->", "checkPrivileges", "(", "$", "path", ",", "'{DAV:}write-acl'", ")", ";", "break", ";", "case", "'COPY'", ":", "case", "'MOVE'", ":", "// Copy requires read privileges on the entire source tree.", "// If the target exists write-content normally needs to be", "// checked, however, we're deleting the node beforehand and", "// creating a new one after, so this is handled by the", "// beforeUnbind event.", "//", "// The creation of the new node is handled by the beforeBind", "// event.", "//", "// If MOVE is used beforeUnbind will also be used to check if", "// the sourcenode can be deleted.", "$", "this", "->", "checkPrivileges", "(", "$", "path", ",", "'{DAV:}read'", ",", "self", "::", "R_RECURSIVE", ")", ";", "break", ";", "}", "}" ]
Triggered before any method is handled. @param RequestInterface $request @param ResponseInterface $response
[ "Triggered", "before", "any", "method", "is", "handled", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L836-L893
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.beforeBind
public function beforeBind($uri) { list($parentUri) = Uri\split($uri); $this->checkPrivileges($parentUri, '{DAV:}bind'); }
php
public function beforeBind($uri) { list($parentUri) = Uri\split($uri); $this->checkPrivileges($parentUri, '{DAV:}bind'); }
[ "public", "function", "beforeBind", "(", "$", "uri", ")", "{", "list", "(", "$", "parentUri", ")", "=", "Uri", "\\", "split", "(", "$", "uri", ")", ";", "$", "this", "->", "checkPrivileges", "(", "$", "parentUri", ",", "'{DAV:}bind'", ")", ";", "}" ]
Triggered before a new node is created. This allows us to check permissions for any operation that creates a new node, such as PUT, MKCOL, MKCALENDAR, LOCK, COPY and MOVE. @param string $uri
[ "Triggered", "before", "a", "new", "node", "is", "created", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L903-L907
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.beforeUnbind
public function beforeUnbind($uri) { list($parentUri) = Uri\split($uri); $this->checkPrivileges($parentUri, '{DAV:}unbind', self::R_RECURSIVEPARENTS); }
php
public function beforeUnbind($uri) { list($parentUri) = Uri\split($uri); $this->checkPrivileges($parentUri, '{DAV:}unbind', self::R_RECURSIVEPARENTS); }
[ "public", "function", "beforeUnbind", "(", "$", "uri", ")", "{", "list", "(", "$", "parentUri", ")", "=", "Uri", "\\", "split", "(", "$", "uri", ")", ";", "$", "this", "->", "checkPrivileges", "(", "$", "parentUri", ",", "'{DAV:}unbind'", ",", "self", "::", "R_RECURSIVEPARENTS", ")", ";", "}" ]
Triggered before a node is deleted. This allows us to check permissions for any operation that will delete an existing node. @param string $uri
[ "Triggered", "before", "a", "node", "is", "deleted", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L917-L921
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.propFind
public function propFind(DAV\PropFind $propFind, DAV\INode $node) { $path = $propFind->getPath(); // Checking the read permission if (!$this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false)) { // User is not allowed to read properties // Returning false causes the property-fetching system to pretend // that the node does not exist, and will cause it to be hidden // from listings such as PROPFIND or the browser plugin. if ($this->hideNodesFromListings) { return false; } // Otherwise we simply mark every property as 403. foreach ($propFind->getRequestedProperties() as $requestedProperty) { $propFind->set($requestedProperty, null, 403); } return; } /* Adding principal properties */ if ($node instanceof IPrincipal) { $propFind->handle('{DAV:}alternate-URI-set', function () use ($node) { return new Href($node->getAlternateUriSet()); }); $propFind->handle('{DAV:}principal-URL', function () use ($node) { return new Href($node->getPrincipalUrl().'/'); }); $propFind->handle('{DAV:}group-member-set', function () use ($node) { $members = $node->getGroupMemberSet(); foreach ($members as $k => $member) { $members[$k] = rtrim($member, '/').'/'; } return new Href($members); }); $propFind->handle('{DAV:}group-membership', function () use ($node) { $members = $node->getGroupMembership(); foreach ($members as $k => $member) { $members[$k] = rtrim($member, '/').'/'; } return new Href($members); }); $propFind->handle('{DAV:}displayname', [$node, 'getDisplayName']); } $propFind->handle('{DAV:}principal-collection-set', function () { $val = $this->principalCollectionSet; // Ensuring all collections end with a slash foreach ($val as $k => $v) { $val[$k] = $v.'/'; } return new Href($val); }); $propFind->handle('{DAV:}current-user-principal', function () { if ($url = $this->getCurrentUserPrincipal()) { return new Xml\Property\Principal(Xml\Property\Principal::HREF, $url.'/'); } else { return new Xml\Property\Principal(Xml\Property\Principal::UNAUTHENTICATED); } }); $propFind->handle('{DAV:}supported-privilege-set', function () use ($node) { return new Xml\Property\SupportedPrivilegeSet($this->getSupportedPrivilegeSet($node)); }); $propFind->handle('{DAV:}current-user-privilege-set', function () use ($node, $propFind, $path) { if (!$this->checkPrivileges($path, '{DAV:}read-current-user-privilege-set', self::R_PARENT, false)) { $propFind->set('{DAV:}current-user-privilege-set', null, 403); } else { $val = $this->getCurrentUserPrivilegeSet($node); return new Xml\Property\CurrentUserPrivilegeSet($val); } }); $propFind->handle('{DAV:}acl', function () use ($node, $propFind, $path) { /* The ACL property contains all the permissions */ if (!$this->checkPrivileges($path, '{DAV:}read-acl', self::R_PARENT, false)) { $propFind->set('{DAV:}acl', null, 403); } else { $acl = $this->getACL($node); return new Xml\Property\Acl($this->getACL($node)); } }); $propFind->handle('{DAV:}acl-restrictions', function () { return new Xml\Property\AclRestrictions(); }); /* Adding ACL properties */ if ($node instanceof IACL) { $propFind->handle('{DAV:}owner', function () use ($node) { return new Href($node->getOwner().'/'); }); } }
php
public function propFind(DAV\PropFind $propFind, DAV\INode $node) { $path = $propFind->getPath(); if (!$this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false)) { if ($this->hideNodesFromListings) { return false; } foreach ($propFind->getRequestedProperties() as $requestedProperty) { $propFind->set($requestedProperty, null, 403); } return; } if ($node instanceof IPrincipal) { $propFind->handle('{DAV:}alternate-URI-set', function () use ($node) { return new Href($node->getAlternateUriSet()); }); $propFind->handle('{DAV:}principal-URL', function () use ($node) { return new Href($node->getPrincipalUrl().'/'); }); $propFind->handle('{DAV:}group-member-set', function () use ($node) { $members = $node->getGroupMemberSet(); foreach ($members as $k => $member) { $members[$k] = rtrim($member, '/').'/'; } return new Href($members); }); $propFind->handle('{DAV:}group-membership', function () use ($node) { $members = $node->getGroupMembership(); foreach ($members as $k => $member) { $members[$k] = rtrim($member, '/').'/'; } return new Href($members); }); $propFind->handle('{DAV:}displayname', [$node, 'getDisplayName']); } $propFind->handle('{DAV:}principal-collection-set', function () { $val = $this->principalCollectionSet; foreach ($val as $k => $v) { $val[$k] = $v.'/'; } return new Href($val); }); $propFind->handle('{DAV:}current-user-principal', function () { if ($url = $this->getCurrentUserPrincipal()) { return new Xml\Property\Principal(Xml\Property\Principal::HREF, $url.'/'); } else { return new Xml\Property\Principal(Xml\Property\Principal::UNAUTHENTICATED); } }); $propFind->handle('{DAV:}supported-privilege-set', function () use ($node) { return new Xml\Property\SupportedPrivilegeSet($this->getSupportedPrivilegeSet($node)); }); $propFind->handle('{DAV:}current-user-privilege-set', function () use ($node, $propFind, $path) { if (!$this->checkPrivileges($path, '{DAV:}read-current-user-privilege-set', self::R_PARENT, false)) { $propFind->set('{DAV:}current-user-privilege-set', null, 403); } else { $val = $this->getCurrentUserPrivilegeSet($node); return new Xml\Property\CurrentUserPrivilegeSet($val); } }); $propFind->handle('{DAV:}acl', function () use ($node, $propFind, $path) { if (!$this->checkPrivileges($path, '{DAV:}read-acl', self::R_PARENT, false)) { $propFind->set('{DAV:}acl', null, 403); } else { $acl = $this->getACL($node); return new Xml\Property\Acl($this->getACL($node)); } }); $propFind->handle('{DAV:}acl-restrictions', function () { return new Xml\Property\AclRestrictions(); }); if ($node instanceof IACL) { $propFind->handle('{DAV:}owner', function () use ($node) { return new Href($node->getOwner().'/'); }); } }
[ "public", "function", "propFind", "(", "DAV", "\\", "PropFind", "$", "propFind", ",", "DAV", "\\", "INode", "$", "node", ")", "{", "$", "path", "=", "$", "propFind", "->", "getPath", "(", ")", ";", "// Checking the read permission", "if", "(", "!", "$", "this", "->", "checkPrivileges", "(", "$", "path", ",", "'{DAV:}read'", ",", "self", "::", "R_PARENT", ",", "false", ")", ")", "{", "// User is not allowed to read properties", "// Returning false causes the property-fetching system to pretend", "// that the node does not exist, and will cause it to be hidden", "// from listings such as PROPFIND or the browser plugin.", "if", "(", "$", "this", "->", "hideNodesFromListings", ")", "{", "return", "false", ";", "}", "// Otherwise we simply mark every property as 403.", "foreach", "(", "$", "propFind", "->", "getRequestedProperties", "(", ")", "as", "$", "requestedProperty", ")", "{", "$", "propFind", "->", "set", "(", "$", "requestedProperty", ",", "null", ",", "403", ")", ";", "}", "return", ";", "}", "/* Adding principal properties */", "if", "(", "$", "node", "instanceof", "IPrincipal", ")", "{", "$", "propFind", "->", "handle", "(", "'{DAV:}alternate-URI-set'", ",", "function", "(", ")", "use", "(", "$", "node", ")", "{", "return", "new", "Href", "(", "$", "node", "->", "getAlternateUriSet", "(", ")", ")", ";", "}", ")", ";", "$", "propFind", "->", "handle", "(", "'{DAV:}principal-URL'", ",", "function", "(", ")", "use", "(", "$", "node", ")", "{", "return", "new", "Href", "(", "$", "node", "->", "getPrincipalUrl", "(", ")", ".", "'/'", ")", ";", "}", ")", ";", "$", "propFind", "->", "handle", "(", "'{DAV:}group-member-set'", ",", "function", "(", ")", "use", "(", "$", "node", ")", "{", "$", "members", "=", "$", "node", "->", "getGroupMemberSet", "(", ")", ";", "foreach", "(", "$", "members", "as", "$", "k", "=>", "$", "member", ")", "{", "$", "members", "[", "$", "k", "]", "=", "rtrim", "(", "$", "member", ",", "'/'", ")", ".", "'/'", ";", "}", "return", "new", "Href", "(", "$", "members", ")", ";", "}", ")", ";", "$", "propFind", "->", "handle", "(", "'{DAV:}group-membership'", ",", "function", "(", ")", "use", "(", "$", "node", ")", "{", "$", "members", "=", "$", "node", "->", "getGroupMembership", "(", ")", ";", "foreach", "(", "$", "members", "as", "$", "k", "=>", "$", "member", ")", "{", "$", "members", "[", "$", "k", "]", "=", "rtrim", "(", "$", "member", ",", "'/'", ")", ".", "'/'", ";", "}", "return", "new", "Href", "(", "$", "members", ")", ";", "}", ")", ";", "$", "propFind", "->", "handle", "(", "'{DAV:}displayname'", ",", "[", "$", "node", ",", "'getDisplayName'", "]", ")", ";", "}", "$", "propFind", "->", "handle", "(", "'{DAV:}principal-collection-set'", ",", "function", "(", ")", "{", "$", "val", "=", "$", "this", "->", "principalCollectionSet", ";", "// Ensuring all collections end with a slash", "foreach", "(", "$", "val", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "val", "[", "$", "k", "]", "=", "$", "v", ".", "'/'", ";", "}", "return", "new", "Href", "(", "$", "val", ")", ";", "}", ")", ";", "$", "propFind", "->", "handle", "(", "'{DAV:}current-user-principal'", ",", "function", "(", ")", "{", "if", "(", "$", "url", "=", "$", "this", "->", "getCurrentUserPrincipal", "(", ")", ")", "{", "return", "new", "Xml", "\\", "Property", "\\", "Principal", "(", "Xml", "\\", "Property", "\\", "Principal", "::", "HREF", ",", "$", "url", ".", "'/'", ")", ";", "}", "else", "{", "return", "new", "Xml", "\\", "Property", "\\", "Principal", "(", "Xml", "\\", "Property", "\\", "Principal", "::", "UNAUTHENTICATED", ")", ";", "}", "}", ")", ";", "$", "propFind", "->", "handle", "(", "'{DAV:}supported-privilege-set'", ",", "function", "(", ")", "use", "(", "$", "node", ")", "{", "return", "new", "Xml", "\\", "Property", "\\", "SupportedPrivilegeSet", "(", "$", "this", "->", "getSupportedPrivilegeSet", "(", "$", "node", ")", ")", ";", "}", ")", ";", "$", "propFind", "->", "handle", "(", "'{DAV:}current-user-privilege-set'", ",", "function", "(", ")", "use", "(", "$", "node", ",", "$", "propFind", ",", "$", "path", ")", "{", "if", "(", "!", "$", "this", "->", "checkPrivileges", "(", "$", "path", ",", "'{DAV:}read-current-user-privilege-set'", ",", "self", "::", "R_PARENT", ",", "false", ")", ")", "{", "$", "propFind", "->", "set", "(", "'{DAV:}current-user-privilege-set'", ",", "null", ",", "403", ")", ";", "}", "else", "{", "$", "val", "=", "$", "this", "->", "getCurrentUserPrivilegeSet", "(", "$", "node", ")", ";", "return", "new", "Xml", "\\", "Property", "\\", "CurrentUserPrivilegeSet", "(", "$", "val", ")", ";", "}", "}", ")", ";", "$", "propFind", "->", "handle", "(", "'{DAV:}acl'", ",", "function", "(", ")", "use", "(", "$", "node", ",", "$", "propFind", ",", "$", "path", ")", "{", "/* The ACL property contains all the permissions */", "if", "(", "!", "$", "this", "->", "checkPrivileges", "(", "$", "path", ",", "'{DAV:}read-acl'", ",", "self", "::", "R_PARENT", ",", "false", ")", ")", "{", "$", "propFind", "->", "set", "(", "'{DAV:}acl'", ",", "null", ",", "403", ")", ";", "}", "else", "{", "$", "acl", "=", "$", "this", "->", "getACL", "(", "$", "node", ")", ";", "return", "new", "Xml", "\\", "Property", "\\", "Acl", "(", "$", "this", "->", "getACL", "(", "$", "node", ")", ")", ";", "}", "}", ")", ";", "$", "propFind", "->", "handle", "(", "'{DAV:}acl-restrictions'", ",", "function", "(", ")", "{", "return", "new", "Xml", "\\", "Property", "\\", "AclRestrictions", "(", ")", ";", "}", ")", ";", "/* Adding ACL properties */", "if", "(", "$", "node", "instanceof", "IACL", ")", "{", "$", "propFind", "->", "handle", "(", "'{DAV:}owner'", ",", "function", "(", ")", "use", "(", "$", "node", ")", "{", "return", "new", "Href", "(", "$", "node", "->", "getOwner", "(", ")", ".", "'/'", ")", ";", "}", ")", ";", "}", "}" ]
Triggered before properties are looked up in specific nodes. @param DAV\PropFind $propFind @param DAV\INode $node @TODO really should be broken into multiple methods, or even a class. @return bool
[ "Triggered", "before", "properties", "are", "looked", "up", "in", "specific", "nodes", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L943-L1041
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.propPatch
public function propPatch($path, DAV\PropPatch $propPatch) { $propPatch->handle('{DAV:}group-member-set', function ($value) use ($path) { if (is_null($value)) { $memberSet = []; } elseif ($value instanceof Href) { $memberSet = array_map( [$this->server, 'calculateUri'], $value->getHrefs() ); } else { throw new DAV\Exception('The group-member-set property MUST be an instance of Sabre\DAV\Property\HrefList or null'); } $node = $this->server->tree->getNodeForPath($path); if (!($node instanceof IPrincipal)) { // Fail return false; } $node->setGroupMemberSet($memberSet); // We must also clear our cache, just in case $this->principalMembershipCache = []; return true; }); }
php
public function propPatch($path, DAV\PropPatch $propPatch) { $propPatch->handle('{DAV:}group-member-set', function ($value) use ($path) { if (is_null($value)) { $memberSet = []; } elseif ($value instanceof Href) { $memberSet = array_map( [$this->server, 'calculateUri'], $value->getHrefs() ); } else { throw new DAV\Exception('The group-member-set property MUST be an instance of Sabre\DAV\Property\HrefList or null'); } $node = $this->server->tree->getNodeForPath($path); if (!($node instanceof IPrincipal)) { return false; } $node->setGroupMemberSet($memberSet); $this->principalMembershipCache = []; return true; }); }
[ "public", "function", "propPatch", "(", "$", "path", ",", "DAV", "\\", "PropPatch", "$", "propPatch", ")", "{", "$", "propPatch", "->", "handle", "(", "'{DAV:}group-member-set'", ",", "function", "(", "$", "value", ")", "use", "(", "$", "path", ")", "{", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "$", "memberSet", "=", "[", "]", ";", "}", "elseif", "(", "$", "value", "instanceof", "Href", ")", "{", "$", "memberSet", "=", "array_map", "(", "[", "$", "this", "->", "server", ",", "'calculateUri'", "]", ",", "$", "value", "->", "getHrefs", "(", ")", ")", ";", "}", "else", "{", "throw", "new", "DAV", "\\", "Exception", "(", "'The group-member-set property MUST be an instance of Sabre\\DAV\\Property\\HrefList or null'", ")", ";", "}", "$", "node", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "path", ")", ";", "if", "(", "!", "(", "$", "node", "instanceof", "IPrincipal", ")", ")", "{", "// Fail", "return", "false", ";", "}", "$", "node", "->", "setGroupMemberSet", "(", "$", "memberSet", ")", ";", "// We must also clear our cache, just in case", "$", "this", "->", "principalMembershipCache", "=", "[", "]", ";", "return", "true", ";", "}", ")", ";", "}" ]
This method intercepts PROPPATCH methods and make sure the group-member-set is updated correctly. @param string $path @param DAV\PropPatch $propPatch
[ "This", "method", "intercepts", "PROPPATCH", "methods", "and", "make", "sure", "the", "group", "-", "member", "-", "set", "is", "updated", "correctly", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L1050-L1076
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.report
public function report($reportName, $report, $path) { switch ($reportName) { case '{DAV:}principal-property-search': $this->server->transactionType = 'report-principal-property-search'; $this->principalPropertySearchReport($path, $report); return false; case '{DAV:}principal-search-property-set': $this->server->transactionType = 'report-principal-search-property-set'; $this->principalSearchPropertySetReport($path, $report); return false; case '{DAV:}expand-property': $this->server->transactionType = 'report-expand-property'; $this->expandPropertyReport($path, $report); return false; case '{DAV:}principal-match': $this->server->transactionType = 'report-principal-match'; $this->principalMatchReport($path, $report); return false; case '{DAV:}acl-principal-prop-set': $this->server->transactionType = 'acl-principal-prop-set'; $this->aclPrincipalPropSetReport($path, $report); return false; } }
php
public function report($reportName, $report, $path) { switch ($reportName) { case '{DAV:}principal-property-search': $this->server->transactionType = 'report-principal-property-search'; $this->principalPropertySearchReport($path, $report); return false; case '{DAV:}principal-search-property-set': $this->server->transactionType = 'report-principal-search-property-set'; $this->principalSearchPropertySetReport($path, $report); return false; case '{DAV:}expand-property': $this->server->transactionType = 'report-expand-property'; $this->expandPropertyReport($path, $report); return false; case '{DAV:}principal-match': $this->server->transactionType = 'report-principal-match'; $this->principalMatchReport($path, $report); return false; case '{DAV:}acl-principal-prop-set': $this->server->transactionType = 'acl-principal-prop-set'; $this->aclPrincipalPropSetReport($path, $report); return false; } }
[ "public", "function", "report", "(", "$", "reportName", ",", "$", "report", ",", "$", "path", ")", "{", "switch", "(", "$", "reportName", ")", "{", "case", "'{DAV:}principal-property-search'", ":", "$", "this", "->", "server", "->", "transactionType", "=", "'report-principal-property-search'", ";", "$", "this", "->", "principalPropertySearchReport", "(", "$", "path", ",", "$", "report", ")", ";", "return", "false", ";", "case", "'{DAV:}principal-search-property-set'", ":", "$", "this", "->", "server", "->", "transactionType", "=", "'report-principal-search-property-set'", ";", "$", "this", "->", "principalSearchPropertySetReport", "(", "$", "path", ",", "$", "report", ")", ";", "return", "false", ";", "case", "'{DAV:}expand-property'", ":", "$", "this", "->", "server", "->", "transactionType", "=", "'report-expand-property'", ";", "$", "this", "->", "expandPropertyReport", "(", "$", "path", ",", "$", "report", ")", ";", "return", "false", ";", "case", "'{DAV:}principal-match'", ":", "$", "this", "->", "server", "->", "transactionType", "=", "'report-principal-match'", ";", "$", "this", "->", "principalMatchReport", "(", "$", "path", ",", "$", "report", ")", ";", "return", "false", ";", "case", "'{DAV:}acl-principal-prop-set'", ":", "$", "this", "->", "server", "->", "transactionType", "=", "'acl-principal-prop-set'", ";", "$", "this", "->", "aclPrincipalPropSetReport", "(", "$", "path", ",", "$", "report", ")", ";", "return", "false", ";", "}", "}" ]
This method handles HTTP REPORT requests. @param string $reportName @param mixed $report @param mixed $path @return bool
[ "This", "method", "handles", "HTTP", "REPORT", "requests", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L1087-L1116
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.httpAcl
public function httpAcl(RequestInterface $request, ResponseInterface $response) { $path = $request->getPath(); $body = $request->getBodyAsString(); if (!$body) { throw new DAV\Exception\BadRequest('XML body expected in ACL request'); } $acl = $this->server->xml->expect('{DAV:}acl', $body); $newAcl = $acl->getPrivileges(); // Normalizing urls foreach ($newAcl as $k => $newAce) { $newAcl[$k]['principal'] = $this->server->calculateUri($newAce['principal']); } $node = $this->server->tree->getNodeForPath($path); if (!$node instanceof IACL) { throw new DAV\Exception\MethodNotAllowed('This node does not support the ACL method'); } $oldAcl = $this->getACL($node); $supportedPrivileges = $this->getFlatPrivilegeSet($node); /* Checking if protected principals from the existing principal set are not overwritten. */ foreach ($oldAcl as $oldAce) { if (!isset($oldAce['protected']) || !$oldAce['protected']) { continue; } $found = false; foreach ($newAcl as $newAce) { if ( $newAce['privilege'] === $oldAce['privilege'] && $newAce['principal'] === $oldAce['principal'] && $newAce['protected'] ) { $found = true; } } if (!$found) { throw new Exception\AceConflict('This resource contained a protected {DAV:}ace, but this privilege did not occur in the ACL request'); } } foreach ($newAcl as $newAce) { // Do we recognize the privilege if (!isset($supportedPrivileges[$newAce['privilege']])) { throw new Exception\NotSupportedPrivilege('The privilege you specified ('.$newAce['privilege'].') is not recognized by this server'); } if ($supportedPrivileges[$newAce['privilege']]['abstract']) { throw new Exception\NoAbstract('The privilege you specified ('.$newAce['privilege'].') is an abstract privilege'); } // Looking up the principal try { $principal = $this->server->tree->getNodeForPath($newAce['principal']); } catch (NotFound $e) { throw new Exception\NotRecognizedPrincipal('The specified principal ('.$newAce['principal'].') does not exist'); } if (!($principal instanceof IPrincipal)) { throw new Exception\NotRecognizedPrincipal('The specified uri ('.$newAce['principal'].') is not a principal'); } } $node->setACL($newAcl); $response->setStatus(200); // Breaking the event chain, because we handled this method. return false; }
php
public function httpAcl(RequestInterface $request, ResponseInterface $response) { $path = $request->getPath(); $body = $request->getBodyAsString(); if (!$body) { throw new DAV\Exception\BadRequest('XML body expected in ACL request'); } $acl = $this->server->xml->expect('{DAV:}acl', $body); $newAcl = $acl->getPrivileges(); foreach ($newAcl as $k => $newAce) { $newAcl[$k]['principal'] = $this->server->calculateUri($newAce['principal']); } $node = $this->server->tree->getNodeForPath($path); if (!$node instanceof IACL) { throw new DAV\Exception\MethodNotAllowed('This node does not support the ACL method'); } $oldAcl = $this->getACL($node); $supportedPrivileges = $this->getFlatPrivilegeSet($node); foreach ($oldAcl as $oldAce) { if (!isset($oldAce['protected']) || !$oldAce['protected']) { continue; } $found = false; foreach ($newAcl as $newAce) { if ( $newAce['privilege'] === $oldAce['privilege'] && $newAce['principal'] === $oldAce['principal'] && $newAce['protected'] ) { $found = true; } } if (!$found) { throw new Exception\AceConflict('This resource contained a protected {DAV:}ace, but this privilege did not occur in the ACL request'); } } foreach ($newAcl as $newAce) { if (!isset($supportedPrivileges[$newAce['privilege']])) { throw new Exception\NotSupportedPrivilege('The privilege you specified ('.$newAce['privilege'].') is not recognized by this server'); } if ($supportedPrivileges[$newAce['privilege']]['abstract']) { throw new Exception\NoAbstract('The privilege you specified ('.$newAce['privilege'].') is an abstract privilege'); } try { $principal = $this->server->tree->getNodeForPath($newAce['principal']); } catch (NotFound $e) { throw new Exception\NotRecognizedPrincipal('The specified principal ('.$newAce['principal'].') does not exist'); } if (!($principal instanceof IPrincipal)) { throw new Exception\NotRecognizedPrincipal('The specified uri ('.$newAce['principal'].') is not a principal'); } } $node->setACL($newAcl); $response->setStatus(200); return false; }
[ "public", "function", "httpAcl", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "path", "=", "$", "request", "->", "getPath", "(", ")", ";", "$", "body", "=", "$", "request", "->", "getBodyAsString", "(", ")", ";", "if", "(", "!", "$", "body", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "BadRequest", "(", "'XML body expected in ACL request'", ")", ";", "}", "$", "acl", "=", "$", "this", "->", "server", "->", "xml", "->", "expect", "(", "'{DAV:}acl'", ",", "$", "body", ")", ";", "$", "newAcl", "=", "$", "acl", "->", "getPrivileges", "(", ")", ";", "// Normalizing urls", "foreach", "(", "$", "newAcl", "as", "$", "k", "=>", "$", "newAce", ")", "{", "$", "newAcl", "[", "$", "k", "]", "[", "'principal'", "]", "=", "$", "this", "->", "server", "->", "calculateUri", "(", "$", "newAce", "[", "'principal'", "]", ")", ";", "}", "$", "node", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "path", ")", ";", "if", "(", "!", "$", "node", "instanceof", "IACL", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "MethodNotAllowed", "(", "'This node does not support the ACL method'", ")", ";", "}", "$", "oldAcl", "=", "$", "this", "->", "getACL", "(", "$", "node", ")", ";", "$", "supportedPrivileges", "=", "$", "this", "->", "getFlatPrivilegeSet", "(", "$", "node", ")", ";", "/* Checking if protected principals from the existing principal set are\n not overwritten. */", "foreach", "(", "$", "oldAcl", "as", "$", "oldAce", ")", "{", "if", "(", "!", "isset", "(", "$", "oldAce", "[", "'protected'", "]", ")", "||", "!", "$", "oldAce", "[", "'protected'", "]", ")", "{", "continue", ";", "}", "$", "found", "=", "false", ";", "foreach", "(", "$", "newAcl", "as", "$", "newAce", ")", "{", "if", "(", "$", "newAce", "[", "'privilege'", "]", "===", "$", "oldAce", "[", "'privilege'", "]", "&&", "$", "newAce", "[", "'principal'", "]", "===", "$", "oldAce", "[", "'principal'", "]", "&&", "$", "newAce", "[", "'protected'", "]", ")", "{", "$", "found", "=", "true", ";", "}", "}", "if", "(", "!", "$", "found", ")", "{", "throw", "new", "Exception", "\\", "AceConflict", "(", "'This resource contained a protected {DAV:}ace, but this privilege did not occur in the ACL request'", ")", ";", "}", "}", "foreach", "(", "$", "newAcl", "as", "$", "newAce", ")", "{", "// Do we recognize the privilege", "if", "(", "!", "isset", "(", "$", "supportedPrivileges", "[", "$", "newAce", "[", "'privilege'", "]", "]", ")", ")", "{", "throw", "new", "Exception", "\\", "NotSupportedPrivilege", "(", "'The privilege you specified ('", ".", "$", "newAce", "[", "'privilege'", "]", ".", "') is not recognized by this server'", ")", ";", "}", "if", "(", "$", "supportedPrivileges", "[", "$", "newAce", "[", "'privilege'", "]", "]", "[", "'abstract'", "]", ")", "{", "throw", "new", "Exception", "\\", "NoAbstract", "(", "'The privilege you specified ('", ".", "$", "newAce", "[", "'privilege'", "]", ".", "') is an abstract privilege'", ")", ";", "}", "// Looking up the principal", "try", "{", "$", "principal", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "newAce", "[", "'principal'", "]", ")", ";", "}", "catch", "(", "NotFound", "$", "e", ")", "{", "throw", "new", "Exception", "\\", "NotRecognizedPrincipal", "(", "'The specified principal ('", ".", "$", "newAce", "[", "'principal'", "]", ".", "') does not exist'", ")", ";", "}", "if", "(", "!", "(", "$", "principal", "instanceof", "IPrincipal", ")", ")", "{", "throw", "new", "Exception", "\\", "NotRecognizedPrincipal", "(", "'The specified uri ('", ".", "$", "newAce", "[", "'principal'", "]", ".", "') is not a principal'", ")", ";", "}", "}", "$", "node", "->", "setACL", "(", "$", "newAcl", ")", ";", "$", "response", "->", "setStatus", "(", "200", ")", ";", "// Breaking the event chain, because we handled this method.", "return", "false", ";", "}" ]
This method is responsible for handling the 'ACL' event. @param RequestInterface $request @param ResponseInterface $response @return bool
[ "This", "method", "is", "responsible", "for", "handling", "the", "ACL", "event", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L1126-L1201
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.principalMatchReport
protected function principalMatchReport($path, Xml\Request\PrincipalMatchReport $report) { $depth = $this->server->getHTTPDepth(0); if (0 !== $depth) { throw new BadRequest('The principal-match report is only defined on Depth: 0'); } $currentPrincipals = $this->getCurrentUserPrincipals(); $result = []; if (Xml\Request\PrincipalMatchReport::SELF === $report->type) { // Finding all principals under the request uri that match the // current principal. foreach ($currentPrincipals as $currentPrincipal) { if ($currentPrincipal === $path || 0 === strpos($currentPrincipal, $path.'/')) { $result[] = $currentPrincipal; } } } else { // We need to find all resources that have a property that matches // one of the current principals. $candidates = $this->server->getPropertiesForPath( $path, [$report->principalProperty], 1 ); foreach ($candidates as $candidate) { if (!isset($candidate[200][$report->principalProperty])) { continue; } $hrefs = $candidate[200][$report->principalProperty]; if (!$hrefs instanceof Href) { continue; } foreach ($hrefs->getHrefs() as $href) { if (in_array(trim($href, '/'), $currentPrincipals)) { $result[] = $candidate['href']; continue 2; } } } } $responses = []; foreach ($result as $item) { $properties = []; if ($report->properties) { $foo = $this->server->getPropertiesForPath($item, $report->properties); $foo = $foo[0]; $item = $foo['href']; unset($foo['href']); $properties = $foo; } $responses[] = new DAV\Xml\Element\Response( $item, $properties, '200' ); } $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); $this->server->httpResponse->setStatus(207); $this->server->httpResponse->setBody( $this->server->xml->write( '{DAV:}multistatus', $responses, $this->server->getBaseUri() ) ); }
php
protected function principalMatchReport($path, Xml\Request\PrincipalMatchReport $report) { $depth = $this->server->getHTTPDepth(0); if (0 !== $depth) { throw new BadRequest('The principal-match report is only defined on Depth: 0'); } $currentPrincipals = $this->getCurrentUserPrincipals(); $result = []; if (Xml\Request\PrincipalMatchReport::SELF === $report->type) { foreach ($currentPrincipals as $currentPrincipal) { if ($currentPrincipal === $path || 0 === strpos($currentPrincipal, $path.'/')) { $result[] = $currentPrincipal; } } } else { $candidates = $this->server->getPropertiesForPath( $path, [$report->principalProperty], 1 ); foreach ($candidates as $candidate) { if (!isset($candidate[200][$report->principalProperty])) { continue; } $hrefs = $candidate[200][$report->principalProperty]; if (!$hrefs instanceof Href) { continue; } foreach ($hrefs->getHrefs() as $href) { if (in_array(trim($href, '/'), $currentPrincipals)) { $result[] = $candidate['href']; continue 2; } } } } $responses = []; foreach ($result as $item) { $properties = []; if ($report->properties) { $foo = $this->server->getPropertiesForPath($item, $report->properties); $foo = $foo[0]; $item = $foo['href']; unset($foo['href']); $properties = $foo; } $responses[] = new DAV\Xml\Element\Response( $item, $properties, '200' ); } $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); $this->server->httpResponse->setStatus(207); $this->server->httpResponse->setBody( $this->server->xml->write( '{DAV:}multistatus', $responses, $this->server->getBaseUri() ) ); }
[ "protected", "function", "principalMatchReport", "(", "$", "path", ",", "Xml", "\\", "Request", "\\", "PrincipalMatchReport", "$", "report", ")", "{", "$", "depth", "=", "$", "this", "->", "server", "->", "getHTTPDepth", "(", "0", ")", ";", "if", "(", "0", "!==", "$", "depth", ")", "{", "throw", "new", "BadRequest", "(", "'The principal-match report is only defined on Depth: 0'", ")", ";", "}", "$", "currentPrincipals", "=", "$", "this", "->", "getCurrentUserPrincipals", "(", ")", ";", "$", "result", "=", "[", "]", ";", "if", "(", "Xml", "\\", "Request", "\\", "PrincipalMatchReport", "::", "SELF", "===", "$", "report", "->", "type", ")", "{", "// Finding all principals under the request uri that match the", "// current principal.", "foreach", "(", "$", "currentPrincipals", "as", "$", "currentPrincipal", ")", "{", "if", "(", "$", "currentPrincipal", "===", "$", "path", "||", "0", "===", "strpos", "(", "$", "currentPrincipal", ",", "$", "path", ".", "'/'", ")", ")", "{", "$", "result", "[", "]", "=", "$", "currentPrincipal", ";", "}", "}", "}", "else", "{", "// We need to find all resources that have a property that matches", "// one of the current principals.", "$", "candidates", "=", "$", "this", "->", "server", "->", "getPropertiesForPath", "(", "$", "path", ",", "[", "$", "report", "->", "principalProperty", "]", ",", "1", ")", ";", "foreach", "(", "$", "candidates", "as", "$", "candidate", ")", "{", "if", "(", "!", "isset", "(", "$", "candidate", "[", "200", "]", "[", "$", "report", "->", "principalProperty", "]", ")", ")", "{", "continue", ";", "}", "$", "hrefs", "=", "$", "candidate", "[", "200", "]", "[", "$", "report", "->", "principalProperty", "]", ";", "if", "(", "!", "$", "hrefs", "instanceof", "Href", ")", "{", "continue", ";", "}", "foreach", "(", "$", "hrefs", "->", "getHrefs", "(", ")", "as", "$", "href", ")", "{", "if", "(", "in_array", "(", "trim", "(", "$", "href", ",", "'/'", ")", ",", "$", "currentPrincipals", ")", ")", "{", "$", "result", "[", "]", "=", "$", "candidate", "[", "'href'", "]", ";", "continue", "2", ";", "}", "}", "}", "}", "$", "responses", "=", "[", "]", ";", "foreach", "(", "$", "result", "as", "$", "item", ")", "{", "$", "properties", "=", "[", "]", ";", "if", "(", "$", "report", "->", "properties", ")", "{", "$", "foo", "=", "$", "this", "->", "server", "->", "getPropertiesForPath", "(", "$", "item", ",", "$", "report", "->", "properties", ")", ";", "$", "foo", "=", "$", "foo", "[", "0", "]", ";", "$", "item", "=", "$", "foo", "[", "'href'", "]", ";", "unset", "(", "$", "foo", "[", "'href'", "]", ")", ";", "$", "properties", "=", "$", "foo", ";", "}", "$", "responses", "[", "]", "=", "new", "DAV", "\\", "Xml", "\\", "Element", "\\", "Response", "(", "$", "item", ",", "$", "properties", ",", "'200'", ")", ";", "}", "$", "this", "->", "server", "->", "httpResponse", "->", "setHeader", "(", "'Content-Type'", ",", "'application/xml; charset=utf-8'", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setStatus", "(", "207", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setBody", "(", "$", "this", "->", "server", "->", "xml", "->", "write", "(", "'{DAV:}multistatus'", ",", "$", "responses", ",", "$", "this", "->", "server", "->", "getBaseUri", "(", ")", ")", ")", ";", "}" ]
The principal-match report is defined in RFC3744, section 9.3. This report allows a client to figure out based on the current user, or a principal URL, the principal URL and principal URLs of groups that principal belongs to. @param string $path @param Xml\Request\PrincipalMatchReport $report
[ "The", "principal", "-", "match", "report", "is", "defined", "in", "RFC3744", "section", "9", ".", "3", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L1217-L1294
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.expandPropertyReport
protected function expandPropertyReport($path, $report) { $depth = $this->server->getHTTPDepth(0); $result = $this->expandProperties($path, $report->properties, $depth); $xml = $this->server->xml->write( '{DAV:}multistatus', new DAV\Xml\Response\MultiStatus($result), $this->server->getBaseUri() ); $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); $this->server->httpResponse->setStatus(207); $this->server->httpResponse->setBody($xml); }
php
protected function expandPropertyReport($path, $report) { $depth = $this->server->getHTTPDepth(0); $result = $this->expandProperties($path, $report->properties, $depth); $xml = $this->server->xml->write( '{DAV:}multistatus', new DAV\Xml\Response\MultiStatus($result), $this->server->getBaseUri() ); $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); $this->server->httpResponse->setStatus(207); $this->server->httpResponse->setBody($xml); }
[ "protected", "function", "expandPropertyReport", "(", "$", "path", ",", "$", "report", ")", "{", "$", "depth", "=", "$", "this", "->", "server", "->", "getHTTPDepth", "(", "0", ")", ";", "$", "result", "=", "$", "this", "->", "expandProperties", "(", "$", "path", ",", "$", "report", "->", "properties", ",", "$", "depth", ")", ";", "$", "xml", "=", "$", "this", "->", "server", "->", "xml", "->", "write", "(", "'{DAV:}multistatus'", ",", "new", "DAV", "\\", "Xml", "\\", "Response", "\\", "MultiStatus", "(", "$", "result", ")", ",", "$", "this", "->", "server", "->", "getBaseUri", "(", ")", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setHeader", "(", "'Content-Type'", ",", "'application/xml; charset=utf-8'", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setStatus", "(", "207", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setBody", "(", "$", "xml", ")", ";", "}" ]
The expand-property report is defined in RFC3253 section 3.8. This report is very similar to a standard PROPFIND. The difference is that it has the additional ability to look at properties containing a {DAV:}href element, follow that property and grab additional elements there. Other rfc's, such as ACL rely on this report, so it made sense to put it in this plugin. @param string $path @param Xml\Request\ExpandPropertyReport $report
[ "The", "expand", "-", "property", "report", "is", "defined", "in", "RFC3253", "section", "3", ".", "8", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L1310-L1324
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.expandProperties
protected function expandProperties($path, array $requestedProperties, $depth) { $foundProperties = $this->server->getPropertiesForPath($path, array_keys($requestedProperties), $depth); $result = []; foreach ($foundProperties as $node) { foreach ($requestedProperties as $propertyName => $childRequestedProperties) { // We're only traversing if sub-properties were requested if (!is_array($childRequestedProperties) || 0 === count($childRequestedProperties)) { continue; } // We only have to do the expansion if the property was found // and it contains an href element. if (!array_key_exists($propertyName, $node[200])) { continue; } if (!$node[200][$propertyName] instanceof DAV\Xml\Property\Href) { continue; } $childHrefs = $node[200][$propertyName]->getHrefs(); $childProps = []; foreach ($childHrefs as $href) { // Gathering the result of the children $childProps[] = [ 'name' => '{DAV:}response', 'value' => $this->expandProperties($href, $childRequestedProperties, 0)[0], ]; } // Replacing the property with its expanded form. $node[200][$propertyName] = $childProps; } $result[] = new DAV\Xml\Element\Response($node['href'], $node); } return $result; }
php
protected function expandProperties($path, array $requestedProperties, $depth) { $foundProperties = $this->server->getPropertiesForPath($path, array_keys($requestedProperties), $depth); $result = []; foreach ($foundProperties as $node) { foreach ($requestedProperties as $propertyName => $childRequestedProperties) { if (!is_array($childRequestedProperties) || 0 === count($childRequestedProperties)) { continue; } if (!array_key_exists($propertyName, $node[200])) { continue; } if (!$node[200][$propertyName] instanceof DAV\Xml\Property\Href) { continue; } $childHrefs = $node[200][$propertyName]->getHrefs(); $childProps = []; foreach ($childHrefs as $href) { $childProps[] = [ 'name' => '{DAV:}response', 'value' => $this->expandProperties($href, $childRequestedProperties, 0)[0], ]; } $node[200][$propertyName] = $childProps; } $result[] = new DAV\Xml\Element\Response($node['href'], $node); } return $result; }
[ "protected", "function", "expandProperties", "(", "$", "path", ",", "array", "$", "requestedProperties", ",", "$", "depth", ")", "{", "$", "foundProperties", "=", "$", "this", "->", "server", "->", "getPropertiesForPath", "(", "$", "path", ",", "array_keys", "(", "$", "requestedProperties", ")", ",", "$", "depth", ")", ";", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "foundProperties", "as", "$", "node", ")", "{", "foreach", "(", "$", "requestedProperties", "as", "$", "propertyName", "=>", "$", "childRequestedProperties", ")", "{", "// We're only traversing if sub-properties were requested", "if", "(", "!", "is_array", "(", "$", "childRequestedProperties", ")", "||", "0", "===", "count", "(", "$", "childRequestedProperties", ")", ")", "{", "continue", ";", "}", "// We only have to do the expansion if the property was found", "// and it contains an href element.", "if", "(", "!", "array_key_exists", "(", "$", "propertyName", ",", "$", "node", "[", "200", "]", ")", ")", "{", "continue", ";", "}", "if", "(", "!", "$", "node", "[", "200", "]", "[", "$", "propertyName", "]", "instanceof", "DAV", "\\", "Xml", "\\", "Property", "\\", "Href", ")", "{", "continue", ";", "}", "$", "childHrefs", "=", "$", "node", "[", "200", "]", "[", "$", "propertyName", "]", "->", "getHrefs", "(", ")", ";", "$", "childProps", "=", "[", "]", ";", "foreach", "(", "$", "childHrefs", "as", "$", "href", ")", "{", "// Gathering the result of the children", "$", "childProps", "[", "]", "=", "[", "'name'", "=>", "'{DAV:}response'", ",", "'value'", "=>", "$", "this", "->", "expandProperties", "(", "$", "href", ",", "$", "childRequestedProperties", ",", "0", ")", "[", "0", "]", ",", "]", ";", "}", "// Replacing the property with its expanded form.", "$", "node", "[", "200", "]", "[", "$", "propertyName", "]", "=", "$", "childProps", ";", "}", "$", "result", "[", "]", "=", "new", "DAV", "\\", "Xml", "\\", "Element", "\\", "Response", "(", "$", "node", "[", "'href'", "]", ",", "$", "node", ")", ";", "}", "return", "$", "result", ";", "}" ]
This method expands all the properties and returns a list with property values. @param array $path @param array $requestedProperties the list of required properties @param int $depth @return array
[ "This", "method", "expands", "all", "the", "properties", "and", "returns", "a", "list", "with", "property", "values", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L1336-L1377
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.principalSearchPropertySetReport
protected function principalSearchPropertySetReport($path, $report) { $httpDepth = $this->server->getHTTPDepth(0); if (0 !== $httpDepth) { throw new DAV\Exception\BadRequest('This report is only defined when Depth: 0'); } $writer = $this->server->xml->getWriter(); $writer->openMemory(); $writer->startDocument(); $writer->startElement('{DAV:}principal-search-property-set'); foreach ($this->principalSearchPropertySet as $propertyName => $description) { $writer->startElement('{DAV:}principal-search-property'); $writer->startElement('{DAV:}prop'); $writer->writeElement($propertyName); $writer->endElement(); // prop if ($description) { $writer->write([[ 'name' => '{DAV:}description', 'value' => $description, 'attributes' => ['xml:lang' => 'en'], ]]); } $writer->endElement(); // principal-search-property } $writer->endElement(); // principal-search-property-set $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); $this->server->httpResponse->setStatus(200); $this->server->httpResponse->setBody($writer->outputMemory()); }
php
protected function principalSearchPropertySetReport($path, $report) { $httpDepth = $this->server->getHTTPDepth(0); if (0 !== $httpDepth) { throw new DAV\Exception\BadRequest('This report is only defined when Depth: 0'); } $writer = $this->server->xml->getWriter(); $writer->openMemory(); $writer->startDocument(); $writer->startElement('{DAV:}principal-search-property-set'); foreach ($this->principalSearchPropertySet as $propertyName => $description) { $writer->startElement('{DAV:}principal-search-property'); $writer->startElement('{DAV:}prop'); $writer->writeElement($propertyName); $writer->endElement(); if ($description) { $writer->write([[ 'name' => '{DAV:}description', 'value' => $description, 'attributes' => ['xml:lang' => 'en'], ]]); } $writer->endElement(); } $writer->endElement(); $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); $this->server->httpResponse->setStatus(200); $this->server->httpResponse->setBody($writer->outputMemory()); }
[ "protected", "function", "principalSearchPropertySetReport", "(", "$", "path", ",", "$", "report", ")", "{", "$", "httpDepth", "=", "$", "this", "->", "server", "->", "getHTTPDepth", "(", "0", ")", ";", "if", "(", "0", "!==", "$", "httpDepth", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "BadRequest", "(", "'This report is only defined when Depth: 0'", ")", ";", "}", "$", "writer", "=", "$", "this", "->", "server", "->", "xml", "->", "getWriter", "(", ")", ";", "$", "writer", "->", "openMemory", "(", ")", ";", "$", "writer", "->", "startDocument", "(", ")", ";", "$", "writer", "->", "startElement", "(", "'{DAV:}principal-search-property-set'", ")", ";", "foreach", "(", "$", "this", "->", "principalSearchPropertySet", "as", "$", "propertyName", "=>", "$", "description", ")", "{", "$", "writer", "->", "startElement", "(", "'{DAV:}principal-search-property'", ")", ";", "$", "writer", "->", "startElement", "(", "'{DAV:}prop'", ")", ";", "$", "writer", "->", "writeElement", "(", "$", "propertyName", ")", ";", "$", "writer", "->", "endElement", "(", ")", ";", "// prop", "if", "(", "$", "description", ")", "{", "$", "writer", "->", "write", "(", "[", "[", "'name'", "=>", "'{DAV:}description'", ",", "'value'", "=>", "$", "description", ",", "'attributes'", "=>", "[", "'xml:lang'", "=>", "'en'", "]", ",", "]", "]", ")", ";", "}", "$", "writer", "->", "endElement", "(", ")", ";", "// principal-search-property", "}", "$", "writer", "->", "endElement", "(", ")", ";", "// principal-search-property-set", "$", "this", "->", "server", "->", "httpResponse", "->", "setHeader", "(", "'Content-Type'", ",", "'application/xml; charset=utf-8'", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setStatus", "(", "200", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setBody", "(", "$", "writer", "->", "outputMemory", "(", ")", ")", ";", "}" ]
principalSearchPropertySetReport. This method responsible for handing the {DAV:}principal-search-property-set report. This report returns a list of properties the client may search on, using the {DAV:}principal-property-search report. @param string $path @param Xml\Request\PrincipalSearchPropertySetReport $report
[ "principalSearchPropertySetReport", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L1390-L1427
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.principalPropertySearchReport
protected function principalPropertySearchReport($path, Xml\Request\PrincipalPropertySearchReport $report) { if ($report->applyToPrincipalCollectionSet) { $path = null; } if (0 !== $this->server->getHttpDepth('0')) { throw new BadRequest('Depth must be 0'); } $result = $this->principalSearch( $report->searchProperties, $report->properties, $path, $report->test ); $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
protected function principalPropertySearchReport($path, Xml\Request\PrincipalPropertySearchReport $report) { if ($report->applyToPrincipalCollectionSet) { $path = null; } if (0 !== $this->server->getHttpDepth('0')) { throw new BadRequest('Depth must be 0'); } $result = $this->principalSearch( $report->searchProperties, $report->properties, $path, $report->test ); $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'])); }
[ "protected", "function", "principalPropertySearchReport", "(", "$", "path", ",", "Xml", "\\", "Request", "\\", "PrincipalPropertySearchReport", "$", "report", ")", "{", "if", "(", "$", "report", "->", "applyToPrincipalCollectionSet", ")", "{", "$", "path", "=", "null", ";", "}", "if", "(", "0", "!==", "$", "this", "->", "server", "->", "getHttpDepth", "(", "'0'", ")", ")", "{", "throw", "new", "BadRequest", "(", "'Depth must be 0'", ")", ";", "}", "$", "result", "=", "$", "this", "->", "principalSearch", "(", "$", "report", "->", "searchProperties", ",", "$", "report", "->", "properties", ",", "$", "path", ",", "$", "report", "->", "test", ")", ";", "$", "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'", "]", ")", ")", ";", "}" ]
principalPropertySearchReport. This method is responsible for handing the {DAV:}principal-property-search report. This report can be used for clients to search for groups of principals, based on the value of one or more properties. @param string $path @param Xml\Request\PrincipalPropertySearchReport $report
[ "principalPropertySearchReport", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L1440-L1461
sabre-io/dav
lib/DAVACL/Plugin.php
Plugin.aclPrincipalPropSetReport
protected function aclPrincipalPropSetReport($path, Xml\Request\AclPrincipalPropSetReport $report) { if (0 !== $this->server->getHTTPDepth(0)) { throw new BadRequest('The {DAV:}acl-principal-prop-set REPORT only supports Depth 0'); } // Fetching ACL rules for the given path. We're using the property // API and not the local getACL, because it will ensure that all // business rules and restrictions are applied. $acl = $this->server->getProperties($path, '{DAV:}acl'); if (!$acl || !isset($acl['{DAV:}acl'])) { throw new Forbidden('Could not fetch ACL rules for this path'); } $principals = []; foreach ($acl['{DAV:}acl']->getPrivileges() as $ace) { if ('{' === $ace['principal'][0]) { // It's not a principal, it's one of the special rules such as {DAV:}authenticated continue; } $principals[] = $ace['principal']; } $properties = $this->server->getPropertiesForMultiplePaths( $principals, $report->properties ); $this->server->httpResponse->setStatus(207); $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); $this->server->httpResponse->setBody( $this->server->generateMultiStatus($properties) ); }
php
protected function aclPrincipalPropSetReport($path, Xml\Request\AclPrincipalPropSetReport $report) { if (0 !== $this->server->getHTTPDepth(0)) { throw new BadRequest('The {DAV:}acl-principal-prop-set REPORT only supports Depth 0'); } $acl = $this->server->getProperties($path, '{DAV:}acl'); if (!$acl || !isset($acl['{DAV:}acl'])) { throw new Forbidden('Could not fetch ACL rules for this path'); } $principals = []; foreach ($acl['{DAV:}acl']->getPrivileges() as $ace) { if ('{' === $ace['principal'][0]) { continue; } $principals[] = $ace['principal']; } $properties = $this->server->getPropertiesForMultiplePaths( $principals, $report->properties ); $this->server->httpResponse->setStatus(207); $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); $this->server->httpResponse->setBody( $this->server->generateMultiStatus($properties) ); }
[ "protected", "function", "aclPrincipalPropSetReport", "(", "$", "path", ",", "Xml", "\\", "Request", "\\", "AclPrincipalPropSetReport", "$", "report", ")", "{", "if", "(", "0", "!==", "$", "this", "->", "server", "->", "getHTTPDepth", "(", "0", ")", ")", "{", "throw", "new", "BadRequest", "(", "'The {DAV:}acl-principal-prop-set REPORT only supports Depth 0'", ")", ";", "}", "// Fetching ACL rules for the given path. We're using the property", "// API and not the local getACL, because it will ensure that all", "// business rules and restrictions are applied.", "$", "acl", "=", "$", "this", "->", "server", "->", "getProperties", "(", "$", "path", ",", "'{DAV:}acl'", ")", ";", "if", "(", "!", "$", "acl", "||", "!", "isset", "(", "$", "acl", "[", "'{DAV:}acl'", "]", ")", ")", "{", "throw", "new", "Forbidden", "(", "'Could not fetch ACL rules for this path'", ")", ";", "}", "$", "principals", "=", "[", "]", ";", "foreach", "(", "$", "acl", "[", "'{DAV:}acl'", "]", "->", "getPrivileges", "(", ")", "as", "$", "ace", ")", "{", "if", "(", "'{'", "===", "$", "ace", "[", "'principal'", "]", "[", "0", "]", ")", "{", "// It's not a principal, it's one of the special rules such as {DAV:}authenticated", "continue", ";", "}", "$", "principals", "[", "]", "=", "$", "ace", "[", "'principal'", "]", ";", "}", "$", "properties", "=", "$", "this", "->", "server", "->", "getPropertiesForMultiplePaths", "(", "$", "principals", ",", "$", "report", "->", "properties", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setStatus", "(", "207", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setHeader", "(", "'Content-Type'", ",", "'application/xml; charset=utf-8'", ")", ";", "$", "this", "->", "server", "->", "httpResponse", "->", "setBody", "(", "$", "this", "->", "server", "->", "generateMultiStatus", "(", "$", "properties", ")", ")", ";", "}" ]
aclPrincipalPropSet REPORT. This method is responsible for handling the {DAV:}acl-principal-prop-set REPORT, as defined in: https://tools.ietf.org/html/rfc3744#section-9.2 This REPORT allows a user to quickly fetch information about all principals specified in the access control list. Most commonly this is used to for example generate a UI with ACL rules, allowing you to show names for principals for every entry. @param string $path @param Xml\Request\AclPrincipalPropSetReport $report
[ "aclPrincipalPropSet", "REPORT", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Plugin.php#L1479-L1514
sabre-io/dav
lib/DAV/Exception/MethodNotAllowed.php
MethodNotAllowed.getHTTPHeaders
public function getHTTPHeaders(\Sabre\DAV\Server $server) { $methods = $server->getAllowedMethods($server->getRequestUri()); return [ 'Allow' => strtoupper(implode(', ', $methods)), ]; }
php
public function getHTTPHeaders(\Sabre\DAV\Server $server) { $methods = $server->getAllowedMethods($server->getRequestUri()); return [ 'Allow' => strtoupper(implode(', ', $methods)), ]; }
[ "public", "function", "getHTTPHeaders", "(", "\\", "Sabre", "\\", "DAV", "\\", "Server", "$", "server", ")", "{", "$", "methods", "=", "$", "server", "->", "getAllowedMethods", "(", "$", "server", "->", "getRequestUri", "(", ")", ")", ";", "return", "[", "'Allow'", "=>", "strtoupper", "(", "implode", "(", "', '", ",", "$", "methods", ")", ")", ",", "]", ";", "}" ]
This method allows the exception to return any extra HTTP response headers. The headers must be returned as an array. @param \Sabre\DAV\Server $server @return array
[ "This", "method", "allows", "the", "exception", "to", "return", "any", "extra", "HTTP", "response", "headers", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Exception/MethodNotAllowed.php#L39-L46
sabre-io/dav
lib/CalDAV/Subscriptions/Subscription.php
Subscription.getProperties
public function getProperties($properties) { $r = []; foreach ($properties as $prop) { switch ($prop) { case '{http://calendarserver.org/ns/}source': $r[$prop] = new Href($this->subscriptionInfo['source']); break; default: if (array_key_exists($prop, $this->subscriptionInfo)) { $r[$prop] = $this->subscriptionInfo[$prop]; } break; } } return $r; }
php
public function getProperties($properties) { $r = []; foreach ($properties as $prop) { switch ($prop) { case '{http: $r[$prop] = new Href($this->subscriptionInfo['source']); break; default: if (array_key_exists($prop, $this->subscriptionInfo)) { $r[$prop] = $this->subscriptionInfo[$prop]; } break; } } return $r; }
[ "public", "function", "getProperties", "(", "$", "properties", ")", "{", "$", "r", "=", "[", "]", ";", "foreach", "(", "$", "properties", "as", "$", "prop", ")", "{", "switch", "(", "$", "prop", ")", "{", "case", "'{http://calendarserver.org/ns/}source'", ":", "$", "r", "[", "$", "prop", "]", "=", "new", "Href", "(", "$", "this", "->", "subscriptionInfo", "[", "'source'", "]", ")", ";", "break", ";", "default", ":", "if", "(", "array_key_exists", "(", "$", "prop", ",", "$", "this", "->", "subscriptionInfo", ")", ")", "{", "$", "r", "[", "$", "prop", "]", "=", "$", "this", "->", "subscriptionInfo", "[", "$", "prop", "]", ";", "}", "break", ";", "}", "}", "return", "$", "r", ";", "}" ]
Returns a list of properties for this nodes. The properties list is a list of propertynames the client requested, encoded in clark-notation {xmlnamespace}tagname. If the array is empty, it means 'all properties' were requested. Note that it's fine to liberally give properties back, instead of conforming to the list of requested properties. The Server class will filter out the extra. @param array $properties @return array
[ "Returns", "a", "list", "of", "properties", "for", "this", "nodes", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Subscriptions/Subscription.php#L145-L163
sabre-io/dav
lib/CalDAV/Subscriptions/Subscription.php
Subscription.getACL
public function getACL() { return [ [ 'privilege' => '{DAV:}all', 'principal' => $this->getOwner(), 'protected' => true, ], [ 'privilege' => '{DAV:}all', 'principal' => $this->getOwner().'/calendar-proxy-write', 'protected' => true, ], [ 'privilege' => '{DAV:}read', 'principal' => $this->getOwner().'/calendar-proxy-read', 'protected' => true, ], ]; }
php
public function getACL() { return [ [ 'privilege' => '{DAV:}all', 'principal' => $this->getOwner(), 'protected' => true, ], [ 'privilege' => '{DAV:}all', 'principal' => $this->getOwner().'/calendar-proxy-write', 'protected' => true, ], [ 'privilege' => '{DAV:}read', 'principal' => $this->getOwner().'/calendar-proxy-read', 'protected' => true, ], ]; }
[ "public", "function", "getACL", "(", ")", "{", "return", "[", "[", "'privilege'", "=>", "'{DAV:}all'", ",", "'principal'", "=>", "$", "this", "->", "getOwner", "(", ")", ",", "'protected'", "=>", "true", ",", "]", ",", "[", "'privilege'", "=>", "'{DAV:}all'", ",", "'principal'", "=>", "$", "this", "->", "getOwner", "(", ")", ".", "'/calendar-proxy-write'", ",", "'protected'", "=>", "true", ",", "]", ",", "[", "'privilege'", "=>", "'{DAV:}read'", ",", "'principal'", "=>", "$", "this", "->", "getOwner", "(", ")", ".", "'/calendar-proxy-read'", ",", "'protected'", "=>", "true", ",", "]", ",", "]", ";", "}" ]
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/Subscriptions/Subscription.php#L189-L208
sabre-io/dav
lib/CalDAV/Xml/Notification/SystemStatus.php
SystemStatus.xmlSerialize
public function xmlSerialize(Writer $writer) { switch ($this->type) { case self::TYPE_LOW: $type = 'low'; break; case self::TYPE_MEDIUM: $type = 'medium'; break; default: case self::TYPE_HIGH: $type = 'high'; break; } $writer->startElement('{'.Plugin::NS_CALENDARSERVER.'}systemstatus'); $writer->writeAttribute('type', $type); $writer->endElement(); }
php
public function xmlSerialize(Writer $writer) { switch ($this->type) { case self::TYPE_LOW: $type = 'low'; break; case self::TYPE_MEDIUM: $type = 'medium'; break; default: case self::TYPE_HIGH: $type = 'high'; break; } $writer->startElement('{'.Plugin::NS_CALENDARSERVER.'}systemstatus'); $writer->writeAttribute('type', $type); $writer->endElement(); }
[ "public", "function", "xmlSerialize", "(", "Writer", "$", "writer", ")", "{", "switch", "(", "$", "this", "->", "type", ")", "{", "case", "self", "::", "TYPE_LOW", ":", "$", "type", "=", "'low'", ";", "break", ";", "case", "self", "::", "TYPE_MEDIUM", ":", "$", "type", "=", "'medium'", ";", "break", ";", "default", ":", "case", "self", "::", "TYPE_HIGH", ":", "$", "type", "=", "'high'", ";", "break", ";", "}", "$", "writer", "->", "startElement", "(", "'{'", ".", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}systemstatus'", ")", ";", "$", "writer", "->", "writeAttribute", "(", "'type'", ",", "$", "type", ")", ";", "$", "writer", "->", "endElement", "(", ")", ";", "}" ]
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/CalDAV/Xml/Notification/SystemStatus.php#L96-L114
sabre-io/dav
lib/CalDAV/Xml/Notification/SystemStatus.php
SystemStatus.xmlSerializeFull
public function xmlSerializeFull(Writer $writer) { $cs = '{'.Plugin::NS_CALENDARSERVER.'}'; switch ($this->type) { case self::TYPE_LOW: $type = 'low'; break; case self::TYPE_MEDIUM: $type = 'medium'; break; default: case self::TYPE_HIGH: $type = 'high'; break; } $writer->startElement($cs.'systemstatus'); $writer->writeAttribute('type', $type); if ($this->description) { $writer->writeElement($cs.'description', $this->description); } if ($this->href) { $writer->writeElement('{DAV:}href', $this->href); } $writer->endElement(); // systemstatus }
php
public function xmlSerializeFull(Writer $writer) { $cs = '{'.Plugin::NS_CALENDARSERVER.'}'; switch ($this->type) { case self::TYPE_LOW: $type = 'low'; break; case self::TYPE_MEDIUM: $type = 'medium'; break; default: case self::TYPE_HIGH: $type = 'high'; break; } $writer->startElement($cs.'systemstatus'); $writer->writeAttribute('type', $type); if ($this->description) { $writer->writeElement($cs.'description', $this->description); } if ($this->href) { $writer->writeElement('{DAV:}href', $this->href); } $writer->endElement(); }
[ "public", "function", "xmlSerializeFull", "(", "Writer", "$", "writer", ")", "{", "$", "cs", "=", "'{'", ".", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}'", ";", "switch", "(", "$", "this", "->", "type", ")", "{", "case", "self", "::", "TYPE_LOW", ":", "$", "type", "=", "'low'", ";", "break", ";", "case", "self", "::", "TYPE_MEDIUM", ":", "$", "type", "=", "'medium'", ";", "break", ";", "default", ":", "case", "self", "::", "TYPE_HIGH", ":", "$", "type", "=", "'high'", ";", "break", ";", "}", "$", "writer", "->", "startElement", "(", "$", "cs", ".", "'systemstatus'", ")", ";", "$", "writer", "->", "writeAttribute", "(", "'type'", ",", "$", "type", ")", ";", "if", "(", "$", "this", "->", "description", ")", "{", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'description'", ",", "$", "this", "->", "description", ")", ";", "}", "if", "(", "$", "this", "->", "href", ")", "{", "$", "writer", "->", "writeElement", "(", "'{DAV:}href'", ",", "$", "this", "->", "href", ")", ";", "}", "$", "writer", "->", "endElement", "(", ")", ";", "// systemstatus", "}" ]
This method serializes the entire notification, as it is used in the response body. @param Writer $writer
[ "This", "method", "serializes", "the", "entire", "notification", "as", "it", "is", "used", "in", "the", "response", "body", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Xml/Notification/SystemStatus.php#L122-L149
sabre-io/dav
lib/DAVACL/PrincipalCollection.php
PrincipalCollection.createExtendedCollection
public function createExtendedCollection($name, MkCol $mkCol) { if (!$mkCol->hasResourceType('{DAV:}principal')) { throw new InvalidResourceType('Only resources of type {DAV:}principal may be created here'); } $this->principalBackend->createPrincipal( $this->principalPrefix.'/'.$name, $mkCol ); }
php
public function createExtendedCollection($name, MkCol $mkCol) { if (!$mkCol->hasResourceType('{DAV:}principal')) { throw new InvalidResourceType('Only resources of type {DAV:}principal may be created here'); } $this->principalBackend->createPrincipal( $this->principalPrefix.'/'.$name, $mkCol ); }
[ "public", "function", "createExtendedCollection", "(", "$", "name", ",", "MkCol", "$", "mkCol", ")", "{", "if", "(", "!", "$", "mkCol", "->", "hasResourceType", "(", "'{DAV:}principal'", ")", ")", "{", "throw", "new", "InvalidResourceType", "(", "'Only resources of type {DAV:}principal may be created here'", ")", ";", "}", "$", "this", "->", "principalBackend", "->", "createPrincipal", "(", "$", "this", "->", "principalPrefix", ".", "'/'", ".", "$", "name", ",", "$", "mkCol", ")", ";", "}" ]
Creates a new collection. This method will receive a MkCol object with all the information about the new collection that's being created. The MkCol object contains information about the resourceType of the new collection. If you don't support the specified resourceType, you should throw Exception\InvalidResourceType. The object also contains a list of WebDAV properties for the new collection. You should call the handle() method on this object to specify exactly which properties you are storing. This allows the system to figure out exactly which properties you didn't store, which in turn allows other plugins (such as the propertystorage plugin) to handle storing the property for you. @param string $name @param MkCol $mkCol @throws InvalidResourceType
[ "Creates", "a", "new", "collection", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/PrincipalCollection.php#L65-L75
sabre-io/dav
lib/DAV/PropertyStorage/Plugin.php
Plugin.propFind
public function propFind(PropFind $propFind, INode $node) { $path = $propFind->getPath(); $pathFilter = $this->pathFilter; if ($pathFilter && !$pathFilter($path)) { return; } $this->backend->propFind($propFind->getPath(), $propFind); }
php
public function propFind(PropFind $propFind, INode $node) { $path = $propFind->getPath(); $pathFilter = $this->pathFilter; if ($pathFilter && !$pathFilter($path)) { return; } $this->backend->propFind($propFind->getPath(), $propFind); }
[ "public", "function", "propFind", "(", "PropFind", "$", "propFind", ",", "INode", "$", "node", ")", "{", "$", "path", "=", "$", "propFind", "->", "getPath", "(", ")", ";", "$", "pathFilter", "=", "$", "this", "->", "pathFilter", ";", "if", "(", "$", "pathFilter", "&&", "!", "$", "pathFilter", "(", "$", "path", ")", ")", "{", "return", ";", "}", "$", "this", "->", "backend", "->", "propFind", "(", "$", "propFind", "->", "getPath", "(", ")", ",", "$", "propFind", ")", ";", "}" ]
Called during PROPFIND operations. If there's any requested properties that don't have a value yet, this plugin will look in the property storage backend to find them. @param PropFind $propFind @param INode $node
[ "Called", "during", "PROPFIND", "operations", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PropertyStorage/Plugin.php#L84-L92
sabre-io/dav
lib/DAV/PropertyStorage/Plugin.php
Plugin.propPatch
public function propPatch($path, PropPatch $propPatch) { $pathFilter = $this->pathFilter; if ($pathFilter && !$pathFilter($path)) { return; } $this->backend->propPatch($path, $propPatch); }
php
public function propPatch($path, PropPatch $propPatch) { $pathFilter = $this->pathFilter; if ($pathFilter && !$pathFilter($path)) { return; } $this->backend->propPatch($path, $propPatch); }
[ "public", "function", "propPatch", "(", "$", "path", ",", "PropPatch", "$", "propPatch", ")", "{", "$", "pathFilter", "=", "$", "this", "->", "pathFilter", ";", "if", "(", "$", "pathFilter", "&&", "!", "$", "pathFilter", "(", "$", "path", ")", ")", "{", "return", ";", "}", "$", "this", "->", "backend", "->", "propPatch", "(", "$", "path", ",", "$", "propPatch", ")", ";", "}" ]
Called during PROPPATCH operations. If there's any updated properties that haven't been stored, the propertystorage backend can handle it. @param string $path @param PropPatch $propPatch
[ "Called", "during", "PROPPATCH", "operations", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PropertyStorage/Plugin.php#L103-L110
sabre-io/dav
lib/DAV/PropertyStorage/Plugin.php
Plugin.afterUnbind
public function afterUnbind($path) { $pathFilter = $this->pathFilter; if ($pathFilter && !$pathFilter($path)) { return; } $this->backend->delete($path); }
php
public function afterUnbind($path) { $pathFilter = $this->pathFilter; if ($pathFilter && !$pathFilter($path)) { return; } $this->backend->delete($path); }
[ "public", "function", "afterUnbind", "(", "$", "path", ")", "{", "$", "pathFilter", "=", "$", "this", "->", "pathFilter", ";", "if", "(", "$", "pathFilter", "&&", "!", "$", "pathFilter", "(", "$", "path", ")", ")", "{", "return", ";", "}", "$", "this", "->", "backend", "->", "delete", "(", "$", "path", ")", ";", "}" ]
Called after a node is deleted. This allows the backend to clean up any properties still in the database. @param string $path
[ "Called", "after", "a", "node", "is", "deleted", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PropertyStorage/Plugin.php#L120-L127
sabre-io/dav
lib/DAV/PropertyStorage/Plugin.php
Plugin.afterMove
public function afterMove($source, $destination) { $pathFilter = $this->pathFilter; if ($pathFilter && !$pathFilter($source)) { return; } // If the destination is filtered, afterUnbind will handle cleaning up // the properties. if ($pathFilter && !$pathFilter($destination)) { return; } $this->backend->move($source, $destination); }
php
public function afterMove($source, $destination) { $pathFilter = $this->pathFilter; if ($pathFilter && !$pathFilter($source)) { return; } if ($pathFilter && !$pathFilter($destination)) { return; } $this->backend->move($source, $destination); }
[ "public", "function", "afterMove", "(", "$", "source", ",", "$", "destination", ")", "{", "$", "pathFilter", "=", "$", "this", "->", "pathFilter", ";", "if", "(", "$", "pathFilter", "&&", "!", "$", "pathFilter", "(", "$", "source", ")", ")", "{", "return", ";", "}", "// If the destination is filtered, afterUnbind will handle cleaning up", "// the properties.", "if", "(", "$", "pathFilter", "&&", "!", "$", "pathFilter", "(", "$", "destination", ")", ")", "{", "return", ";", "}", "$", "this", "->", "backend", "->", "move", "(", "$", "source", ",", "$", "destination", ")", ";", "}" ]
Called after a node is moved. This allows the backend to move all the associated properties. @param string $source @param string $destination
[ "Called", "after", "a", "node", "is", "moved", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PropertyStorage/Plugin.php#L137-L150
sabre-io/dav
lib/DAV/Auth/Backend/AbstractBearer.php
AbstractBearer.check
public function check(RequestInterface $request, ResponseInterface $response) { $auth = new HTTP\Auth\Bearer( $this->realm, $request, $response ); $bearerToken = $auth->getToken($request); if (!$bearerToken) { return [false, "No 'Authorization: Bearer' header found. Either the client didn't send one, or the server is mis-configured"]; } $principalUrl = $this->validateBearerToken($bearerToken); if (!$principalUrl) { return [false, 'Bearer token was incorrect']; } return [true, $principalUrl]; }
php
public function check(RequestInterface $request, ResponseInterface $response) { $auth = new HTTP\Auth\Bearer( $this->realm, $request, $response ); $bearerToken = $auth->getToken($request); if (!$bearerToken) { return [false, "No 'Authorization: Bearer' header found. Either the client didn't send one, or the server is mis-configured"]; } $principalUrl = $this->validateBearerToken($bearerToken); if (!$principalUrl) { return [false, 'Bearer token was incorrect']; } return [true, $principalUrl]; }
[ "public", "function", "check", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "auth", "=", "new", "HTTP", "\\", "Auth", "\\", "Bearer", "(", "$", "this", "->", "realm", ",", "$", "request", ",", "$", "response", ")", ";", "$", "bearerToken", "=", "$", "auth", "->", "getToken", "(", "$", "request", ")", ";", "if", "(", "!", "$", "bearerToken", ")", "{", "return", "[", "false", ",", "\"No 'Authorization: Bearer' header found. Either the client didn't send one, or the server is mis-configured\"", "]", ";", "}", "$", "principalUrl", "=", "$", "this", "->", "validateBearerToken", "(", "$", "bearerToken", ")", ";", "if", "(", "!", "$", "principalUrl", ")", "{", "return", "[", "false", ",", "'Bearer token was incorrect'", "]", ";", "}", "return", "[", "true", ",", "$", "principalUrl", "]", ";", "}" ]
When this method is called, the backend must check if authentication was successful. The returned value must be one of the following [true, "principals/username"] [false, "reason for failure"] If authentication was successful, it's expected that the authentication backend returns a so-called principal url. Examples of a principal url: principals/admin principals/user1 principals/users/joe principals/uid/123457 If you don't use WebDAV ACL (RFC3744) we recommend that you simply return a string such as: principals/users/[username] @param RequestInterface $request @param ResponseInterface $response @return array
[ "When", "this", "method", "is", "called", "the", "backend", "must", "check", "if", "authentication", "was", "successful", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Auth/Backend/AbstractBearer.php#L87-L105
sabre-io/dav
lib/DAVACL/Xml/Property/CurrentUserPrivilegeSet.php
CurrentUserPrivilegeSet.xmlSerialize
public function xmlSerialize(Writer $writer) { foreach ($this->privileges as $privName) { $writer->startElement('{DAV:}privilege'); $writer->writeElement($privName); $writer->endElement(); } }
php
public function xmlSerialize(Writer $writer) { foreach ($this->privileges as $privName) { $writer->startElement('{DAV:}privilege'); $writer->writeElement($privName); $writer->endElement(); } }
[ "public", "function", "xmlSerialize", "(", "Writer", "$", "writer", ")", "{", "foreach", "(", "$", "this", "->", "privileges", "as", "$", "privName", ")", "{", "$", "writer", "->", "startElement", "(", "'{DAV:}privilege'", ")", ";", "$", "writer", "->", "writeElement", "(", "$", "privName", ")", ";", "$", "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/DAVACL/Xml/Property/CurrentUserPrivilegeSet.php#L62-L69
sabre-io/dav
lib/DAVACL/Xml/Property/CurrentUserPrivilegeSet.php
CurrentUserPrivilegeSet.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { $result = []; $tree = $reader->parseInnerTree(['{DAV:}privilege' => 'Sabre\\Xml\\Element\\Elements']); foreach ($tree as $element) { if ('{DAV:}privilege' !== $element['name']) { continue; } $result[] = $element['value'][0]; } return new self($result); }
php
public static function xmlDeserialize(Reader $reader) { $result = []; $tree = $reader->parseInnerTree(['{DAV:}privilege' => 'Sabre\\Xml\\Element\\Elements']); foreach ($tree as $element) { if ('{DAV:}privilege' !== $element['name']) { continue; } $result[] = $element['value'][0]; } return new self($result); }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "$", "result", "=", "[", "]", ";", "$", "tree", "=", "$", "reader", "->", "parseInnerTree", "(", "[", "'{DAV:}privilege'", "=>", "'Sabre\\\\Xml\\\\Element\\\\Elements'", "]", ")", ";", "foreach", "(", "$", "tree", "as", "$", "element", ")", "{", "if", "(", "'{DAV:}privilege'", "!==", "$", "element", "[", "'name'", "]", ")", "{", "continue", ";", "}", "$", "result", "[", "]", "=", "$", "element", "[", "'value'", "]", "[", "0", "]", ";", "}", "return", "new", "self", "(", "$", "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/DAVACL/Xml/Property/CurrentUserPrivilegeSet.php#L116-L129
sabre-io/dav
lib/DAV/Xml/Response/MultiStatus.php
MultiStatus.xmlSerialize
public function xmlSerialize(Writer $writer) { foreach ($this->getResponses() as $response) { $writer->writeElement('{DAV:}response', $response); } if ($syncToken = $this->getSyncToken()) { $writer->writeElement('{DAV:}sync-token', $syncToken); } }
php
public function xmlSerialize(Writer $writer) { foreach ($this->getResponses() as $response) { $writer->writeElement('{DAV:}response', $response); } if ($syncToken = $this->getSyncToken()) { $writer->writeElement('{DAV:}sync-token', $syncToken); } }
[ "public", "function", "xmlSerialize", "(", "Writer", "$", "writer", ")", "{", "foreach", "(", "$", "this", "->", "getResponses", "(", ")", "as", "$", "response", ")", "{", "$", "writer", "->", "writeElement", "(", "'{DAV:}response'", ",", "$", "response", ")", ";", "}", "if", "(", "$", "syncToken", "=", "$", "this", "->", "getSyncToken", "(", ")", ")", "{", "$", "writer", "->", "writeElement", "(", "'{DAV:}sync-token'", ",", "$", "syncToken", ")", ";", "}", "}" ]
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/Response/MultiStatus.php#L86-L94
sabre-io/dav
lib/DAV/Xml/Response/MultiStatus.php
MultiStatus.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { $elementMap = $reader->elementMap; $elementMap['{DAV:}prop'] = 'Sabre\\DAV\\Xml\\Element\\Prop'; $elements = $reader->parseInnerTree($elementMap); $responses = []; $syncToken = null; if ($elements) { foreach ($elements as $elem) { if ('{DAV:}response' === $elem['name']) { $responses[] = $elem['value']; } if ('{DAV:}sync-token' === $elem['name']) { $syncToken = $elem['value']; } } } return new self($responses, $syncToken); }
php
public static function xmlDeserialize(Reader $reader) { $elementMap = $reader->elementMap; $elementMap['{DAV:}prop'] = 'Sabre\\DAV\\Xml\\Element\\Prop'; $elements = $reader->parseInnerTree($elementMap); $responses = []; $syncToken = null; if ($elements) { foreach ($elements as $elem) { if ('{DAV:}response' === $elem['name']) { $responses[] = $elem['value']; } if ('{DAV:}sync-token' === $elem['name']) { $syncToken = $elem['value']; } } } return new self($responses, $syncToken); }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "$", "elementMap", "=", "$", "reader", "->", "elementMap", ";", "$", "elementMap", "[", "'{DAV:}prop'", "]", "=", "'Sabre\\\\DAV\\\\Xml\\\\Element\\\\Prop'", ";", "$", "elements", "=", "$", "reader", "->", "parseInnerTree", "(", "$", "elementMap", ")", ";", "$", "responses", "=", "[", "]", ";", "$", "syncToken", "=", "null", ";", "if", "(", "$", "elements", ")", "{", "foreach", "(", "$", "elements", "as", "$", "elem", ")", "{", "if", "(", "'{DAV:}response'", "===", "$", "elem", "[", "'name'", "]", ")", "{", "$", "responses", "[", "]", "=", "$", "elem", "[", "'value'", "]", ";", "}", "if", "(", "'{DAV:}sync-token'", "===", "$", "elem", "[", "'name'", "]", ")", "{", "$", "syncToken", "=", "$", "elem", "[", "'value'", "]", ";", "}", "}", "}", "return", "new", "self", "(", "$", "responses", ",", "$", "syncToken", ")", ";", "}" ]
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/Response/MultiStatus.php#L118-L139
sabre-io/dav
lib/CalDAV/Calendar.php
Calendar.getProperties
public function getProperties($requestedProperties) { $response = []; foreach ($this->calendarInfo as $propName => $propValue) { if (!is_null($propValue) && '{' === $propName[0]) { $response[$propName] = $this->calendarInfo[$propName]; } } return $response; }
php
public function getProperties($requestedProperties) { $response = []; foreach ($this->calendarInfo as $propName => $propValue) { if (!is_null($propValue) && '{' === $propName[0]) { $response[$propName] = $this->calendarInfo[$propName]; } } return $response; }
[ "public", "function", "getProperties", "(", "$", "requestedProperties", ")", "{", "$", "response", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "calendarInfo", "as", "$", "propName", "=>", "$", "propValue", ")", "{", "if", "(", "!", "is_null", "(", "$", "propValue", ")", "&&", "'{'", "===", "$", "propName", "[", "0", "]", ")", "{", "$", "response", "[", "$", "propName", "]", "=", "$", "this", "->", "calendarInfo", "[", "$", "propName", "]", ";", "}", "}", "return", "$", "response", ";", "}" ]
Returns the list of properties. @param array $requestedProperties @return array
[ "Returns", "the", "list", "of", "properties", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Calendar.php#L84-L95
sabre-io/dav
lib/CalDAV/Calendar.php
Calendar.getChild
public function getChild($name) { $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); if (!$obj) { throw new DAV\Exception\NotFound('Calendar object not found'); } $obj['acl'] = $this->getChildACL(); return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); }
php
public function getChild($name) { $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); if (!$obj) { throw new DAV\Exception\NotFound('Calendar object not found'); } $obj['acl'] = $this->getChildACL(); return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); }
[ "public", "function", "getChild", "(", "$", "name", ")", "{", "$", "obj", "=", "$", "this", "->", "caldavBackend", "->", "getCalendarObject", "(", "$", "this", "->", "calendarInfo", "[", "'id'", "]", ",", "$", "name", ")", ";", "if", "(", "!", "$", "obj", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "NotFound", "(", "'Calendar object not found'", ")", ";", "}", "$", "obj", "[", "'acl'", "]", "=", "$", "this", "->", "getChildACL", "(", ")", ";", "return", "new", "CalendarObject", "(", "$", "this", "->", "caldavBackend", ",", "$", "this", "->", "calendarInfo", ",", "$", "obj", ")", ";", "}" ]
Returns a calendar object. The contained calendar objects are for example Events or Todo's. @param string $name @return \Sabre\CalDAV\ICalendarObject
[ "Returns", "a", "calendar", "object", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Calendar.php#L106-L116
sabre-io/dav
lib/CalDAV/Calendar.php
Calendar.getChildren
public function getChildren() { $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']); $children = []; foreach ($objs as $obj) { $obj['acl'] = $this->getChildACL(); $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); } return $children; }
php
public function getChildren() { $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']); $children = []; foreach ($objs as $obj) { $obj['acl'] = $this->getChildACL(); $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); } return $children; }
[ "public", "function", "getChildren", "(", ")", "{", "$", "objs", "=", "$", "this", "->", "caldavBackend", "->", "getCalendarObjects", "(", "$", "this", "->", "calendarInfo", "[", "'id'", "]", ")", ";", "$", "children", "=", "[", "]", ";", "foreach", "(", "$", "objs", "as", "$", "obj", ")", "{", "$", "obj", "[", "'acl'", "]", "=", "$", "this", "->", "getChildACL", "(", ")", ";", "$", "children", "[", "]", "=", "new", "CalendarObject", "(", "$", "this", "->", "caldavBackend", ",", "$", "this", "->", "calendarInfo", ",", "$", "obj", ")", ";", "}", "return", "$", "children", ";", "}" ]
Returns the full list of calendar objects. @return array
[ "Returns", "the", "full", "list", "of", "calendar", "objects", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Calendar.php#L123-L133
sabre-io/dav
lib/CalDAV/Calendar.php
Calendar.getMultipleChildren
public function getMultipleChildren(array $paths) { $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths); $children = []; foreach ($objs as $obj) { $obj['acl'] = $this->getChildACL(); $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); } return $children; }
php
public function getMultipleChildren(array $paths) { $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths); $children = []; foreach ($objs as $obj) { $obj['acl'] = $this->getChildACL(); $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); } return $children; }
[ "public", "function", "getMultipleChildren", "(", "array", "$", "paths", ")", "{", "$", "objs", "=", "$", "this", "->", "caldavBackend", "->", "getMultipleCalendarObjects", "(", "$", "this", "->", "calendarInfo", "[", "'id'", "]", ",", "$", "paths", ")", ";", "$", "children", "=", "[", "]", ";", "foreach", "(", "$", "objs", "as", "$", "obj", ")", "{", "$", "obj", "[", "'acl'", "]", "=", "$", "this", "->", "getChildACL", "(", ")", ";", "$", "children", "[", "]", "=", "new", "CalendarObject", "(", "$", "this", "->", "caldavBackend", ",", "$", "this", "->", "calendarInfo", ",", "$", "obj", ")", ";", "}", "return", "$", "children", ";", "}" ]
This method receives a list of paths in it's first argument. It must return an array with Node objects. If any children are not found, you do not have to return them. @param string[] $paths @return array
[ "This", "method", "receives", "a", "list", "of", "paths", "in", "it", "s", "first", "argument", ".", "It", "must", "return", "an", "array", "with", "Node", "objects", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Calendar.php#L145-L155
sabre-io/dav
lib/CalDAV/Calendar.php
Calendar.childExists
public function childExists($name) { $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); if (!$obj) { return false; } else { return true; } }
php
public function childExists($name) { $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); if (!$obj) { return false; } else { return true; } }
[ "public", "function", "childExists", "(", "$", "name", ")", "{", "$", "obj", "=", "$", "this", "->", "caldavBackend", "->", "getCalendarObject", "(", "$", "this", "->", "calendarInfo", "[", "'id'", "]", ",", "$", "name", ")", ";", "if", "(", "!", "$", "obj", ")", "{", "return", "false", ";", "}", "else", "{", "return", "true", ";", "}", "}" ]
Checks if a child-node exists. @param string $name @return bool
[ "Checks", "if", "a", "child", "-", "node", "exists", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Calendar.php#L164-L172
sabre-io/dav
lib/CalDAV/Calendar.php
Calendar.createFile
public function createFile($name, $calendarData = null) { if (is_resource($calendarData)) { $calendarData = stream_get_contents($calendarData); } return $this->caldavBackend->createCalendarObject($this->calendarInfo['id'], $name, $calendarData); }
php
public function createFile($name, $calendarData = null) { if (is_resource($calendarData)) { $calendarData = stream_get_contents($calendarData); } return $this->caldavBackend->createCalendarObject($this->calendarInfo['id'], $name, $calendarData); }
[ "public", "function", "createFile", "(", "$", "name", ",", "$", "calendarData", "=", "null", ")", "{", "if", "(", "is_resource", "(", "$", "calendarData", ")", ")", "{", "$", "calendarData", "=", "stream_get_contents", "(", "$", "calendarData", ")", ";", "}", "return", "$", "this", "->", "caldavBackend", "->", "createCalendarObject", "(", "$", "this", "->", "calendarInfo", "[", "'id'", "]", ",", "$", "name", ",", "$", "calendarData", ")", ";", "}" ]
Creates a new file. The contents of the new file must be a valid ICalendar string. @param string $name @param resource $calendarData @return string|null
[ "Creates", "a", "new", "file", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Calendar.php#L196-L203
sabre-io/dav
lib/CalDAV/Calendar.php
Calendar.getACL
public function getACL() { $acl = [ [ 'privilege' => '{DAV:}read', 'principal' => $this->getOwner(), 'protected' => true, ], [ 'privilege' => '{DAV:}read', 'principal' => $this->getOwner().'/calendar-proxy-write', 'protected' => true, ], [ 'privilege' => '{DAV:}read', 'principal' => $this->getOwner().'/calendar-proxy-read', 'protected' => true, ], [ 'privilege' => '{'.Plugin::NS_CALDAV.'}read-free-busy', 'principal' => '{DAV:}authenticated', 'protected' => true, ], ]; if (empty($this->calendarInfo['{http://sabredav.org/ns}read-only'])) { $acl[] = [ 'privilege' => '{DAV:}write', 'principal' => $this->getOwner(), 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}write', 'principal' => $this->getOwner().'/calendar-proxy-write', 'protected' => true, ]; } return $acl; }
php
public function getACL() { $acl = [ [ 'privilege' => '{DAV:}read', 'principal' => $this->getOwner(), 'protected' => true, ], [ 'privilege' => '{DAV:}read', 'principal' => $this->getOwner().'/calendar-proxy-write', 'protected' => true, ], [ 'privilege' => '{DAV:}read', 'principal' => $this->getOwner().'/calendar-proxy-read', 'protected' => true, ], [ 'privilege' => '{'.Plugin::NS_CALDAV.'}read-free-busy', 'principal' => '{DAV:}authenticated', 'protected' => true, ], ]; if (empty($this->calendarInfo['{http: $acl[] = [ 'privilege' => '{DAV:}write', 'principal' => $this->getOwner(), 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}write', 'principal' => $this->getOwner().'/calendar-proxy-write', 'protected' => true, ]; } return $acl; }
[ "public", "function", "getACL", "(", ")", "{", "$", "acl", "=", "[", "[", "'privilege'", "=>", "'{DAV:}read'", ",", "'principal'", "=>", "$", "this", "->", "getOwner", "(", ")", ",", "'protected'", "=>", "true", ",", "]", ",", "[", "'privilege'", "=>", "'{DAV:}read'", ",", "'principal'", "=>", "$", "this", "->", "getOwner", "(", ")", ".", "'/calendar-proxy-write'", ",", "'protected'", "=>", "true", ",", "]", ",", "[", "'privilege'", "=>", "'{DAV:}read'", ",", "'principal'", "=>", "$", "this", "->", "getOwner", "(", ")", ".", "'/calendar-proxy-read'", ",", "'protected'", "=>", "true", ",", "]", ",", "[", "'privilege'", "=>", "'{'", ".", "Plugin", "::", "NS_CALDAV", ".", "'}read-free-busy'", ",", "'principal'", "=>", "'{DAV:}authenticated'", ",", "'protected'", "=>", "true", ",", "]", ",", "]", ";", "if", "(", "empty", "(", "$", "this", "->", "calendarInfo", "[", "'{http://sabredav.org/ns}read-only'", "]", ")", ")", "{", "$", "acl", "[", "]", "=", "[", "'privilege'", "=>", "'{DAV:}write'", ",", "'principal'", "=>", "$", "this", "->", "getOwner", "(", ")", ",", "'protected'", "=>", "true", ",", "]", ";", "$", "acl", "[", "]", "=", "[", "'privilege'", "=>", "'{DAV:}write'", ",", "'principal'", "=>", "$", "this", "->", "getOwner", "(", ")", ".", "'/calendar-proxy-write'", ",", "'protected'", "=>", "true", ",", "]", ";", "}", "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/Calendar.php#L256-L294
sabre-io/dav
lib/CalDAV/Calendar.php
Calendar.getChildACL
public function getChildACL() { $acl = [ [ 'privilege' => '{DAV:}read', 'principal' => $this->getOwner(), 'protected' => true, ], [ 'privilege' => '{DAV:}read', 'principal' => $this->getOwner().'/calendar-proxy-write', 'protected' => true, ], [ 'privilege' => '{DAV:}read', 'principal' => $this->getOwner().'/calendar-proxy-read', 'protected' => true, ], ]; if (empty($this->calendarInfo['{http://sabredav.org/ns}read-only'])) { $acl[] = [ 'privilege' => '{DAV:}write', 'principal' => $this->getOwner(), 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}write', 'principal' => $this->getOwner().'/calendar-proxy-write', 'protected' => true, ]; } return $acl; }
php
public function getChildACL() { $acl = [ [ 'privilege' => '{DAV:}read', 'principal' => $this->getOwner(), 'protected' => true, ], [ 'privilege' => '{DAV:}read', 'principal' => $this->getOwner().'/calendar-proxy-write', 'protected' => true, ], [ 'privilege' => '{DAV:}read', 'principal' => $this->getOwner().'/calendar-proxy-read', 'protected' => true, ], ]; if (empty($this->calendarInfo['{http: $acl[] = [ 'privilege' => '{DAV:}write', 'principal' => $this->getOwner(), 'protected' => true, ]; $acl[] = [ 'privilege' => '{DAV:}write', 'principal' => $this->getOwner().'/calendar-proxy-write', 'protected' => true, ]; } return $acl; }
[ "public", "function", "getChildACL", "(", ")", "{", "$", "acl", "=", "[", "[", "'privilege'", "=>", "'{DAV:}read'", ",", "'principal'", "=>", "$", "this", "->", "getOwner", "(", ")", ",", "'protected'", "=>", "true", ",", "]", ",", "[", "'privilege'", "=>", "'{DAV:}read'", ",", "'principal'", "=>", "$", "this", "->", "getOwner", "(", ")", ".", "'/calendar-proxy-write'", ",", "'protected'", "=>", "true", ",", "]", ",", "[", "'privilege'", "=>", "'{DAV:}read'", ",", "'principal'", "=>", "$", "this", "->", "getOwner", "(", ")", ".", "'/calendar-proxy-read'", ",", "'protected'", "=>", "true", ",", "]", ",", "]", ";", "if", "(", "empty", "(", "$", "this", "->", "calendarInfo", "[", "'{http://sabredav.org/ns}read-only'", "]", ")", ")", "{", "$", "acl", "[", "]", "=", "[", "'privilege'", "=>", "'{DAV:}write'", ",", "'principal'", "=>", "$", "this", "->", "getOwner", "(", ")", ",", "'protected'", "=>", "true", ",", "]", ";", "$", "acl", "[", "]", "=", "[", "'privilege'", "=>", "'{DAV:}write'", ",", "'principal'", "=>", "$", "this", "->", "getOwner", "(", ")", ".", "'/calendar-proxy-write'", ",", "'protected'", "=>", "true", ",", "]", ";", "}", "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/Calendar.php#L303-L337
sabre-io/dav
lib/CalDAV/Calendar.php
Calendar.getSyncToken
public function getSyncToken() { if ( $this->caldavBackend instanceof Backend\SyncSupport && isset($this->calendarInfo['{DAV:}sync-token']) ) { return $this->calendarInfo['{DAV:}sync-token']; } if ( $this->caldavBackend instanceof Backend\SyncSupport && isset($this->calendarInfo['{http://sabredav.org/ns}sync-token']) ) { return $this->calendarInfo['{http://sabredav.org/ns}sync-token']; } }
php
public function getSyncToken() { if ( $this->caldavBackend instanceof Backend\SyncSupport && isset($this->calendarInfo['{DAV:}sync-token']) ) { return $this->calendarInfo['{DAV:}sync-token']; } if ( $this->caldavBackend instanceof Backend\SyncSupport && isset($this->calendarInfo['{http: ) { return $this->calendarInfo['{http: } }
[ "public", "function", "getSyncToken", "(", ")", "{", "if", "(", "$", "this", "->", "caldavBackend", "instanceof", "Backend", "\\", "SyncSupport", "&&", "isset", "(", "$", "this", "->", "calendarInfo", "[", "'{DAV:}sync-token'", "]", ")", ")", "{", "return", "$", "this", "->", "calendarInfo", "[", "'{DAV:}sync-token'", "]", ";", "}", "if", "(", "$", "this", "->", "caldavBackend", "instanceof", "Backend", "\\", "SyncSupport", "&&", "isset", "(", "$", "this", "->", "calendarInfo", "[", "'{http://sabredav.org/ns}sync-token'", "]", ")", ")", "{", "return", "$", "this", "->", "calendarInfo", "[", "'{http://sabredav.org/ns}sync-token'", "]", ";", "}", "}" ]
This method returns the current sync-token for this collection. This can be any string. If null is returned from this function, the plugin assumes there's no sync information available. @return string|null
[ "This", "method", "returns", "the", "current", "sync", "-", "token", "for", "this", "collection", ".", "This", "can", "be", "any", "string", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Calendar.php#L371-L385
sabre-io/dav
lib/CalDAV/Calendar.php
Calendar.getChanges
public function getChanges($syncToken, $syncLevel, $limit = null) { if (!$this->caldavBackend instanceof Backend\SyncSupport) { return null; } return $this->caldavBackend->getChangesForCalendar( $this->calendarInfo['id'], $syncToken, $syncLevel, $limit ); }
php
public function getChanges($syncToken, $syncLevel, $limit = null) { if (!$this->caldavBackend instanceof Backend\SyncSupport) { return null; } return $this->caldavBackend->getChangesForCalendar( $this->calendarInfo['id'], $syncToken, $syncLevel, $limit ); }
[ "public", "function", "getChanges", "(", "$", "syncToken", ",", "$", "syncLevel", ",", "$", "limit", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "caldavBackend", "instanceof", "Backend", "\\", "SyncSupport", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "caldavBackend", "->", "getChangesForCalendar", "(", "$", "this", "->", "calendarInfo", "[", "'id'", "]", ",", "$", "syncToken", ",", "$", "syncLevel", ",", "$", "limit", ")", ";", "}" ]
The getChanges method returns all the changes that have happened, since the specified syncToken and the current collection. This function should return an array, such as the following: [ 'syncToken' => 'The current synctoken', 'added' => [ 'new.txt', ], 'modified' => [ 'modified.txt', ], 'deleted' => [ 'foo.php.bak', 'old.txt' ] ]; The syncToken property should reflect the *current* syncToken of the collection, as reported getSyncToken(). This is needed here too, to ensure the operation is atomic. If the syncToken is specified as null, this is an initial sync, and all members should be reported. The modified property is an array of nodenames that have changed since the last token. The deleted property is an array with nodenames, that have been deleted from collection. The second argument is basically the 'depth' of the report. If it's 1, you only have to report changes that happened only directly in immediate descendants. If it's 2, it should also include changes from the nodes below the child collections. (grandchildren) The third (optional) argument allows a client to specify how many results should be returned at most. If the limit is not specified, it should be treated as infinite. If the limit (infinite or not) is higher than you're willing to return, you should throw a Sabre\DAV\Exception\TooMuchMatches() exception. If the syncToken is expired (due to data cleanup) or unknown, you must return null. The limit is 'suggestive'. You are free to ignore it. @param string $syncToken @param int $syncLevel @param int $limit @return array
[ "The", "getChanges", "method", "returns", "all", "the", "changes", "that", "have", "happened", "since", "the", "specified", "syncToken", "and", "the", "current", "collection", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Calendar.php#L443-L455
sabre-io/dav
lib/DAV/Auth/Backend/IMAP.php
IMAP.imapOpen
protected function imapOpen($username, $password) { $success = false; try { $imap = imap_open($this->mailbox, $username, $password, OP_HALFOPEN | OP_READONLY, 1); if ($imap) { $success = true; } } catch (\ErrorException $e) { error_log($e->getMessage()); } $errors = imap_errors(); if ($errors) { foreach ($errors as $error) { error_log($error); } } if (isset($imap) && $imap) { imap_close($imap); } return $success; }
php
protected function imapOpen($username, $password) { $success = false; try { $imap = imap_open($this->mailbox, $username, $password, OP_HALFOPEN | OP_READONLY, 1); if ($imap) { $success = true; } } catch (\ErrorException $e) { error_log($e->getMessage()); } $errors = imap_errors(); if ($errors) { foreach ($errors as $error) { error_log($error); } } if (isset($imap) && $imap) { imap_close($imap); } return $success; }
[ "protected", "function", "imapOpen", "(", "$", "username", ",", "$", "password", ")", "{", "$", "success", "=", "false", ";", "try", "{", "$", "imap", "=", "imap_open", "(", "$", "this", "->", "mailbox", ",", "$", "username", ",", "$", "password", ",", "OP_HALFOPEN", "|", "OP_READONLY", ",", "1", ")", ";", "if", "(", "$", "imap", ")", "{", "$", "success", "=", "true", ";", "}", "}", "catch", "(", "\\", "ErrorException", "$", "e", ")", "{", "error_log", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "$", "errors", "=", "imap_errors", "(", ")", ";", "if", "(", "$", "errors", ")", "{", "foreach", "(", "$", "errors", "as", "$", "error", ")", "{", "error_log", "(", "$", "error", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "imap", ")", "&&", "$", "imap", ")", "{", "imap_close", "(", "$", "imap", ")", ";", "}", "return", "$", "success", ";", "}" ]
Connects to an IMAP server and tries to authenticate. @param string $username @param string $password @return bool
[ "Connects", "to", "an", "IMAP", "server", "and", "tries", "to", "authenticate", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Auth/Backend/IMAP.php#L43-L68
sabre-io/dav
lib/DAV/UUIDUtil.php
UUIDUtil.getUUID
public static function getUUID() { return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', // 32 bits for "time_low" mt_rand(0, 0xffff), mt_rand(0, 0xffff), // 16 bits for "time_mid" mt_rand(0, 0xffff), // 16 bits for "time_hi_and_version", // four most significant bits holds version number 4 mt_rand(0, 0x0fff) | 0x4000, // 16 bits, 8 bits for "clk_seq_hi_res", // 8 bits for "clk_seq_low", // two most significant bits holds zero and one for variant DCE1.1 mt_rand(0, 0x3fff) | 0x8000, // 48 bits for "node" mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) ); }
php
public static function getUUID() { return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) ); }
[ "public", "static", "function", "getUUID", "(", ")", "{", "return", "sprintf", "(", "'%04x%04x-%04x-%04x-%04x-%04x%04x%04x'", ",", "// 32 bits for \"time_low\"", "mt_rand", "(", "0", ",", "0xffff", ")", ",", "mt_rand", "(", "0", ",", "0xffff", ")", ",", "// 16 bits for \"time_mid\"", "mt_rand", "(", "0", ",", "0xffff", ")", ",", "// 16 bits for \"time_hi_and_version\",", "// four most significant bits holds version number 4", "mt_rand", "(", "0", ",", "0x0fff", ")", "|", "0x4000", ",", "// 16 bits, 8 bits for \"clk_seq_hi_res\",", "// 8 bits for \"clk_seq_low\",", "// two most significant bits holds zero and one for variant DCE1.1", "mt_rand", "(", "0", ",", "0x3fff", ")", "|", "0x8000", ",", "// 48 bits for \"node\"", "mt_rand", "(", "0", ",", "0xffff", ")", ",", "mt_rand", "(", "0", ",", "0xffff", ")", ",", "mt_rand", "(", "0", ",", "0xffff", ")", ")", ";", "}" ]
Returns a pseudo-random v4 UUID. This function is based on a comment by Andrew Moore on php.net @see http://www.php.net/manual/en/function.uniqid.php#94959 @return string
[ "Returns", "a", "pseudo", "-", "random", "v4", "UUID", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/UUIDUtil.php#L29-L50
sabre-io/dav
lib/DAV/Auth/Backend/Apache.php
Apache.check
public function check(RequestInterface $request, ResponseInterface $response) { $remoteUser = $request->getRawServerValue('REMOTE_USER'); if (is_null($remoteUser)) { $remoteUser = $request->getRawServerValue('REDIRECT_REMOTE_USER'); } if (is_null($remoteUser)) { $remoteUser = $request->getRawServerValue('PHP_AUTH_USER'); } if (is_null($remoteUser)) { return [false, 'No REMOTE_USER, REDIRECT_REMOTE_USER, or PHP_AUTH_USER property was found in the PHP $_SERVER super-global. This likely means your server is not configured correctly']; } return [true, $this->principalPrefix.$remoteUser]; }
php
public function check(RequestInterface $request, ResponseInterface $response) { $remoteUser = $request->getRawServerValue('REMOTE_USER'); if (is_null($remoteUser)) { $remoteUser = $request->getRawServerValue('REDIRECT_REMOTE_USER'); } if (is_null($remoteUser)) { $remoteUser = $request->getRawServerValue('PHP_AUTH_USER'); } if (is_null($remoteUser)) { return [false, 'No REMOTE_USER, REDIRECT_REMOTE_USER, or PHP_AUTH_USER property was found in the PHP $_SERVER super-global. This likely means your server is not configured correctly']; } return [true, $this->principalPrefix.$remoteUser]; }
[ "public", "function", "check", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "remoteUser", "=", "$", "request", "->", "getRawServerValue", "(", "'REMOTE_USER'", ")", ";", "if", "(", "is_null", "(", "$", "remoteUser", ")", ")", "{", "$", "remoteUser", "=", "$", "request", "->", "getRawServerValue", "(", "'REDIRECT_REMOTE_USER'", ")", ";", "}", "if", "(", "is_null", "(", "$", "remoteUser", ")", ")", "{", "$", "remoteUser", "=", "$", "request", "->", "getRawServerValue", "(", "'PHP_AUTH_USER'", ")", ";", "}", "if", "(", "is_null", "(", "$", "remoteUser", ")", ")", "{", "return", "[", "false", ",", "'No REMOTE_USER, REDIRECT_REMOTE_USER, or PHP_AUTH_USER property was found in the PHP $_SERVER super-global. This likely means your server is not configured correctly'", "]", ";", "}", "return", "[", "true", ",", "$", "this", "->", "principalPrefix", ".", "$", "remoteUser", "]", ";", "}" ]
When this method is called, the backend must check if authentication was successful. The returned value must be one of the following [true, "principals/username"] [false, "reason for failure"] If authentication was successful, it's expected that the authentication backend returns a so-called principal url. Examples of a principal url: principals/admin principals/user1 principals/users/joe principals/uid/123457 If you don't use WebDAV ACL (RFC3744) we recommend that you simply return a string such as: principals/users/[username] @param RequestInterface $request @param ResponseInterface $response @return array
[ "When", "this", "method", "is", "called", "the", "backend", "must", "check", "if", "authentication", "was", "successful", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Auth/Backend/Apache.php#L60-L74
sabre-io/dav
lib/CardDAV/VCFExportPlugin.php
VCFExportPlugin.initialize
public function initialize(DAV\Server $server) { $this->server = $server; $this->server->on('method:GET', [$this, 'httpGet'], 90); $server->on('browserButtonActions', function ($path, $node, &$actions) { if ($node instanceof IAddressBook) { $actions .= '<a href="'.htmlspecialchars($path, ENT_QUOTES, 'UTF-8').'?export"><span class="oi" data-glyph="book"></span></a>'; } }); }
php
public function initialize(DAV\Server $server) { $this->server = $server; $this->server->on('method:GET', [$this, 'httpGet'], 90); $server->on('browserButtonActions', function ($path, $node, &$actions) { if ($node instanceof IAddressBook) { $actions .= '<a href="'.htmlspecialchars($path, ENT_QUOTES, 'UTF-8').'?export"><span class="oi" data-glyph="book"></span></a>'; } }); }
[ "public", "function", "initialize", "(", "DAV", "\\", "Server", "$", "server", ")", "{", "$", "this", "->", "server", "=", "$", "server", ";", "$", "this", "->", "server", "->", "on", "(", "'method:GET'", ",", "[", "$", "this", ",", "'httpGet'", "]", ",", "90", ")", ";", "$", "server", "->", "on", "(", "'browserButtonActions'", ",", "function", "(", "$", "path", ",", "$", "node", ",", "&", "$", "actions", ")", "{", "if", "(", "$", "node", "instanceof", "IAddressBook", ")", "{", "$", "actions", ".=", "'<a href=\"'", ".", "htmlspecialchars", "(", "$", "path", ",", "ENT_QUOTES", ",", "'UTF-8'", ")", ".", "'?export\"><span class=\"oi\" data-glyph=\"book\"></span></a>'", ";", "}", "}", ")", ";", "}" ]
Initializes the plugin and registers event handlers. @param DAV\Server $server
[ "Initializes", "the", "plugin", "and", "registers", "event", "handlers", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/VCFExportPlugin.php#L38-L47
sabre-io/dav
lib/CardDAV/VCFExportPlugin.php
VCFExportPlugin.httpGet
public function httpGet(RequestInterface $request, ResponseInterface $response) { $queryParams = $request->getQueryParameters(); if (!array_key_exists('export', $queryParams)) { return; } $path = $request->getPath(); $node = $this->server->tree->getNodeForPath($path); if (!($node instanceof IAddressBook)) { return; } $this->server->transactionType = 'get-addressbook-export'; // Checking ACL, if available. if ($aclPlugin = $this->server->getPlugin('acl')) { $aclPlugin->checkPrivileges($path, '{DAV:}read'); } $nodes = $this->server->getPropertiesForPath($path, [ '{'.Plugin::NS_CARDDAV.'}address-data', ], 1); $format = 'text/directory'; $output = null; $filenameExtension = null; switch ($format) { case 'text/directory': $output = $this->generateVCF($nodes); $filenameExtension = '.vcf'; break; } $filename = preg_replace( '/[^a-zA-Z0-9-_ ]/um', '', $node->getName() ); $filename .= '-'.date('Y-m-d').$filenameExtension; $response->setHeader('Content-Disposition', 'attachment; filename="'.$filename.'"'); $response->setHeader('Content-Type', $format); $response->setStatus(200); $response->setBody($output); // 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->tree->getNodeForPath($path); if (!($node instanceof IAddressBook)) { return; } $this->server->transactionType = 'get-addressbook-export'; if ($aclPlugin = $this->server->getPlugin('acl')) { $aclPlugin->checkPrivileges($path, '{DAV:}read'); } $nodes = $this->server->getPropertiesForPath($path, [ '{'.Plugin::NS_CARDDAV.'}address-data', ], 1); $format = 'text/directory'; $output = null; $filenameExtension = null; switch ($format) { case 'text/directory': $output = $this->generateVCF($nodes); $filenameExtension = '.vcf'; break; } $filename = preg_replace( '/[^a-zA-Z0-9-_ ]/um', '', $node->getName() ); $filename .= '-'.date('Y-m-d').$filenameExtension; $response->setHeader('Content-Disposition', 'attachment; filename="'.$filename.'"'); $response->setHeader('Content-Type', $format); $response->setStatus(200); $response->setBody($output); 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", "->", "tree", "->", "getNodeForPath", "(", "$", "path", ")", ";", "if", "(", "!", "(", "$", "node", "instanceof", "IAddressBook", ")", ")", "{", "return", ";", "}", "$", "this", "->", "server", "->", "transactionType", "=", "'get-addressbook-export'", ";", "// Checking ACL, if available.", "if", "(", "$", "aclPlugin", "=", "$", "this", "->", "server", "->", "getPlugin", "(", "'acl'", ")", ")", "{", "$", "aclPlugin", "->", "checkPrivileges", "(", "$", "path", ",", "'{DAV:}read'", ")", ";", "}", "$", "nodes", "=", "$", "this", "->", "server", "->", "getPropertiesForPath", "(", "$", "path", ",", "[", "'{'", ".", "Plugin", "::", "NS_CARDDAV", ".", "'}address-data'", ",", "]", ",", "1", ")", ";", "$", "format", "=", "'text/directory'", ";", "$", "output", "=", "null", ";", "$", "filenameExtension", "=", "null", ";", "switch", "(", "$", "format", ")", "{", "case", "'text/directory'", ":", "$", "output", "=", "$", "this", "->", "generateVCF", "(", "$", "nodes", ")", ";", "$", "filenameExtension", "=", "'.vcf'", ";", "break", ";", "}", "$", "filename", "=", "preg_replace", "(", "'/[^a-zA-Z0-9-_ ]/um'", ",", "''", ",", "$", "node", "->", "getName", "(", ")", ")", ";", "$", "filename", ".=", "'-'", ".", "date", "(", "'Y-m-d'", ")", ".", "$", "filenameExtension", ";", "$", "response", "->", "setHeader", "(", "'Content-Disposition'", ",", "'attachment; filename=\"'", ".", "$", "filename", ".", "'\"'", ")", ";", "$", "response", "->", "setHeader", "(", "'Content-Type'", ",", "$", "format", ")", ";", "$", "response", "->", "setStatus", "(", "200", ")", ";", "$", "response", "->", "setBody", "(", "$", "output", ")", ";", "// Returning false to break the event chain", "return", "false", ";", "}" ]
Intercepts GET requests on addressbook urls ending with ?export. @param RequestInterface $request @param ResponseInterface $response @return bool
[ "Intercepts", "GET", "requests", "on", "addressbook", "urls", "ending", "with", "?export", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/VCFExportPlugin.php#L57-L110
sabre-io/dav
lib/CardDAV/VCFExportPlugin.php
VCFExportPlugin.generateVCF
public function generateVCF(array $nodes) { $output = ''; foreach ($nodes as $node) { if (!isset($node[200]['{'.Plugin::NS_CARDDAV.'}address-data'])) { continue; } $nodeData = $node[200]['{'.Plugin::NS_CARDDAV.'}address-data']; // Parsing this node so VObject can clean up the output. $vcard = VObject\Reader::read($nodeData); $output .= $vcard->serialize(); // Destroy circular references to PHP will GC the object. $vcard->destroy(); } return $output; }
php
public function generateVCF(array $nodes) { $output = ''; foreach ($nodes as $node) { if (!isset($node[200]['{'.Plugin::NS_CARDDAV.'}address-data'])) { continue; } $nodeData = $node[200]['{'.Plugin::NS_CARDDAV.'}address-data']; $vcard = VObject\Reader::read($nodeData); $output .= $vcard->serialize(); $vcard->destroy(); } return $output; }
[ "public", "function", "generateVCF", "(", "array", "$", "nodes", ")", "{", "$", "output", "=", "''", ";", "foreach", "(", "$", "nodes", "as", "$", "node", ")", "{", "if", "(", "!", "isset", "(", "$", "node", "[", "200", "]", "[", "'{'", ".", "Plugin", "::", "NS_CARDDAV", ".", "'}address-data'", "]", ")", ")", "{", "continue", ";", "}", "$", "nodeData", "=", "$", "node", "[", "200", "]", "[", "'{'", ".", "Plugin", "::", "NS_CARDDAV", ".", "'}address-data'", "]", ";", "// Parsing this node so VObject can clean up the output.", "$", "vcard", "=", "VObject", "\\", "Reader", "::", "read", "(", "$", "nodeData", ")", ";", "$", "output", ".=", "$", "vcard", "->", "serialize", "(", ")", ";", "// Destroy circular references to PHP will GC the object.", "$", "vcard", "->", "destroy", "(", ")", ";", "}", "return", "$", "output", ";", "}" ]
Merges all vcard objects, and builds one big vcf export. @param array $nodes @return string
[ "Merges", "all", "vcard", "objects", "and", "builds", "one", "big", "vcf", "export", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/VCFExportPlugin.php#L119-L138