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/DAVACL/PrincipalBackend/PDO.php | PDO.getPrincipalsByPrefix | public function getPrincipalsByPrefix($prefixPath)
{
$fields = [
'uri',
];
foreach ($this->fieldMap as $key => $value) {
$fields[] = $value['dbField'];
}
$result = $this->pdo->query('SELECT '.implode(',', $fields).' FROM '.$this->tableName);
$principals = [];
while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
// Checking if the principal is in the prefix
list($rowPrefix) = Uri\split($row['uri']);
if ($rowPrefix !== $prefixPath) {
continue;
}
$principal = [
'uri' => $row['uri'],
];
foreach ($this->fieldMap as $key => $value) {
if ($row[$value['dbField']]) {
$principal[$key] = $row[$value['dbField']];
}
}
$principals[] = $principal;
}
return $principals;
} | php | public function getPrincipalsByPrefix($prefixPath)
{
$fields = [
'uri',
];
foreach ($this->fieldMap as $key => $value) {
$fields[] = $value['dbField'];
}
$result = $this->pdo->query('SELECT '.implode(',', $fields).' FROM '.$this->tableName);
$principals = [];
while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
list($rowPrefix) = Uri\split($row['uri']);
if ($rowPrefix !== $prefixPath) {
continue;
}
$principal = [
'uri' => $row['uri'],
];
foreach ($this->fieldMap as $key => $value) {
if ($row[$value['dbField']]) {
$principal[$key] = $row[$value['dbField']];
}
}
$principals[] = $principal;
}
return $principals;
} | [
"public",
"function",
"getPrincipalsByPrefix",
"(",
"$",
"prefixPath",
")",
"{",
"$",
"fields",
"=",
"[",
"'uri'",
",",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"fieldMap",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"fields",
"[",
"]",
"=",
"$",
"value",
"[",
"'dbField'",
"]",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"pdo",
"->",
"query",
"(",
"'SELECT '",
".",
"implode",
"(",
"','",
",",
"$",
"fields",
")",
".",
"' FROM '",
".",
"$",
"this",
"->",
"tableName",
")",
";",
"$",
"principals",
"=",
"[",
"]",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"result",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
")",
"{",
"// Checking if the principal is in the prefix",
"list",
"(",
"$",
"rowPrefix",
")",
"=",
"Uri",
"\\",
"split",
"(",
"$",
"row",
"[",
"'uri'",
"]",
")",
";",
"if",
"(",
"$",
"rowPrefix",
"!==",
"$",
"prefixPath",
")",
"{",
"continue",
";",
"}",
"$",
"principal",
"=",
"[",
"'uri'",
"=>",
"$",
"row",
"[",
"'uri'",
"]",
",",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"fieldMap",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"row",
"[",
"$",
"value",
"[",
"'dbField'",
"]",
"]",
")",
"{",
"$",
"principal",
"[",
"$",
"key",
"]",
"=",
"$",
"row",
"[",
"$",
"value",
"[",
"'dbField'",
"]",
"]",
";",
"}",
"}",
"$",
"principals",
"[",
"]",
"=",
"$",
"principal",
";",
"}",
"return",
"$",
"principals",
";",
"}"
] | Returns a list of principals based on a prefix.
This prefix will often contain something like 'principals'. You are only
expected to return principals that are in this base path.
You are expected to return at least a 'uri' for every user, you can
return any additional properties if you wish so. Common properties are:
{DAV:}displayname
{http://sabredav.org/ns}email-address - This is a custom SabreDAV
field that's actualy injected in a number of other properties. If
you have an email address, use this property.
@param string $prefixPath
@return array | [
"Returns",
"a",
"list",
"of",
"principals",
"based",
"on",
"a",
"prefix",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/PrincipalBackend/PDO.php#L93-L125 |
sabre-io/dav | lib/DAVACL/PrincipalBackend/PDO.php | PDO.getPrincipalByPath | public function getPrincipalByPath($path)
{
$fields = [
'id',
'uri',
];
foreach ($this->fieldMap as $key => $value) {
$fields[] = $value['dbField'];
}
$stmt = $this->pdo->prepare('SELECT '.implode(',', $fields).' FROM '.$this->tableName.' WHERE uri = ?');
$stmt->execute([$path]);
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
if (!$row) {
return;
}
$principal = [
'id' => $row['id'],
'uri' => $row['uri'],
];
foreach ($this->fieldMap as $key => $value) {
if ($row[$value['dbField']]) {
$principal[$key] = $row[$value['dbField']];
}
}
return $principal;
} | php | public function getPrincipalByPath($path)
{
$fields = [
'id',
'uri',
];
foreach ($this->fieldMap as $key => $value) {
$fields[] = $value['dbField'];
}
$stmt = $this->pdo->prepare('SELECT '.implode(',', $fields).' FROM '.$this->tableName.' WHERE uri = ?');
$stmt->execute([$path]);
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
if (!$row) {
return;
}
$principal = [
'id' => $row['id'],
'uri' => $row['uri'],
];
foreach ($this->fieldMap as $key => $value) {
if ($row[$value['dbField']]) {
$principal[$key] = $row[$value['dbField']];
}
}
return $principal;
} | [
"public",
"function",
"getPrincipalByPath",
"(",
"$",
"path",
")",
"{",
"$",
"fields",
"=",
"[",
"'id'",
",",
"'uri'",
",",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"fieldMap",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"fields",
"[",
"]",
"=",
"$",
"value",
"[",
"'dbField'",
"]",
";",
"}",
"$",
"stmt",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"'SELECT '",
".",
"implode",
"(",
"','",
",",
"$",
"fields",
")",
".",
"' FROM '",
".",
"$",
"this",
"->",
"tableName",
".",
"' WHERE uri = ?'",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"[",
"$",
"path",
"]",
")",
";",
"$",
"row",
"=",
"$",
"stmt",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"if",
"(",
"!",
"$",
"row",
")",
"{",
"return",
";",
"}",
"$",
"principal",
"=",
"[",
"'id'",
"=>",
"$",
"row",
"[",
"'id'",
"]",
",",
"'uri'",
"=>",
"$",
"row",
"[",
"'uri'",
"]",
",",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"fieldMap",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"row",
"[",
"$",
"value",
"[",
"'dbField'",
"]",
"]",
")",
"{",
"$",
"principal",
"[",
"$",
"key",
"]",
"=",
"$",
"row",
"[",
"$",
"value",
"[",
"'dbField'",
"]",
"]",
";",
"}",
"}",
"return",
"$",
"principal",
";",
"}"
] | Returns a specific principal, specified by it's path.
The returned structure should be the exact same as from
getPrincipalsByPrefix.
@param string $path
@return array | [
"Returns",
"a",
"specific",
"principal",
"specified",
"by",
"it",
"s",
"path",
".",
"The",
"returned",
"structure",
"should",
"be",
"the",
"exact",
"same",
"as",
"from",
"getPrincipalsByPrefix",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/PrincipalBackend/PDO.php#L136-L165 |
sabre-io/dav | lib/DAVACL/PrincipalBackend/PDO.php | PDO.updatePrincipal | public function updatePrincipal($path, DAV\PropPatch $propPatch)
{
$propPatch->handle(array_keys($this->fieldMap), function ($properties) use ($path) {
$query = 'UPDATE '.$this->tableName.' SET ';
$first = true;
$values = [];
foreach ($properties as $key => $value) {
$dbField = $this->fieldMap[$key]['dbField'];
if (!$first) {
$query .= ', ';
}
$first = false;
$query .= $dbField.' = :'.$dbField;
$values[$dbField] = $value;
}
$query .= ' WHERE uri = :uri';
$values['uri'] = $path;
$stmt = $this->pdo->prepare($query);
$stmt->execute($values);
return true;
});
} | php | public function updatePrincipal($path, DAV\PropPatch $propPatch)
{
$propPatch->handle(array_keys($this->fieldMap), function ($properties) use ($path) {
$query = 'UPDATE '.$this->tableName.' SET ';
$first = true;
$values = [];
foreach ($properties as $key => $value) {
$dbField = $this->fieldMap[$key]['dbField'];
if (!$first) {
$query .= ', ';
}
$first = false;
$query .= $dbField.' = :'.$dbField;
$values[$dbField] = $value;
}
$query .= ' WHERE uri = :uri';
$values['uri'] = $path;
$stmt = $this->pdo->prepare($query);
$stmt->execute($values);
return true;
});
} | [
"public",
"function",
"updatePrincipal",
"(",
"$",
"path",
",",
"DAV",
"\\",
"PropPatch",
"$",
"propPatch",
")",
"{",
"$",
"propPatch",
"->",
"handle",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"fieldMap",
")",
",",
"function",
"(",
"$",
"properties",
")",
"use",
"(",
"$",
"path",
")",
"{",
"$",
"query",
"=",
"'UPDATE '",
".",
"$",
"this",
"->",
"tableName",
".",
"' SET '",
";",
"$",
"first",
"=",
"true",
";",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"dbField",
"=",
"$",
"this",
"->",
"fieldMap",
"[",
"$",
"key",
"]",
"[",
"'dbField'",
"]",
";",
"if",
"(",
"!",
"$",
"first",
")",
"{",
"$",
"query",
".=",
"', '",
";",
"}",
"$",
"first",
"=",
"false",
";",
"$",
"query",
".=",
"$",
"dbField",
".",
"' = :'",
".",
"$",
"dbField",
";",
"$",
"values",
"[",
"$",
"dbField",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"query",
".=",
"' WHERE uri = :uri'",
";",
"$",
"values",
"[",
"'uri'",
"]",
"=",
"$",
"path",
";",
"$",
"stmt",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"$",
"values",
")",
";",
"return",
"true",
";",
"}",
")",
";",
"}"
] | Updates one ore more webdav properties on a principal.
The list of mutations is stored in a Sabre\DAV\PropPatch object.
To do the actual updates, you must tell this object which properties
you're going to process with the handle() method.
Calling the handle method is like telling the PropPatch object "I
promise I can handle updating this property".
Read the PropPatch documentation for more info and examples.
@param string $path
@param DAV\PropPatch $propPatch | [
"Updates",
"one",
"ore",
"more",
"webdav",
"properties",
"on",
"a",
"principal",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/PrincipalBackend/PDO.php#L182-L209 |
sabre-io/dav | lib/DAVACL/PrincipalBackend/PDO.php | PDO.searchPrincipals | public function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof')
{
if (0 == count($searchProperties)) {
return [];
} //No criteria
$query = 'SELECT uri FROM '.$this->tableName.' WHERE ';
$values = [];
foreach ($searchProperties as $property => $value) {
switch ($property) {
case '{DAV:}displayname':
$column = 'displayname';
break;
case '{http://sabredav.org/ns}email-address':
$column = 'email';
break;
default:
// Unsupported property
return [];
}
if (count($values) > 0) {
$query .= (0 == strcmp($test, 'anyof') ? ' OR ' : ' AND ');
}
$query .= 'lower('.$column.') LIKE lower(?)';
$values[] = '%'.$value.'%';
}
$stmt = $this->pdo->prepare($query);
$stmt->execute($values);
$principals = [];
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
// Checking if the principal is in the prefix
list($rowPrefix) = Uri\split($row['uri']);
if ($rowPrefix !== $prefixPath) {
continue;
}
$principals[] = $row['uri'];
}
return $principals;
} | php | public function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof')
{
if (0 == count($searchProperties)) {
return [];
}
$query = 'SELECT uri FROM '.$this->tableName.' WHERE ';
$values = [];
foreach ($searchProperties as $property => $value) {
switch ($property) {
case '{DAV:}displayname':
$column = 'displayname';
break;
case '{http:
$column = 'email';
break;
default:
return [];
}
if (count($values) > 0) {
$query .= (0 == strcmp($test, 'anyof') ? ' OR ' : ' AND ');
}
$query .= 'lower('.$column.') LIKE lower(?)';
$values[] = '%'.$value.'%';
}
$stmt = $this->pdo->prepare($query);
$stmt->execute($values);
$principals = [];
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
list($rowPrefix) = Uri\split($row['uri']);
if ($rowPrefix !== $prefixPath) {
continue;
}
$principals[] = $row['uri'];
}
return $principals;
} | [
"public",
"function",
"searchPrincipals",
"(",
"$",
"prefixPath",
",",
"array",
"$",
"searchProperties",
",",
"$",
"test",
"=",
"'allof'",
")",
"{",
"if",
"(",
"0",
"==",
"count",
"(",
"$",
"searchProperties",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"//No criteria",
"$",
"query",
"=",
"'SELECT uri FROM '",
".",
"$",
"this",
"->",
"tableName",
".",
"' WHERE '",
";",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"searchProperties",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"property",
")",
"{",
"case",
"'{DAV:}displayname'",
":",
"$",
"column",
"=",
"'displayname'",
";",
"break",
";",
"case",
"'{http://sabredav.org/ns}email-address'",
":",
"$",
"column",
"=",
"'email'",
";",
"break",
";",
"default",
":",
"// Unsupported property",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"values",
")",
">",
"0",
")",
"{",
"$",
"query",
".=",
"(",
"0",
"==",
"strcmp",
"(",
"$",
"test",
",",
"'anyof'",
")",
"?",
"' OR '",
":",
"' AND '",
")",
";",
"}",
"$",
"query",
".=",
"'lower('",
".",
"$",
"column",
".",
"') LIKE lower(?)'",
";",
"$",
"values",
"[",
"]",
"=",
"'%'",
".",
"$",
"value",
".",
"'%'",
";",
"}",
"$",
"stmt",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"$",
"values",
")",
";",
"$",
"principals",
"=",
"[",
"]",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"stmt",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
")",
"{",
"// Checking if the principal is in the prefix",
"list",
"(",
"$",
"rowPrefix",
")",
"=",
"Uri",
"\\",
"split",
"(",
"$",
"row",
"[",
"'uri'",
"]",
")",
";",
"if",
"(",
"$",
"rowPrefix",
"!==",
"$",
"prefixPath",
")",
"{",
"continue",
";",
"}",
"$",
"principals",
"[",
"]",
"=",
"$",
"row",
"[",
"'uri'",
"]",
";",
"}",
"return",
"$",
"principals",
";",
"}"
] | This method is used to search for principals matching a set of
properties.
This search is specifically used by RFC3744's principal-property-search
REPORT.
The actual search should be a unicode-non-case-sensitive search. The
keys in searchProperties are the WebDAV property names, while the values
are the property values to search on.
By default, if multiple properties are submitted to this method, the
various properties should be combined with 'AND'. If $test is set to
'anyof', it should be combined using 'OR'.
This method should simply return an array with full principal uri's.
If somebody attempted to search on a property the backend does not
support, you should simply return 0 results.
You can also just return 0 results if you choose to not support
searching at all, but keep in mind that this may stop certain features
from working.
@param string $prefixPath
@param array $searchProperties
@param string $test
@return array | [
"This",
"method",
"is",
"used",
"to",
"search",
"for",
"principals",
"matching",
"a",
"set",
"of",
"properties",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/PrincipalBackend/PDO.php#L241-L282 |
sabre-io/dav | lib/DAVACL/PrincipalBackend/PDO.php | PDO.findByUri | public function findByUri($uri, $principalPrefix)
{
$value = null;
$scheme = null;
list($scheme, $value) = explode(':', $uri, 2);
if (empty($value)) {
return null;
}
$uri = null;
switch ($scheme) {
case 'mailto':
$query = 'SELECT uri FROM '.$this->tableName.' WHERE lower(email)=lower(?)';
$stmt = $this->pdo->prepare($query);
$stmt->execute([$value]);
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
// Checking if the principal is in the prefix
list($rowPrefix) = Uri\split($row['uri']);
if ($rowPrefix !== $principalPrefix) {
continue;
}
$uri = $row['uri'];
break; //Stop on first match
}
break;
default:
//unsupported uri scheme
return null;
}
return $uri;
} | php | public function findByUri($uri, $principalPrefix)
{
$value = null;
$scheme = null;
list($scheme, $value) = explode(':', $uri, 2);
if (empty($value)) {
return null;
}
$uri = null;
switch ($scheme) {
case 'mailto':
$query = 'SELECT uri FROM '.$this->tableName.' WHERE lower(email)=lower(?)';
$stmt = $this->pdo->prepare($query);
$stmt->execute([$value]);
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
list($rowPrefix) = Uri\split($row['uri']);
if ($rowPrefix !== $principalPrefix) {
continue;
}
$uri = $row['uri'];
break;
}
break;
default:
return null;
}
return $uri;
} | [
"public",
"function",
"findByUri",
"(",
"$",
"uri",
",",
"$",
"principalPrefix",
")",
"{",
"$",
"value",
"=",
"null",
";",
"$",
"scheme",
"=",
"null",
";",
"list",
"(",
"$",
"scheme",
",",
"$",
"value",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"uri",
",",
"2",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"uri",
"=",
"null",
";",
"switch",
"(",
"$",
"scheme",
")",
"{",
"case",
"'mailto'",
":",
"$",
"query",
"=",
"'SELECT uri FROM '",
".",
"$",
"this",
"->",
"tableName",
".",
"' WHERE lower(email)=lower(?)'",
";",
"$",
"stmt",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"[",
"$",
"value",
"]",
")",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"stmt",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
")",
"{",
"// Checking if the principal is in the prefix",
"list",
"(",
"$",
"rowPrefix",
")",
"=",
"Uri",
"\\",
"split",
"(",
"$",
"row",
"[",
"'uri'",
"]",
")",
";",
"if",
"(",
"$",
"rowPrefix",
"!==",
"$",
"principalPrefix",
")",
"{",
"continue",
";",
"}",
"$",
"uri",
"=",
"$",
"row",
"[",
"'uri'",
"]",
";",
"break",
";",
"//Stop on first match",
"}",
"break",
";",
"default",
":",
"//unsupported uri scheme",
"return",
"null",
";",
"}",
"return",
"$",
"uri",
";",
"}"
] | Finds a principal by its URI.
This method may receive any type of uri, but mailto: addresses will be
the most common.
Implementation of this API is optional. It is currently used by the
CalDAV system to find principals based on their email addresses. If this
API is not implemented, some features may not work correctly.
This method must return a relative principal path, or null, if the
principal was not found or you refuse to find it.
@param string $uri
@param string $principalPrefix
@return string | [
"Finds",
"a",
"principal",
"by",
"its",
"URI",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/PrincipalBackend/PDO.php#L302-L335 |
sabre-io/dav | lib/DAVACL/PrincipalBackend/PDO.php | PDO.getGroupMemberSet | public function getGroupMemberSet($principal)
{
$principal = $this->getPrincipalByPath($principal);
if (!$principal) {
throw new DAV\Exception('Principal not found');
}
$stmt = $this->pdo->prepare('SELECT principals.uri as uri FROM '.$this->groupMembersTableName.' AS groupmembers LEFT JOIN '.$this->tableName.' AS principals ON groupmembers.member_id = principals.id WHERE groupmembers.principal_id = ?');
$stmt->execute([$principal['id']]);
$result = [];
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$result[] = $row['uri'];
}
return $result;
} | php | public function getGroupMemberSet($principal)
{
$principal = $this->getPrincipalByPath($principal);
if (!$principal) {
throw new DAV\Exception('Principal not found');
}
$stmt = $this->pdo->prepare('SELECT principals.uri as uri FROM '.$this->groupMembersTableName.' AS groupmembers LEFT JOIN '.$this->tableName.' AS principals ON groupmembers.member_id = principals.id WHERE groupmembers.principal_id = ?');
$stmt->execute([$principal['id']]);
$result = [];
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$result[] = $row['uri'];
}
return $result;
} | [
"public",
"function",
"getGroupMemberSet",
"(",
"$",
"principal",
")",
"{",
"$",
"principal",
"=",
"$",
"this",
"->",
"getPrincipalByPath",
"(",
"$",
"principal",
")",
";",
"if",
"(",
"!",
"$",
"principal",
")",
"{",
"throw",
"new",
"DAV",
"\\",
"Exception",
"(",
"'Principal not found'",
")",
";",
"}",
"$",
"stmt",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"'SELECT principals.uri as uri FROM '",
".",
"$",
"this",
"->",
"groupMembersTableName",
".",
"' AS groupmembers LEFT JOIN '",
".",
"$",
"this",
"->",
"tableName",
".",
"' AS principals ON groupmembers.member_id = principals.id WHERE groupmembers.principal_id = ?'",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"[",
"$",
"principal",
"[",
"'id'",
"]",
"]",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"stmt",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"row",
"[",
"'uri'",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns the list of members for a group-principal.
@param string $principal
@return array | [
"Returns",
"the",
"list",
"of",
"members",
"for",
"a",
"group",
"-",
"principal",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/PrincipalBackend/PDO.php#L344-L359 |
sabre-io/dav | lib/DAVACL/PrincipalBackend/PDO.php | PDO.setGroupMemberSet | public function setGroupMemberSet($principal, array $members)
{
// Grabbing the list of principal id's.
$stmt = $this->pdo->prepare('SELECT id, uri FROM '.$this->tableName.' WHERE uri IN (? '.str_repeat(', ? ', count($members)).');');
$stmt->execute(array_merge([$principal], $members));
$memberIds = [];
$principalId = null;
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
if ($row['uri'] == $principal) {
$principalId = $row['id'];
} else {
$memberIds[] = $row['id'];
}
}
if (!$principalId) {
throw new DAV\Exception('Principal not found');
}
// Wiping out old members
$stmt = $this->pdo->prepare('DELETE FROM '.$this->groupMembersTableName.' WHERE principal_id = ?;');
$stmt->execute([$principalId]);
foreach ($memberIds as $memberId) {
$stmt = $this->pdo->prepare('INSERT INTO '.$this->groupMembersTableName.' (principal_id, member_id) VALUES (?, ?);');
$stmt->execute([$principalId, $memberId]);
}
} | php | public function setGroupMemberSet($principal, array $members)
{
$stmt = $this->pdo->prepare('SELECT id, uri FROM '.$this->tableName.' WHERE uri IN (? '.str_repeat(', ? ', count($members)).');');
$stmt->execute(array_merge([$principal], $members));
$memberIds = [];
$principalId = null;
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
if ($row['uri'] == $principal) {
$principalId = $row['id'];
} else {
$memberIds[] = $row['id'];
}
}
if (!$principalId) {
throw new DAV\Exception('Principal not found');
}
$stmt = $this->pdo->prepare('DELETE FROM '.$this->groupMembersTableName.' WHERE principal_id = ?;');
$stmt->execute([$principalId]);
foreach ($memberIds as $memberId) {
$stmt = $this->pdo->prepare('INSERT INTO '.$this->groupMembersTableName.' (principal_id, member_id) VALUES (?, ?);');
$stmt->execute([$principalId, $memberId]);
}
} | [
"public",
"function",
"setGroupMemberSet",
"(",
"$",
"principal",
",",
"array",
"$",
"members",
")",
"{",
"// Grabbing the list of principal id's.",
"$",
"stmt",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"'SELECT id, uri FROM '",
".",
"$",
"this",
"->",
"tableName",
".",
"' WHERE uri IN (? '",
".",
"str_repeat",
"(",
"', ? '",
",",
"count",
"(",
"$",
"members",
")",
")",
".",
"');'",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"array_merge",
"(",
"[",
"$",
"principal",
"]",
",",
"$",
"members",
")",
")",
";",
"$",
"memberIds",
"=",
"[",
"]",
";",
"$",
"principalId",
"=",
"null",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"stmt",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
")",
"{",
"if",
"(",
"$",
"row",
"[",
"'uri'",
"]",
"==",
"$",
"principal",
")",
"{",
"$",
"principalId",
"=",
"$",
"row",
"[",
"'id'",
"]",
";",
"}",
"else",
"{",
"$",
"memberIds",
"[",
"]",
"=",
"$",
"row",
"[",
"'id'",
"]",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"principalId",
")",
"{",
"throw",
"new",
"DAV",
"\\",
"Exception",
"(",
"'Principal not found'",
")",
";",
"}",
"// Wiping out old members",
"$",
"stmt",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"'DELETE FROM '",
".",
"$",
"this",
"->",
"groupMembersTableName",
".",
"' WHERE principal_id = ?;'",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"[",
"$",
"principalId",
"]",
")",
";",
"foreach",
"(",
"$",
"memberIds",
"as",
"$",
"memberId",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"'INSERT INTO '",
".",
"$",
"this",
"->",
"groupMembersTableName",
".",
"' (principal_id, member_id) VALUES (?, ?);'",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"[",
"$",
"principalId",
",",
"$",
"memberId",
"]",
")",
";",
"}",
"}"
] | Updates the list of group members for a group principal.
The principals should be passed as a list of uri's.
@param string $principal
@param array $members | [
"Updates",
"the",
"list",
"of",
"group",
"members",
"for",
"a",
"group",
"principal",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/PrincipalBackend/PDO.php#L393-L420 |
sabre-io/dav | lib/DAVACL/PrincipalBackend/PDO.php | PDO.createPrincipal | public function createPrincipal($path, MkCol $mkCol)
{
$stmt = $this->pdo->prepare('INSERT INTO '.$this->tableName.' (uri) VALUES (?)');
$stmt->execute([$path]);
$this->updatePrincipal($path, $mkCol);
} | php | public function createPrincipal($path, MkCol $mkCol)
{
$stmt = $this->pdo->prepare('INSERT INTO '.$this->tableName.' (uri) VALUES (?)');
$stmt->execute([$path]);
$this->updatePrincipal($path, $mkCol);
} | [
"public",
"function",
"createPrincipal",
"(",
"$",
"path",
",",
"MkCol",
"$",
"mkCol",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"'INSERT INTO '",
".",
"$",
"this",
"->",
"tableName",
".",
"' (uri) VALUES (?)'",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"[",
"$",
"path",
"]",
")",
";",
"$",
"this",
"->",
"updatePrincipal",
"(",
"$",
"path",
",",
"$",
"mkCol",
")",
";",
"}"
] | Creates a new principal.
This method receives a full path for the new principal. The mkCol object
contains any additional webdav properties specified during the creation
of the principal.
@param string $path
@param MkCol $mkCol | [
"Creates",
"a",
"new",
"principal",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/PrincipalBackend/PDO.php#L432-L437 |
sabre-io/dav | lib/DAV/Xml/Request/ShareResource.php | ShareResource.xmlDeserialize | public static function xmlDeserialize(Reader $reader)
{
$elems = $reader->parseInnerTree([
'{DAV:}sharee' => 'Sabre\DAV\Xml\Element\Sharee',
'{DAV:}share-access' => 'Sabre\DAV\Xml\Property\ShareAccess',
'{DAV:}prop' => 'Sabre\Xml\Deserializer\keyValue',
]);
$sharees = [];
foreach ($elems as $elem) {
if ('{DAV:}sharee' !== $elem['name']) {
continue;
}
$sharees[] = $elem['value'];
}
return new self($sharees);
} | php | public static function xmlDeserialize(Reader $reader)
{
$elems = $reader->parseInnerTree([
'{DAV:}sharee' => 'Sabre\DAV\Xml\Element\Sharee',
'{DAV:}share-access' => 'Sabre\DAV\Xml\Property\ShareAccess',
'{DAV:}prop' => 'Sabre\Xml\Deserializer\keyValue',
]);
$sharees = [];
foreach ($elems as $elem) {
if ('{DAV:}sharee' !== $elem['name']) {
continue;
}
$sharees[] = $elem['value'];
}
return new self($sharees);
} | [
"public",
"static",
"function",
"xmlDeserialize",
"(",
"Reader",
"$",
"reader",
")",
"{",
"$",
"elems",
"=",
"$",
"reader",
"->",
"parseInnerTree",
"(",
"[",
"'{DAV:}sharee'",
"=>",
"'Sabre\\DAV\\Xml\\Element\\Sharee'",
",",
"'{DAV:}share-access'",
"=>",
"'Sabre\\DAV\\Xml\\Property\\ShareAccess'",
",",
"'{DAV:}prop'",
"=>",
"'Sabre\\Xml\\Deserializer\\keyValue'",
",",
"]",
")",
";",
"$",
"sharees",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"elems",
"as",
"$",
"elem",
")",
"{",
"if",
"(",
"'{DAV:}sharee'",
"!==",
"$",
"elem",
"[",
"'name'",
"]",
")",
"{",
"continue",
";",
"}",
"$",
"sharees",
"[",
"]",
"=",
"$",
"elem",
"[",
"'value'",
"]",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"sharees",
")",
";",
"}"
] | The deserialize method is called during xml parsing.
This method is called statically, this is because in theory this method
may be used as a type of constructor, or factory method.
Often you want to return an instance of the current class, but you are
free to return other data as well.
You are responsible for advancing the reader to the next element. Not
doing anything will result in a never-ending loop.
If you just want to skip parsing for this element altogether, you can
just call $reader->next();
$reader->parseInnerTree() will parse the entire sub-tree, and advance to
the next element.
@param Reader $reader
@return mixed | [
"The",
"deserialize",
"method",
"is",
"called",
"during",
"xml",
"parsing",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Request/ShareResource.php#L63-L81 |
sabre-io/dav | lib/DAV/TemporaryFileFilterPlugin.php | TemporaryFileFilterPlugin.initialize | public function initialize(Server $server)
{
$this->server = $server;
$server->on('beforeMethod:*', [$this, 'beforeMethod']);
$server->on('beforeCreateFile', [$this, 'beforeCreateFile']);
} | php | public function initialize(Server $server)
{
$this->server = $server;
$server->on('beforeMethod:*', [$this, 'beforeMethod']);
$server->on('beforeCreateFile', [$this, 'beforeCreateFile']);
} | [
"public",
"function",
"initialize",
"(",
"Server",
"$",
"server",
")",
"{",
"$",
"this",
"->",
"server",
"=",
"$",
"server",
";",
"$",
"server",
"->",
"on",
"(",
"'beforeMethod:*'",
",",
"[",
"$",
"this",
",",
"'beforeMethod'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'beforeCreateFile'",
",",
"[",
"$",
"this",
",",
"'beforeCreateFile'",
"]",
")",
";",
"}"
] | Initialize the plugin.
This is called automatically be the Server class after this plugin is
added with Sabre\DAV\Server::addPlugin()
@param Server $server | [
"Initialize",
"the",
"plugin",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/TemporaryFileFilterPlugin.php#L96-L101 |
sabre-io/dav | lib/DAV/TemporaryFileFilterPlugin.php | TemporaryFileFilterPlugin.beforeMethod | public function beforeMethod(RequestInterface $request, ResponseInterface $response)
{
if (!$tempLocation = $this->isTempFile($request->getPath())) {
return;
}
switch ($request->getMethod()) {
case 'GET':
return $this->httpGet($request, $response, $tempLocation);
case 'PUT':
return $this->httpPut($request, $response, $tempLocation);
case 'PROPFIND':
return $this->httpPropfind($request, $response, $tempLocation);
case 'DELETE':
return $this->httpDelete($request, $response, $tempLocation);
}
return;
} | php | public function beforeMethod(RequestInterface $request, ResponseInterface $response)
{
if (!$tempLocation = $this->isTempFile($request->getPath())) {
return;
}
switch ($request->getMethod()) {
case 'GET':
return $this->httpGet($request, $response, $tempLocation);
case 'PUT':
return $this->httpPut($request, $response, $tempLocation);
case 'PROPFIND':
return $this->httpPropfind($request, $response, $tempLocation);
case 'DELETE':
return $this->httpDelete($request, $response, $tempLocation);
}
return;
} | [
"public",
"function",
"beforeMethod",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"if",
"(",
"!",
"$",
"tempLocation",
"=",
"$",
"this",
"->",
"isTempFile",
"(",
"$",
"request",
"->",
"getPath",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"switch",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
")",
"{",
"case",
"'GET'",
":",
"return",
"$",
"this",
"->",
"httpGet",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"tempLocation",
")",
";",
"case",
"'PUT'",
":",
"return",
"$",
"this",
"->",
"httpPut",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"tempLocation",
")",
";",
"case",
"'PROPFIND'",
":",
"return",
"$",
"this",
"->",
"httpPropfind",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"tempLocation",
")",
";",
"case",
"'DELETE'",
":",
"return",
"$",
"this",
"->",
"httpDelete",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"tempLocation",
")",
";",
"}",
"return",
";",
"}"
] | This method is called before any HTTP method handler.
This method intercepts any GET, DELETE, PUT and PROPFIND calls to
filenames that are known to match the 'temporary file' regex.
@param RequestInterface $request
@param ResponseInterface $response
@return bool | [
"This",
"method",
"is",
"called",
"before",
"any",
"HTTP",
"method",
"handler",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/TemporaryFileFilterPlugin.php#L114-L132 |
sabre-io/dav | lib/DAV/TemporaryFileFilterPlugin.php | TemporaryFileFilterPlugin.beforeCreateFile | public function beforeCreateFile($uri, $data, ICollection $parent, $modified)
{
if ($tempPath = $this->isTempFile($uri)) {
$hR = $this->server->httpResponse;
$hR->setHeader('X-Sabre-Temp', 'true');
file_put_contents($tempPath, $data);
return false;
}
return;
} | php | public function beforeCreateFile($uri, $data, ICollection $parent, $modified)
{
if ($tempPath = $this->isTempFile($uri)) {
$hR = $this->server->httpResponse;
$hR->setHeader('X-Sabre-Temp', 'true');
file_put_contents($tempPath, $data);
return false;
}
return;
} | [
"public",
"function",
"beforeCreateFile",
"(",
"$",
"uri",
",",
"$",
"data",
",",
"ICollection",
"$",
"parent",
",",
"$",
"modified",
")",
"{",
"if",
"(",
"$",
"tempPath",
"=",
"$",
"this",
"->",
"isTempFile",
"(",
"$",
"uri",
")",
")",
"{",
"$",
"hR",
"=",
"$",
"this",
"->",
"server",
"->",
"httpResponse",
";",
"$",
"hR",
"->",
"setHeader",
"(",
"'X-Sabre-Temp'",
",",
"'true'",
")",
";",
"file_put_contents",
"(",
"$",
"tempPath",
",",
"$",
"data",
")",
";",
"return",
"false",
";",
"}",
"return",
";",
"}"
] | This method is invoked if some subsystem creates a new file.
This is used to deal with HTTP LOCK requests which create a new
file.
@param string $uri
@param resource $data
@param ICollection $parent
@param bool $modified should be set to true, if this event handler
changed &$data
@return bool | [
"This",
"method",
"is",
"invoked",
"if",
"some",
"subsystem",
"creates",
"a",
"new",
"file",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/TemporaryFileFilterPlugin.php#L148-L159 |
sabre-io/dav | lib/DAV/TemporaryFileFilterPlugin.php | TemporaryFileFilterPlugin.isTempFile | protected function isTempFile($path)
{
// We're only interested in the basename.
list(, $tempPath) = Uri\split($path);
foreach ($this->temporaryFilePatterns as $tempFile) {
if (preg_match($tempFile, $tempPath)) {
return $this->getDataDir().'/sabredav_'.md5($path).'.tempfile';
}
}
return false;
} | php | protected function isTempFile($path)
{
list(, $tempPath) = Uri\split($path);
foreach ($this->temporaryFilePatterns as $tempFile) {
if (preg_match($tempFile, $tempPath)) {
return $this->getDataDir().'/sabredav_'.md5($path).'.tempfile';
}
}
return false;
} | [
"protected",
"function",
"isTempFile",
"(",
"$",
"path",
")",
"{",
"// We're only interested in the basename.",
"list",
"(",
",",
"$",
"tempPath",
")",
"=",
"Uri",
"\\",
"split",
"(",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"temporaryFilePatterns",
"as",
"$",
"tempFile",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"tempFile",
",",
"$",
"tempPath",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getDataDir",
"(",
")",
".",
"'/sabredav_'",
".",
"md5",
"(",
"$",
"path",
")",
".",
"'.tempfile'",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | This method will check if the url matches the temporary file pattern
if it does, it will return an path based on $this->dataDir for the
temporary file storage.
@param string $path
@return bool|string | [
"This",
"method",
"will",
"check",
"if",
"the",
"url",
"matches",
"the",
"temporary",
"file",
"pattern",
"if",
"it",
"does",
"it",
"will",
"return",
"an",
"path",
"based",
"on",
"$this",
"-",
">",
"dataDir",
"for",
"the",
"temporary",
"file",
"storage",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/TemporaryFileFilterPlugin.php#L170-L182 |
sabre-io/dav | lib/DAV/TemporaryFileFilterPlugin.php | TemporaryFileFilterPlugin.httpGet | public function httpGet(RequestInterface $request, ResponseInterface $hR, $tempLocation)
{
if (!file_exists($tempLocation)) {
return;
}
$hR->setHeader('Content-Type', 'application/octet-stream');
$hR->setHeader('Content-Length', filesize($tempLocation));
$hR->setHeader('X-Sabre-Temp', 'true');
$hR->setStatus(200);
$hR->setBody(fopen($tempLocation, 'r'));
return false;
} | php | public function httpGet(RequestInterface $request, ResponseInterface $hR, $tempLocation)
{
if (!file_exists($tempLocation)) {
return;
}
$hR->setHeader('Content-Type', 'application/octet-stream');
$hR->setHeader('Content-Length', filesize($tempLocation));
$hR->setHeader('X-Sabre-Temp', 'true');
$hR->setStatus(200);
$hR->setBody(fopen($tempLocation, 'r'));
return false;
} | [
"public",
"function",
"httpGet",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"hR",
",",
"$",
"tempLocation",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"tempLocation",
")",
")",
"{",
"return",
";",
"}",
"$",
"hR",
"->",
"setHeader",
"(",
"'Content-Type'",
",",
"'application/octet-stream'",
")",
";",
"$",
"hR",
"->",
"setHeader",
"(",
"'Content-Length'",
",",
"filesize",
"(",
"$",
"tempLocation",
")",
")",
";",
"$",
"hR",
"->",
"setHeader",
"(",
"'X-Sabre-Temp'",
",",
"'true'",
")",
";",
"$",
"hR",
"->",
"setStatus",
"(",
"200",
")",
";",
"$",
"hR",
"->",
"setBody",
"(",
"fopen",
"(",
"$",
"tempLocation",
",",
"'r'",
")",
")",
";",
"return",
"false",
";",
"}"
] | This method handles the GET method for temporary files.
If the file doesn't exist, it will return false which will kick in
the regular system for the GET method.
@param RequestInterface $request
@param ResponseInterface $hR
@param string $tempLocation
@return bool | [
"This",
"method",
"handles",
"the",
"GET",
"method",
"for",
"temporary",
"files",
".",
"If",
"the",
"file",
"doesn",
"t",
"exist",
"it",
"will",
"return",
"false",
"which",
"will",
"kick",
"in",
"the",
"regular",
"system",
"for",
"the",
"GET",
"method",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/TemporaryFileFilterPlugin.php#L195-L208 |
sabre-io/dav | lib/DAV/TemporaryFileFilterPlugin.php | TemporaryFileFilterPlugin.httpPut | public function httpPut(RequestInterface $request, ResponseInterface $hR, $tempLocation)
{
$hR->setHeader('X-Sabre-Temp', 'true');
$newFile = !file_exists($tempLocation);
if (!$newFile && ($this->server->httpRequest->getHeader('If-None-Match'))) {
throw new Exception\PreconditionFailed('The resource already exists, and an If-None-Match header was supplied');
}
file_put_contents($tempLocation, $this->server->httpRequest->getBody());
$hR->setStatus($newFile ? 201 : 200);
return false;
} | php | public function httpPut(RequestInterface $request, ResponseInterface $hR, $tempLocation)
{
$hR->setHeader('X-Sabre-Temp', 'true');
$newFile = !file_exists($tempLocation);
if (!$newFile && ($this->server->httpRequest->getHeader('If-None-Match'))) {
throw new Exception\PreconditionFailed('The resource already exists, and an If-None-Match header was supplied');
}
file_put_contents($tempLocation, $this->server->httpRequest->getBody());
$hR->setStatus($newFile ? 201 : 200);
return false;
} | [
"public",
"function",
"httpPut",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"hR",
",",
"$",
"tempLocation",
")",
"{",
"$",
"hR",
"->",
"setHeader",
"(",
"'X-Sabre-Temp'",
",",
"'true'",
")",
";",
"$",
"newFile",
"=",
"!",
"file_exists",
"(",
"$",
"tempLocation",
")",
";",
"if",
"(",
"!",
"$",
"newFile",
"&&",
"(",
"$",
"this",
"->",
"server",
"->",
"httpRequest",
"->",
"getHeader",
"(",
"'If-None-Match'",
")",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"PreconditionFailed",
"(",
"'The resource already exists, and an If-None-Match header was supplied'",
")",
";",
"}",
"file_put_contents",
"(",
"$",
"tempLocation",
",",
"$",
"this",
"->",
"server",
"->",
"httpRequest",
"->",
"getBody",
"(",
")",
")",
";",
"$",
"hR",
"->",
"setStatus",
"(",
"$",
"newFile",
"?",
"201",
":",
"200",
")",
";",
"return",
"false",
";",
"}"
] | This method handles the PUT method.
@param RequestInterface $request
@param ResponseInterface $hR
@param string $tempLocation
@return bool | [
"This",
"method",
"handles",
"the",
"PUT",
"method",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/TemporaryFileFilterPlugin.php#L219-L233 |
sabre-io/dav | lib/DAV/TemporaryFileFilterPlugin.php | TemporaryFileFilterPlugin.httpDelete | public function httpDelete(RequestInterface $request, ResponseInterface $hR, $tempLocation)
{
if (!file_exists($tempLocation)) {
return;
}
unlink($tempLocation);
$hR->setHeader('X-Sabre-Temp', 'true');
$hR->setStatus(204);
return false;
} | php | public function httpDelete(RequestInterface $request, ResponseInterface $hR, $tempLocation)
{
if (!file_exists($tempLocation)) {
return;
}
unlink($tempLocation);
$hR->setHeader('X-Sabre-Temp', 'true');
$hR->setStatus(204);
return false;
} | [
"public",
"function",
"httpDelete",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"hR",
",",
"$",
"tempLocation",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"tempLocation",
")",
")",
"{",
"return",
";",
"}",
"unlink",
"(",
"$",
"tempLocation",
")",
";",
"$",
"hR",
"->",
"setHeader",
"(",
"'X-Sabre-Temp'",
",",
"'true'",
")",
";",
"$",
"hR",
"->",
"setStatus",
"(",
"204",
")",
";",
"return",
"false",
";",
"}"
] | This method handles the DELETE method.
If the file didn't exist, it will return false, which will make the
standard HTTP DELETE handler kick in.
@param RequestInterface $request
@param ResponseInterface $hR
@param string $tempLocation
@return bool | [
"This",
"method",
"handles",
"the",
"DELETE",
"method",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/TemporaryFileFilterPlugin.php#L247-L258 |
sabre-io/dav | lib/DAV/TemporaryFileFilterPlugin.php | TemporaryFileFilterPlugin.httpPropfind | public function httpPropfind(RequestInterface $request, ResponseInterface $hR, $tempLocation)
{
if (!file_exists($tempLocation)) {
return;
}
$hR->setHeader('X-Sabre-Temp', 'true');
$hR->setStatus(207);
$hR->setHeader('Content-Type', 'application/xml; charset=utf-8');
$properties = [
'href' => $request->getPath(),
200 => [
'{DAV:}getlastmodified' => new Xml\Property\GetLastModified(filemtime($tempLocation)),
'{DAV:}getcontentlength' => filesize($tempLocation),
'{DAV:}resourcetype' => new Xml\Property\ResourceType(null),
'{'.Server::NS_SABREDAV.'}tempFile' => true,
],
];
$data = $this->server->generateMultiStatus([$properties]);
$hR->setBody($data);
return false;
} | php | public function httpPropfind(RequestInterface $request, ResponseInterface $hR, $tempLocation)
{
if (!file_exists($tempLocation)) {
return;
}
$hR->setHeader('X-Sabre-Temp', 'true');
$hR->setStatus(207);
$hR->setHeader('Content-Type', 'application/xml; charset=utf-8');
$properties = [
'href' => $request->getPath(),
200 => [
'{DAV:}getlastmodified' => new Xml\Property\GetLastModified(filemtime($tempLocation)),
'{DAV:}getcontentlength' => filesize($tempLocation),
'{DAV:}resourcetype' => new Xml\Property\ResourceType(null),
'{'.Server::NS_SABREDAV.'}tempFile' => true,
],
];
$data = $this->server->generateMultiStatus([$properties]);
$hR->setBody($data);
return false;
} | [
"public",
"function",
"httpPropfind",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"hR",
",",
"$",
"tempLocation",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"tempLocation",
")",
")",
"{",
"return",
";",
"}",
"$",
"hR",
"->",
"setHeader",
"(",
"'X-Sabre-Temp'",
",",
"'true'",
")",
";",
"$",
"hR",
"->",
"setStatus",
"(",
"207",
")",
";",
"$",
"hR",
"->",
"setHeader",
"(",
"'Content-Type'",
",",
"'application/xml; charset=utf-8'",
")",
";",
"$",
"properties",
"=",
"[",
"'href'",
"=>",
"$",
"request",
"->",
"getPath",
"(",
")",
",",
"200",
"=>",
"[",
"'{DAV:}getlastmodified'",
"=>",
"new",
"Xml",
"\\",
"Property",
"\\",
"GetLastModified",
"(",
"filemtime",
"(",
"$",
"tempLocation",
")",
")",
",",
"'{DAV:}getcontentlength'",
"=>",
"filesize",
"(",
"$",
"tempLocation",
")",
",",
"'{DAV:}resourcetype'",
"=>",
"new",
"Xml",
"\\",
"Property",
"\\",
"ResourceType",
"(",
"null",
")",
",",
"'{'",
".",
"Server",
"::",
"NS_SABREDAV",
".",
"'}tempFile'",
"=>",
"true",
",",
"]",
",",
"]",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"server",
"->",
"generateMultiStatus",
"(",
"[",
"$",
"properties",
"]",
")",
";",
"$",
"hR",
"->",
"setBody",
"(",
"$",
"data",
")",
";",
"return",
"false",
";",
"}"
] | This method handles the PROPFIND method.
It's a very lazy method, it won't bother checking the request body
for which properties were requested, and just sends back a default
set of properties.
@param RequestInterface $request
@param ResponseInterface $hR
@param string $tempLocation
@return bool | [
"This",
"method",
"handles",
"the",
"PROPFIND",
"method",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/TemporaryFileFilterPlugin.php#L273-L297 |
sabre-io/dav | lib/DAV/Xml/Request/SyncCollectionReport.php | SyncCollectionReport.xmlDeserialize | public static function xmlDeserialize(Reader $reader)
{
$self = new self();
$reader->pushContext();
$reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Element\Elements';
$elems = KeyValue::xmlDeserialize($reader);
$reader->popContext();
$required = [
'{DAV:}sync-token',
'{DAV:}prop',
];
foreach ($required as $elem) {
if (!array_key_exists($elem, $elems)) {
throw new BadRequest('The '.$elem.' element in the {DAV:}sync-collection report is required');
}
}
$self->properties = $elems['{DAV:}prop'];
$self->syncToken = $elems['{DAV:}sync-token'];
if (isset($elems['{DAV:}limit'])) {
$nresults = null;
foreach ($elems['{DAV:}limit'] as $child) {
if ('{DAV:}nresults' === $child['name']) {
$nresults = (int) $child['value'];
}
}
$self->limit = $nresults;
}
if (isset($elems['{DAV:}sync-level'])) {
$value = $elems['{DAV:}sync-level'];
if ('infinity' === $value) {
$value = \Sabre\DAV\Server::DEPTH_INFINITY;
}
$self->syncLevel = $value;
}
return $self;
} | php | public static function xmlDeserialize(Reader $reader)
{
$self = new self();
$reader->pushContext();
$reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Element\Elements';
$elems = KeyValue::xmlDeserialize($reader);
$reader->popContext();
$required = [
'{DAV:}sync-token',
'{DAV:}prop',
];
foreach ($required as $elem) {
if (!array_key_exists($elem, $elems)) {
throw new BadRequest('The '.$elem.' element in the {DAV:}sync-collection report is required');
}
}
$self->properties = $elems['{DAV:}prop'];
$self->syncToken = $elems['{DAV:}sync-token'];
if (isset($elems['{DAV:}limit'])) {
$nresults = null;
foreach ($elems['{DAV:}limit'] as $child) {
if ('{DAV:}nresults' === $child['name']) {
$nresults = (int) $child['value'];
}
}
$self->limit = $nresults;
}
if (isset($elems['{DAV:}sync-level'])) {
$value = $elems['{DAV:}sync-level'];
if ('infinity' === $value) {
$value = \Sabre\DAV\Server::DEPTH_INFINITY;
}
$self->syncLevel = $value;
}
return $self;
} | [
"public",
"static",
"function",
"xmlDeserialize",
"(",
"Reader",
"$",
"reader",
")",
"{",
"$",
"self",
"=",
"new",
"self",
"(",
")",
";",
"$",
"reader",
"->",
"pushContext",
"(",
")",
";",
"$",
"reader",
"->",
"elementMap",
"[",
"'{DAV:}prop'",
"]",
"=",
"'Sabre\\Xml\\Element\\Elements'",
";",
"$",
"elems",
"=",
"KeyValue",
"::",
"xmlDeserialize",
"(",
"$",
"reader",
")",
";",
"$",
"reader",
"->",
"popContext",
"(",
")",
";",
"$",
"required",
"=",
"[",
"'{DAV:}sync-token'",
",",
"'{DAV:}prop'",
",",
"]",
";",
"foreach",
"(",
"$",
"required",
"as",
"$",
"elem",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"elem",
",",
"$",
"elems",
")",
")",
"{",
"throw",
"new",
"BadRequest",
"(",
"'The '",
".",
"$",
"elem",
".",
"' element in the {DAV:}sync-collection report is required'",
")",
";",
"}",
"}",
"$",
"self",
"->",
"properties",
"=",
"$",
"elems",
"[",
"'{DAV:}prop'",
"]",
";",
"$",
"self",
"->",
"syncToken",
"=",
"$",
"elems",
"[",
"'{DAV:}sync-token'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"elems",
"[",
"'{DAV:}limit'",
"]",
")",
")",
"{",
"$",
"nresults",
"=",
"null",
";",
"foreach",
"(",
"$",
"elems",
"[",
"'{DAV:}limit'",
"]",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"'{DAV:}nresults'",
"===",
"$",
"child",
"[",
"'name'",
"]",
")",
"{",
"$",
"nresults",
"=",
"(",
"int",
")",
"$",
"child",
"[",
"'value'",
"]",
";",
"}",
"}",
"$",
"self",
"->",
"limit",
"=",
"$",
"nresults",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"elems",
"[",
"'{DAV:}sync-level'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"elems",
"[",
"'{DAV:}sync-level'",
"]",
";",
"if",
"(",
"'infinity'",
"===",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"\\",
"Sabre",
"\\",
"DAV",
"\\",
"Server",
"::",
"DEPTH_INFINITY",
";",
"}",
"$",
"self",
"->",
"syncLevel",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"self",
";",
"}"
] | The deserialize method is called during xml parsing.
This method is called statically, this is because in theory this method
may be used as a type of constructor, or factory method.
Often you want to return an instance of the current class, but you are
free to return other data as well.
You are responsible for advancing the reader to the next element. Not
doing anything will result in a never-ending loop.
If you just want to skip parsing for this element altogether, you can
just call $reader->next();
$reader->parseInnerTree() will parse the entire sub-tree, and advance to
the next element.
@param Reader $reader
@return mixed | [
"The",
"deserialize",
"method",
"is",
"called",
"during",
"xml",
"parsing",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Request/SyncCollectionReport.php#L75-L119 |
sabre-io/dav | lib/DAVACL/Xml/Request/ExpandPropertyReport.php | ExpandPropertyReport.xmlDeserialize | public static function xmlDeserialize(Reader $reader)
{
$elems = $reader->parseInnerTree();
$obj = new self();
$obj->properties = self::traverse($elems);
return $obj;
} | php | public static function xmlDeserialize(Reader $reader)
{
$elems = $reader->parseInnerTree();
$obj = new self();
$obj->properties = self::traverse($elems);
return $obj;
} | [
"public",
"static",
"function",
"xmlDeserialize",
"(",
"Reader",
"$",
"reader",
")",
"{",
"$",
"elems",
"=",
"$",
"reader",
"->",
"parseInnerTree",
"(",
")",
";",
"$",
"obj",
"=",
"new",
"self",
"(",
")",
";",
"$",
"obj",
"->",
"properties",
"=",
"self",
"::",
"traverse",
"(",
"$",
"elems",
")",
";",
"return",
"$",
"obj",
";",
"}"
] | The deserialize method is called during xml parsing.
This method is called statically, this is because in theory this method
may be used as a type of constructor, or factory method.
Often you want to return an instance of the current class, but you are
free to return other data as well.
You are responsible for advancing the reader to the next element. Not
doing anything will result in a never-ending loop.
If you just want to skip parsing for this element altogether, you can
just call $reader->next();
$reader->parseInnerTree() will parse the entire sub-tree, and advance to
the next element.
@param Reader $reader
@return mixed | [
"The",
"deserialize",
"method",
"is",
"called",
"during",
"xml",
"parsing",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Xml/Request/ExpandPropertyReport.php#L59-L67 |
sabre-io/dav | lib/DAVACL/Xml/Request/ExpandPropertyReport.php | ExpandPropertyReport.traverse | private static function traverse($elems)
{
$result = [];
foreach ($elems as $elem) {
if ('{DAV:}property' !== $elem['name']) {
continue;
}
$namespace = isset($elem['attributes']['namespace']) ?
$elem['attributes']['namespace'] :
'DAV:';
$propName = '{'.$namespace.'}'.$elem['attributes']['name'];
$value = null;
if (is_array($elem['value'])) {
$value = self::traverse($elem['value']);
}
$result[$propName] = $value;
}
return $result;
} | php | private static function traverse($elems)
{
$result = [];
foreach ($elems as $elem) {
if ('{DAV:}property' !== $elem['name']) {
continue;
}
$namespace = isset($elem['attributes']['namespace']) ?
$elem['attributes']['namespace'] :
'DAV:';
$propName = '{'.$namespace.'}'.$elem['attributes']['name'];
$value = null;
if (is_array($elem['value'])) {
$value = self::traverse($elem['value']);
}
$result[$propName] = $value;
}
return $result;
} | [
"private",
"static",
"function",
"traverse",
"(",
"$",
"elems",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"elems",
"as",
"$",
"elem",
")",
"{",
"if",
"(",
"'{DAV:}property'",
"!==",
"$",
"elem",
"[",
"'name'",
"]",
")",
"{",
"continue",
";",
"}",
"$",
"namespace",
"=",
"isset",
"(",
"$",
"elem",
"[",
"'attributes'",
"]",
"[",
"'namespace'",
"]",
")",
"?",
"$",
"elem",
"[",
"'attributes'",
"]",
"[",
"'namespace'",
"]",
":",
"'DAV:'",
";",
"$",
"propName",
"=",
"'{'",
".",
"$",
"namespace",
".",
"'}'",
".",
"$",
"elem",
"[",
"'attributes'",
"]",
"[",
"'name'",
"]",
";",
"$",
"value",
"=",
"null",
";",
"if",
"(",
"is_array",
"(",
"$",
"elem",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"self",
"::",
"traverse",
"(",
"$",
"elem",
"[",
"'value'",
"]",
")",
";",
"}",
"$",
"result",
"[",
"$",
"propName",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | This method is used by deserializeXml, to recursively parse the
{DAV:}property elements.
@param array $elems
@return array | [
"This",
"method",
"is",
"used",
"by",
"deserializeXml",
"to",
"recursively",
"parse",
"the",
"{",
"DAV",
":",
"}",
"property",
"elements",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Xml/Request/ExpandPropertyReport.php#L77-L101 |
sabre-io/dav | lib/DAV/Xml/Property/Href.php | Href.xmlSerialize | public function xmlSerialize(Writer $writer)
{
foreach ($this->getHrefs() as $href) {
$href = Uri\resolve($writer->contextUri, $href);
$writer->writeElement('{DAV:}href', $href);
}
} | php | public function xmlSerialize(Writer $writer)
{
foreach ($this->getHrefs() as $href) {
$href = Uri\resolve($writer->contextUri, $href);
$writer->writeElement('{DAV:}href', $href);
}
} | [
"public",
"function",
"xmlSerialize",
"(",
"Writer",
"$",
"writer",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getHrefs",
"(",
")",
"as",
"$",
"href",
")",
"{",
"$",
"href",
"=",
"Uri",
"\\",
"resolve",
"(",
"$",
"writer",
"->",
"contextUri",
",",
"$",
"href",
")",
";",
"$",
"writer",
"->",
"writeElement",
"(",
"'{DAV:}href'",
",",
"$",
"href",
")",
";",
"}",
"}"
] | The xmlSerialize method is called during xml writing.
Use the $writer argument to write its own xml serialization.
An important note: do _not_ create a parent element. Any element
implementing XmlSerializable should only ever write what's considered
its 'inner xml'.
The parent of the current element is responsible for writing a
containing element.
This allows serializers to be re-used for different element names.
If you are opening new elements, you must also close them again.
@param Writer $writer | [
"The",
"xmlSerialize",
"method",
"is",
"called",
"during",
"xml",
"writing",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Property/Href.php#L93-L99 |
sabre-io/dav | lib/DAV/Xml/Property/Href.php | Href.toHtml | public function toHtml(HtmlOutputHelper $html)
{
$links = [];
foreach ($this->getHrefs() as $href) {
$links[] = $html->link($href);
}
return implode('<br />', $links);
} | php | public function toHtml(HtmlOutputHelper $html)
{
$links = [];
foreach ($this->getHrefs() as $href) {
$links[] = $html->link($href);
}
return implode('<br />', $links);
} | [
"public",
"function",
"toHtml",
"(",
"HtmlOutputHelper",
"$",
"html",
")",
"{",
"$",
"links",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getHrefs",
"(",
")",
"as",
"$",
"href",
")",
"{",
"$",
"links",
"[",
"]",
"=",
"$",
"html",
"->",
"link",
"(",
"$",
"href",
")",
";",
"}",
"return",
"implode",
"(",
"'<br />'",
",",
"$",
"links",
")",
";",
"}"
] | 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/DAV/Xml/Property/Href.php#L116-L124 |
sabre-io/dav | lib/DAV/Xml/Property/Href.php | Href.xmlDeserialize | public static function xmlDeserialize(Reader $reader)
{
$hrefs = [];
foreach ((array) $reader->parseInnerTree() as $elem) {
if ('{DAV:}href' !== $elem['name']) {
continue;
}
$hrefs[] = $elem['value'];
}
if ($hrefs) {
return new self($hrefs);
}
} | php | public static function xmlDeserialize(Reader $reader)
{
$hrefs = [];
foreach ((array) $reader->parseInnerTree() as $elem) {
if ('{DAV:}href' !== $elem['name']) {
continue;
}
$hrefs[] = $elem['value'];
}
if ($hrefs) {
return new self($hrefs);
}
} | [
"public",
"static",
"function",
"xmlDeserialize",
"(",
"Reader",
"$",
"reader",
")",
"{",
"$",
"hrefs",
"=",
"[",
"]",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"reader",
"->",
"parseInnerTree",
"(",
")",
"as",
"$",
"elem",
")",
"{",
"if",
"(",
"'{DAV:}href'",
"!==",
"$",
"elem",
"[",
"'name'",
"]",
")",
"{",
"continue",
";",
"}",
"$",
"hrefs",
"[",
"]",
"=",
"$",
"elem",
"[",
"'value'",
"]",
";",
"}",
"if",
"(",
"$",
"hrefs",
")",
"{",
"return",
"new",
"self",
"(",
"$",
"hrefs",
")",
";",
"}",
"}"
] | 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/Property/Href.php#L148-L161 |
sabre-io/dav | lib/CalDAV/Xml/Property/SupportedCalendarData.php | SupportedCalendarData.xmlSerialize | public function xmlSerialize(Writer $writer)
{
$writer->startElement('{'.Plugin::NS_CALDAV.'}calendar-data');
$writer->writeAttributes([
'content-type' => 'text/calendar',
'version' => '2.0',
]);
$writer->endElement(); // calendar-data
$writer->startElement('{'.Plugin::NS_CALDAV.'}calendar-data');
$writer->writeAttributes([
'content-type' => 'application/calendar+json',
]);
$writer->endElement(); // calendar-data
} | php | public function xmlSerialize(Writer $writer)
{
$writer->startElement('{'.Plugin::NS_CALDAV.'}calendar-data');
$writer->writeAttributes([
'content-type' => 'text/calendar',
'version' => '2.0',
]);
$writer->endElement();
$writer->startElement('{'.Plugin::NS_CALDAV.'}calendar-data');
$writer->writeAttributes([
'content-type' => 'application/calendar+json',
]);
$writer->endElement();
} | [
"public",
"function",
"xmlSerialize",
"(",
"Writer",
"$",
"writer",
")",
"{",
"$",
"writer",
"->",
"startElement",
"(",
"'{'",
".",
"Plugin",
"::",
"NS_CALDAV",
".",
"'}calendar-data'",
")",
";",
"$",
"writer",
"->",
"writeAttributes",
"(",
"[",
"'content-type'",
"=>",
"'text/calendar'",
",",
"'version'",
"=>",
"'2.0'",
",",
"]",
")",
";",
"$",
"writer",
"->",
"endElement",
"(",
")",
";",
"// calendar-data",
"$",
"writer",
"->",
"startElement",
"(",
"'{'",
".",
"Plugin",
"::",
"NS_CALDAV",
".",
"'}calendar-data'",
")",
";",
"$",
"writer",
"->",
"writeAttributes",
"(",
"[",
"'content-type'",
"=>",
"'application/calendar+json'",
",",
"]",
")",
";",
"$",
"writer",
"->",
"endElement",
"(",
")",
";",
"// calendar-data",
"}"
] | The xmlSerialize method is called during xml writing.
Use the $writer argument to write its own xml serialization.
An important note: do _not_ create a parent element. Any element
implementing XmlSerializable should only ever write what's considered
its 'inner xml'.
The parent of the current element is responsible for writing a
containing element.
This allows serializers to be re-used for different element names.
If you are opening new elements, you must also close them again.
@param Writer $writer | [
"The",
"xmlSerialize",
"method",
"is",
"called",
"during",
"xml",
"writing",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Xml/Property/SupportedCalendarData.php#L45-L58 |
sabre-io/dav | lib/CalDAV/Exception/InvalidComponentType.php | InvalidComponentType.serialize | public function serialize(DAV\Server $server, \DOMElement $errorNode)
{
$doc = $errorNode->ownerDocument;
$np = $doc->createElementNS(CalDAV\Plugin::NS_CALDAV, 'cal:supported-calendar-component');
$errorNode->appendChild($np);
} | php | public function serialize(DAV\Server $server, \DOMElement $errorNode)
{
$doc = $errorNode->ownerDocument;
$np = $doc->createElementNS(CalDAV\Plugin::NS_CALDAV, 'cal:supported-calendar-component');
$errorNode->appendChild($np);
} | [
"public",
"function",
"serialize",
"(",
"DAV",
"\\",
"Server",
"$",
"server",
",",
"\\",
"DOMElement",
"$",
"errorNode",
")",
"{",
"$",
"doc",
"=",
"$",
"errorNode",
"->",
"ownerDocument",
";",
"$",
"np",
"=",
"$",
"doc",
"->",
"createElementNS",
"(",
"CalDAV",
"\\",
"Plugin",
"::",
"NS_CALDAV",
",",
"'cal:supported-calendar-component'",
")",
";",
"$",
"errorNode",
"->",
"appendChild",
"(",
"$",
"np",
")",
";",
"}"
] | Adds in extra information in the xml response.
This method adds the {CALDAV:}supported-calendar-component as defined in rfc4791
@param DAV\Server $server
@param \DOMElement $errorNode | [
"Adds",
"in",
"extra",
"information",
"in",
"the",
"xml",
"response",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Exception/InvalidComponentType.php#L27-L33 |
sabre-io/dav | lib/DAV/Xml/Property/SupportedMethodSet.php | SupportedMethodSet.xmlSerialize | public function xmlSerialize(Writer $writer)
{
foreach ($this->getValue() as $val) {
$writer->startElement('{DAV:}supported-method');
$writer->writeAttribute('name', $val);
$writer->endElement();
}
} | php | public function xmlSerialize(Writer $writer)
{
foreach ($this->getValue() as $val) {
$writer->startElement('{DAV:}supported-method');
$writer->writeAttribute('name', $val);
$writer->endElement();
}
} | [
"public",
"function",
"xmlSerialize",
"(",
"Writer",
"$",
"writer",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getValue",
"(",
")",
"as",
"$",
"val",
")",
"{",
"$",
"writer",
"->",
"startElement",
"(",
"'{DAV:}supported-method'",
")",
";",
"$",
"writer",
"->",
"writeAttribute",
"(",
"'name'",
",",
"$",
"val",
")",
";",
"$",
"writer",
"->",
"endElement",
"(",
")",
";",
"}",
"}"
] | The xmlSerialize method is called during xml writing.
Use the $writer argument to write its own xml serialization.
An important note: do _not_ create a parent element. Any element
implementing XmlSerializable should only ever write what's considered
its 'inner xml'.
The parent of the current element is responsible for writing a
containing element.
This allows serializers to be re-used for different element names.
If you are opening new elements, you must also close them again.
@param Writer $writer | [
"The",
"xmlSerialize",
"method",
"is",
"called",
"during",
"xml",
"writing",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Property/SupportedMethodSet.php#L87-L94 |
sabre-io/dav | lib/DAV/Sharing/Plugin.php | Plugin.initialize | public function initialize(Server $server)
{
$this->server = $server;
$server->xml->elementMap['{DAV:}share-resource'] = 'Sabre\\DAV\\Xml\\Request\\ShareResource';
array_push(
$server->protectedProperties,
'{DAV:}share-mode'
);
$server->on('method:POST', [$this, 'httpPost']);
$server->on('propFind', [$this, 'propFind']);
$server->on('getSupportedPrivilegeSet', [$this, 'getSupportedPrivilegeSet']);
$server->on('onHTMLActionsPanel', [$this, 'htmlActionsPanel']);
$server->on('onBrowserPostAction', [$this, 'browserPostAction']);
} | php | public function initialize(Server $server)
{
$this->server = $server;
$server->xml->elementMap['{DAV:}share-resource'] = 'Sabre\\DAV\\Xml\\Request\\ShareResource';
array_push(
$server->protectedProperties,
'{DAV:}share-mode'
);
$server->on('method:POST', [$this, 'httpPost']);
$server->on('propFind', [$this, 'propFind']);
$server->on('getSupportedPrivilegeSet', [$this, 'getSupportedPrivilegeSet']);
$server->on('onHTMLActionsPanel', [$this, 'htmlActionsPanel']);
$server->on('onBrowserPostAction', [$this, 'browserPostAction']);
} | [
"public",
"function",
"initialize",
"(",
"Server",
"$",
"server",
")",
"{",
"$",
"this",
"->",
"server",
"=",
"$",
"server",
";",
"$",
"server",
"->",
"xml",
"->",
"elementMap",
"[",
"'{DAV:}share-resource'",
"]",
"=",
"'Sabre\\\\DAV\\\\Xml\\\\Request\\\\ShareResource'",
";",
"array_push",
"(",
"$",
"server",
"->",
"protectedProperties",
",",
"'{DAV:}share-mode'",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'method:POST'",
",",
"[",
"$",
"this",
",",
"'httpPost'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'propFind'",
",",
"[",
"$",
"this",
",",
"'propFind'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'getSupportedPrivilegeSet'",
",",
"[",
"$",
"this",
",",
"'getSupportedPrivilegeSet'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'onHTMLActionsPanel'",
",",
"[",
"$",
"this",
",",
"'htmlActionsPanel'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'onBrowserPostAction'",
",",
"[",
"$",
"this",
",",
"'browserPostAction'",
"]",
")",
";",
"}"
] | 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/DAV/Sharing/Plugin.php#L85-L101 |
sabre-io/dav | lib/DAV/Sharing/Plugin.php | Plugin.shareResource | public function shareResource($path, array $sharees)
{
$node = $this->server->tree->getNodeForPath($path);
if (!$node instanceof ISharedNode) {
throw new Forbidden('Sharing is not allowed on this node');
}
// Getting ACL info
$acl = $this->server->getPlugin('acl');
// If there's no ACL support, we allow everything
if ($acl) {
$acl->checkPrivileges($path, '{DAV:}share');
}
foreach ($sharees as $sharee) {
// We're going to attempt to get a local principal uri for a share
// href by emitting the getPrincipalByUri event.
$principal = null;
$this->server->emit('getPrincipalByUri', [$sharee->href, &$principal]);
$sharee->principal = $principal;
}
$node->updateInvites($sharees);
} | php | public function shareResource($path, array $sharees)
{
$node = $this->server->tree->getNodeForPath($path);
if (!$node instanceof ISharedNode) {
throw new Forbidden('Sharing is not allowed on this node');
}
$acl = $this->server->getPlugin('acl');
if ($acl) {
$acl->checkPrivileges($path, '{DAV:}share');
}
foreach ($sharees as $sharee) {
$principal = null;
$this->server->emit('getPrincipalByUri', [$sharee->href, &$principal]);
$sharee->principal = $principal;
}
$node->updateInvites($sharees);
} | [
"public",
"function",
"shareResource",
"(",
"$",
"path",
",",
"array",
"$",
"sharees",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"$",
"node",
"instanceof",
"ISharedNode",
")",
"{",
"throw",
"new",
"Forbidden",
"(",
"'Sharing is not allowed on this node'",
")",
";",
"}",
"// Getting ACL info",
"$",
"acl",
"=",
"$",
"this",
"->",
"server",
"->",
"getPlugin",
"(",
"'acl'",
")",
";",
"// If there's no ACL support, we allow everything",
"if",
"(",
"$",
"acl",
")",
"{",
"$",
"acl",
"->",
"checkPrivileges",
"(",
"$",
"path",
",",
"'{DAV:}share'",
")",
";",
"}",
"foreach",
"(",
"$",
"sharees",
"as",
"$",
"sharee",
")",
"{",
"// We're going to attempt to get a local principal uri for a share",
"// href by emitting the getPrincipalByUri event.",
"$",
"principal",
"=",
"null",
";",
"$",
"this",
"->",
"server",
"->",
"emit",
"(",
"'getPrincipalByUri'",
",",
"[",
"$",
"sharee",
"->",
"href",
",",
"&",
"$",
"principal",
"]",
")",
";",
"$",
"sharee",
"->",
"principal",
"=",
"$",
"principal",
";",
"}",
"$",
"node",
"->",
"updateInvites",
"(",
"$",
"sharees",
")",
";",
"}"
] | Updates the list of sharees on a shared resource.
The sharees array is a list of people that are to be added modified
or removed in the list of shares.
@param string $path
@param Sharee[] $sharees | [
"Updates",
"the",
"list",
"of",
"sharees",
"on",
"a",
"shared",
"resource",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Sharing/Plugin.php#L112-L136 |
sabre-io/dav | lib/DAV/Sharing/Plugin.php | Plugin.propFind | public function propFind(PropFind $propFind, INode $node)
{
if ($node instanceof ISharedNode) {
$propFind->handle('{DAV:}share-access', function () use ($node) {
return new Property\ShareAccess($node->getShareAccess());
});
$propFind->handle('{DAV:}invite', function () use ($node) {
return new Property\Invite($node->getInvites());
});
$propFind->handle('{DAV:}share-resource-uri', function () use ($node) {
return new Property\Href($node->getShareResourceUri());
});
}
} | php | public function propFind(PropFind $propFind, INode $node)
{
if ($node instanceof ISharedNode) {
$propFind->handle('{DAV:}share-access', function () use ($node) {
return new Property\ShareAccess($node->getShareAccess());
});
$propFind->handle('{DAV:}invite', function () use ($node) {
return new Property\Invite($node->getInvites());
});
$propFind->handle('{DAV:}share-resource-uri', function () use ($node) {
return new Property\Href($node->getShareResourceUri());
});
}
} | [
"public",
"function",
"propFind",
"(",
"PropFind",
"$",
"propFind",
",",
"INode",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"ISharedNode",
")",
"{",
"$",
"propFind",
"->",
"handle",
"(",
"'{DAV:}share-access'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"node",
")",
"{",
"return",
"new",
"Property",
"\\",
"ShareAccess",
"(",
"$",
"node",
"->",
"getShareAccess",
"(",
")",
")",
";",
"}",
")",
";",
"$",
"propFind",
"->",
"handle",
"(",
"'{DAV:}invite'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"node",
")",
"{",
"return",
"new",
"Property",
"\\",
"Invite",
"(",
"$",
"node",
"->",
"getInvites",
"(",
")",
")",
";",
"}",
")",
";",
"$",
"propFind",
"->",
"handle",
"(",
"'{DAV:}share-resource-uri'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"node",
")",
"{",
"return",
"new",
"Property",
"\\",
"Href",
"(",
"$",
"node",
"->",
"getShareResourceUri",
"(",
")",
")",
";",
"}",
")",
";",
"}",
"}"
] | This event is triggered when properties are requested for nodes.
This allows us to inject any sharings-specific properties.
@param PropFind $propFind
@param INode $node | [
"This",
"event",
"is",
"triggered",
"when",
"properties",
"are",
"requested",
"for",
"nodes",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Sharing/Plugin.php#L146-L159 |
sabre-io/dav | lib/DAV/Sharing/Plugin.php | Plugin.httpPost | public function httpPost(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
$contentType = $request->getHeader('Content-Type');
if (null === $contentType) {
return;
}
// We're only interested in the davsharing content type.
if (false === strpos($contentType, 'application/davsharing+xml')) {
return;
}
$message = $this->server->xml->parse(
$request->getBody(),
$request->getUrl(),
$documentType
);
switch ($documentType) {
case '{DAV:}share-resource':
$this->shareResource($path, $message->sharees);
$response->setStatus(200);
// Adding this because sending a response body may cause issues,
// and I wanted some type of indicator the response was handled.
$response->setHeader('X-Sabre-Status', 'everything-went-well');
// Breaking the event chain
return false;
default:
throw new BadRequest('Unexpected document type: '.$documentType.' for this Content-Type');
}
} | php | public function httpPost(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
$contentType = $request->getHeader('Content-Type');
if (null === $contentType) {
return;
}
if (false === strpos($contentType, 'application/davsharing+xml')) {
return;
}
$message = $this->server->xml->parse(
$request->getBody(),
$request->getUrl(),
$documentType
);
switch ($documentType) {
case '{DAV:}share-resource':
$this->shareResource($path, $message->sharees);
$response->setStatus(200);
$response->setHeader('X-Sabre-Status', 'everything-went-well');
return false;
default:
throw new BadRequest('Unexpected document type: '.$documentType.' for this Content-Type');
}
} | [
"public",
"function",
"httpPost",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"path",
"=",
"$",
"request",
"->",
"getPath",
"(",
")",
";",
"$",
"contentType",
"=",
"$",
"request",
"->",
"getHeader",
"(",
"'Content-Type'",
")",
";",
"if",
"(",
"null",
"===",
"$",
"contentType",
")",
"{",
"return",
";",
"}",
"// We're only interested in the davsharing content type.",
"if",
"(",
"false",
"===",
"strpos",
"(",
"$",
"contentType",
",",
"'application/davsharing+xml'",
")",
")",
"{",
"return",
";",
"}",
"$",
"message",
"=",
"$",
"this",
"->",
"server",
"->",
"xml",
"->",
"parse",
"(",
"$",
"request",
"->",
"getBody",
"(",
")",
",",
"$",
"request",
"->",
"getUrl",
"(",
")",
",",
"$",
"documentType",
")",
";",
"switch",
"(",
"$",
"documentType",
")",
"{",
"case",
"'{DAV:}share-resource'",
":",
"$",
"this",
"->",
"shareResource",
"(",
"$",
"path",
",",
"$",
"message",
"->",
"sharees",
")",
";",
"$",
"response",
"->",
"setStatus",
"(",
"200",
")",
";",
"// Adding this because sending a response body may cause issues,",
"// and I wanted some type of indicator the response was handled.",
"$",
"response",
"->",
"setHeader",
"(",
"'X-Sabre-Status'",
",",
"'everything-went-well'",
")",
";",
"// Breaking the event chain",
"return",
"false",
";",
"default",
":",
"throw",
"new",
"BadRequest",
"(",
"'Unexpected document type: '",
".",
"$",
"documentType",
".",
"' for this Content-Type'",
")",
";",
"}",
"}"
] | We intercept this to handle POST requests on shared resources.
@param RequestInterface $request
@param ResponseInterface $response
@return bool|null | [
"We",
"intercept",
"this",
"to",
"handle",
"POST",
"requests",
"on",
"shared",
"resources",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Sharing/Plugin.php#L169-L203 |
sabre-io/dav | lib/DAV/Sharing/Plugin.php | Plugin.htmlActionsPanel | public function htmlActionsPanel(INode $node, &$output, $path)
{
if (!$node instanceof ISharedNode) {
return;
}
$aclPlugin = $this->server->getPlugin('acl');
if ($aclPlugin) {
if (!$aclPlugin->checkPrivileges($path, '{DAV:}share', \Sabre\DAVACL\Plugin::R_PARENT, false)) {
// Sharing is not permitted, we will not draw this interface.
return;
}
}
$output .= '<tr><td colspan="2"><form method="post" action="">
<h3>Share this resource</h3>
<input type="hidden" name="sabreAction" value="share" />
<label>Share with (uri):</label> <input type="text" name="href" placeholder="mailto:[email protected]"/><br />
<label>Access</label>
<select name="access">
<option value="readwrite">Read-write</option>
<option value="read">Read-only</option>
<option value="no-access">Revoke access</option>
</select><br />
<input type="submit" value="share" />
</form>
</td></tr>';
} | php | public function htmlActionsPanel(INode $node, &$output, $path)
{
if (!$node instanceof ISharedNode) {
return;
}
$aclPlugin = $this->server->getPlugin('acl');
if ($aclPlugin) {
if (!$aclPlugin->checkPrivileges($path, '{DAV:}share', \Sabre\DAVACL\Plugin::R_PARENT, false)) {
return;
}
}
$output .= '<tr><td colspan="2"><form method="post" action="">
<h3>Share this resource</h3>
<input type="hidden" name="sabreAction" value="share" />
<label>Share with (uri):</label> <input type="text" name="href" placeholder="mailto:[email protected]"/><br />
<label>Access</label>
<select name="access">
<option value="readwrite">Read-write</option>
<option value="read">Read-only</option>
<option value="no-access">Revoke access</option>
</select><br />
<input type="submit" value="share" />
</form>
</td></tr>';
} | [
"public",
"function",
"htmlActionsPanel",
"(",
"INode",
"$",
"node",
",",
"&",
"$",
"output",
",",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"$",
"node",
"instanceof",
"ISharedNode",
")",
"{",
"return",
";",
"}",
"$",
"aclPlugin",
"=",
"$",
"this",
"->",
"server",
"->",
"getPlugin",
"(",
"'acl'",
")",
";",
"if",
"(",
"$",
"aclPlugin",
")",
"{",
"if",
"(",
"!",
"$",
"aclPlugin",
"->",
"checkPrivileges",
"(",
"$",
"path",
",",
"'{DAV:}share'",
",",
"\\",
"Sabre",
"\\",
"DAVACL",
"\\",
"Plugin",
"::",
"R_PARENT",
",",
"false",
")",
")",
"{",
"// Sharing is not permitted, we will not draw this interface.",
"return",
";",
"}",
"}",
"$",
"output",
".=",
"'<tr><td colspan=\"2\"><form method=\"post\" action=\"\">\n <h3>Share this resource</h3>\n <input type=\"hidden\" name=\"sabreAction\" value=\"share\" />\n <label>Share with (uri):</label> <input type=\"text\" name=\"href\" placeholder=\"mailto:[email protected]\"/><br />\n <label>Access</label>\n <select name=\"access\">\n <option value=\"readwrite\">Read-write</option>\n <option value=\"read\">Read-only</option>\n <option value=\"no-access\">Revoke access</option>\n </select><br />\n <input type=\"submit\" value=\"share\" />\n </form>\n </td></tr>'",
";",
"}"
] | This method is used to generate HTML output for the
DAV\Browser\Plugin.
@param INode $node
@param string $output
@param string $path
@return bool|null | [
"This",
"method",
"is",
"used",
"to",
"generate",
"HTML",
"output",
"for",
"the",
"DAV",
"\\",
"Browser",
"\\",
"Plugin",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Sharing/Plugin.php#L254-L281 |
sabre-io/dav | lib/DAV/Sharing/Plugin.php | Plugin.browserPostAction | public function browserPostAction($path, $action, $postVars)
{
if ('share' !== $action) {
return;
}
if (empty($postVars['href'])) {
throw new BadRequest('The "href" POST parameter is required');
}
if (empty($postVars['access'])) {
throw new BadRequest('The "access" POST parameter is required');
}
$accessMap = [
'readwrite' => self::ACCESS_READWRITE,
'read' => self::ACCESS_READ,
'no-access' => self::ACCESS_NOACCESS,
];
if (!isset($accessMap[$postVars['access']])) {
throw new BadRequest('The "access" POST must be readwrite, read or no-access');
}
$sharee = new Sharee([
'href' => $postVars['href'],
'access' => $accessMap[$postVars['access']],
]);
$this->shareResource(
$path,
[$sharee]
);
return false;
} | php | public function browserPostAction($path, $action, $postVars)
{
if ('share' !== $action) {
return;
}
if (empty($postVars['href'])) {
throw new BadRequest('The "href" POST parameter is required');
}
if (empty($postVars['access'])) {
throw new BadRequest('The "access" POST parameter is required');
}
$accessMap = [
'readwrite' => self::ACCESS_READWRITE,
'read' => self::ACCESS_READ,
'no-access' => self::ACCESS_NOACCESS,
];
if (!isset($accessMap[$postVars['access']])) {
throw new BadRequest('The "access" POST must be readwrite, read or no-access');
}
$sharee = new Sharee([
'href' => $postVars['href'],
'access' => $accessMap[$postVars['access']],
]);
$this->shareResource(
$path,
[$sharee]
);
return false;
} | [
"public",
"function",
"browserPostAction",
"(",
"$",
"path",
",",
"$",
"action",
",",
"$",
"postVars",
")",
"{",
"if",
"(",
"'share'",
"!==",
"$",
"action",
")",
"{",
"return",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"postVars",
"[",
"'href'",
"]",
")",
")",
"{",
"throw",
"new",
"BadRequest",
"(",
"'The \"href\" POST parameter is required'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"postVars",
"[",
"'access'",
"]",
")",
")",
"{",
"throw",
"new",
"BadRequest",
"(",
"'The \"access\" POST parameter is required'",
")",
";",
"}",
"$",
"accessMap",
"=",
"[",
"'readwrite'",
"=>",
"self",
"::",
"ACCESS_READWRITE",
",",
"'read'",
"=>",
"self",
"::",
"ACCESS_READ",
",",
"'no-access'",
"=>",
"self",
"::",
"ACCESS_NOACCESS",
",",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"accessMap",
"[",
"$",
"postVars",
"[",
"'access'",
"]",
"]",
")",
")",
"{",
"throw",
"new",
"BadRequest",
"(",
"'The \"access\" POST must be readwrite, read or no-access'",
")",
";",
"}",
"$",
"sharee",
"=",
"new",
"Sharee",
"(",
"[",
"'href'",
"=>",
"$",
"postVars",
"[",
"'href'",
"]",
",",
"'access'",
"=>",
"$",
"accessMap",
"[",
"$",
"postVars",
"[",
"'access'",
"]",
"]",
",",
"]",
")",
";",
"$",
"this",
"->",
"shareResource",
"(",
"$",
"path",
",",
"[",
"$",
"sharee",
"]",
")",
";",
"return",
"false",
";",
"}"
] | This method is triggered for POST actions generated by the browser
plugin.
@param string $path
@param string $action
@param array $postVars | [
"This",
"method",
"is",
"triggered",
"for",
"POST",
"actions",
"generated",
"by",
"the",
"browser",
"plugin",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Sharing/Plugin.php#L291-L324 |
sabre-io/dav | lib/DAV/Xml/Request/Lock.php | Lock.xmlDeserialize | public static function xmlDeserialize(Reader $reader)
{
$reader->pushContext();
$reader->elementMap['{DAV:}owner'] = 'Sabre\\Xml\\Element\\XmlFragment';
$values = KeyValue::xmlDeserialize($reader);
$reader->popContext();
$new = new self();
$new->owner = !empty($values['{DAV:}owner']) ? $values['{DAV:}owner']->getXml() : null;
$new->scope = LockInfo::SHARED;
if (isset($values['{DAV:}lockscope'])) {
foreach ($values['{DAV:}lockscope'] as $elem) {
if ('{DAV:}exclusive' === $elem['name']) {
$new->scope = LockInfo::EXCLUSIVE;
}
}
}
return $new;
} | php | public static function xmlDeserialize(Reader $reader)
{
$reader->pushContext();
$reader->elementMap['{DAV:}owner'] = 'Sabre\\Xml\\Element\\XmlFragment';
$values = KeyValue::xmlDeserialize($reader);
$reader->popContext();
$new = new self();
$new->owner = !empty($values['{DAV:}owner']) ? $values['{DAV:}owner']->getXml() : null;
$new->scope = LockInfo::SHARED;
if (isset($values['{DAV:}lockscope'])) {
foreach ($values['{DAV:}lockscope'] as $elem) {
if ('{DAV:}exclusive' === $elem['name']) {
$new->scope = LockInfo::EXCLUSIVE;
}
}
}
return $new;
} | [
"public",
"static",
"function",
"xmlDeserialize",
"(",
"Reader",
"$",
"reader",
")",
"{",
"$",
"reader",
"->",
"pushContext",
"(",
")",
";",
"$",
"reader",
"->",
"elementMap",
"[",
"'{DAV:}owner'",
"]",
"=",
"'Sabre\\\\Xml\\\\Element\\\\XmlFragment'",
";",
"$",
"values",
"=",
"KeyValue",
"::",
"xmlDeserialize",
"(",
"$",
"reader",
")",
";",
"$",
"reader",
"->",
"popContext",
"(",
")",
";",
"$",
"new",
"=",
"new",
"self",
"(",
")",
";",
"$",
"new",
"->",
"owner",
"=",
"!",
"empty",
"(",
"$",
"values",
"[",
"'{DAV:}owner'",
"]",
")",
"?",
"$",
"values",
"[",
"'{DAV:}owner'",
"]",
"->",
"getXml",
"(",
")",
":",
"null",
";",
"$",
"new",
"->",
"scope",
"=",
"LockInfo",
"::",
"SHARED",
";",
"if",
"(",
"isset",
"(",
"$",
"values",
"[",
"'{DAV:}lockscope'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"values",
"[",
"'{DAV:}lockscope'",
"]",
"as",
"$",
"elem",
")",
"{",
"if",
"(",
"'{DAV:}exclusive'",
"===",
"$",
"elem",
"[",
"'name'",
"]",
")",
"{",
"$",
"new",
"->",
"scope",
"=",
"LockInfo",
"::",
"EXCLUSIVE",
";",
"}",
"}",
"}",
"return",
"$",
"new",
";",
"}"
] | The deserialize method is called during xml parsing.
This method is called statically, this is because in theory this method
may be used as a type of constructor, or factory method.
Often you want to return an instance of the current class, but you are
free to return other data as well.
You are responsible for advancing the reader to the next element. Not
doing anything will result in a never-ending loop.
If you just want to skip parsing for this element altogether, you can
just call $reader->next();
$reader->parseInnerTree() will parse the entire sub-tree, and advance to
the next element.
@param Reader $reader
@return mixed | [
"The",
"deserialize",
"method",
"is",
"called",
"during",
"xml",
"parsing",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Request/Lock.php#L63-L85 |
sabre-io/dav | lib/DAV/Xml/Request/MkCol.php | MkCol.xmlDeserialize | public static function xmlDeserialize(Reader $reader)
{
$self = new self();
$elementMap = $reader->elementMap;
$elementMap['{DAV:}prop'] = 'Sabre\DAV\Xml\Element\Prop';
$elementMap['{DAV:}set'] = 'Sabre\Xml\Element\KeyValue';
$elementMap['{DAV:}remove'] = 'Sabre\Xml\Element\KeyValue';
$elems = $reader->parseInnerTree($elementMap);
foreach ($elems as $elem) {
if ('{DAV:}set' === $elem['name']) {
$self->properties = array_merge($self->properties, $elem['value']['{DAV:}prop']);
}
}
return $self;
} | php | public static function xmlDeserialize(Reader $reader)
{
$self = new self();
$elementMap = $reader->elementMap;
$elementMap['{DAV:}prop'] = 'Sabre\DAV\Xml\Element\Prop';
$elementMap['{DAV:}set'] = 'Sabre\Xml\Element\KeyValue';
$elementMap['{DAV:}remove'] = 'Sabre\Xml\Element\KeyValue';
$elems = $reader->parseInnerTree($elementMap);
foreach ($elems as $elem) {
if ('{DAV:}set' === $elem['name']) {
$self->properties = array_merge($self->properties, $elem['value']['{DAV:}prop']);
}
}
return $self;
} | [
"public",
"static",
"function",
"xmlDeserialize",
"(",
"Reader",
"$",
"reader",
")",
"{",
"$",
"self",
"=",
"new",
"self",
"(",
")",
";",
"$",
"elementMap",
"=",
"$",
"reader",
"->",
"elementMap",
";",
"$",
"elementMap",
"[",
"'{DAV:}prop'",
"]",
"=",
"'Sabre\\DAV\\Xml\\Element\\Prop'",
";",
"$",
"elementMap",
"[",
"'{DAV:}set'",
"]",
"=",
"'Sabre\\Xml\\Element\\KeyValue'",
";",
"$",
"elementMap",
"[",
"'{DAV:}remove'",
"]",
"=",
"'Sabre\\Xml\\Element\\KeyValue'",
";",
"$",
"elems",
"=",
"$",
"reader",
"->",
"parseInnerTree",
"(",
"$",
"elementMap",
")",
";",
"foreach",
"(",
"$",
"elems",
"as",
"$",
"elem",
")",
"{",
"if",
"(",
"'{DAV:}set'",
"===",
"$",
"elem",
"[",
"'name'",
"]",
")",
"{",
"$",
"self",
"->",
"properties",
"=",
"array_merge",
"(",
"$",
"self",
"->",
"properties",
",",
"$",
"elem",
"[",
"'value'",
"]",
"[",
"'{DAV:}prop'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"self",
";",
"}"
] | The deserialize method is called during xml parsing.
This method is called statically, this is because in theory this method
may be used as a type of constructor, or factory method.
Often you want to return an instance of the current class, but you are
free to return other data as well.
You are responsible for advancing the reader to the next element. Not
doing anything will result in a never-ending loop.
If you just want to skip parsing for this element altogether, you can
just call $reader->next();
$reader->parseInnerTree() will parse the entire sub-tree, and advance to
the next element.
@param Reader $reader
@return mixed | [
"The",
"deserialize",
"method",
"is",
"called",
"during",
"xml",
"parsing",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Request/MkCol.php#L63-L81 |
sabre-io/dav | lib/CalDAV/Schedule/Inbox.php | Inbox.getChildren | public function getChildren()
{
$objs = $this->caldavBackend->getSchedulingObjects($this->principalUri);
$children = [];
foreach ($objs as $obj) {
//$obj['acl'] = $this->getACL();
$obj['principaluri'] = $this->principalUri;
$children[] = new SchedulingObject($this->caldavBackend, $obj);
}
return $children;
} | php | public function getChildren()
{
$objs = $this->caldavBackend->getSchedulingObjects($this->principalUri);
$children = [];
foreach ($objs as $obj) {
$obj['principaluri'] = $this->principalUri;
$children[] = new SchedulingObject($this->caldavBackend, $obj);
}
return $children;
} | [
"public",
"function",
"getChildren",
"(",
")",
"{",
"$",
"objs",
"=",
"$",
"this",
"->",
"caldavBackend",
"->",
"getSchedulingObjects",
"(",
"$",
"this",
"->",
"principalUri",
")",
";",
"$",
"children",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"objs",
"as",
"$",
"obj",
")",
"{",
"//$obj['acl'] = $this->getACL();",
"$",
"obj",
"[",
"'principaluri'",
"]",
"=",
"$",
"this",
"->",
"principalUri",
";",
"$",
"children",
"[",
"]",
"=",
"new",
"SchedulingObject",
"(",
"$",
"this",
"->",
"caldavBackend",
",",
"$",
"obj",
")",
";",
"}",
"return",
"$",
"children",
";",
"}"
] | Returns an array with all the child nodes.
@return \Sabre\DAV\INode[] | [
"Returns",
"an",
"array",
"with",
"all",
"the",
"child",
"nodes",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/Inbox.php#L67-L78 |
sabre-io/dav | lib/CalDAV/Schedule/Inbox.php | Inbox.createFile | public function createFile($name, $data = null)
{
$this->caldavBackend->createSchedulingObject($this->principalUri, $name, $data);
} | php | public function createFile($name, $data = null)
{
$this->caldavBackend->createSchedulingObject($this->principalUri, $name, $data);
} | [
"public",
"function",
"createFile",
"(",
"$",
"name",
",",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"caldavBackend",
"->",
"createSchedulingObject",
"(",
"$",
"this",
"->",
"principalUri",
",",
"$",
"name",
",",
"$",
"data",
")",
";",
"}"
] | 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/CalDAV/Schedule/Inbox.php#L105-L108 |
sabre-io/dav | lib/CalDAV/Schedule/Inbox.php | Inbox.getACL | public function getACL()
{
return [
[
'privilege' => '{DAV:}read',
'principal' => '{DAV:}authenticated',
'protected' => true,
],
[
'privilege' => '{DAV:}write-properties',
'principal' => $this->getOwner(),
'protected' => true,
],
[
'privilege' => '{DAV:}unbind',
'principal' => $this->getOwner(),
'protected' => true,
],
[
'privilege' => '{DAV:}unbind',
'principal' => $this->getOwner().'/calendar-proxy-write',
'protected' => true,
],
[
'privilege' => '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-deliver',
'principal' => '{DAV:}authenticated',
'protected' => true,
],
];
} | php | public function getACL()
{
return [
[
'privilege' => '{DAV:}read',
'principal' => '{DAV:}authenticated',
'protected' => true,
],
[
'privilege' => '{DAV:}write-properties',
'principal' => $this->getOwner(),
'protected' => true,
],
[
'privilege' => '{DAV:}unbind',
'principal' => $this->getOwner(),
'protected' => true,
],
[
'privilege' => '{DAV:}unbind',
'principal' => $this->getOwner().'/calendar-proxy-write',
'protected' => true,
],
[
'privilege' => '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-deliver',
'principal' => '{DAV:}authenticated',
'protected' => true,
],
];
} | [
"public",
"function",
"getACL",
"(",
")",
"{",
"return",
"[",
"[",
"'privilege'",
"=>",
"'{DAV:}read'",
",",
"'principal'",
"=>",
"'{DAV:}authenticated'",
",",
"'protected'",
"=>",
"true",
",",
"]",
",",
"[",
"'privilege'",
"=>",
"'{DAV:}write-properties'",
",",
"'principal'",
"=>",
"$",
"this",
"->",
"getOwner",
"(",
")",
",",
"'protected'",
"=>",
"true",
",",
"]",
",",
"[",
"'privilege'",
"=>",
"'{DAV:}unbind'",
",",
"'principal'",
"=>",
"$",
"this",
"->",
"getOwner",
"(",
")",
",",
"'protected'",
"=>",
"true",
",",
"]",
",",
"[",
"'privilege'",
"=>",
"'{DAV:}unbind'",
",",
"'principal'",
"=>",
"$",
"this",
"->",
"getOwner",
"(",
")",
".",
"'/calendar-proxy-write'",
",",
"'protected'",
"=>",
"true",
",",
"]",
",",
"[",
"'privilege'",
"=>",
"'{'",
".",
"CalDAV",
"\\",
"Plugin",
"::",
"NS_CALDAV",
".",
"'}schedule-deliver'",
",",
"'principal'",
"=>",
"'{DAV:}authenticated'",
",",
"'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/Schedule/Inbox.php#L134-L163 |
sabre-io/dav | lib/CalDAV/Schedule/Inbox.php | Inbox.calendarQuery | public function calendarQuery(array $filters)
{
$result = [];
$validator = new CalDAV\CalendarQueryValidator();
$objects = $this->caldavBackend->getSchedulingObjects($this->principalUri);
foreach ($objects as $object) {
$vObject = VObject\Reader::read($object['calendardata']);
if ($validator->validate($vObject, $filters)) {
$result[] = $object['uri'];
}
// Destroy circular references to PHP will GC the object.
$vObject->destroy();
}
return $result;
} | php | public function calendarQuery(array $filters)
{
$result = [];
$validator = new CalDAV\CalendarQueryValidator();
$objects = $this->caldavBackend->getSchedulingObjects($this->principalUri);
foreach ($objects as $object) {
$vObject = VObject\Reader::read($object['calendardata']);
if ($validator->validate($vObject, $filters)) {
$result[] = $object['uri'];
}
$vObject->destroy();
}
return $result;
} | [
"public",
"function",
"calendarQuery",
"(",
"array",
"$",
"filters",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"validator",
"=",
"new",
"CalDAV",
"\\",
"CalendarQueryValidator",
"(",
")",
";",
"$",
"objects",
"=",
"$",
"this",
"->",
"caldavBackend",
"->",
"getSchedulingObjects",
"(",
"$",
"this",
"->",
"principalUri",
")",
";",
"foreach",
"(",
"$",
"objects",
"as",
"$",
"object",
")",
"{",
"$",
"vObject",
"=",
"VObject",
"\\",
"Reader",
"::",
"read",
"(",
"$",
"object",
"[",
"'calendardata'",
"]",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"validate",
"(",
"$",
"vObject",
",",
"$",
"filters",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"object",
"[",
"'uri'",
"]",
";",
"}",
"// Destroy circular references to PHP will GC the object.",
"$",
"vObject",
"->",
"destroy",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Performs a calendar-query on the contents of this calendar.
The calendar-query is defined in RFC4791 : CalDAV. Using the
calendar-query it is possible for a client to request a specific set of
object, based on contents of iCalendar properties, date-ranges and
iCalendar component types (VTODO, VEVENT).
This method should just return a list of (relative) urls that match this
query.
The list of filters are specified as an array. The exact array is
documented by \Sabre\CalDAV\CalendarQueryParser.
@param array $filters
@return array | [
"Performs",
"a",
"calendar",
"-",
"query",
"on",
"the",
"contents",
"of",
"this",
"calendar",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/Inbox.php#L183-L200 |
sabre-io/dav | lib/DAV/Xml/Property/ShareAccess.php | ShareAccess.xmlSerialize | public function xmlSerialize(Writer $writer)
{
switch ($this->value) {
case SharingPlugin::ACCESS_NOTSHARED:
$writer->writeElement('{DAV:}not-shared');
break;
case SharingPlugin::ACCESS_SHAREDOWNER:
$writer->writeElement('{DAV:}shared-owner');
break;
case SharingPlugin::ACCESS_READ:
$writer->writeElement('{DAV:}read');
break;
case SharingPlugin::ACCESS_READWRITE:
$writer->writeElement('{DAV:}read-write');
break;
case SharingPlugin::ACCESS_NOACCESS:
$writer->writeElement('{DAV:}no-access');
break;
}
} | php | public function xmlSerialize(Writer $writer)
{
switch ($this->value) {
case SharingPlugin::ACCESS_NOTSHARED:
$writer->writeElement('{DAV:}not-shared');
break;
case SharingPlugin::ACCESS_SHAREDOWNER:
$writer->writeElement('{DAV:}shared-owner');
break;
case SharingPlugin::ACCESS_READ:
$writer->writeElement('{DAV:}read');
break;
case SharingPlugin::ACCESS_READWRITE:
$writer->writeElement('{DAV:}read-write');
break;
case SharingPlugin::ACCESS_NOACCESS:
$writer->writeElement('{DAV:}no-access');
break;
}
} | [
"public",
"function",
"xmlSerialize",
"(",
"Writer",
"$",
"writer",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"value",
")",
"{",
"case",
"SharingPlugin",
"::",
"ACCESS_NOTSHARED",
":",
"$",
"writer",
"->",
"writeElement",
"(",
"'{DAV:}not-shared'",
")",
";",
"break",
";",
"case",
"SharingPlugin",
"::",
"ACCESS_SHAREDOWNER",
":",
"$",
"writer",
"->",
"writeElement",
"(",
"'{DAV:}shared-owner'",
")",
";",
"break",
";",
"case",
"SharingPlugin",
"::",
"ACCESS_READ",
":",
"$",
"writer",
"->",
"writeElement",
"(",
"'{DAV:}read'",
")",
";",
"break",
";",
"case",
"SharingPlugin",
"::",
"ACCESS_READWRITE",
":",
"$",
"writer",
"->",
"writeElement",
"(",
"'{DAV:}read-write'",
")",
";",
"break",
";",
"case",
"SharingPlugin",
"::",
"ACCESS_NOACCESS",
":",
"$",
"writer",
"->",
"writeElement",
"(",
"'{DAV:}no-access'",
")",
";",
"break",
";",
"}",
"}"
] | The xmlSerialize method is called during xml writing.
Use the $writer argument to write its own xml serialization.
An important note: do _not_ create a parent element. Any element
implementing XmlSerializable should only ever write what's considered
its 'inner xml'.
The parent of the current element is responsible for writing a
containing element.
This allows serializers to be re-used for different element names.
If you are opening new elements, you must also close them again.
@param Writer $writer | [
"The",
"xmlSerialize",
"method",
"is",
"called",
"during",
"xml",
"writing",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Property/ShareAccess.php#L77-L96 |
sabre-io/dav | lib/DAV/Xml/Property/ShareAccess.php | ShareAccess.xmlDeserialize | public static function xmlDeserialize(Reader $reader)
{
$elems = $reader->parseInnerTree();
foreach ($elems as $elem) {
switch ($elem['name']) {
case '{DAV:}not-shared':
return new self(SharingPlugin::ACCESS_NOTSHARED);
case '{DAV:}shared-owner':
return new self(SharingPlugin::ACCESS_SHAREDOWNER);
case '{DAV:}read':
return new self(SharingPlugin::ACCESS_READ);
case '{DAV:}read-write':
return new self(SharingPlugin::ACCESS_READWRITE);
case '{DAV:}no-access':
return new self(SharingPlugin::ACCESS_NOACCESS);
}
}
throw new BadRequest('Invalid value for {DAV:}share-access element');
} | php | public static function xmlDeserialize(Reader $reader)
{
$elems = $reader->parseInnerTree();
foreach ($elems as $elem) {
switch ($elem['name']) {
case '{DAV:}not-shared':
return new self(SharingPlugin::ACCESS_NOTSHARED);
case '{DAV:}shared-owner':
return new self(SharingPlugin::ACCESS_SHAREDOWNER);
case '{DAV:}read':
return new self(SharingPlugin::ACCESS_READ);
case '{DAV:}read-write':
return new self(SharingPlugin::ACCESS_READWRITE);
case '{DAV:}no-access':
return new self(SharingPlugin::ACCESS_NOACCESS);
}
}
throw new BadRequest('Invalid value for {DAV:}share-access element');
} | [
"public",
"static",
"function",
"xmlDeserialize",
"(",
"Reader",
"$",
"reader",
")",
"{",
"$",
"elems",
"=",
"$",
"reader",
"->",
"parseInnerTree",
"(",
")",
";",
"foreach",
"(",
"$",
"elems",
"as",
"$",
"elem",
")",
"{",
"switch",
"(",
"$",
"elem",
"[",
"'name'",
"]",
")",
"{",
"case",
"'{DAV:}not-shared'",
":",
"return",
"new",
"self",
"(",
"SharingPlugin",
"::",
"ACCESS_NOTSHARED",
")",
";",
"case",
"'{DAV:}shared-owner'",
":",
"return",
"new",
"self",
"(",
"SharingPlugin",
"::",
"ACCESS_SHAREDOWNER",
")",
";",
"case",
"'{DAV:}read'",
":",
"return",
"new",
"self",
"(",
"SharingPlugin",
"::",
"ACCESS_READ",
")",
";",
"case",
"'{DAV:}read-write'",
":",
"return",
"new",
"self",
"(",
"SharingPlugin",
"::",
"ACCESS_READWRITE",
")",
";",
"case",
"'{DAV:}no-access'",
":",
"return",
"new",
"self",
"(",
"SharingPlugin",
"::",
"ACCESS_NOACCESS",
")",
";",
"}",
"}",
"throw",
"new",
"BadRequest",
"(",
"'Invalid value for {DAV:}share-access element'",
")",
";",
"}"
] | 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/Property/ShareAccess.php#L120-L138 |
sabre-io/dav | lib/DAV/Server.php | Server.start | public function start()
{
try {
// If nginx (pre-1.2) is used as a proxy server, and SabreDAV as an
// origin, we must make sure we send back HTTP/1.0 if this was
// requested.
// This is mainly because nginx doesn't support Chunked Transfer
// Encoding, and this forces the webserver SabreDAV is running on,
// to buffer entire responses to calculate Content-Length.
$this->httpResponse->setHTTPVersion($this->httpRequest->getHTTPVersion());
// Setting the base url
$this->httpRequest->setBaseUrl($this->getBaseUri());
$this->invokeMethod($this->httpRequest, $this->httpResponse);
} catch (\Throwable $e) {
try {
$this->emit('exception', [$e]);
} catch (\Exception $ignore) {
}
$DOM = new \DOMDocument('1.0', 'utf-8');
$DOM->formatOutput = true;
$error = $DOM->createElementNS('DAV:', 'd:error');
$error->setAttribute('xmlns:s', self::NS_SABREDAV);
$DOM->appendChild($error);
$h = function ($v) {
return htmlspecialchars((string) $v, ENT_NOQUOTES, 'UTF-8');
};
if (self::$exposeVersion) {
$error->appendChild($DOM->createElement('s:sabredav-version', $h(Version::VERSION)));
}
$error->appendChild($DOM->createElement('s:exception', $h(get_class($e))));
$error->appendChild($DOM->createElement('s:message', $h($e->getMessage())));
if ($this->debugExceptions) {
$error->appendChild($DOM->createElement('s:file', $h($e->getFile())));
$error->appendChild($DOM->createElement('s:line', $h($e->getLine())));
$error->appendChild($DOM->createElement('s:code', $h($e->getCode())));
$error->appendChild($DOM->createElement('s:stacktrace', $h($e->getTraceAsString())));
}
if ($this->debugExceptions) {
$previous = $e;
while ($previous = $previous->getPrevious()) {
$xPrevious = $DOM->createElement('s:previous-exception');
$xPrevious->appendChild($DOM->createElement('s:exception', $h(get_class($previous))));
$xPrevious->appendChild($DOM->createElement('s:message', $h($previous->getMessage())));
$xPrevious->appendChild($DOM->createElement('s:file', $h($previous->getFile())));
$xPrevious->appendChild($DOM->createElement('s:line', $h($previous->getLine())));
$xPrevious->appendChild($DOM->createElement('s:code', $h($previous->getCode())));
$xPrevious->appendChild($DOM->createElement('s:stacktrace', $h($previous->getTraceAsString())));
$error->appendChild($xPrevious);
}
}
if ($e instanceof Exception) {
$httpCode = $e->getHTTPCode();
$e->serialize($this, $error);
$headers = $e->getHTTPHeaders($this);
} else {
$httpCode = 500;
$headers = [];
}
$headers['Content-Type'] = 'application/xml; charset=utf-8';
$this->httpResponse->setStatus($httpCode);
$this->httpResponse->setHeaders($headers);
$this->httpResponse->setBody($DOM->saveXML());
$this->sapi->sendResponse($this->httpResponse);
}
} | php | public function start()
{
try {
$this->httpResponse->setHTTPVersion($this->httpRequest->getHTTPVersion());
$this->httpRequest->setBaseUrl($this->getBaseUri());
$this->invokeMethod($this->httpRequest, $this->httpResponse);
} catch (\Throwable $e) {
try {
$this->emit('exception', [$e]);
} catch (\Exception $ignore) {
}
$DOM = new \DOMDocument('1.0', 'utf-8');
$DOM->formatOutput = true;
$error = $DOM->createElementNS('DAV:', 'd:error');
$error->setAttribute('xmlns:s', self::NS_SABREDAV);
$DOM->appendChild($error);
$h = function ($v) {
return htmlspecialchars((string) $v, ENT_NOQUOTES, 'UTF-8');
};
if (self::$exposeVersion) {
$error->appendChild($DOM->createElement('s:sabredav-version', $h(Version::VERSION)));
}
$error->appendChild($DOM->createElement('s:exception', $h(get_class($e))));
$error->appendChild($DOM->createElement('s:message', $h($e->getMessage())));
if ($this->debugExceptions) {
$error->appendChild($DOM->createElement('s:file', $h($e->getFile())));
$error->appendChild($DOM->createElement('s:line', $h($e->getLine())));
$error->appendChild($DOM->createElement('s:code', $h($e->getCode())));
$error->appendChild($DOM->createElement('s:stacktrace', $h($e->getTraceAsString())));
}
if ($this->debugExceptions) {
$previous = $e;
while ($previous = $previous->getPrevious()) {
$xPrevious = $DOM->createElement('s:previous-exception');
$xPrevious->appendChild($DOM->createElement('s:exception', $h(get_class($previous))));
$xPrevious->appendChild($DOM->createElement('s:message', $h($previous->getMessage())));
$xPrevious->appendChild($DOM->createElement('s:file', $h($previous->getFile())));
$xPrevious->appendChild($DOM->createElement('s:line', $h($previous->getLine())));
$xPrevious->appendChild($DOM->createElement('s:code', $h($previous->getCode())));
$xPrevious->appendChild($DOM->createElement('s:stacktrace', $h($previous->getTraceAsString())));
$error->appendChild($xPrevious);
}
}
if ($e instanceof Exception) {
$httpCode = $e->getHTTPCode();
$e->serialize($this, $error);
$headers = $e->getHTTPHeaders($this);
} else {
$httpCode = 500;
$headers = [];
}
$headers['Content-Type'] = 'application/xml; charset=utf-8';
$this->httpResponse->setStatus($httpCode);
$this->httpResponse->setHeaders($headers);
$this->httpResponse->setBody($DOM->saveXML());
$this->sapi->sendResponse($this->httpResponse);
}
} | [
"public",
"function",
"start",
"(",
")",
"{",
"try",
"{",
"// If nginx (pre-1.2) is used as a proxy server, and SabreDAV as an",
"// origin, we must make sure we send back HTTP/1.0 if this was",
"// requested.",
"// This is mainly because nginx doesn't support Chunked Transfer",
"// Encoding, and this forces the webserver SabreDAV is running on,",
"// to buffer entire responses to calculate Content-Length.",
"$",
"this",
"->",
"httpResponse",
"->",
"setHTTPVersion",
"(",
"$",
"this",
"->",
"httpRequest",
"->",
"getHTTPVersion",
"(",
")",
")",
";",
"// Setting the base url",
"$",
"this",
"->",
"httpRequest",
"->",
"setBaseUrl",
"(",
"$",
"this",
"->",
"getBaseUri",
"(",
")",
")",
";",
"$",
"this",
"->",
"invokeMethod",
"(",
"$",
"this",
"->",
"httpRequest",
",",
"$",
"this",
"->",
"httpResponse",
")",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"emit",
"(",
"'exception'",
",",
"[",
"$",
"e",
"]",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ignore",
")",
"{",
"}",
"$",
"DOM",
"=",
"new",
"\\",
"DOMDocument",
"(",
"'1.0'",
",",
"'utf-8'",
")",
";",
"$",
"DOM",
"->",
"formatOutput",
"=",
"true",
";",
"$",
"error",
"=",
"$",
"DOM",
"->",
"createElementNS",
"(",
"'DAV:'",
",",
"'d:error'",
")",
";",
"$",
"error",
"->",
"setAttribute",
"(",
"'xmlns:s'",
",",
"self",
"::",
"NS_SABREDAV",
")",
";",
"$",
"DOM",
"->",
"appendChild",
"(",
"$",
"error",
")",
";",
"$",
"h",
"=",
"function",
"(",
"$",
"v",
")",
"{",
"return",
"htmlspecialchars",
"(",
"(",
"string",
")",
"$",
"v",
",",
"ENT_NOQUOTES",
",",
"'UTF-8'",
")",
";",
"}",
";",
"if",
"(",
"self",
"::",
"$",
"exposeVersion",
")",
"{",
"$",
"error",
"->",
"appendChild",
"(",
"$",
"DOM",
"->",
"createElement",
"(",
"'s:sabredav-version'",
",",
"$",
"h",
"(",
"Version",
"::",
"VERSION",
")",
")",
")",
";",
"}",
"$",
"error",
"->",
"appendChild",
"(",
"$",
"DOM",
"->",
"createElement",
"(",
"'s:exception'",
",",
"$",
"h",
"(",
"get_class",
"(",
"$",
"e",
")",
")",
")",
")",
";",
"$",
"error",
"->",
"appendChild",
"(",
"$",
"DOM",
"->",
"createElement",
"(",
"'s:message'",
",",
"$",
"h",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"debugExceptions",
")",
"{",
"$",
"error",
"->",
"appendChild",
"(",
"$",
"DOM",
"->",
"createElement",
"(",
"'s:file'",
",",
"$",
"h",
"(",
"$",
"e",
"->",
"getFile",
"(",
")",
")",
")",
")",
";",
"$",
"error",
"->",
"appendChild",
"(",
"$",
"DOM",
"->",
"createElement",
"(",
"'s:line'",
",",
"$",
"h",
"(",
"$",
"e",
"->",
"getLine",
"(",
")",
")",
")",
")",
";",
"$",
"error",
"->",
"appendChild",
"(",
"$",
"DOM",
"->",
"createElement",
"(",
"'s:code'",
",",
"$",
"h",
"(",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
")",
")",
";",
"$",
"error",
"->",
"appendChild",
"(",
"$",
"DOM",
"->",
"createElement",
"(",
"'s:stacktrace'",
",",
"$",
"h",
"(",
"$",
"e",
"->",
"getTraceAsString",
"(",
")",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"debugExceptions",
")",
"{",
"$",
"previous",
"=",
"$",
"e",
";",
"while",
"(",
"$",
"previous",
"=",
"$",
"previous",
"->",
"getPrevious",
"(",
")",
")",
"{",
"$",
"xPrevious",
"=",
"$",
"DOM",
"->",
"createElement",
"(",
"'s:previous-exception'",
")",
";",
"$",
"xPrevious",
"->",
"appendChild",
"(",
"$",
"DOM",
"->",
"createElement",
"(",
"'s:exception'",
",",
"$",
"h",
"(",
"get_class",
"(",
"$",
"previous",
")",
")",
")",
")",
";",
"$",
"xPrevious",
"->",
"appendChild",
"(",
"$",
"DOM",
"->",
"createElement",
"(",
"'s:message'",
",",
"$",
"h",
"(",
"$",
"previous",
"->",
"getMessage",
"(",
")",
")",
")",
")",
";",
"$",
"xPrevious",
"->",
"appendChild",
"(",
"$",
"DOM",
"->",
"createElement",
"(",
"'s:file'",
",",
"$",
"h",
"(",
"$",
"previous",
"->",
"getFile",
"(",
")",
")",
")",
")",
";",
"$",
"xPrevious",
"->",
"appendChild",
"(",
"$",
"DOM",
"->",
"createElement",
"(",
"'s:line'",
",",
"$",
"h",
"(",
"$",
"previous",
"->",
"getLine",
"(",
")",
")",
")",
")",
";",
"$",
"xPrevious",
"->",
"appendChild",
"(",
"$",
"DOM",
"->",
"createElement",
"(",
"'s:code'",
",",
"$",
"h",
"(",
"$",
"previous",
"->",
"getCode",
"(",
")",
")",
")",
")",
";",
"$",
"xPrevious",
"->",
"appendChild",
"(",
"$",
"DOM",
"->",
"createElement",
"(",
"'s:stacktrace'",
",",
"$",
"h",
"(",
"$",
"previous",
"->",
"getTraceAsString",
"(",
")",
")",
")",
")",
";",
"$",
"error",
"->",
"appendChild",
"(",
"$",
"xPrevious",
")",
";",
"}",
"}",
"if",
"(",
"$",
"e",
"instanceof",
"Exception",
")",
"{",
"$",
"httpCode",
"=",
"$",
"e",
"->",
"getHTTPCode",
"(",
")",
";",
"$",
"e",
"->",
"serialize",
"(",
"$",
"this",
",",
"$",
"error",
")",
";",
"$",
"headers",
"=",
"$",
"e",
"->",
"getHTTPHeaders",
"(",
"$",
"this",
")",
";",
"}",
"else",
"{",
"$",
"httpCode",
"=",
"500",
";",
"$",
"headers",
"=",
"[",
"]",
";",
"}",
"$",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"'application/xml; charset=utf-8'",
";",
"$",
"this",
"->",
"httpResponse",
"->",
"setStatus",
"(",
"$",
"httpCode",
")",
";",
"$",
"this",
"->",
"httpResponse",
"->",
"setHeaders",
"(",
"$",
"headers",
")",
";",
"$",
"this",
"->",
"httpResponse",
"->",
"setBody",
"(",
"$",
"DOM",
"->",
"saveXML",
"(",
")",
")",
";",
"$",
"this",
"->",
"sapi",
"->",
"sendResponse",
"(",
"$",
"this",
"->",
"httpResponse",
")",
";",
"}",
"}"
] | Starts the DAV Server. | [
"Starts",
"the",
"DAV",
"Server",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L228-L300 |
sabre-io/dav | lib/DAV/Server.php | Server.getBaseUri | public function getBaseUri()
{
if (is_null($this->baseUri)) {
$this->baseUri = $this->guessBaseUri();
}
return $this->baseUri;
} | php | public function getBaseUri()
{
if (is_null($this->baseUri)) {
$this->baseUri = $this->guessBaseUri();
}
return $this->baseUri;
} | [
"public",
"function",
"getBaseUri",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"baseUri",
")",
")",
"{",
"$",
"this",
"->",
"baseUri",
"=",
"$",
"this",
"->",
"guessBaseUri",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"baseUri",
";",
"}"
] | Returns the base responding uri.
@return string | [
"Returns",
"the",
"base",
"responding",
"uri",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L332-L339 |
sabre-io/dav | lib/DAV/Server.php | Server.guessBaseUri | public function guessBaseUri()
{
$pathInfo = $this->httpRequest->getRawServerValue('PATH_INFO');
$uri = $this->httpRequest->getRawServerValue('REQUEST_URI');
// If PATH_INFO is found, we can assume it's accurate.
if (!empty($pathInfo)) {
// We need to make sure we ignore the QUERY_STRING part
if ($pos = strpos($uri, '?')) {
$uri = substr($uri, 0, $pos);
}
// PATH_INFO is only set for urls, such as: /example.php/path
// in that case PATH_INFO contains '/path'.
// Note that REQUEST_URI is percent encoded, while PATH_INFO is
// not, Therefore they are only comparable if we first decode
// REQUEST_INFO as well.
$decodedUri = HTTP\decodePath($uri);
// A simple sanity check:
if (substr($decodedUri, strlen($decodedUri) - strlen($pathInfo)) === $pathInfo) {
$baseUri = substr($decodedUri, 0, strlen($decodedUri) - strlen($pathInfo));
return rtrim($baseUri, '/').'/';
}
throw new Exception('The REQUEST_URI ('.$uri.') did not end with the contents of PATH_INFO ('.$pathInfo.'). This server might be misconfigured.');
}
// The last fallback is that we're just going to assume the server root.
return '/';
} | php | public function guessBaseUri()
{
$pathInfo = $this->httpRequest->getRawServerValue('PATH_INFO');
$uri = $this->httpRequest->getRawServerValue('REQUEST_URI');
if (!empty($pathInfo)) {
if ($pos = strpos($uri, '?')) {
$uri = substr($uri, 0, $pos);
}
$decodedUri = HTTP\decodePath($uri);
if (substr($decodedUri, strlen($decodedUri) - strlen($pathInfo)) === $pathInfo) {
$baseUri = substr($decodedUri, 0, strlen($decodedUri) - strlen($pathInfo));
return rtrim($baseUri, '/').'/';
}
throw new Exception('The REQUEST_URI ('.$uri.') did not end with the contents of PATH_INFO ('.$pathInfo.'). This server might be misconfigured.');
}
return '/';
} | [
"public",
"function",
"guessBaseUri",
"(",
")",
"{",
"$",
"pathInfo",
"=",
"$",
"this",
"->",
"httpRequest",
"->",
"getRawServerValue",
"(",
"'PATH_INFO'",
")",
";",
"$",
"uri",
"=",
"$",
"this",
"->",
"httpRequest",
"->",
"getRawServerValue",
"(",
"'REQUEST_URI'",
")",
";",
"// If PATH_INFO is found, we can assume it's accurate.",
"if",
"(",
"!",
"empty",
"(",
"$",
"pathInfo",
")",
")",
"{",
"// We need to make sure we ignore the QUERY_STRING part",
"if",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"uri",
",",
"'?'",
")",
")",
"{",
"$",
"uri",
"=",
"substr",
"(",
"$",
"uri",
",",
"0",
",",
"$",
"pos",
")",
";",
"}",
"// PATH_INFO is only set for urls, such as: /example.php/path",
"// in that case PATH_INFO contains '/path'.",
"// Note that REQUEST_URI is percent encoded, while PATH_INFO is",
"// not, Therefore they are only comparable if we first decode",
"// REQUEST_INFO as well.",
"$",
"decodedUri",
"=",
"HTTP",
"\\",
"decodePath",
"(",
"$",
"uri",
")",
";",
"// A simple sanity check:",
"if",
"(",
"substr",
"(",
"$",
"decodedUri",
",",
"strlen",
"(",
"$",
"decodedUri",
")",
"-",
"strlen",
"(",
"$",
"pathInfo",
")",
")",
"===",
"$",
"pathInfo",
")",
"{",
"$",
"baseUri",
"=",
"substr",
"(",
"$",
"decodedUri",
",",
"0",
",",
"strlen",
"(",
"$",
"decodedUri",
")",
"-",
"strlen",
"(",
"$",
"pathInfo",
")",
")",
";",
"return",
"rtrim",
"(",
"$",
"baseUri",
",",
"'/'",
")",
".",
"'/'",
";",
"}",
"throw",
"new",
"Exception",
"(",
"'The REQUEST_URI ('",
".",
"$",
"uri",
".",
"') did not end with the contents of PATH_INFO ('",
".",
"$",
"pathInfo",
".",
"'). This server might be misconfigured.'",
")",
";",
"}",
"// The last fallback is that we're just going to assume the server root.",
"return",
"'/'",
";",
"}"
] | This method attempts to detect the base uri.
Only the PATH_INFO variable is considered.
If this variable is not set, the root (/) is assumed.
@return string | [
"This",
"method",
"attempts",
"to",
"detect",
"the",
"base",
"uri",
".",
"Only",
"the",
"PATH_INFO",
"variable",
"is",
"considered",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L349-L380 |
sabre-io/dav | lib/DAV/Server.php | Server.addPlugin | public function addPlugin(ServerPlugin $plugin)
{
$this->plugins[$plugin->getPluginName()] = $plugin;
$plugin->initialize($this);
} | php | public function addPlugin(ServerPlugin $plugin)
{
$this->plugins[$plugin->getPluginName()] = $plugin;
$plugin->initialize($this);
} | [
"public",
"function",
"addPlugin",
"(",
"ServerPlugin",
"$",
"plugin",
")",
"{",
"$",
"this",
"->",
"plugins",
"[",
"$",
"plugin",
"->",
"getPluginName",
"(",
")",
"]",
"=",
"$",
"plugin",
";",
"$",
"plugin",
"->",
"initialize",
"(",
"$",
"this",
")",
";",
"}"
] | Adds a plugin to the server.
For more information, console the documentation of Sabre\DAV\ServerPlugin
@param ServerPlugin $plugin | [
"Adds",
"a",
"plugin",
"to",
"the",
"server",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L389-L393 |
sabre-io/dav | lib/DAV/Server.php | Server.getPlugin | public function getPlugin($name)
{
if (isset($this->plugins[$name])) {
return $this->plugins[$name];
}
return null;
} | php | public function getPlugin($name)
{
if (isset($this->plugins[$name])) {
return $this->plugins[$name];
}
return null;
} | [
"public",
"function",
"getPlugin",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"plugins",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"plugins",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Returns an initialized plugin by it's name.
This function returns null if the plugin was not found.
@param string $name
@return ServerPlugin | [
"Returns",
"an",
"initialized",
"plugin",
"by",
"it",
"s",
"name",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L404-L411 |
sabre-io/dav | lib/DAV/Server.php | Server.invokeMethod | public function invokeMethod(RequestInterface $request, ResponseInterface $response, $sendResponse = true)
{
$method = $request->getMethod();
if (!$this->emit('beforeMethod:'.$method, [$request, $response])) {
return;
}
if (self::$exposeVersion) {
$response->setHeader('X-Sabre-Version', Version::VERSION);
}
$this->transactionType = strtolower($method);
if (!$this->checkPreconditions($request, $response)) {
$this->sapi->sendResponse($response);
return;
}
if ($this->emit('method:'.$method, [$request, $response])) {
$exMessage = 'There was no plugin in the system that was willing to handle this '.$method.' method.';
if ('GET' === $method) {
$exMessage .= ' Enable the Browser plugin to get a better result here.';
}
// Unsupported method
throw new Exception\NotImplemented($exMessage);
}
if (!$this->emit('afterMethod:'.$method, [$request, $response])) {
return;
}
if (null === $response->getStatus()) {
throw new Exception('No subsystem set a valid HTTP status code. Something must have interrupted the request without providing further detail.');
}
if ($sendResponse) {
$this->sapi->sendResponse($response);
$this->emit('afterResponse', [$request, $response]);
}
} | php | public function invokeMethod(RequestInterface $request, ResponseInterface $response, $sendResponse = true)
{
$method = $request->getMethod();
if (!$this->emit('beforeMethod:'.$method, [$request, $response])) {
return;
}
if (self::$exposeVersion) {
$response->setHeader('X-Sabre-Version', Version::VERSION);
}
$this->transactionType = strtolower($method);
if (!$this->checkPreconditions($request, $response)) {
$this->sapi->sendResponse($response);
return;
}
if ($this->emit('method:'.$method, [$request, $response])) {
$exMessage = 'There was no plugin in the system that was willing to handle this '.$method.' method.';
if ('GET' === $method) {
$exMessage .= ' Enable the Browser plugin to get a better result here.';
}
throw new Exception\NotImplemented($exMessage);
}
if (!$this->emit('afterMethod:'.$method, [$request, $response])) {
return;
}
if (null === $response->getStatus()) {
throw new Exception('No subsystem set a valid HTTP status code. Something must have interrupted the request without providing further detail.');
}
if ($sendResponse) {
$this->sapi->sendResponse($response);
$this->emit('afterResponse', [$request, $response]);
}
} | [
"public",
"function",
"invokeMethod",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
",",
"$",
"sendResponse",
"=",
"true",
")",
"{",
"$",
"method",
"=",
"$",
"request",
"->",
"getMethod",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"emit",
"(",
"'beforeMethod:'",
".",
"$",
"method",
",",
"[",
"$",
"request",
",",
"$",
"response",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"self",
"::",
"$",
"exposeVersion",
")",
"{",
"$",
"response",
"->",
"setHeader",
"(",
"'X-Sabre-Version'",
",",
"Version",
"::",
"VERSION",
")",
";",
"}",
"$",
"this",
"->",
"transactionType",
"=",
"strtolower",
"(",
"$",
"method",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"checkPreconditions",
"(",
"$",
"request",
",",
"$",
"response",
")",
")",
"{",
"$",
"this",
"->",
"sapi",
"->",
"sendResponse",
"(",
"$",
"response",
")",
";",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"emit",
"(",
"'method:'",
".",
"$",
"method",
",",
"[",
"$",
"request",
",",
"$",
"response",
"]",
")",
")",
"{",
"$",
"exMessage",
"=",
"'There was no plugin in the system that was willing to handle this '",
".",
"$",
"method",
".",
"' method.'",
";",
"if",
"(",
"'GET'",
"===",
"$",
"method",
")",
"{",
"$",
"exMessage",
".=",
"' Enable the Browser plugin to get a better result here.'",
";",
"}",
"// Unsupported method",
"throw",
"new",
"Exception",
"\\",
"NotImplemented",
"(",
"$",
"exMessage",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"emit",
"(",
"'afterMethod:'",
".",
"$",
"method",
",",
"[",
"$",
"request",
",",
"$",
"response",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"response",
"->",
"getStatus",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'No subsystem set a valid HTTP status code. Something must have interrupted the request without providing further detail.'",
")",
";",
"}",
"if",
"(",
"$",
"sendResponse",
")",
"{",
"$",
"this",
"->",
"sapi",
"->",
"sendResponse",
"(",
"$",
"response",
")",
";",
"$",
"this",
"->",
"emit",
"(",
"'afterResponse'",
",",
"[",
"$",
"request",
",",
"$",
"response",
"]",
")",
";",
"}",
"}"
] | Handles a http request, and execute a method based on its name.
@param RequestInterface $request
@param ResponseInterface $response
@param bool $sendResponse whether to send the HTTP response to the DAV client | [
"Handles",
"a",
"http",
"request",
"and",
"execute",
"a",
"method",
"based",
"on",
"its",
"name",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L444-L485 |
sabre-io/dav | lib/DAV/Server.php | Server.getAllowedMethods | public function getAllowedMethods($path)
{
$methods = [
'OPTIONS',
'GET',
'HEAD',
'DELETE',
'PROPFIND',
'PUT',
'PROPPATCH',
'COPY',
'MOVE',
'REPORT',
];
// The MKCOL is only allowed on an unmapped uri
try {
$this->tree->getNodeForPath($path);
} catch (Exception\NotFound $e) {
$methods[] = 'MKCOL';
}
// We're also checking if any of the plugins register any new methods
foreach ($this->plugins as $plugin) {
$methods = array_merge($methods, $plugin->getHTTPMethods($path));
}
array_unique($methods);
return $methods;
} | php | public function getAllowedMethods($path)
{
$methods = [
'OPTIONS',
'GET',
'HEAD',
'DELETE',
'PROPFIND',
'PUT',
'PROPPATCH',
'COPY',
'MOVE',
'REPORT',
];
try {
$this->tree->getNodeForPath($path);
} catch (Exception\NotFound $e) {
$methods[] = 'MKCOL';
}
foreach ($this->plugins as $plugin) {
$methods = array_merge($methods, $plugin->getHTTPMethods($path));
}
array_unique($methods);
return $methods;
} | [
"public",
"function",
"getAllowedMethods",
"(",
"$",
"path",
")",
"{",
"$",
"methods",
"=",
"[",
"'OPTIONS'",
",",
"'GET'",
",",
"'HEAD'",
",",
"'DELETE'",
",",
"'PROPFIND'",
",",
"'PUT'",
",",
"'PROPPATCH'",
",",
"'COPY'",
",",
"'MOVE'",
",",
"'REPORT'",
",",
"]",
";",
"// The MKCOL is only allowed on an unmapped uri",
"try",
"{",
"$",
"this",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"path",
")",
";",
"}",
"catch",
"(",
"Exception",
"\\",
"NotFound",
"$",
"e",
")",
"{",
"$",
"methods",
"[",
"]",
"=",
"'MKCOL'",
";",
"}",
"// We're also checking if any of the plugins register any new methods",
"foreach",
"(",
"$",
"this",
"->",
"plugins",
"as",
"$",
"plugin",
")",
"{",
"$",
"methods",
"=",
"array_merge",
"(",
"$",
"methods",
",",
"$",
"plugin",
"->",
"getHTTPMethods",
"(",
"$",
"path",
")",
")",
";",
"}",
"array_unique",
"(",
"$",
"methods",
")",
";",
"return",
"$",
"methods",
";",
"}"
] | Returns an array with all the supported HTTP methods for a specific uri.
@param string $path
@return array | [
"Returns",
"an",
"array",
"with",
"all",
"the",
"supported",
"HTTP",
"methods",
"for",
"a",
"specific",
"uri",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L496-L525 |
sabre-io/dav | lib/DAV/Server.php | Server.calculateUri | public function calculateUri($uri)
{
if ('' != $uri && '/' != $uri[0] && strpos($uri, '://')) {
$uri = parse_url($uri, PHP_URL_PATH);
}
$uri = Uri\normalize(preg_replace('|/+|', '/', $uri));
$baseUri = Uri\normalize($this->getBaseUri());
if (0 === strpos($uri, $baseUri)) {
return trim(HTTP\decodePath(substr($uri, strlen($baseUri))), '/');
// A special case, if the baseUri was accessed without a trailing
// slash, we'll accept it as well.
} elseif ($uri.'/' === $baseUri) {
return '';
} else {
throw new Exception\Forbidden('Requested uri ('.$uri.') is out of base uri ('.$this->getBaseUri().')');
}
} | php | public function calculateUri($uri)
{
if ('' != $uri && '/' != $uri[0] && strpos($uri, ':
$uri = parse_url($uri, PHP_URL_PATH);
}
$uri = Uri\normalize(preg_replace('|/+|', '/', $uri));
$baseUri = Uri\normalize($this->getBaseUri());
if (0 === strpos($uri, $baseUri)) {
return trim(HTTP\decodePath(substr($uri, strlen($baseUri))), '/');
} elseif ($uri.'/' === $baseUri) {
return '';
} else {
throw new Exception\Forbidden('Requested uri ('.$uri.') is out of base uri ('.$this->getBaseUri().')');
}
} | [
"public",
"function",
"calculateUri",
"(",
"$",
"uri",
")",
"{",
"if",
"(",
"''",
"!=",
"$",
"uri",
"&&",
"'/'",
"!=",
"$",
"uri",
"[",
"0",
"]",
"&&",
"strpos",
"(",
"$",
"uri",
",",
"'://'",
")",
")",
"{",
"$",
"uri",
"=",
"parse_url",
"(",
"$",
"uri",
",",
"PHP_URL_PATH",
")",
";",
"}",
"$",
"uri",
"=",
"Uri",
"\\",
"normalize",
"(",
"preg_replace",
"(",
"'|/+|'",
",",
"'/'",
",",
"$",
"uri",
")",
")",
";",
"$",
"baseUri",
"=",
"Uri",
"\\",
"normalize",
"(",
"$",
"this",
"->",
"getBaseUri",
"(",
")",
")",
";",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"uri",
",",
"$",
"baseUri",
")",
")",
"{",
"return",
"trim",
"(",
"HTTP",
"\\",
"decodePath",
"(",
"substr",
"(",
"$",
"uri",
",",
"strlen",
"(",
"$",
"baseUri",
")",
")",
")",
",",
"'/'",
")",
";",
"// A special case, if the baseUri was accessed without a trailing",
"// slash, we'll accept it as well.",
"}",
"elseif",
"(",
"$",
"uri",
".",
"'/'",
"===",
"$",
"baseUri",
")",
"{",
"return",
"''",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"\\",
"Forbidden",
"(",
"'Requested uri ('",
".",
"$",
"uri",
".",
"') is out of base uri ('",
".",
"$",
"this",
"->",
"getBaseUri",
"(",
")",
".",
"')'",
")",
";",
"}",
"}"
] | Turns a URI such as the REQUEST_URI into a local path.
This method:
* strips off the base path
* normalizes the path
* uri-decodes the path
@param string $uri
@throws Exception\Forbidden A permission denied exception is thrown whenever there was an attempt to supply a uri outside of the base uri
@return string | [
"Turns",
"a",
"URI",
"such",
"as",
"the",
"REQUEST_URI",
"into",
"a",
"local",
"path",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L551-L570 |
sabre-io/dav | lib/DAV/Server.php | Server.getHTTPDepth | public function getHTTPDepth($default = self::DEPTH_INFINITY)
{
// If its not set, we'll grab the default
$depth = $this->httpRequest->getHeader('Depth');
if (is_null($depth)) {
return $default;
}
if ('infinity' == $depth) {
return self::DEPTH_INFINITY;
}
// If its an unknown value. we'll grab the default
if (!ctype_digit($depth)) {
return $default;
}
return (int) $depth;
} | php | public function getHTTPDepth($default = self::DEPTH_INFINITY)
{
$depth = $this->httpRequest->getHeader('Depth');
if (is_null($depth)) {
return $default;
}
if ('infinity' == $depth) {
return self::DEPTH_INFINITY;
}
if (!ctype_digit($depth)) {
return $default;
}
return (int) $depth;
} | [
"public",
"function",
"getHTTPDepth",
"(",
"$",
"default",
"=",
"self",
"::",
"DEPTH_INFINITY",
")",
"{",
"// If its not set, we'll grab the default",
"$",
"depth",
"=",
"$",
"this",
"->",
"httpRequest",
"->",
"getHeader",
"(",
"'Depth'",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"depth",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"if",
"(",
"'infinity'",
"==",
"$",
"depth",
")",
"{",
"return",
"self",
"::",
"DEPTH_INFINITY",
";",
"}",
"// If its an unknown value. we'll grab the default",
"if",
"(",
"!",
"ctype_digit",
"(",
"$",
"depth",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"return",
"(",
"int",
")",
"$",
"depth",
";",
"}"
] | Returns the HTTP depth header.
This method returns the contents of the HTTP depth request header. If the depth header was 'infinity' it will return the Sabre\DAV\Server::DEPTH_INFINITY object
It is possible to supply a default depth value, which is used when the depth header has invalid content, or is completely non-existent
@param mixed $default
@return int | [
"Returns",
"the",
"HTTP",
"depth",
"header",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L582-L601 |
sabre-io/dav | lib/DAV/Server.php | Server.getHTTPRange | public function getHTTPRange()
{
$range = $this->httpRequest->getHeader('range');
if (is_null($range)) {
return null;
}
// Matching "Range: bytes=1234-5678: both numbers are optional
if (!preg_match('/^bytes=([0-9]*)-([0-9]*)$/i', $range, $matches)) {
return null;
}
if ('' === $matches[1] && '' === $matches[2]) {
return null;
}
return [
'' !== $matches[1] ? (int) $matches[1] : null,
'' !== $matches[2] ? (int) $matches[2] : null,
];
} | php | public function getHTTPRange()
{
$range = $this->httpRequest->getHeader('range');
if (is_null($range)) {
return null;
}
if (!preg_match('/^bytes=([0-9]*)-([0-9]*)$/i', $range, $matches)) {
return null;
}
if ('' === $matches[1] && '' === $matches[2]) {
return null;
}
return [
'' !== $matches[1] ? (int) $matches[1] : null,
'' !== $matches[2] ? (int) $matches[2] : null,
];
} | [
"public",
"function",
"getHTTPRange",
"(",
")",
"{",
"$",
"range",
"=",
"$",
"this",
"->",
"httpRequest",
"->",
"getHeader",
"(",
"'range'",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"range",
")",
")",
"{",
"return",
"null",
";",
"}",
"// Matching \"Range: bytes=1234-5678: both numbers are optional",
"if",
"(",
"!",
"preg_match",
"(",
"'/^bytes=([0-9]*)-([0-9]*)$/i'",
",",
"$",
"range",
",",
"$",
"matches",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"''",
"===",
"$",
"matches",
"[",
"1",
"]",
"&&",
"''",
"===",
"$",
"matches",
"[",
"2",
"]",
")",
"{",
"return",
"null",
";",
"}",
"return",
"[",
"''",
"!==",
"$",
"matches",
"[",
"1",
"]",
"?",
"(",
"int",
")",
"$",
"matches",
"[",
"1",
"]",
":",
"null",
",",
"''",
"!==",
"$",
"matches",
"[",
"2",
"]",
"?",
"(",
"int",
")",
"$",
"matches",
"[",
"2",
"]",
":",
"null",
",",
"]",
";",
"}"
] | Returns the HTTP range header.
This method returns null if there is no well-formed HTTP range request
header or array($start, $end).
The first number is the offset of the first byte in the range.
The second number is the offset of the last byte in the range.
If the second offset is null, it should be treated as the offset of the last byte of the entity
If the first offset is null, the second offset should be used to retrieve the last x bytes of the entity
@return int[]|null | [
"Returns",
"the",
"HTTP",
"range",
"header",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L617-L638 |
sabre-io/dav | lib/DAV/Server.php | Server.getHTTPPrefer | public function getHTTPPrefer()
{
$result = [
// can be true or false
'respond-async' => false,
// Could be set to 'representation' or 'minimal'.
'return' => null,
// Used as a timeout, is usually a number.
'wait' => null,
// can be 'strict' or 'lenient'.
'handling' => false,
];
if ($prefer = $this->httpRequest->getHeader('Prefer')) {
$result = array_merge(
$result,
HTTP\parsePrefer($prefer)
);
} elseif ('t' == $this->httpRequest->getHeader('Brief')) {
$result['return'] = 'minimal';
}
return $result;
} | php | public function getHTTPPrefer()
{
$result = [
'respond-async' => false,
'return' => null,
'wait' => null,
'handling' => false,
];
if ($prefer = $this->httpRequest->getHeader('Prefer')) {
$result = array_merge(
$result,
HTTP\parsePrefer($prefer)
);
} elseif ('t' == $this->httpRequest->getHeader('Brief')) {
$result['return'] = 'minimal';
}
return $result;
} | [
"public",
"function",
"getHTTPPrefer",
"(",
")",
"{",
"$",
"result",
"=",
"[",
"// can be true or false",
"'respond-async'",
"=>",
"false",
",",
"// Could be set to 'representation' or 'minimal'.",
"'return'",
"=>",
"null",
",",
"// Used as a timeout, is usually a number.",
"'wait'",
"=>",
"null",
",",
"// can be 'strict' or 'lenient'.",
"'handling'",
"=>",
"false",
",",
"]",
";",
"if",
"(",
"$",
"prefer",
"=",
"$",
"this",
"->",
"httpRequest",
"->",
"getHeader",
"(",
"'Prefer'",
")",
")",
"{",
"$",
"result",
"=",
"array_merge",
"(",
"$",
"result",
",",
"HTTP",
"\\",
"parsePrefer",
"(",
"$",
"prefer",
")",
")",
";",
"}",
"elseif",
"(",
"'t'",
"==",
"$",
"this",
"->",
"httpRequest",
"->",
"getHeader",
"(",
"'Brief'",
")",
")",
"{",
"$",
"result",
"[",
"'return'",
"]",
"=",
"'minimal'",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns the HTTP Prefer header information.
The prefer header is defined in:
http://tools.ietf.org/html/draft-snell-http-prefer-14
This method will return an array with options.
Currently, the following options may be returned:
[
'return-asynch' => true,
'return-minimal' => true,
'return-representation' => true,
'wait' => 30,
'strict' => true,
'lenient' => true,
]
This method also supports the Brief header, and will also return
'return-minimal' if the brief header was set to 't'.
For the boolean options, false will be returned if the headers are not
specified. For the integer options it will be 'null'.
@return array | [
"Returns",
"the",
"HTTP",
"Prefer",
"header",
"information",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L666-L689 |
sabre-io/dav | lib/DAV/Server.php | Server.getCopyAndMoveInfo | public function getCopyAndMoveInfo(RequestInterface $request)
{
// Collecting the relevant HTTP headers
if (!$request->getHeader('Destination')) {
throw new Exception\BadRequest('The destination header was not supplied');
}
$destination = $this->calculateUri($request->getHeader('Destination'));
$overwrite = $request->getHeader('Overwrite');
if (!$overwrite) {
$overwrite = 'T';
}
if ('T' == strtoupper($overwrite)) {
$overwrite = true;
} elseif ('F' == strtoupper($overwrite)) {
$overwrite = false;
}
// We need to throw a bad request exception, if the header was invalid
else {
throw new Exception\BadRequest('The HTTP Overwrite header should be either T or F');
}
list($destinationDir) = Uri\split($destination);
try {
$destinationParent = $this->tree->getNodeForPath($destinationDir);
if (!($destinationParent instanceof ICollection)) {
throw new Exception\UnsupportedMediaType('The destination node is not a collection');
}
} catch (Exception\NotFound $e) {
// If the destination parent node is not found, we throw a 409
throw new Exception\Conflict('The destination node is not found');
}
try {
$destinationNode = $this->tree->getNodeForPath($destination);
// If this succeeded, it means the destination already exists
// we'll need to throw precondition failed in case overwrite is false
if (!$overwrite) {
throw new Exception\PreconditionFailed('The destination node already exists, and the overwrite header is set to false', 'Overwrite');
}
} catch (Exception\NotFound $e) {
// Destination didn't exist, we're all good
$destinationNode = false;
}
$requestPath = $request->getPath();
if ($destination === $requestPath) {
throw new Exception\Forbidden('Source and destination uri are identical.');
}
if (substr($destination, 0, strlen($requestPath) + 1) === $requestPath.'/') {
throw new Exception\Conflict('The destination may not be part of the same subtree as the source path.');
}
// These are the three relevant properties we need to return
return [
'destination' => $destination,
'destinationExists' => (bool) $destinationNode,
'destinationNode' => $destinationNode,
];
} | php | public function getCopyAndMoveInfo(RequestInterface $request)
{
if (!$request->getHeader('Destination')) {
throw new Exception\BadRequest('The destination header was not supplied');
}
$destination = $this->calculateUri($request->getHeader('Destination'));
$overwrite = $request->getHeader('Overwrite');
if (!$overwrite) {
$overwrite = 'T';
}
if ('T' == strtoupper($overwrite)) {
$overwrite = true;
} elseif ('F' == strtoupper($overwrite)) {
$overwrite = false;
}
else {
throw new Exception\BadRequest('The HTTP Overwrite header should be either T or F');
}
list($destinationDir) = Uri\split($destination);
try {
$destinationParent = $this->tree->getNodeForPath($destinationDir);
if (!($destinationParent instanceof ICollection)) {
throw new Exception\UnsupportedMediaType('The destination node is not a collection');
}
} catch (Exception\NotFound $e) {
throw new Exception\Conflict('The destination node is not found');
}
try {
$destinationNode = $this->tree->getNodeForPath($destination);
if (!$overwrite) {
throw new Exception\PreconditionFailed('The destination node already exists, and the overwrite header is set to false', 'Overwrite');
}
} catch (Exception\NotFound $e) {
$destinationNode = false;
}
$requestPath = $request->getPath();
if ($destination === $requestPath) {
throw new Exception\Forbidden('Source and destination uri are identical.');
}
if (substr($destination, 0, strlen($requestPath) + 1) === $requestPath.'/') {
throw new Exception\Conflict('The destination may not be part of the same subtree as the source path.');
}
return [
'destination' => $destination,
'destinationExists' => (bool) $destinationNode,
'destinationNode' => $destinationNode,
];
} | [
"public",
"function",
"getCopyAndMoveInfo",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"// Collecting the relevant HTTP headers",
"if",
"(",
"!",
"$",
"request",
"->",
"getHeader",
"(",
"'Destination'",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"BadRequest",
"(",
"'The destination header was not supplied'",
")",
";",
"}",
"$",
"destination",
"=",
"$",
"this",
"->",
"calculateUri",
"(",
"$",
"request",
"->",
"getHeader",
"(",
"'Destination'",
")",
")",
";",
"$",
"overwrite",
"=",
"$",
"request",
"->",
"getHeader",
"(",
"'Overwrite'",
")",
";",
"if",
"(",
"!",
"$",
"overwrite",
")",
"{",
"$",
"overwrite",
"=",
"'T'",
";",
"}",
"if",
"(",
"'T'",
"==",
"strtoupper",
"(",
"$",
"overwrite",
")",
")",
"{",
"$",
"overwrite",
"=",
"true",
";",
"}",
"elseif",
"(",
"'F'",
"==",
"strtoupper",
"(",
"$",
"overwrite",
")",
")",
"{",
"$",
"overwrite",
"=",
"false",
";",
"}",
"// We need to throw a bad request exception, if the header was invalid",
"else",
"{",
"throw",
"new",
"Exception",
"\\",
"BadRequest",
"(",
"'The HTTP Overwrite header should be either T or F'",
")",
";",
"}",
"list",
"(",
"$",
"destinationDir",
")",
"=",
"Uri",
"\\",
"split",
"(",
"$",
"destination",
")",
";",
"try",
"{",
"$",
"destinationParent",
"=",
"$",
"this",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"destinationDir",
")",
";",
"if",
"(",
"!",
"(",
"$",
"destinationParent",
"instanceof",
"ICollection",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"UnsupportedMediaType",
"(",
"'The destination node is not a collection'",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"\\",
"NotFound",
"$",
"e",
")",
"{",
"// If the destination parent node is not found, we throw a 409",
"throw",
"new",
"Exception",
"\\",
"Conflict",
"(",
"'The destination node is not found'",
")",
";",
"}",
"try",
"{",
"$",
"destinationNode",
"=",
"$",
"this",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"destination",
")",
";",
"// If this succeeded, it means the destination already exists",
"// we'll need to throw precondition failed in case overwrite is false",
"if",
"(",
"!",
"$",
"overwrite",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"PreconditionFailed",
"(",
"'The destination node already exists, and the overwrite header is set to false'",
",",
"'Overwrite'",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"\\",
"NotFound",
"$",
"e",
")",
"{",
"// Destination didn't exist, we're all good",
"$",
"destinationNode",
"=",
"false",
";",
"}",
"$",
"requestPath",
"=",
"$",
"request",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"$",
"destination",
"===",
"$",
"requestPath",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"Forbidden",
"(",
"'Source and destination uri are identical.'",
")",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"destination",
",",
"0",
",",
"strlen",
"(",
"$",
"requestPath",
")",
"+",
"1",
")",
"===",
"$",
"requestPath",
".",
"'/'",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"Conflict",
"(",
"'The destination may not be part of the same subtree as the source path.'",
")",
";",
"}",
"// These are the three relevant properties we need to return",
"return",
"[",
"'destination'",
"=>",
"$",
"destination",
",",
"'destinationExists'",
"=>",
"(",
"bool",
")",
"$",
"destinationNode",
",",
"'destinationNode'",
"=>",
"$",
"destinationNode",
",",
"]",
";",
"}"
] | Returns information about Copy and Move requests.
This function is created to help getting information about the source and the destination for the
WebDAV MOVE and COPY HTTP request. It also validates a lot of information and throws proper exceptions
The returned value is an array with the following keys:
* destination - Destination path
* destinationExists - Whether or not the destination is an existing url (and should therefore be overwritten)
@param RequestInterface $request
@throws Exception\BadRequest upon missing or broken request headers
@throws Exception\UnsupportedMediaType when trying to copy into a
non-collection
@throws Exception\PreconditionFailed if overwrite is set to false, but
the destination exists
@throws Exception\Forbidden when source and destination paths are
identical
@throws Exception\Conflict when trying to copy a node into its own
subtree
@return array | [
"Returns",
"information",
"about",
"Copy",
"and",
"Move",
"requests",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L715-L774 |
sabre-io/dav | lib/DAV/Server.php | Server.getProperties | public function getProperties($path, $propertyNames)
{
$result = $this->getPropertiesForPath($path, $propertyNames, 0);
if (isset($result[0][200])) {
return $result[0][200];
} else {
return [];
}
} | php | public function getProperties($path, $propertyNames)
{
$result = $this->getPropertiesForPath($path, $propertyNames, 0);
if (isset($result[0][200])) {
return $result[0][200];
} else {
return [];
}
} | [
"public",
"function",
"getProperties",
"(",
"$",
"path",
",",
"$",
"propertyNames",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getPropertiesForPath",
"(",
"$",
"path",
",",
"$",
"propertyNames",
",",
"0",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"0",
"]",
"[",
"200",
"]",
")",
")",
"{",
"return",
"$",
"result",
"[",
"0",
"]",
"[",
"200",
"]",
";",
"}",
"else",
"{",
"return",
"[",
"]",
";",
"}",
"}"
] | Returns a list of properties for a path.
This is a simplified version getPropertiesForPath. If you aren't
interested in status codes, but you just want to have a flat list of
properties, use this method.
Please note though that any problems related to retrieving properties,
such as permission issues will just result in an empty array being
returned.
@param string $path
@param array $propertyNames
@return array | [
"Returns",
"a",
"list",
"of",
"properties",
"for",
"a",
"path",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L792-L800 |
sabre-io/dav | lib/DAV/Server.php | Server.getPropertiesForChildren | public function getPropertiesForChildren($path, $propertyNames)
{
$result = [];
foreach ($this->getPropertiesForPath($path, $propertyNames, 1) as $k => $row) {
// Skipping the parent path
if (0 === $k) {
continue;
}
$result[$row['href']] = $row[200];
}
return $result;
} | php | public function getPropertiesForChildren($path, $propertyNames)
{
$result = [];
foreach ($this->getPropertiesForPath($path, $propertyNames, 1) as $k => $row) {
if (0 === $k) {
continue;
}
$result[$row['href']] = $row[200];
}
return $result;
} | [
"public",
"function",
"getPropertiesForChildren",
"(",
"$",
"path",
",",
"$",
"propertyNames",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getPropertiesForPath",
"(",
"$",
"path",
",",
"$",
"propertyNames",
",",
"1",
")",
"as",
"$",
"k",
"=>",
"$",
"row",
")",
"{",
"// Skipping the parent path",
"if",
"(",
"0",
"===",
"$",
"k",
")",
"{",
"continue",
";",
"}",
"$",
"result",
"[",
"$",
"row",
"[",
"'href'",
"]",
"]",
"=",
"$",
"row",
"[",
"200",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | A kid-friendly way to fetch properties for a node's children.
The returned array will be indexed by the path of the of child node.
Only properties that are actually found will be returned.
The parent node will not be returned.
@param string $path
@param array $propertyNames
@return array | [
"A",
"kid",
"-",
"friendly",
"way",
"to",
"fetch",
"properties",
"for",
"a",
"node",
"s",
"children",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L815-L828 |
sabre-io/dav | lib/DAV/Server.php | Server.getHTTPHeaders | public function getHTTPHeaders($path)
{
$propertyMap = [
'{DAV:}getcontenttype' => 'Content-Type',
'{DAV:}getcontentlength' => 'Content-Length',
'{DAV:}getlastmodified' => 'Last-Modified',
'{DAV:}getetag' => 'ETag',
];
$properties = $this->getProperties($path, array_keys($propertyMap));
$headers = [];
foreach ($propertyMap as $property => $header) {
if (!isset($properties[$property])) {
continue;
}
if (is_scalar($properties[$property])) {
$headers[$header] = $properties[$property];
// GetLastModified gets special cased
} elseif ($properties[$property] instanceof Xml\Property\GetLastModified) {
$headers[$header] = HTTP\toDate($properties[$property]->getTime());
}
}
return $headers;
} | php | public function getHTTPHeaders($path)
{
$propertyMap = [
'{DAV:}getcontenttype' => 'Content-Type',
'{DAV:}getcontentlength' => 'Content-Length',
'{DAV:}getlastmodified' => 'Last-Modified',
'{DAV:}getetag' => 'ETag',
];
$properties = $this->getProperties($path, array_keys($propertyMap));
$headers = [];
foreach ($propertyMap as $property => $header) {
if (!isset($properties[$property])) {
continue;
}
if (is_scalar($properties[$property])) {
$headers[$header] = $properties[$property];
} elseif ($properties[$property] instanceof Xml\Property\GetLastModified) {
$headers[$header] = HTTP\toDate($properties[$property]->getTime());
}
}
return $headers;
} | [
"public",
"function",
"getHTTPHeaders",
"(",
"$",
"path",
")",
"{",
"$",
"propertyMap",
"=",
"[",
"'{DAV:}getcontenttype'",
"=>",
"'Content-Type'",
",",
"'{DAV:}getcontentlength'",
"=>",
"'Content-Length'",
",",
"'{DAV:}getlastmodified'",
"=>",
"'Last-Modified'",
",",
"'{DAV:}getetag'",
"=>",
"'ETag'",
",",
"]",
";",
"$",
"properties",
"=",
"$",
"this",
"->",
"getProperties",
"(",
"$",
"path",
",",
"array_keys",
"(",
"$",
"propertyMap",
")",
")",
";",
"$",
"headers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"propertyMap",
"as",
"$",
"property",
"=>",
"$",
"header",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"properties",
"[",
"$",
"property",
"]",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"is_scalar",
"(",
"$",
"properties",
"[",
"$",
"property",
"]",
")",
")",
"{",
"$",
"headers",
"[",
"$",
"header",
"]",
"=",
"$",
"properties",
"[",
"$",
"property",
"]",
";",
"// GetLastModified gets special cased",
"}",
"elseif",
"(",
"$",
"properties",
"[",
"$",
"property",
"]",
"instanceof",
"Xml",
"\\",
"Property",
"\\",
"GetLastModified",
")",
"{",
"$",
"headers",
"[",
"$",
"header",
"]",
"=",
"HTTP",
"\\",
"toDate",
"(",
"$",
"properties",
"[",
"$",
"property",
"]",
"->",
"getTime",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"headers",
";",
"}"
] | Returns a list of HTTP headers for a particular resource.
The generated http headers are based on properties provided by the
resource. The method basically provides a simple mapping between
DAV property and HTTP header.
The headers are intended to be used for HEAD and GET requests.
@param string $path
@return array | [
"Returns",
"a",
"list",
"of",
"HTTP",
"headers",
"for",
"a",
"particular",
"resource",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L843-L870 |
sabre-io/dav | lib/DAV/Server.php | Server.generatePathNodes | private function generatePathNodes(PropFind $propFind, array $yieldFirst = null)
{
if (null !== $yieldFirst) {
yield $yieldFirst;
}
$newDepth = $propFind->getDepth();
$path = $propFind->getPath();
if (self::DEPTH_INFINITY !== $newDepth) {
--$newDepth;
}
$propertyNames = $propFind->getRequestedProperties();
$propFindType = !empty($propertyNames) ? PropFind::NORMAL : PropFind::ALLPROPS;
foreach ($this->tree->getChildren($path) as $childNode) {
if ('' !== $path) {
$subPath = $path.'/'.$childNode->getName();
} else {
$subPath = $childNode->getName();
}
$subPropFind = new PropFind($subPath, $propertyNames, $newDepth, $propFindType);
yield [
$subPropFind,
$childNode,
];
if ((self::DEPTH_INFINITY === $newDepth || $newDepth >= 1) && $childNode instanceof ICollection) {
foreach ($this->generatePathNodes($subPropFind) as $subItem) {
yield $subItem;
}
}
}
} | php | private function generatePathNodes(PropFind $propFind, array $yieldFirst = null)
{
if (null !== $yieldFirst) {
yield $yieldFirst;
}
$newDepth = $propFind->getDepth();
$path = $propFind->getPath();
if (self::DEPTH_INFINITY !== $newDepth) {
--$newDepth;
}
$propertyNames = $propFind->getRequestedProperties();
$propFindType = !empty($propertyNames) ? PropFind::NORMAL : PropFind::ALLPROPS;
foreach ($this->tree->getChildren($path) as $childNode) {
if ('' !== $path) {
$subPath = $path.'/'.$childNode->getName();
} else {
$subPath = $childNode->getName();
}
$subPropFind = new PropFind($subPath, $propertyNames, $newDepth, $propFindType);
yield [
$subPropFind,
$childNode,
];
if ((self::DEPTH_INFINITY === $newDepth || $newDepth >= 1) && $childNode instanceof ICollection) {
foreach ($this->generatePathNodes($subPropFind) as $subItem) {
yield $subItem;
}
}
}
} | [
"private",
"function",
"generatePathNodes",
"(",
"PropFind",
"$",
"propFind",
",",
"array",
"$",
"yieldFirst",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"yieldFirst",
")",
"{",
"yield",
"$",
"yieldFirst",
";",
"}",
"$",
"newDepth",
"=",
"$",
"propFind",
"->",
"getDepth",
"(",
")",
";",
"$",
"path",
"=",
"$",
"propFind",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"self",
"::",
"DEPTH_INFINITY",
"!==",
"$",
"newDepth",
")",
"{",
"--",
"$",
"newDepth",
";",
"}",
"$",
"propertyNames",
"=",
"$",
"propFind",
"->",
"getRequestedProperties",
"(",
")",
";",
"$",
"propFindType",
"=",
"!",
"empty",
"(",
"$",
"propertyNames",
")",
"?",
"PropFind",
"::",
"NORMAL",
":",
"PropFind",
"::",
"ALLPROPS",
";",
"foreach",
"(",
"$",
"this",
"->",
"tree",
"->",
"getChildren",
"(",
"$",
"path",
")",
"as",
"$",
"childNode",
")",
"{",
"if",
"(",
"''",
"!==",
"$",
"path",
")",
"{",
"$",
"subPath",
"=",
"$",
"path",
".",
"'/'",
".",
"$",
"childNode",
"->",
"getName",
"(",
")",
";",
"}",
"else",
"{",
"$",
"subPath",
"=",
"$",
"childNode",
"->",
"getName",
"(",
")",
";",
"}",
"$",
"subPropFind",
"=",
"new",
"PropFind",
"(",
"$",
"subPath",
",",
"$",
"propertyNames",
",",
"$",
"newDepth",
",",
"$",
"propFindType",
")",
";",
"yield",
"[",
"$",
"subPropFind",
",",
"$",
"childNode",
",",
"]",
";",
"if",
"(",
"(",
"self",
"::",
"DEPTH_INFINITY",
"===",
"$",
"newDepth",
"||",
"$",
"newDepth",
">=",
"1",
")",
"&&",
"$",
"childNode",
"instanceof",
"ICollection",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"generatePathNodes",
"(",
"$",
"subPropFind",
")",
"as",
"$",
"subItem",
")",
"{",
"yield",
"$",
"subItem",
";",
"}",
"}",
"}",
"}"
] | Small helper to support PROPFIND with DEPTH_INFINITY.
@param PropFind $propFind
@param array $yieldFirst
@return \Traversable | [
"Small",
"helper",
"to",
"support",
"PROPFIND",
"with",
"DEPTH_INFINITY",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L880-L914 |
sabre-io/dav | lib/DAV/Server.php | Server.getPropertiesForPath | public function getPropertiesForPath($path, $propertyNames = [], $depth = 0)
{
return iterator_to_array($this->getPropertiesIteratorForPath($path, $propertyNames, $depth));
} | php | public function getPropertiesForPath($path, $propertyNames = [], $depth = 0)
{
return iterator_to_array($this->getPropertiesIteratorForPath($path, $propertyNames, $depth));
} | [
"public",
"function",
"getPropertiesForPath",
"(",
"$",
"path",
",",
"$",
"propertyNames",
"=",
"[",
"]",
",",
"$",
"depth",
"=",
"0",
")",
"{",
"return",
"iterator_to_array",
"(",
"$",
"this",
"->",
"getPropertiesIteratorForPath",
"(",
"$",
"path",
",",
"$",
"propertyNames",
",",
"$",
"depth",
")",
")",
";",
"}"
] | Returns a list of properties for a given path.
The path that should be supplied should have the baseUrl stripped out
The list of properties should be supplied in Clark notation. If the list is empty
'allprops' is assumed.
If a depth of 1 is requested child elements will also be returned.
@param string $path
@param array $propertyNames
@param int $depth
@return array
@deprecated Use getPropertiesIteratorForPath() instead (as it's more memory efficient)
@see getPropertiesIteratorForPath() | [
"Returns",
"a",
"list",
"of",
"properties",
"for",
"a",
"given",
"path",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L934-L937 |
sabre-io/dav | lib/DAV/Server.php | Server.getPropertiesIteratorForPath | public function getPropertiesIteratorForPath($path, $propertyNames = [], $depth = 0)
{
// The only two options for the depth of a propfind is 0 or 1 - as long as depth infinity is not enabled
if (!$this->enablePropfindDepthInfinity && 0 != $depth) {
$depth = 1;
}
$path = trim($path, '/');
$propFindType = $propertyNames ? PropFind::NORMAL : PropFind::ALLPROPS;
$propFind = new PropFind($path, (array) $propertyNames, $depth, $propFindType);
$parentNode = $this->tree->getNodeForPath($path);
$propFindRequests = [[
$propFind,
$parentNode,
]];
if (($depth > 0 || self::DEPTH_INFINITY === $depth) && $parentNode instanceof ICollection) {
$propFindRequests = $this->generatePathNodes(clone $propFind, current($propFindRequests));
}
foreach ($propFindRequests as $propFindRequest) {
list($propFind, $node) = $propFindRequest;
$r = $this->getPropertiesByNode($propFind, $node);
if ($r) {
$result = $propFind->getResultForMultiStatus();
$result['href'] = $propFind->getPath();
// WebDAV recommends adding a slash to the path, if the path is
// a collection.
// Furthermore, iCal also demands this to be the case for
// principals. This is non-standard, but we support it.
$resourceType = $this->getResourceTypeForNode($node);
if (in_array('{DAV:}collection', $resourceType) || in_array('{DAV:}principal', $resourceType)) {
$result['href'] .= '/';
}
yield $result;
}
}
} | php | public function getPropertiesIteratorForPath($path, $propertyNames = [], $depth = 0)
{
if (!$this->enablePropfindDepthInfinity && 0 != $depth) {
$depth = 1;
}
$path = trim($path, '/');
$propFindType = $propertyNames ? PropFind::NORMAL : PropFind::ALLPROPS;
$propFind = new PropFind($path, (array) $propertyNames, $depth, $propFindType);
$parentNode = $this->tree->getNodeForPath($path);
$propFindRequests = [[
$propFind,
$parentNode,
]];
if (($depth > 0 || self::DEPTH_INFINITY === $depth) && $parentNode instanceof ICollection) {
$propFindRequests = $this->generatePathNodes(clone $propFind, current($propFindRequests));
}
foreach ($propFindRequests as $propFindRequest) {
list($propFind, $node) = $propFindRequest;
$r = $this->getPropertiesByNode($propFind, $node);
if ($r) {
$result = $propFind->getResultForMultiStatus();
$result['href'] = $propFind->getPath();
$resourceType = $this->getResourceTypeForNode($node);
if (in_array('{DAV:}collection', $resourceType) || in_array('{DAV:}principal', $resourceType)) {
$result['href'] .= '/';
}
yield $result;
}
}
} | [
"public",
"function",
"getPropertiesIteratorForPath",
"(",
"$",
"path",
",",
"$",
"propertyNames",
"=",
"[",
"]",
",",
"$",
"depth",
"=",
"0",
")",
"{",
"// The only two options for the depth of a propfind is 0 or 1 - as long as depth infinity is not enabled",
"if",
"(",
"!",
"$",
"this",
"->",
"enablePropfindDepthInfinity",
"&&",
"0",
"!=",
"$",
"depth",
")",
"{",
"$",
"depth",
"=",
"1",
";",
"}",
"$",
"path",
"=",
"trim",
"(",
"$",
"path",
",",
"'/'",
")",
";",
"$",
"propFindType",
"=",
"$",
"propertyNames",
"?",
"PropFind",
"::",
"NORMAL",
":",
"PropFind",
"::",
"ALLPROPS",
";",
"$",
"propFind",
"=",
"new",
"PropFind",
"(",
"$",
"path",
",",
"(",
"array",
")",
"$",
"propertyNames",
",",
"$",
"depth",
",",
"$",
"propFindType",
")",
";",
"$",
"parentNode",
"=",
"$",
"this",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"path",
")",
";",
"$",
"propFindRequests",
"=",
"[",
"[",
"$",
"propFind",
",",
"$",
"parentNode",
",",
"]",
"]",
";",
"if",
"(",
"(",
"$",
"depth",
">",
"0",
"||",
"self",
"::",
"DEPTH_INFINITY",
"===",
"$",
"depth",
")",
"&&",
"$",
"parentNode",
"instanceof",
"ICollection",
")",
"{",
"$",
"propFindRequests",
"=",
"$",
"this",
"->",
"generatePathNodes",
"(",
"clone",
"$",
"propFind",
",",
"current",
"(",
"$",
"propFindRequests",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"propFindRequests",
"as",
"$",
"propFindRequest",
")",
"{",
"list",
"(",
"$",
"propFind",
",",
"$",
"node",
")",
"=",
"$",
"propFindRequest",
";",
"$",
"r",
"=",
"$",
"this",
"->",
"getPropertiesByNode",
"(",
"$",
"propFind",
",",
"$",
"node",
")",
";",
"if",
"(",
"$",
"r",
")",
"{",
"$",
"result",
"=",
"$",
"propFind",
"->",
"getResultForMultiStatus",
"(",
")",
";",
"$",
"result",
"[",
"'href'",
"]",
"=",
"$",
"propFind",
"->",
"getPath",
"(",
")",
";",
"// WebDAV recommends adding a slash to the path, if the path is",
"// a collection.",
"// Furthermore, iCal also demands this to be the case for",
"// principals. This is non-standard, but we support it.",
"$",
"resourceType",
"=",
"$",
"this",
"->",
"getResourceTypeForNode",
"(",
"$",
"node",
")",
";",
"if",
"(",
"in_array",
"(",
"'{DAV:}collection'",
",",
"$",
"resourceType",
")",
"||",
"in_array",
"(",
"'{DAV:}principal'",
",",
"$",
"resourceType",
")",
")",
"{",
"$",
"result",
"[",
"'href'",
"]",
".=",
"'/'",
";",
"}",
"yield",
"$",
"result",
";",
"}",
"}",
"}"
] | Returns a list of properties for a given path.
The path that should be supplied should have the baseUrl stripped out
The list of properties should be supplied in Clark notation. If the list is empty
'allprops' is assumed.
If a depth of 1 is requested child elements will also be returned.
@param string $path
@param array $propertyNames
@param int $depth
@return \Iterator | [
"Returns",
"a",
"list",
"of",
"properties",
"for",
"a",
"given",
"path",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L954-L995 |
sabre-io/dav | lib/DAV/Server.php | Server.getPropertiesForMultiplePaths | public function getPropertiesForMultiplePaths(array $paths, array $propertyNames = [])
{
$result = [
];
$nodes = $this->tree->getMultipleNodes($paths);
foreach ($nodes as $path => $node) {
$propFind = new PropFind($path, $propertyNames);
$r = $this->getPropertiesByNode($propFind, $node);
if ($r) {
$result[$path] = $propFind->getResultForMultiStatus();
$result[$path]['href'] = $path;
$resourceType = $this->getResourceTypeForNode($node);
if (in_array('{DAV:}collection', $resourceType) || in_array('{DAV:}principal', $resourceType)) {
$result[$path]['href'] .= '/';
}
}
}
return $result;
} | php | public function getPropertiesForMultiplePaths(array $paths, array $propertyNames = [])
{
$result = [
];
$nodes = $this->tree->getMultipleNodes($paths);
foreach ($nodes as $path => $node) {
$propFind = new PropFind($path, $propertyNames);
$r = $this->getPropertiesByNode($propFind, $node);
if ($r) {
$result[$path] = $propFind->getResultForMultiStatus();
$result[$path]['href'] = $path;
$resourceType = $this->getResourceTypeForNode($node);
if (in_array('{DAV:}collection', $resourceType) || in_array('{DAV:}principal', $resourceType)) {
$result[$path]['href'] .= '/';
}
}
}
return $result;
} | [
"public",
"function",
"getPropertiesForMultiplePaths",
"(",
"array",
"$",
"paths",
",",
"array",
"$",
"propertyNames",
"=",
"[",
"]",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"nodes",
"=",
"$",
"this",
"->",
"tree",
"->",
"getMultipleNodes",
"(",
"$",
"paths",
")",
";",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"path",
"=>",
"$",
"node",
")",
"{",
"$",
"propFind",
"=",
"new",
"PropFind",
"(",
"$",
"path",
",",
"$",
"propertyNames",
")",
";",
"$",
"r",
"=",
"$",
"this",
"->",
"getPropertiesByNode",
"(",
"$",
"propFind",
",",
"$",
"node",
")",
";",
"if",
"(",
"$",
"r",
")",
"{",
"$",
"result",
"[",
"$",
"path",
"]",
"=",
"$",
"propFind",
"->",
"getResultForMultiStatus",
"(",
")",
";",
"$",
"result",
"[",
"$",
"path",
"]",
"[",
"'href'",
"]",
"=",
"$",
"path",
";",
"$",
"resourceType",
"=",
"$",
"this",
"->",
"getResourceTypeForNode",
"(",
"$",
"node",
")",
";",
"if",
"(",
"in_array",
"(",
"'{DAV:}collection'",
",",
"$",
"resourceType",
")",
"||",
"in_array",
"(",
"'{DAV:}principal'",
",",
"$",
"resourceType",
")",
")",
"{",
"$",
"result",
"[",
"$",
"path",
"]",
"[",
"'href'",
"]",
".=",
"'/'",
";",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns a list of properties for a list of paths.
The path that should be supplied should have the baseUrl stripped out
The list of properties should be supplied in Clark notation. If the list is empty
'allprops' is assumed.
The result is returned as an array, with paths for it's keys.
The result may be returned out of order.
@param array $paths
@param array $propertyNames
@return array | [
"Returns",
"a",
"list",
"of",
"properties",
"for",
"a",
"list",
"of",
"paths",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L1012-L1034 |
sabre-io/dav | lib/DAV/Server.php | Server.createFile | public function createFile($uri, $data, &$etag = null)
{
list($dir, $name) = Uri\split($uri);
if (!$this->emit('beforeBind', [$uri])) {
return false;
}
$parent = $this->tree->getNodeForPath($dir);
if (!$parent instanceof ICollection) {
throw new Exception\Conflict('Files can only be created as children of collections');
}
// It is possible for an event handler to modify the content of the
// body, before it gets written. If this is the case, $modified
// should be set to true.
//
// If $modified is true, we must not send back an ETag.
$modified = false;
if (!$this->emit('beforeCreateFile', [$uri, &$data, $parent, &$modified])) {
return false;
}
$etag = $parent->createFile($name, $data);
if ($modified) {
$etag = null;
}
$this->tree->markDirty($dir.'/'.$name);
$this->emit('afterBind', [$uri]);
$this->emit('afterCreateFile', [$uri, $parent]);
return true;
} | php | public function createFile($uri, $data, &$etag = null)
{
list($dir, $name) = Uri\split($uri);
if (!$this->emit('beforeBind', [$uri])) {
return false;
}
$parent = $this->tree->getNodeForPath($dir);
if (!$parent instanceof ICollection) {
throw new Exception\Conflict('Files can only be created as children of collections');
}
$modified = false;
if (!$this->emit('beforeCreateFile', [$uri, &$data, $parent, &$modified])) {
return false;
}
$etag = $parent->createFile($name, $data);
if ($modified) {
$etag = null;
}
$this->tree->markDirty($dir.'/'.$name);
$this->emit('afterBind', [$uri]);
$this->emit('afterCreateFile', [$uri, $parent]);
return true;
} | [
"public",
"function",
"createFile",
"(",
"$",
"uri",
",",
"$",
"data",
",",
"&",
"$",
"etag",
"=",
"null",
")",
"{",
"list",
"(",
"$",
"dir",
",",
"$",
"name",
")",
"=",
"Uri",
"\\",
"split",
"(",
"$",
"uri",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"emit",
"(",
"'beforeBind'",
",",
"[",
"$",
"uri",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"parent",
"=",
"$",
"this",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"dir",
")",
";",
"if",
"(",
"!",
"$",
"parent",
"instanceof",
"ICollection",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"Conflict",
"(",
"'Files can only be created as children of collections'",
")",
";",
"}",
"// It is possible for an event handler to modify the content of the",
"// body, before it gets written. If this is the case, $modified",
"// should be set to true.",
"//",
"// If $modified is true, we must not send back an ETag.",
"$",
"modified",
"=",
"false",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"emit",
"(",
"'beforeCreateFile'",
",",
"[",
"$",
"uri",
",",
"&",
"$",
"data",
",",
"$",
"parent",
",",
"&",
"$",
"modified",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"etag",
"=",
"$",
"parent",
"->",
"createFile",
"(",
"$",
"name",
",",
"$",
"data",
")",
";",
"if",
"(",
"$",
"modified",
")",
"{",
"$",
"etag",
"=",
"null",
";",
"}",
"$",
"this",
"->",
"tree",
"->",
"markDirty",
"(",
"$",
"dir",
".",
"'/'",
".",
"$",
"name",
")",
";",
"$",
"this",
"->",
"emit",
"(",
"'afterBind'",
",",
"[",
"$",
"uri",
"]",
")",
";",
"$",
"this",
"->",
"emit",
"(",
"'afterCreateFile'",
",",
"[",
"$",
"uri",
",",
"$",
"parent",
"]",
")",
";",
"return",
"true",
";",
"}"
] | This method is invoked by sub-systems creating a new file.
Currently this is done by HTTP PUT and HTTP LOCK (in the Locks_Plugin).
It was important to get this done through a centralized function,
allowing plugins to intercept this using the beforeCreateFile event.
This method will return true if the file was actually created
@param string $uri
@param resource $data
@param string $etag
@return bool | [
"This",
"method",
"is",
"invoked",
"by",
"sub",
"-",
"systems",
"creating",
"a",
"new",
"file",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L1071-L1106 |
sabre-io/dav | lib/DAV/Server.php | Server.updateFile | public function updateFile($uri, $data, &$etag = null)
{
$node = $this->tree->getNodeForPath($uri);
// It is possible for an event handler to modify the content of the
// body, before it gets written. If this is the case, $modified
// should be set to true.
//
// If $modified is true, we must not send back an ETag.
$modified = false;
if (!$this->emit('beforeWriteContent', [$uri, $node, &$data, &$modified])) {
return false;
}
$etag = $node->put($data);
if ($modified) {
$etag = null;
}
$this->emit('afterWriteContent', [$uri, $node]);
return true;
} | php | public function updateFile($uri, $data, &$etag = null)
{
$node = $this->tree->getNodeForPath($uri);
$modified = false;
if (!$this->emit('beforeWriteContent', [$uri, $node, &$data, &$modified])) {
return false;
}
$etag = $node->put($data);
if ($modified) {
$etag = null;
}
$this->emit('afterWriteContent', [$uri, $node]);
return true;
} | [
"public",
"function",
"updateFile",
"(",
"$",
"uri",
",",
"$",
"data",
",",
"&",
"$",
"etag",
"=",
"null",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"uri",
")",
";",
"// It is possible for an event handler to modify the content of the",
"// body, before it gets written. If this is the case, $modified",
"// should be set to true.",
"//",
"// If $modified is true, we must not send back an ETag.",
"$",
"modified",
"=",
"false",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"emit",
"(",
"'beforeWriteContent'",
",",
"[",
"$",
"uri",
",",
"$",
"node",
",",
"&",
"$",
"data",
",",
"&",
"$",
"modified",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"etag",
"=",
"$",
"node",
"->",
"put",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"modified",
")",
"{",
"$",
"etag",
"=",
"null",
";",
"}",
"$",
"this",
"->",
"emit",
"(",
"'afterWriteContent'",
",",
"[",
"$",
"uri",
",",
"$",
"node",
"]",
")",
";",
"return",
"true",
";",
"}"
] | This method is invoked by sub-systems updating a file.
This method will return true if the file was actually updated
@param string $uri
@param resource $data
@param string $etag
@return bool | [
"This",
"method",
"is",
"invoked",
"by",
"sub",
"-",
"systems",
"updating",
"a",
"file",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L1119-L1140 |
sabre-io/dav | lib/DAV/Server.php | Server.createCollection | public function createCollection($uri, MkCol $mkCol)
{
list($parentUri, $newName) = Uri\split($uri);
// Making sure the parent exists
try {
$parent = $this->tree->getNodeForPath($parentUri);
} catch (Exception\NotFound $e) {
throw new Exception\Conflict('Parent node does not exist');
}
// Making sure the parent is a collection
if (!$parent instanceof ICollection) {
throw new Exception\Conflict('Parent node is not a collection');
}
// Making sure the child does not already exist
try {
$parent->getChild($newName);
// If we got here.. it means there's already a node on that url, and we need to throw a 405
throw new Exception\MethodNotAllowed('The resource you tried to create already exists');
} catch (Exception\NotFound $e) {
// NotFound is the expected behavior.
}
if (!$this->emit('beforeBind', [$uri])) {
return;
}
if ($parent instanceof IExtendedCollection) {
/*
* If the parent is an instance of IExtendedCollection, it means that
* we can pass the MkCol object directly as it may be able to store
* properties immediately.
*/
$parent->createExtendedCollection($newName, $mkCol);
} else {
/*
* If the parent is a standard ICollection, it means only
* 'standard' collections can be created, so we should fail any
* MKCOL operation that carries extra resourcetypes.
*/
if (count($mkCol->getResourceType()) > 1) {
throw new Exception\InvalidResourceType('The {DAV:}resourcetype you specified is not supported here.');
}
$parent->createDirectory($newName);
}
// If there are any properties that have not been handled/stored,
// we ask the 'propPatch' event to handle them. This will allow for
// example the propertyStorage system to store properties upon MKCOL.
if ($mkCol->getRemainingMutations()) {
$this->emit('propPatch', [$uri, $mkCol]);
}
$success = $mkCol->commit();
if (!$success) {
$result = $mkCol->getResult();
$formattedResult = [
'href' => $uri,
];
foreach ($result as $propertyName => $status) {
if (!isset($formattedResult[$status])) {
$formattedResult[$status] = [];
}
$formattedResult[$status][$propertyName] = null;
}
return $formattedResult;
}
$this->tree->markDirty($parentUri);
$this->emit('afterBind', [$uri]);
} | php | public function createCollection($uri, MkCol $mkCol)
{
list($parentUri, $newName) = Uri\split($uri);
try {
$parent = $this->tree->getNodeForPath($parentUri);
} catch (Exception\NotFound $e) {
throw new Exception\Conflict('Parent node does not exist');
}
if (!$parent instanceof ICollection) {
throw new Exception\Conflict('Parent node is not a collection');
}
try {
$parent->getChild($newName);
throw new Exception\MethodNotAllowed('The resource you tried to create already exists');
} catch (Exception\NotFound $e) {
}
if (!$this->emit('beforeBind', [$uri])) {
return;
}
if ($parent instanceof IExtendedCollection) {
$parent->createExtendedCollection($newName, $mkCol);
} else {
if (count($mkCol->getResourceType()) > 1) {
throw new Exception\InvalidResourceType('The {DAV:}resourcetype you specified is not supported here.');
}
$parent->createDirectory($newName);
}
if ($mkCol->getRemainingMutations()) {
$this->emit('propPatch', [$uri, $mkCol]);
}
$success = $mkCol->commit();
if (!$success) {
$result = $mkCol->getResult();
$formattedResult = [
'href' => $uri,
];
foreach ($result as $propertyName => $status) {
if (!isset($formattedResult[$status])) {
$formattedResult[$status] = [];
}
$formattedResult[$status][$propertyName] = null;
}
return $formattedResult;
}
$this->tree->markDirty($parentUri);
$this->emit('afterBind', [$uri]);
} | [
"public",
"function",
"createCollection",
"(",
"$",
"uri",
",",
"MkCol",
"$",
"mkCol",
")",
"{",
"list",
"(",
"$",
"parentUri",
",",
"$",
"newName",
")",
"=",
"Uri",
"\\",
"split",
"(",
"$",
"uri",
")",
";",
"// Making sure the parent exists",
"try",
"{",
"$",
"parent",
"=",
"$",
"this",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"parentUri",
")",
";",
"}",
"catch",
"(",
"Exception",
"\\",
"NotFound",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"Conflict",
"(",
"'Parent node does not exist'",
")",
";",
"}",
"// Making sure the parent is a collection",
"if",
"(",
"!",
"$",
"parent",
"instanceof",
"ICollection",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"Conflict",
"(",
"'Parent node is not a collection'",
")",
";",
"}",
"// Making sure the child does not already exist",
"try",
"{",
"$",
"parent",
"->",
"getChild",
"(",
"$",
"newName",
")",
";",
"// If we got here.. it means there's already a node on that url, and we need to throw a 405",
"throw",
"new",
"Exception",
"\\",
"MethodNotAllowed",
"(",
"'The resource you tried to create already exists'",
")",
";",
"}",
"catch",
"(",
"Exception",
"\\",
"NotFound",
"$",
"e",
")",
"{",
"// NotFound is the expected behavior.",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"emit",
"(",
"'beforeBind'",
",",
"[",
"$",
"uri",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"parent",
"instanceof",
"IExtendedCollection",
")",
"{",
"/*\n * If the parent is an instance of IExtendedCollection, it means that\n * we can pass the MkCol object directly as it may be able to store\n * properties immediately.\n */",
"$",
"parent",
"->",
"createExtendedCollection",
"(",
"$",
"newName",
",",
"$",
"mkCol",
")",
";",
"}",
"else",
"{",
"/*\n * If the parent is a standard ICollection, it means only\n * 'standard' collections can be created, so we should fail any\n * MKCOL operation that carries extra resourcetypes.\n */",
"if",
"(",
"count",
"(",
"$",
"mkCol",
"->",
"getResourceType",
"(",
")",
")",
">",
"1",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidResourceType",
"(",
"'The {DAV:}resourcetype you specified is not supported here.'",
")",
";",
"}",
"$",
"parent",
"->",
"createDirectory",
"(",
"$",
"newName",
")",
";",
"}",
"// If there are any properties that have not been handled/stored,",
"// we ask the 'propPatch' event to handle them. This will allow for",
"// example the propertyStorage system to store properties upon MKCOL.",
"if",
"(",
"$",
"mkCol",
"->",
"getRemainingMutations",
"(",
")",
")",
"{",
"$",
"this",
"->",
"emit",
"(",
"'propPatch'",
",",
"[",
"$",
"uri",
",",
"$",
"mkCol",
"]",
")",
";",
"}",
"$",
"success",
"=",
"$",
"mkCol",
"->",
"commit",
"(",
")",
";",
"if",
"(",
"!",
"$",
"success",
")",
"{",
"$",
"result",
"=",
"$",
"mkCol",
"->",
"getResult",
"(",
")",
";",
"$",
"formattedResult",
"=",
"[",
"'href'",
"=>",
"$",
"uri",
",",
"]",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"propertyName",
"=>",
"$",
"status",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"formattedResult",
"[",
"$",
"status",
"]",
")",
")",
"{",
"$",
"formattedResult",
"[",
"$",
"status",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"formattedResult",
"[",
"$",
"status",
"]",
"[",
"$",
"propertyName",
"]",
"=",
"null",
";",
"}",
"return",
"$",
"formattedResult",
";",
"}",
"$",
"this",
"->",
"tree",
"->",
"markDirty",
"(",
"$",
"parentUri",
")",
";",
"$",
"this",
"->",
"emit",
"(",
"'afterBind'",
",",
"[",
"$",
"uri",
"]",
")",
";",
"}"
] | Use this method to create a new collection.
@param string $uri The new uri
@param MkCol $mkCol
@return array|null | [
"Use",
"this",
"method",
"to",
"create",
"a",
"new",
"collection",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L1160-L1237 |
sabre-io/dav | lib/DAV/Server.php | Server.updateProperties | public function updateProperties($path, array $properties)
{
$propPatch = new PropPatch($properties);
$this->emit('propPatch', [$path, $propPatch]);
$propPatch->commit();
return $propPatch->getResult();
} | php | public function updateProperties($path, array $properties)
{
$propPatch = new PropPatch($properties);
$this->emit('propPatch', [$path, $propPatch]);
$propPatch->commit();
return $propPatch->getResult();
} | [
"public",
"function",
"updateProperties",
"(",
"$",
"path",
",",
"array",
"$",
"properties",
")",
"{",
"$",
"propPatch",
"=",
"new",
"PropPatch",
"(",
"$",
"properties",
")",
";",
"$",
"this",
"->",
"emit",
"(",
"'propPatch'",
",",
"[",
"$",
"path",
",",
"$",
"propPatch",
"]",
")",
";",
"$",
"propPatch",
"->",
"commit",
"(",
")",
";",
"return",
"$",
"propPatch",
"->",
"getResult",
"(",
")",
";",
"}"
] | This method updates a resource's properties.
The properties array must be a list of properties. Array-keys are
property names in clarknotation, array-values are it's values.
If a property must be deleted, the value should be null.
Note that this request should either completely succeed, or
completely fail.
The response is an array with properties for keys, and http status codes
as their values.
@param string $path
@param array $properties
@return array | [
"This",
"method",
"updates",
"a",
"resource",
"s",
"properties",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L1257-L1264 |
sabre-io/dav | lib/DAV/Server.php | Server.checkPreconditions | public function checkPreconditions(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
$node = null;
$lastMod = null;
$etag = null;
if ($ifMatch = $request->getHeader('If-Match')) {
// If-Match contains an entity tag. Only if the entity-tag
// matches we are allowed to make the request succeed.
// If the entity-tag is '*' we are only allowed to make the
// request succeed if a resource exists at that url.
try {
$node = $this->tree->getNodeForPath($path);
} catch (Exception\NotFound $e) {
throw new Exception\PreconditionFailed('An If-Match header was specified and the resource did not exist', 'If-Match');
}
// Only need to check entity tags if they are not *
if ('*' !== $ifMatch) {
// There can be multiple ETags
$ifMatch = explode(',', $ifMatch);
$haveMatch = false;
foreach ($ifMatch as $ifMatchItem) {
// Stripping any extra spaces
$ifMatchItem = trim($ifMatchItem, ' ');
$etag = $node instanceof IFile ? $node->getETag() : null;
if ($etag === $ifMatchItem) {
$haveMatch = true;
} else {
// Evolution has a bug where it sometimes prepends the "
// with a \. This is our workaround.
if (str_replace('\\"', '"', $ifMatchItem) === $etag) {
$haveMatch = true;
}
}
}
if (!$haveMatch) {
if ($etag) {
$response->setHeader('ETag', $etag);
}
throw new Exception\PreconditionFailed('An If-Match header was specified, but none of the specified ETags matched.', 'If-Match');
}
}
}
if ($ifNoneMatch = $request->getHeader('If-None-Match')) {
// The If-None-Match header contains an ETag.
// Only if the ETag does not match the current ETag, the request will succeed
// The header can also contain *, in which case the request
// will only succeed if the entity does not exist at all.
$nodeExists = true;
if (!$node) {
try {
$node = $this->tree->getNodeForPath($path);
} catch (Exception\NotFound $e) {
$nodeExists = false;
}
}
if ($nodeExists) {
$haveMatch = false;
if ('*' === $ifNoneMatch) {
$haveMatch = true;
} else {
// There might be multiple ETags
$ifNoneMatch = explode(',', $ifNoneMatch);
$etag = $node instanceof IFile ? $node->getETag() : null;
foreach ($ifNoneMatch as $ifNoneMatchItem) {
// Stripping any extra spaces
$ifNoneMatchItem = trim($ifNoneMatchItem, ' ');
if ($etag === $ifNoneMatchItem) {
$haveMatch = true;
}
}
}
if ($haveMatch) {
if ($etag) {
$response->setHeader('ETag', $etag);
}
if ('GET' === $request->getMethod()) {
$response->setStatus(304);
return false;
} else {
throw new Exception\PreconditionFailed('An If-None-Match header was specified, but the ETag matched (or * was specified).', 'If-None-Match');
}
}
}
}
if (!$ifNoneMatch && ($ifModifiedSince = $request->getHeader('If-Modified-Since'))) {
// The If-Modified-Since header contains a date. We
// will only return the entity if it has been changed since
// that date. If it hasn't been changed, we return a 304
// header
// Note that this header only has to be checked if there was no If-None-Match header
// as per the HTTP spec.
$date = HTTP\parseDate($ifModifiedSince);
if ($date) {
if (is_null($node)) {
$node = $this->tree->getNodeForPath($path);
}
$lastMod = $node->getLastModified();
if ($lastMod) {
$lastMod = new \DateTime('@'.$lastMod);
if ($lastMod <= $date) {
$response->setStatus(304);
$response->setHeader('Last-Modified', HTTP\toDate($lastMod));
return false;
}
}
}
}
if ($ifUnmodifiedSince = $request->getHeader('If-Unmodified-Since')) {
// The If-Unmodified-Since will allow allow the request if the
// entity has not changed since the specified date.
$date = HTTP\parseDate($ifUnmodifiedSince);
// We must only check the date if it's valid
if ($date) {
if (is_null($node)) {
$node = $this->tree->getNodeForPath($path);
}
$lastMod = $node->getLastModified();
if ($lastMod) {
$lastMod = new \DateTime('@'.$lastMod);
if ($lastMod > $date) {
throw new Exception\PreconditionFailed('An If-Unmodified-Since header was specified, but the entity has been changed since the specified date.', 'If-Unmodified-Since');
}
}
}
}
// Now the hardest, the If: header. The If: header can contain multiple
// urls, ETags and so-called 'state tokens'.
//
// Examples of state tokens include lock-tokens (as defined in rfc4918)
// and sync-tokens (as defined in rfc6578).
//
// The only proper way to deal with these, is to emit events, that a
// Sync and Lock plugin can pick up.
$ifConditions = $this->getIfConditions($request);
foreach ($ifConditions as $kk => $ifCondition) {
foreach ($ifCondition['tokens'] as $ii => $token) {
$ifConditions[$kk]['tokens'][$ii]['validToken'] = false;
}
}
// Plugins are responsible for validating all the tokens.
// If a plugin deemed a token 'valid', it will set 'validToken' to
// true.
$this->emit('validateTokens', [$request, &$ifConditions]);
// Now we're going to analyze the result.
// Every ifCondition needs to validate to true, so we exit as soon as
// we have an invalid condition.
foreach ($ifConditions as $ifCondition) {
$uri = $ifCondition['uri'];
$tokens = $ifCondition['tokens'];
// We only need 1 valid token for the condition to succeed.
foreach ($tokens as $token) {
$tokenValid = $token['validToken'] || !$token['token'];
$etagValid = false;
if (!$token['etag']) {
$etagValid = true;
}
// Checking the ETag, only if the token was already deemed
// valid and there is one.
if ($token['etag'] && $tokenValid) {
// The token was valid, and there was an ETag. We must
// grab the current ETag and check it.
$node = $this->tree->getNodeForPath($uri);
$etagValid = $node instanceof IFile && $node->getETag() == $token['etag'];
}
if (($tokenValid && $etagValid) ^ $token['negate']) {
// Both were valid, so we can go to the next condition.
continue 2;
}
}
// If we ended here, it means there was no valid ETag + token
// combination found for the current condition. This means we fail!
throw new Exception\PreconditionFailed('Failed to find a valid token/etag combination for '.$uri, 'If');
}
return true;
} | php | public function checkPreconditions(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
$node = null;
$lastMod = null;
$etag = null;
if ($ifMatch = $request->getHeader('If-Match')) {
try {
$node = $this->tree->getNodeForPath($path);
} catch (Exception\NotFound $e) {
throw new Exception\PreconditionFailed('An If-Match header was specified and the resource did not exist', 'If-Match');
}
if ('*' !== $ifMatch) {
$ifMatch = explode(',', $ifMatch);
$haveMatch = false;
foreach ($ifMatch as $ifMatchItem) {
$ifMatchItem = trim($ifMatchItem, ' ');
$etag = $node instanceof IFile ? $node->getETag() : null;
if ($etag === $ifMatchItem) {
$haveMatch = true;
} else {
if (str_replace('\\"', '"', $ifMatchItem) === $etag) {
$haveMatch = true;
}
}
}
if (!$haveMatch) {
if ($etag) {
$response->setHeader('ETag', $etag);
}
throw new Exception\PreconditionFailed('An If-Match header was specified, but none of the specified ETags matched.', 'If-Match');
}
}
}
if ($ifNoneMatch = $request->getHeader('If-None-Match')) {
$nodeExists = true;
if (!$node) {
try {
$node = $this->tree->getNodeForPath($path);
} catch (Exception\NotFound $e) {
$nodeExists = false;
}
}
if ($nodeExists) {
$haveMatch = false;
if ('*' === $ifNoneMatch) {
$haveMatch = true;
} else {
$ifNoneMatch = explode(',', $ifNoneMatch);
$etag = $node instanceof IFile ? $node->getETag() : null;
foreach ($ifNoneMatch as $ifNoneMatchItem) {
$ifNoneMatchItem = trim($ifNoneMatchItem, ' ');
if ($etag === $ifNoneMatchItem) {
$haveMatch = true;
}
}
}
if ($haveMatch) {
if ($etag) {
$response->setHeader('ETag', $etag);
}
if ('GET' === $request->getMethod()) {
$response->setStatus(304);
return false;
} else {
throw new Exception\PreconditionFailed('An If-None-Match header was specified, but the ETag matched (or * was specified).', 'If-None-Match');
}
}
}
}
if (!$ifNoneMatch && ($ifModifiedSince = $request->getHeader('If-Modified-Since'))) {
$date = HTTP\parseDate($ifModifiedSince);
if ($date) {
if (is_null($node)) {
$node = $this->tree->getNodeForPath($path);
}
$lastMod = $node->getLastModified();
if ($lastMod) {
$lastMod = new \DateTime('@'.$lastMod);
if ($lastMod <= $date) {
$response->setStatus(304);
$response->setHeader('Last-Modified', HTTP\toDate($lastMod));
return false;
}
}
}
}
if ($ifUnmodifiedSince = $request->getHeader('If-Unmodified-Since')) {
$date = HTTP\parseDate($ifUnmodifiedSince);
if ($date) {
if (is_null($node)) {
$node = $this->tree->getNodeForPath($path);
}
$lastMod = $node->getLastModified();
if ($lastMod) {
$lastMod = new \DateTime('@'.$lastMod);
if ($lastMod > $date) {
throw new Exception\PreconditionFailed('An If-Unmodified-Since header was specified, but the entity has been changed since the specified date.', 'If-Unmodified-Since');
}
}
}
}
$ifConditions = $this->getIfConditions($request);
foreach ($ifConditions as $kk => $ifCondition) {
foreach ($ifCondition['tokens'] as $ii => $token) {
$ifConditions[$kk]['tokens'][$ii]['validToken'] = false;
}
}
$this->emit('validateTokens', [$request, &$ifConditions]);
foreach ($ifConditions as $ifCondition) {
$uri = $ifCondition['uri'];
$tokens = $ifCondition['tokens'];
foreach ($tokens as $token) {
$tokenValid = $token['validToken'] || !$token['token'];
$etagValid = false;
if (!$token['etag']) {
$etagValid = true;
}
if ($token['etag'] && $tokenValid) {
$node = $this->tree->getNodeForPath($uri);
$etagValid = $node instanceof IFile && $node->getETag() == $token['etag'];
}
if (($tokenValid && $etagValid) ^ $token['negate']) {
continue 2;
}
}
throw new Exception\PreconditionFailed('Failed to find a valid token/etag combination for '.$uri, 'If');
}
return true;
} | [
"public",
"function",
"checkPreconditions",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"path",
"=",
"$",
"request",
"->",
"getPath",
"(",
")",
";",
"$",
"node",
"=",
"null",
";",
"$",
"lastMod",
"=",
"null",
";",
"$",
"etag",
"=",
"null",
";",
"if",
"(",
"$",
"ifMatch",
"=",
"$",
"request",
"->",
"getHeader",
"(",
"'If-Match'",
")",
")",
"{",
"// If-Match contains an entity tag. Only if the entity-tag",
"// matches we are allowed to make the request succeed.",
"// If the entity-tag is '*' we are only allowed to make the",
"// request succeed if a resource exists at that url.",
"try",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"path",
")",
";",
"}",
"catch",
"(",
"Exception",
"\\",
"NotFound",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"PreconditionFailed",
"(",
"'An If-Match header was specified and the resource did not exist'",
",",
"'If-Match'",
")",
";",
"}",
"// Only need to check entity tags if they are not *",
"if",
"(",
"'*'",
"!==",
"$",
"ifMatch",
")",
"{",
"// There can be multiple ETags",
"$",
"ifMatch",
"=",
"explode",
"(",
"','",
",",
"$",
"ifMatch",
")",
";",
"$",
"haveMatch",
"=",
"false",
";",
"foreach",
"(",
"$",
"ifMatch",
"as",
"$",
"ifMatchItem",
")",
"{",
"// Stripping any extra spaces",
"$",
"ifMatchItem",
"=",
"trim",
"(",
"$",
"ifMatchItem",
",",
"' '",
")",
";",
"$",
"etag",
"=",
"$",
"node",
"instanceof",
"IFile",
"?",
"$",
"node",
"->",
"getETag",
"(",
")",
":",
"null",
";",
"if",
"(",
"$",
"etag",
"===",
"$",
"ifMatchItem",
")",
"{",
"$",
"haveMatch",
"=",
"true",
";",
"}",
"else",
"{",
"// Evolution has a bug where it sometimes prepends the \"",
"// with a \\. This is our workaround.",
"if",
"(",
"str_replace",
"(",
"'\\\\\"'",
",",
"'\"'",
",",
"$",
"ifMatchItem",
")",
"===",
"$",
"etag",
")",
"{",
"$",
"haveMatch",
"=",
"true",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"haveMatch",
")",
"{",
"if",
"(",
"$",
"etag",
")",
"{",
"$",
"response",
"->",
"setHeader",
"(",
"'ETag'",
",",
"$",
"etag",
")",
";",
"}",
"throw",
"new",
"Exception",
"\\",
"PreconditionFailed",
"(",
"'An If-Match header was specified, but none of the specified ETags matched.'",
",",
"'If-Match'",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"ifNoneMatch",
"=",
"$",
"request",
"->",
"getHeader",
"(",
"'If-None-Match'",
")",
")",
"{",
"// The If-None-Match header contains an ETag.",
"// Only if the ETag does not match the current ETag, the request will succeed",
"// The header can also contain *, in which case the request",
"// will only succeed if the entity does not exist at all.",
"$",
"nodeExists",
"=",
"true",
";",
"if",
"(",
"!",
"$",
"node",
")",
"{",
"try",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"path",
")",
";",
"}",
"catch",
"(",
"Exception",
"\\",
"NotFound",
"$",
"e",
")",
"{",
"$",
"nodeExists",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"$",
"nodeExists",
")",
"{",
"$",
"haveMatch",
"=",
"false",
";",
"if",
"(",
"'*'",
"===",
"$",
"ifNoneMatch",
")",
"{",
"$",
"haveMatch",
"=",
"true",
";",
"}",
"else",
"{",
"// There might be multiple ETags",
"$",
"ifNoneMatch",
"=",
"explode",
"(",
"','",
",",
"$",
"ifNoneMatch",
")",
";",
"$",
"etag",
"=",
"$",
"node",
"instanceof",
"IFile",
"?",
"$",
"node",
"->",
"getETag",
"(",
")",
":",
"null",
";",
"foreach",
"(",
"$",
"ifNoneMatch",
"as",
"$",
"ifNoneMatchItem",
")",
"{",
"// Stripping any extra spaces",
"$",
"ifNoneMatchItem",
"=",
"trim",
"(",
"$",
"ifNoneMatchItem",
",",
"' '",
")",
";",
"if",
"(",
"$",
"etag",
"===",
"$",
"ifNoneMatchItem",
")",
"{",
"$",
"haveMatch",
"=",
"true",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"haveMatch",
")",
"{",
"if",
"(",
"$",
"etag",
")",
"{",
"$",
"response",
"->",
"setHeader",
"(",
"'ETag'",
",",
"$",
"etag",
")",
";",
"}",
"if",
"(",
"'GET'",
"===",
"$",
"request",
"->",
"getMethod",
"(",
")",
")",
"{",
"$",
"response",
"->",
"setStatus",
"(",
"304",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"\\",
"PreconditionFailed",
"(",
"'An If-None-Match header was specified, but the ETag matched (or * was specified).'",
",",
"'If-None-Match'",
")",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"ifNoneMatch",
"&&",
"(",
"$",
"ifModifiedSince",
"=",
"$",
"request",
"->",
"getHeader",
"(",
"'If-Modified-Since'",
")",
")",
")",
"{",
"// The If-Modified-Since header contains a date. We",
"// will only return the entity if it has been changed since",
"// that date. If it hasn't been changed, we return a 304",
"// header",
"// Note that this header only has to be checked if there was no If-None-Match header",
"// as per the HTTP spec.",
"$",
"date",
"=",
"HTTP",
"\\",
"parseDate",
"(",
"$",
"ifModifiedSince",
")",
";",
"if",
"(",
"$",
"date",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"node",
")",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"path",
")",
";",
"}",
"$",
"lastMod",
"=",
"$",
"node",
"->",
"getLastModified",
"(",
")",
";",
"if",
"(",
"$",
"lastMod",
")",
"{",
"$",
"lastMod",
"=",
"new",
"\\",
"DateTime",
"(",
"'@'",
".",
"$",
"lastMod",
")",
";",
"if",
"(",
"$",
"lastMod",
"<=",
"$",
"date",
")",
"{",
"$",
"response",
"->",
"setStatus",
"(",
"304",
")",
";",
"$",
"response",
"->",
"setHeader",
"(",
"'Last-Modified'",
",",
"HTTP",
"\\",
"toDate",
"(",
"$",
"lastMod",
")",
")",
";",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"$",
"ifUnmodifiedSince",
"=",
"$",
"request",
"->",
"getHeader",
"(",
"'If-Unmodified-Since'",
")",
")",
"{",
"// The If-Unmodified-Since will allow allow the request if the",
"// entity has not changed since the specified date.",
"$",
"date",
"=",
"HTTP",
"\\",
"parseDate",
"(",
"$",
"ifUnmodifiedSince",
")",
";",
"// We must only check the date if it's valid",
"if",
"(",
"$",
"date",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"node",
")",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"path",
")",
";",
"}",
"$",
"lastMod",
"=",
"$",
"node",
"->",
"getLastModified",
"(",
")",
";",
"if",
"(",
"$",
"lastMod",
")",
"{",
"$",
"lastMod",
"=",
"new",
"\\",
"DateTime",
"(",
"'@'",
".",
"$",
"lastMod",
")",
";",
"if",
"(",
"$",
"lastMod",
">",
"$",
"date",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"PreconditionFailed",
"(",
"'An If-Unmodified-Since header was specified, but the entity has been changed since the specified date.'",
",",
"'If-Unmodified-Since'",
")",
";",
"}",
"}",
"}",
"}",
"// Now the hardest, the If: header. The If: header can contain multiple",
"// urls, ETags and so-called 'state tokens'.",
"//",
"// Examples of state tokens include lock-tokens (as defined in rfc4918)",
"// and sync-tokens (as defined in rfc6578).",
"//",
"// The only proper way to deal with these, is to emit events, that a",
"// Sync and Lock plugin can pick up.",
"$",
"ifConditions",
"=",
"$",
"this",
"->",
"getIfConditions",
"(",
"$",
"request",
")",
";",
"foreach",
"(",
"$",
"ifConditions",
"as",
"$",
"kk",
"=>",
"$",
"ifCondition",
")",
"{",
"foreach",
"(",
"$",
"ifCondition",
"[",
"'tokens'",
"]",
"as",
"$",
"ii",
"=>",
"$",
"token",
")",
"{",
"$",
"ifConditions",
"[",
"$",
"kk",
"]",
"[",
"'tokens'",
"]",
"[",
"$",
"ii",
"]",
"[",
"'validToken'",
"]",
"=",
"false",
";",
"}",
"}",
"// Plugins are responsible for validating all the tokens.",
"// If a plugin deemed a token 'valid', it will set 'validToken' to",
"// true.",
"$",
"this",
"->",
"emit",
"(",
"'validateTokens'",
",",
"[",
"$",
"request",
",",
"&",
"$",
"ifConditions",
"]",
")",
";",
"// Now we're going to analyze the result.",
"// Every ifCondition needs to validate to true, so we exit as soon as",
"// we have an invalid condition.",
"foreach",
"(",
"$",
"ifConditions",
"as",
"$",
"ifCondition",
")",
"{",
"$",
"uri",
"=",
"$",
"ifCondition",
"[",
"'uri'",
"]",
";",
"$",
"tokens",
"=",
"$",
"ifCondition",
"[",
"'tokens'",
"]",
";",
"// We only need 1 valid token for the condition to succeed.",
"foreach",
"(",
"$",
"tokens",
"as",
"$",
"token",
")",
"{",
"$",
"tokenValid",
"=",
"$",
"token",
"[",
"'validToken'",
"]",
"||",
"!",
"$",
"token",
"[",
"'token'",
"]",
";",
"$",
"etagValid",
"=",
"false",
";",
"if",
"(",
"!",
"$",
"token",
"[",
"'etag'",
"]",
")",
"{",
"$",
"etagValid",
"=",
"true",
";",
"}",
"// Checking the ETag, only if the token was already deemed",
"// valid and there is one.",
"if",
"(",
"$",
"token",
"[",
"'etag'",
"]",
"&&",
"$",
"tokenValid",
")",
"{",
"// The token was valid, and there was an ETag. We must",
"// grab the current ETag and check it.",
"$",
"node",
"=",
"$",
"this",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"uri",
")",
";",
"$",
"etagValid",
"=",
"$",
"node",
"instanceof",
"IFile",
"&&",
"$",
"node",
"->",
"getETag",
"(",
")",
"==",
"$",
"token",
"[",
"'etag'",
"]",
";",
"}",
"if",
"(",
"(",
"$",
"tokenValid",
"&&",
"$",
"etagValid",
")",
"^",
"$",
"token",
"[",
"'negate'",
"]",
")",
"{",
"// Both were valid, so we can go to the next condition.",
"continue",
"2",
";",
"}",
"}",
"// If we ended here, it means there was no valid ETag + token",
"// combination found for the current condition. This means we fail!",
"throw",
"new",
"Exception",
"\\",
"PreconditionFailed",
"(",
"'Failed to find a valid token/etag combination for '",
".",
"$",
"uri",
",",
"'If'",
")",
";",
"}",
"return",
"true",
";",
"}"
] | This method checks the main HTTP preconditions.
Currently these are:
* If-Match
* If-None-Match
* If-Modified-Since
* If-Unmodified-Since
The method will return true if all preconditions are met
The method will return false, or throw an exception if preconditions
failed. If false is returned the operation should be aborted, and
the appropriate HTTP response headers are already set.
Normally this method will throw 412 Precondition Failed for failures
related to If-None-Match, If-Match and If-Unmodified Since. It will
set the status to 304 Not Modified for If-Modified_since.
@param RequestInterface $request
@param ResponseInterface $response
@return bool | [
"This",
"method",
"checks",
"the",
"main",
"HTTP",
"preconditions",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L1289-L1487 |
sabre-io/dav | lib/DAV/Server.php | Server.getIfConditions | public function getIfConditions(RequestInterface $request)
{
$header = $request->getHeader('If');
if (!$header) {
return [];
}
$matches = [];
$regex = '/(?:\<(?P<uri>.*?)\>\s)?\((?P<not>Not\s)?(?:\<(?P<token>[^\>]*)\>)?(?:\s?)(?:\[(?P<etag>[^\]]*)\])?\)/im';
preg_match_all($regex, $header, $matches, PREG_SET_ORDER);
$conditions = [];
foreach ($matches as $match) {
// If there was no uri specified in this match, and there were
// already conditions parsed, we add the condition to the list of
// conditions for the previous uri.
if (!$match['uri'] && count($conditions)) {
$conditions[count($conditions) - 1]['tokens'][] = [
'negate' => $match['not'] ? true : false,
'token' => $match['token'],
'etag' => isset($match['etag']) ? $match['etag'] : '',
];
} else {
if (!$match['uri']) {
$realUri = $request->getPath();
} else {
$realUri = $this->calculateUri($match['uri']);
}
$conditions[] = [
'uri' => $realUri,
'tokens' => [
[
'negate' => $match['not'] ? true : false,
'token' => $match['token'],
'etag' => isset($match['etag']) ? $match['etag'] : '',
],
],
];
}
}
return $conditions;
} | php | public function getIfConditions(RequestInterface $request)
{
$header = $request->getHeader('If');
if (!$header) {
return [];
}
$matches = [];
$regex = '/(?:\<(?P<uri>.*?)\>\s)?\((?P<not>Not\s)?(?:\<(?P<token>[^\>]*)\>)?(?:\s?)(?:\[(?P<etag>[^\]]*)\])?\)/im';
preg_match_all($regex, $header, $matches, PREG_SET_ORDER);
$conditions = [];
foreach ($matches as $match) {
if (!$match['uri'] && count($conditions)) {
$conditions[count($conditions) - 1]['tokens'][] = [
'negate' => $match['not'] ? true : false,
'token' => $match['token'],
'etag' => isset($match['etag']) ? $match['etag'] : '',
];
} else {
if (!$match['uri']) {
$realUri = $request->getPath();
} else {
$realUri = $this->calculateUri($match['uri']);
}
$conditions[] = [
'uri' => $realUri,
'tokens' => [
[
'negate' => $match['not'] ? true : false,
'token' => $match['token'],
'etag' => isset($match['etag']) ? $match['etag'] : '',
],
],
];
}
}
return $conditions;
} | [
"public",
"function",
"getIfConditions",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"$",
"header",
"=",
"$",
"request",
"->",
"getHeader",
"(",
"'If'",
")",
";",
"if",
"(",
"!",
"$",
"header",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"matches",
"=",
"[",
"]",
";",
"$",
"regex",
"=",
"'/(?:\\<(?P<uri>.*?)\\>\\s)?\\((?P<not>Not\\s)?(?:\\<(?P<token>[^\\>]*)\\>)?(?:\\s?)(?:\\[(?P<etag>[^\\]]*)\\])?\\)/im'",
";",
"preg_match_all",
"(",
"$",
"regex",
",",
"$",
"header",
",",
"$",
"matches",
",",
"PREG_SET_ORDER",
")",
";",
"$",
"conditions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"match",
")",
"{",
"// If there was no uri specified in this match, and there were",
"// already conditions parsed, we add the condition to the list of",
"// conditions for the previous uri.",
"if",
"(",
"!",
"$",
"match",
"[",
"'uri'",
"]",
"&&",
"count",
"(",
"$",
"conditions",
")",
")",
"{",
"$",
"conditions",
"[",
"count",
"(",
"$",
"conditions",
")",
"-",
"1",
"]",
"[",
"'tokens'",
"]",
"[",
"]",
"=",
"[",
"'negate'",
"=>",
"$",
"match",
"[",
"'not'",
"]",
"?",
"true",
":",
"false",
",",
"'token'",
"=>",
"$",
"match",
"[",
"'token'",
"]",
",",
"'etag'",
"=>",
"isset",
"(",
"$",
"match",
"[",
"'etag'",
"]",
")",
"?",
"$",
"match",
"[",
"'etag'",
"]",
":",
"''",
",",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"match",
"[",
"'uri'",
"]",
")",
"{",
"$",
"realUri",
"=",
"$",
"request",
"->",
"getPath",
"(",
")",
";",
"}",
"else",
"{",
"$",
"realUri",
"=",
"$",
"this",
"->",
"calculateUri",
"(",
"$",
"match",
"[",
"'uri'",
"]",
")",
";",
"}",
"$",
"conditions",
"[",
"]",
"=",
"[",
"'uri'",
"=>",
"$",
"realUri",
",",
"'tokens'",
"=>",
"[",
"[",
"'negate'",
"=>",
"$",
"match",
"[",
"'not'",
"]",
"?",
"true",
":",
"false",
",",
"'token'",
"=>",
"$",
"match",
"[",
"'token'",
"]",
",",
"'etag'",
"=>",
"isset",
"(",
"$",
"match",
"[",
"'etag'",
"]",
")",
"?",
"$",
"match",
"[",
"'etag'",
"]",
":",
"''",
",",
"]",
",",
"]",
",",
"]",
";",
"}",
"}",
"return",
"$",
"conditions",
";",
"}"
] | This method is created to extract information from the WebDAV HTTP 'If:' header.
The If header can be quite complex, and has a bunch of features. We're using a regex to extract all relevant information
The function will return an array, containing structs with the following keys
* uri - the uri the condition applies to.
* tokens - The lock token. another 2 dimensional array containing 3 elements
Example 1:
If: (<opaquelocktoken:181d4fae-7d8c-11d0-a765-00a0c91e6bf2>)
Would result in:
[
[
'uri' => '/request/uri',
'tokens' => [
[
[
'negate' => false,
'token' => 'opaquelocktoken:181d4fae-7d8c-11d0-a765-00a0c91e6bf2',
'etag' => ""
]
]
],
]
]
Example 2:
If: </path/> (Not <opaquelocktoken:181d4fae-7d8c-11d0-a765-00a0c91e6bf2> ["Im An ETag"]) (["Another ETag"]) </path2/> (Not ["Path2 ETag"])
Would result in:
[
[
'uri' => 'path',
'tokens' => [
[
[
'negate' => true,
'token' => 'opaquelocktoken:181d4fae-7d8c-11d0-a765-00a0c91e6bf2',
'etag' => '"Im An ETag"'
],
[
'negate' => false,
'token' => '',
'etag' => '"Another ETag"'
]
]
],
],
[
'uri' => 'path2',
'tokens' => [
[
[
'negate' => true,
'token' => '',
'etag' => '"Path2 ETag"'
]
]
],
],
]
@param RequestInterface $request
@return array | [
"This",
"method",
"is",
"created",
"to",
"extract",
"information",
"from",
"the",
"WebDAV",
"HTTP",
"If",
":",
"header",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L1561-L1606 |
sabre-io/dav | lib/DAV/Server.php | Server.getResourceTypeForNode | public function getResourceTypeForNode(INode $node)
{
$result = [];
foreach ($this->resourceTypeMapping as $className => $resourceType) {
if ($node instanceof $className) {
$result[] = $resourceType;
}
}
return $result;
} | php | public function getResourceTypeForNode(INode $node)
{
$result = [];
foreach ($this->resourceTypeMapping as $className => $resourceType) {
if ($node instanceof $className) {
$result[] = $resourceType;
}
}
return $result;
} | [
"public",
"function",
"getResourceTypeForNode",
"(",
"INode",
"$",
"node",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"resourceTypeMapping",
"as",
"$",
"className",
"=>",
"$",
"resourceType",
")",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"$",
"className",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"resourceType",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns an array with resourcetypes for a node.
@param INode $node
@return array | [
"Returns",
"an",
"array",
"with",
"resourcetypes",
"for",
"a",
"node",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L1615-L1625 |
sabre-io/dav | lib/DAV/Server.php | Server.generateMultiStatus | public function generateMultiStatus($fileProperties, $strip404s = false)
{
$w = $this->xml->getWriter();
$w->openMemory();
$w->contextUri = $this->baseUri;
$w->startDocument();
$w->startElement('{DAV:}multistatus');
foreach ($fileProperties as $entry) {
$href = $entry['href'];
unset($entry['href']);
if ($strip404s) {
unset($entry[404]);
}
$response = new Xml\Element\Response(
ltrim($href, '/'),
$entry
);
$w->write([
'name' => '{DAV:}response',
'value' => $response,
]);
}
$w->endElement();
return $w->outputMemory();
} | php | public function generateMultiStatus($fileProperties, $strip404s = false)
{
$w = $this->xml->getWriter();
$w->openMemory();
$w->contextUri = $this->baseUri;
$w->startDocument();
$w->startElement('{DAV:}multistatus');
foreach ($fileProperties as $entry) {
$href = $entry['href'];
unset($entry['href']);
if ($strip404s) {
unset($entry[404]);
}
$response = new Xml\Element\Response(
ltrim($href, '/'),
$entry
);
$w->write([
'name' => '{DAV:}response',
'value' => $response,
]);
}
$w->endElement();
return $w->outputMemory();
} | [
"public",
"function",
"generateMultiStatus",
"(",
"$",
"fileProperties",
",",
"$",
"strip404s",
"=",
"false",
")",
"{",
"$",
"w",
"=",
"$",
"this",
"->",
"xml",
"->",
"getWriter",
"(",
")",
";",
"$",
"w",
"->",
"openMemory",
"(",
")",
";",
"$",
"w",
"->",
"contextUri",
"=",
"$",
"this",
"->",
"baseUri",
";",
"$",
"w",
"->",
"startDocument",
"(",
")",
";",
"$",
"w",
"->",
"startElement",
"(",
"'{DAV:}multistatus'",
")",
";",
"foreach",
"(",
"$",
"fileProperties",
"as",
"$",
"entry",
")",
"{",
"$",
"href",
"=",
"$",
"entry",
"[",
"'href'",
"]",
";",
"unset",
"(",
"$",
"entry",
"[",
"'href'",
"]",
")",
";",
"if",
"(",
"$",
"strip404s",
")",
"{",
"unset",
"(",
"$",
"entry",
"[",
"404",
"]",
")",
";",
"}",
"$",
"response",
"=",
"new",
"Xml",
"\\",
"Element",
"\\",
"Response",
"(",
"ltrim",
"(",
"$",
"href",
",",
"'/'",
")",
",",
"$",
"entry",
")",
";",
"$",
"w",
"->",
"write",
"(",
"[",
"'name'",
"=>",
"'{DAV:}response'",
",",
"'value'",
"=>",
"$",
"response",
",",
"]",
")",
";",
"}",
"$",
"w",
"->",
"endElement",
"(",
")",
";",
"return",
"$",
"w",
"->",
"outputMemory",
"(",
")",
";",
"}"
] | Generates a WebDAV propfind response body based on a list of nodes.
If 'strip404s' is set to true, all 404 responses will be removed.
@param array|\Traversable $fileProperties The list with nodes
@param bool $strip404s
@return string | [
"Generates",
"a",
"WebDAV",
"propfind",
"response",
"body",
"based",
"on",
"a",
"list",
"of",
"nodes",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L1640-L1667 |
sabre-io/dav | lib/CalDAV/Xml/Property/AllowedSharingModes.php | AllowedSharingModes.xmlSerialize | public function xmlSerialize(Writer $writer)
{
if ($this->canBeShared) {
$writer->writeElement('{'.Plugin::NS_CALENDARSERVER.'}can-be-shared');
}
if ($this->canBePublished) {
$writer->writeElement('{'.Plugin::NS_CALENDARSERVER.'}can-be-published');
}
} | php | public function xmlSerialize(Writer $writer)
{
if ($this->canBeShared) {
$writer->writeElement('{'.Plugin::NS_CALENDARSERVER.'}can-be-shared');
}
if ($this->canBePublished) {
$writer->writeElement('{'.Plugin::NS_CALENDARSERVER.'}can-be-published');
}
} | [
"public",
"function",
"xmlSerialize",
"(",
"Writer",
"$",
"writer",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"canBeShared",
")",
"{",
"$",
"writer",
"->",
"writeElement",
"(",
"'{'",
".",
"Plugin",
"::",
"NS_CALENDARSERVER",
".",
"'}can-be-shared'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"canBePublished",
")",
"{",
"$",
"writer",
"->",
"writeElement",
"(",
"'{'",
".",
"Plugin",
"::",
"NS_CALENDARSERVER",
".",
"'}can-be-published'",
")",
";",
"}",
"}"
] | The xmlSerialize method is called during xml writing.
Use the $writer argument to write its own xml serialization.
An important note: do _not_ create a parent element. Any element
implementing XmlSerializable should only ever write what's considered
its 'inner xml'.
The parent of the current element is responsible for writing a
containing element.
This allows serializers to be re-used for different element names.
If you are opening new elements, you must also close them again.
@param Writer $writer | [
"The",
"xmlSerialize",
"method",
"is",
"called",
"during",
"xml",
"writing",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Xml/Property/AllowedSharingModes.php#L74-L82 |
sabre-io/dav | lib/DAV/Xml/Element/Response.php | Response.xmlSerialize | public function xmlSerialize(Writer $writer)
{
if ($status = $this->getHTTPStatus()) {
$writer->writeElement('{DAV:}status', 'HTTP/1.1 '.$status.' '.\Sabre\HTTP\Response::$statusCodes[$status]);
}
$writer->writeElement('{DAV:}href', $writer->contextUri.\Sabre\HTTP\encodePath($this->getHref()));
$empty = true;
foreach ($this->getResponseProperties() as $status => $properties) {
// Skipping empty lists
if (!$properties || (!ctype_digit($status) && !is_int($status))) {
continue;
}
$empty = false;
$writer->startElement('{DAV:}propstat');
$writer->writeElement('{DAV:}prop', $properties);
$writer->writeElement('{DAV:}status', 'HTTP/1.1 '.$status.' '.\Sabre\HTTP\Response::$statusCodes[$status]);
$writer->endElement(); // {DAV:}propstat
}
if ($empty) {
/*
* The WebDAV spec _requires_ at least one DAV:propstat to appear for
* every DAV:response. In some circumstances however, there are no
* properties to encode.
*
* In those cases we MUST specify at least one DAV:propstat anyway, with
* no properties.
*/
$writer->writeElement('{DAV:}propstat', [
'{DAV:}prop' => [],
'{DAV:}status' => 'HTTP/1.1 418 '.\Sabre\HTTP\Response::$statusCodes[418],
]);
}
} | php | public function xmlSerialize(Writer $writer)
{
if ($status = $this->getHTTPStatus()) {
$writer->writeElement('{DAV:}status', 'HTTP/1.1 '.$status.' '.\Sabre\HTTP\Response::$statusCodes[$status]);
}
$writer->writeElement('{DAV:}href', $writer->contextUri.\Sabre\HTTP\encodePath($this->getHref()));
$empty = true;
foreach ($this->getResponseProperties() as $status => $properties) {
if (!$properties || (!ctype_digit($status) && !is_int($status))) {
continue;
}
$empty = false;
$writer->startElement('{DAV:}propstat');
$writer->writeElement('{DAV:}prop', $properties);
$writer->writeElement('{DAV:}status', 'HTTP/1.1 '.$status.' '.\Sabre\HTTP\Response::$statusCodes[$status]);
$writer->endElement();
}
if ($empty) {
$writer->writeElement('{DAV:}propstat', [
'{DAV:}prop' => [],
'{DAV:}status' => 'HTTP/1.1 418 '.\Sabre\HTTP\Response::$statusCodes[418],
]);
}
} | [
"public",
"function",
"xmlSerialize",
"(",
"Writer",
"$",
"writer",
")",
"{",
"if",
"(",
"$",
"status",
"=",
"$",
"this",
"->",
"getHTTPStatus",
"(",
")",
")",
"{",
"$",
"writer",
"->",
"writeElement",
"(",
"'{DAV:}status'",
",",
"'HTTP/1.1 '",
".",
"$",
"status",
".",
"' '",
".",
"\\",
"Sabre",
"\\",
"HTTP",
"\\",
"Response",
"::",
"$",
"statusCodes",
"[",
"$",
"status",
"]",
")",
";",
"}",
"$",
"writer",
"->",
"writeElement",
"(",
"'{DAV:}href'",
",",
"$",
"writer",
"->",
"contextUri",
".",
"\\",
"Sabre",
"\\",
"HTTP",
"\\",
"encodePath",
"(",
"$",
"this",
"->",
"getHref",
"(",
")",
")",
")",
";",
"$",
"empty",
"=",
"true",
";",
"foreach",
"(",
"$",
"this",
"->",
"getResponseProperties",
"(",
")",
"as",
"$",
"status",
"=>",
"$",
"properties",
")",
"{",
"// Skipping empty lists",
"if",
"(",
"!",
"$",
"properties",
"||",
"(",
"!",
"ctype_digit",
"(",
"$",
"status",
")",
"&&",
"!",
"is_int",
"(",
"$",
"status",
")",
")",
")",
"{",
"continue",
";",
"}",
"$",
"empty",
"=",
"false",
";",
"$",
"writer",
"->",
"startElement",
"(",
"'{DAV:}propstat'",
")",
";",
"$",
"writer",
"->",
"writeElement",
"(",
"'{DAV:}prop'",
",",
"$",
"properties",
")",
";",
"$",
"writer",
"->",
"writeElement",
"(",
"'{DAV:}status'",
",",
"'HTTP/1.1 '",
".",
"$",
"status",
".",
"' '",
".",
"\\",
"Sabre",
"\\",
"HTTP",
"\\",
"Response",
"::",
"$",
"statusCodes",
"[",
"$",
"status",
"]",
")",
";",
"$",
"writer",
"->",
"endElement",
"(",
")",
";",
"// {DAV:}propstat",
"}",
"if",
"(",
"$",
"empty",
")",
"{",
"/*\n * The WebDAV spec _requires_ at least one DAV:propstat to appear for\n * every DAV:response. In some circumstances however, there are no\n * properties to encode.\n *\n * In those cases we MUST specify at least one DAV:propstat anyway, with\n * no properties.\n */",
"$",
"writer",
"->",
"writeElement",
"(",
"'{DAV:}propstat'",
",",
"[",
"'{DAV:}prop'",
"=>",
"[",
"]",
",",
"'{DAV:}status'",
"=>",
"'HTTP/1.1 418 '",
".",
"\\",
"Sabre",
"\\",
"HTTP",
"\\",
"Response",
"::",
"$",
"statusCodes",
"[",
"418",
"]",
",",
"]",
")",
";",
"}",
"}"
] | 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/Element/Response.php#L116-L150 |
sabre-io/dav | lib/DAV/Xml/Element/Response.php | Response.xmlDeserialize | public static function xmlDeserialize(Reader $reader)
{
$reader->pushContext();
$reader->elementMap['{DAV:}propstat'] = 'Sabre\\Xml\\Element\\KeyValue';
// We are overriding the parser for {DAV:}prop. This deserializer is
// almost identical to the one for Sabre\Xml\Element\KeyValue.
//
// The difference is that if there are any child-elements inside of
// {DAV:}prop, that have no value, normally any deserializers are
// called. But we don't want this, because a singular element without
// child-elements implies 'no value' in {DAV:}prop, so we want to skip
// deserializers and just set null for those.
$reader->elementMap['{DAV:}prop'] = function (Reader $reader) {
if ($reader->isEmptyElement) {
$reader->next();
return [];
}
$values = [];
$reader->read();
do {
if (Reader::ELEMENT === $reader->nodeType) {
$clark = $reader->getClark();
if ($reader->isEmptyElement) {
$values[$clark] = null;
$reader->next();
} else {
$values[$clark] = $reader->parseCurrentElement()['value'];
}
} else {
$reader->read();
}
} while (Reader::END_ELEMENT !== $reader->nodeType);
$reader->read();
return $values;
};
$elems = $reader->parseInnerTree();
$reader->popContext();
$href = null;
$propertyLists = [];
$statusCode = null;
foreach ($elems as $elem) {
switch ($elem['name']) {
case '{DAV:}href':
$href = $elem['value'];
break;
case '{DAV:}propstat':
$status = $elem['value']['{DAV:}status'];
list(, $status) = explode(' ', $status, 3);
$properties = isset($elem['value']['{DAV:}prop']) ? $elem['value']['{DAV:}prop'] : [];
if ($properties) {
$propertyLists[$status] = $properties;
}
break;
case '{DAV:}status':
list(, $statusCode) = explode(' ', $elem['value'], 3);
break;
}
}
return new self($href, $propertyLists, $statusCode);
} | php | public static function xmlDeserialize(Reader $reader)
{
$reader->pushContext();
$reader->elementMap['{DAV:}propstat'] = 'Sabre\\Xml\\Element\\KeyValue';
$reader->elementMap['{DAV:}prop'] = function (Reader $reader) {
if ($reader->isEmptyElement) {
$reader->next();
return [];
}
$values = [];
$reader->read();
do {
if (Reader::ELEMENT === $reader->nodeType) {
$clark = $reader->getClark();
if ($reader->isEmptyElement) {
$values[$clark] = null;
$reader->next();
} else {
$values[$clark] = $reader->parseCurrentElement()['value'];
}
} else {
$reader->read();
}
} while (Reader::END_ELEMENT !== $reader->nodeType);
$reader->read();
return $values;
};
$elems = $reader->parseInnerTree();
$reader->popContext();
$href = null;
$propertyLists = [];
$statusCode = null;
foreach ($elems as $elem) {
switch ($elem['name']) {
case '{DAV:}href':
$href = $elem['value'];
break;
case '{DAV:}propstat':
$status = $elem['value']['{DAV:}status'];
list(, $status) = explode(' ', $status, 3);
$properties = isset($elem['value']['{DAV:}prop']) ? $elem['value']['{DAV:}prop'] : [];
if ($properties) {
$propertyLists[$status] = $properties;
}
break;
case '{DAV:}status':
list(, $statusCode) = explode(' ', $elem['value'], 3);
break;
}
}
return new self($href, $propertyLists, $statusCode);
} | [
"public",
"static",
"function",
"xmlDeserialize",
"(",
"Reader",
"$",
"reader",
")",
"{",
"$",
"reader",
"->",
"pushContext",
"(",
")",
";",
"$",
"reader",
"->",
"elementMap",
"[",
"'{DAV:}propstat'",
"]",
"=",
"'Sabre\\\\Xml\\\\Element\\\\KeyValue'",
";",
"// We are overriding the parser for {DAV:}prop. This deserializer is",
"// almost identical to the one for Sabre\\Xml\\Element\\KeyValue.",
"//",
"// The difference is that if there are any child-elements inside of",
"// {DAV:}prop, that have no value, normally any deserializers are",
"// called. But we don't want this, because a singular element without",
"// child-elements implies 'no value' in {DAV:}prop, so we want to skip",
"// deserializers and just set null for those.",
"$",
"reader",
"->",
"elementMap",
"[",
"'{DAV:}prop'",
"]",
"=",
"function",
"(",
"Reader",
"$",
"reader",
")",
"{",
"if",
"(",
"$",
"reader",
"->",
"isEmptyElement",
")",
"{",
"$",
"reader",
"->",
"next",
"(",
")",
";",
"return",
"[",
"]",
";",
"}",
"$",
"values",
"=",
"[",
"]",
";",
"$",
"reader",
"->",
"read",
"(",
")",
";",
"do",
"{",
"if",
"(",
"Reader",
"::",
"ELEMENT",
"===",
"$",
"reader",
"->",
"nodeType",
")",
"{",
"$",
"clark",
"=",
"$",
"reader",
"->",
"getClark",
"(",
")",
";",
"if",
"(",
"$",
"reader",
"->",
"isEmptyElement",
")",
"{",
"$",
"values",
"[",
"$",
"clark",
"]",
"=",
"null",
";",
"$",
"reader",
"->",
"next",
"(",
")",
";",
"}",
"else",
"{",
"$",
"values",
"[",
"$",
"clark",
"]",
"=",
"$",
"reader",
"->",
"parseCurrentElement",
"(",
")",
"[",
"'value'",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"reader",
"->",
"read",
"(",
")",
";",
"}",
"}",
"while",
"(",
"Reader",
"::",
"END_ELEMENT",
"!==",
"$",
"reader",
"->",
"nodeType",
")",
";",
"$",
"reader",
"->",
"read",
"(",
")",
";",
"return",
"$",
"values",
";",
"}",
";",
"$",
"elems",
"=",
"$",
"reader",
"->",
"parseInnerTree",
"(",
")",
";",
"$",
"reader",
"->",
"popContext",
"(",
")",
";",
"$",
"href",
"=",
"null",
";",
"$",
"propertyLists",
"=",
"[",
"]",
";",
"$",
"statusCode",
"=",
"null",
";",
"foreach",
"(",
"$",
"elems",
"as",
"$",
"elem",
")",
"{",
"switch",
"(",
"$",
"elem",
"[",
"'name'",
"]",
")",
"{",
"case",
"'{DAV:}href'",
":",
"$",
"href",
"=",
"$",
"elem",
"[",
"'value'",
"]",
";",
"break",
";",
"case",
"'{DAV:}propstat'",
":",
"$",
"status",
"=",
"$",
"elem",
"[",
"'value'",
"]",
"[",
"'{DAV:}status'",
"]",
";",
"list",
"(",
",",
"$",
"status",
")",
"=",
"explode",
"(",
"' '",
",",
"$",
"status",
",",
"3",
")",
";",
"$",
"properties",
"=",
"isset",
"(",
"$",
"elem",
"[",
"'value'",
"]",
"[",
"'{DAV:}prop'",
"]",
")",
"?",
"$",
"elem",
"[",
"'value'",
"]",
"[",
"'{DAV:}prop'",
"]",
":",
"[",
"]",
";",
"if",
"(",
"$",
"properties",
")",
"{",
"$",
"propertyLists",
"[",
"$",
"status",
"]",
"=",
"$",
"properties",
";",
"}",
"break",
";",
"case",
"'{DAV:}status'",
":",
"list",
"(",
",",
"$",
"statusCode",
")",
"=",
"explode",
"(",
"' '",
",",
"$",
"elem",
"[",
"'value'",
"]",
",",
"3",
")",
";",
"break",
";",
"}",
"}",
"return",
"new",
"self",
"(",
"$",
"href",
",",
"$",
"propertyLists",
",",
"$",
"statusCode",
")",
";",
"}"
] | The deserialize method is called during xml parsing.
This method is called statically, this is because in theory this method
may be used as a type of constructor, or factory method.
Often you want to return an instance of the current class, but you are
free to return other data as well.
You are responsible for advancing the reader to the next element. Not
doing anything will result in a never-ending loop.
If you just want to skip parsing for this element altogether, you can
just call $reader->next();
$reader->parseInnerTree() will parse the entire sub-tree, and advance to
the next element.
@param Reader $reader
@return mixed | [
"The",
"deserialize",
"method",
"is",
"called",
"during",
"xml",
"parsing",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Element/Response.php#L174-L241 |
sabre-io/dav | lib/CalDAV/Xml/Request/FreeBusyQueryReport.php | FreeBusyQueryReport.xmlDeserialize | public static function xmlDeserialize(Reader $reader)
{
$timeRange = '{'.Plugin::NS_CALDAV.'}time-range';
$start = null;
$end = null;
foreach ((array) $reader->parseInnerTree([]) as $elem) {
if ($elem['name'] !== $timeRange) {
continue;
}
$start = empty($elem['attributes']['start']) ?: $elem['attributes']['start'];
$end = empty($elem['attributes']['end']) ?: $elem['attributes']['end'];
}
if (!$start && !$end) {
throw new BadRequest('The freebusy report must have a time-range element');
}
if ($start) {
$start = DateTimeParser::parseDateTime($start);
}
if ($end) {
$end = DateTimeParser::parseDateTime($end);
}
$result = new self();
$result->start = $start;
$result->end = $end;
return $result;
} | php | public static function xmlDeserialize(Reader $reader)
{
$timeRange = '{'.Plugin::NS_CALDAV.'}time-range';
$start = null;
$end = null;
foreach ((array) $reader->parseInnerTree([]) as $elem) {
if ($elem['name'] !== $timeRange) {
continue;
}
$start = empty($elem['attributes']['start']) ?: $elem['attributes']['start'];
$end = empty($elem['attributes']['end']) ?: $elem['attributes']['end'];
}
if (!$start && !$end) {
throw new BadRequest('The freebusy report must have a time-range element');
}
if ($start) {
$start = DateTimeParser::parseDateTime($start);
}
if ($end) {
$end = DateTimeParser::parseDateTime($end);
}
$result = new self();
$result->start = $start;
$result->end = $end;
return $result;
} | [
"public",
"static",
"function",
"xmlDeserialize",
"(",
"Reader",
"$",
"reader",
")",
"{",
"$",
"timeRange",
"=",
"'{'",
".",
"Plugin",
"::",
"NS_CALDAV",
".",
"'}time-range'",
";",
"$",
"start",
"=",
"null",
";",
"$",
"end",
"=",
"null",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"reader",
"->",
"parseInnerTree",
"(",
"[",
"]",
")",
"as",
"$",
"elem",
")",
"{",
"if",
"(",
"$",
"elem",
"[",
"'name'",
"]",
"!==",
"$",
"timeRange",
")",
"{",
"continue",
";",
"}",
"$",
"start",
"=",
"empty",
"(",
"$",
"elem",
"[",
"'attributes'",
"]",
"[",
"'start'",
"]",
")",
"?",
":",
"$",
"elem",
"[",
"'attributes'",
"]",
"[",
"'start'",
"]",
";",
"$",
"end",
"=",
"empty",
"(",
"$",
"elem",
"[",
"'attributes'",
"]",
"[",
"'end'",
"]",
")",
"?",
":",
"$",
"elem",
"[",
"'attributes'",
"]",
"[",
"'end'",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"start",
"&&",
"!",
"$",
"end",
")",
"{",
"throw",
"new",
"BadRequest",
"(",
"'The freebusy report must have a time-range element'",
")",
";",
"}",
"if",
"(",
"$",
"start",
")",
"{",
"$",
"start",
"=",
"DateTimeParser",
"::",
"parseDateTime",
"(",
"$",
"start",
")",
";",
"}",
"if",
"(",
"$",
"end",
")",
"{",
"$",
"end",
"=",
"DateTimeParser",
"::",
"parseDateTime",
"(",
"$",
"end",
")",
";",
"}",
"$",
"result",
"=",
"new",
"self",
"(",
")",
";",
"$",
"result",
"->",
"start",
"=",
"$",
"start",
";",
"$",
"result",
"->",
"end",
"=",
"$",
"end",
";",
"return",
"$",
"result",
";",
"}"
] | The deserialize method is called during xml parsing.
This method is called statically, this is because in theory this method
may be used as a type of constructor, or factory method.
Often you want to return an instance of the current class, but you are
free to return other data as well.
You are responsible for advancing the reader to the next element. Not
doing anything will result in a never-ending loop.
If you just want to skip parsing for this element altogether, you can
just call $reader->next();
$reader->parseInnerTree() will parse the entire sub-tree, and advance to
the next element.
@param Reader $reader
@return mixed | [
"The",
"deserialize",
"method",
"is",
"called",
"during",
"xml",
"parsing",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Xml/Request/FreeBusyQueryReport.php#L62-L91 |
sabre-io/dav | lib/DAV/Xml/Request/PropFind.php | PropFind.xmlDeserialize | public static function xmlDeserialize(Reader $reader)
{
$self = new self();
$reader->pushContext();
$reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Element\Elements';
foreach (KeyValue::xmlDeserialize($reader) as $k => $v) {
switch ($k) {
case '{DAV:}prop':
$self->properties = $v;
break;
case '{DAV:}allprop':
$self->allProp = true;
}
}
$reader->popContext();
return $self;
} | php | public static function xmlDeserialize(Reader $reader)
{
$self = new self();
$reader->pushContext();
$reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Element\Elements';
foreach (KeyValue::xmlDeserialize($reader) as $k => $v) {
switch ($k) {
case '{DAV:}prop':
$self->properties = $v;
break;
case '{DAV:}allprop':
$self->allProp = true;
}
}
$reader->popContext();
return $self;
} | [
"public",
"static",
"function",
"xmlDeserialize",
"(",
"Reader",
"$",
"reader",
")",
"{",
"$",
"self",
"=",
"new",
"self",
"(",
")",
";",
"$",
"reader",
"->",
"pushContext",
"(",
")",
";",
"$",
"reader",
"->",
"elementMap",
"[",
"'{DAV:}prop'",
"]",
"=",
"'Sabre\\Xml\\Element\\Elements'",
";",
"foreach",
"(",
"KeyValue",
"::",
"xmlDeserialize",
"(",
"$",
"reader",
")",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"switch",
"(",
"$",
"k",
")",
"{",
"case",
"'{DAV:}prop'",
":",
"$",
"self",
"->",
"properties",
"=",
"$",
"v",
";",
"break",
";",
"case",
"'{DAV:}allprop'",
":",
"$",
"self",
"->",
"allProp",
"=",
"true",
";",
"}",
"}",
"$",
"reader",
"->",
"popContext",
"(",
")",
";",
"return",
"$",
"self",
";",
"}"
] | The deserialize method is called during xml parsing.
This method is called statically, this is because in theory this method
may be used as a type of constructor, or factory method.
Often you want to return an instance of the current class, but you are
free to return other data as well.
You are responsible for advancing the reader to the next element. Not
doing anything will result in a never-ending loop.
If you just want to skip parsing for this element altogether, you can
just call $reader->next();
$reader->parseInnerTree() will parse the entire sub-tree, and advance to
the next element.
@param Reader $reader
@return mixed | [
"The",
"deserialize",
"method",
"is",
"called",
"during",
"xml",
"parsing",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Request/PropFind.php#L60-L80 |
sabre-io/dav | lib/CalDAV/Xml/Request/Share.php | Share.xmlDeserialize | public static function xmlDeserialize(Reader $reader)
{
$elems = $reader->parseGetElements([
'{'.Plugin::NS_CALENDARSERVER.'}set' => 'Sabre\\Xml\\Element\\KeyValue',
'{'.Plugin::NS_CALENDARSERVER.'}remove' => 'Sabre\\Xml\\Element\\KeyValue',
]);
$sharees = [];
foreach ($elems as $elem) {
switch ($elem['name']) {
case '{'.Plugin::NS_CALENDARSERVER.'}set':
$sharee = $elem['value'];
$sumElem = '{'.Plugin::NS_CALENDARSERVER.'}summary';
$commonName = '{'.Plugin::NS_CALENDARSERVER.'}common-name';
$properties = [];
if (isset($sharee[$commonName])) {
$properties['{DAV:}displayname'] = $sharee[$commonName];
}
$access = array_key_exists('{'.Plugin::NS_CALENDARSERVER.'}read-write', $sharee)
? \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE
: \Sabre\DAV\Sharing\Plugin::ACCESS_READ;
$sharees[] = new Sharee([
'href' => $sharee['{DAV:}href'],
'properties' => $properties,
'access' => $access,
'comment' => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null,
]);
break;
case '{'.Plugin::NS_CALENDARSERVER.'}remove':
$sharees[] = new Sharee([
'href' => $elem['value']['{DAV:}href'],
'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_NOACCESS,
]);
break;
}
}
return new self($sharees);
} | php | public static function xmlDeserialize(Reader $reader)
{
$elems = $reader->parseGetElements([
'{'.Plugin::NS_CALENDARSERVER.'}set' => 'Sabre\\Xml\\Element\\KeyValue',
'{'.Plugin::NS_CALENDARSERVER.'}remove' => 'Sabre\\Xml\\Element\\KeyValue',
]);
$sharees = [];
foreach ($elems as $elem) {
switch ($elem['name']) {
case '{'.Plugin::NS_CALENDARSERVER.'}set':
$sharee = $elem['value'];
$sumElem = '{'.Plugin::NS_CALENDARSERVER.'}summary';
$commonName = '{'.Plugin::NS_CALENDARSERVER.'}common-name';
$properties = [];
if (isset($sharee[$commonName])) {
$properties['{DAV:}displayname'] = $sharee[$commonName];
}
$access = array_key_exists('{'.Plugin::NS_CALENDARSERVER.'}read-write', $sharee)
? \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE
: \Sabre\DAV\Sharing\Plugin::ACCESS_READ;
$sharees[] = new Sharee([
'href' => $sharee['{DAV:}href'],
'properties' => $properties,
'access' => $access,
'comment' => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null,
]);
break;
case '{'.Plugin::NS_CALENDARSERVER.'}remove':
$sharees[] = new Sharee([
'href' => $elem['value']['{DAV:}href'],
'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_NOACCESS,
]);
break;
}
}
return new self($sharees);
} | [
"public",
"static",
"function",
"xmlDeserialize",
"(",
"Reader",
"$",
"reader",
")",
"{",
"$",
"elems",
"=",
"$",
"reader",
"->",
"parseGetElements",
"(",
"[",
"'{'",
".",
"Plugin",
"::",
"NS_CALENDARSERVER",
".",
"'}set'",
"=>",
"'Sabre\\\\Xml\\\\Element\\\\KeyValue'",
",",
"'{'",
".",
"Plugin",
"::",
"NS_CALENDARSERVER",
".",
"'}remove'",
"=>",
"'Sabre\\\\Xml\\\\Element\\\\KeyValue'",
",",
"]",
")",
";",
"$",
"sharees",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"elems",
"as",
"$",
"elem",
")",
"{",
"switch",
"(",
"$",
"elem",
"[",
"'name'",
"]",
")",
"{",
"case",
"'{'",
".",
"Plugin",
"::",
"NS_CALENDARSERVER",
".",
"'}set'",
":",
"$",
"sharee",
"=",
"$",
"elem",
"[",
"'value'",
"]",
";",
"$",
"sumElem",
"=",
"'{'",
".",
"Plugin",
"::",
"NS_CALENDARSERVER",
".",
"'}summary'",
";",
"$",
"commonName",
"=",
"'{'",
".",
"Plugin",
"::",
"NS_CALENDARSERVER",
".",
"'}common-name'",
";",
"$",
"properties",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"sharee",
"[",
"$",
"commonName",
"]",
")",
")",
"{",
"$",
"properties",
"[",
"'{DAV:}displayname'",
"]",
"=",
"$",
"sharee",
"[",
"$",
"commonName",
"]",
";",
"}",
"$",
"access",
"=",
"array_key_exists",
"(",
"'{'",
".",
"Plugin",
"::",
"NS_CALENDARSERVER",
".",
"'}read-write'",
",",
"$",
"sharee",
")",
"?",
"\\",
"Sabre",
"\\",
"DAV",
"\\",
"Sharing",
"\\",
"Plugin",
"::",
"ACCESS_READWRITE",
":",
"\\",
"Sabre",
"\\",
"DAV",
"\\",
"Sharing",
"\\",
"Plugin",
"::",
"ACCESS_READ",
";",
"$",
"sharees",
"[",
"]",
"=",
"new",
"Sharee",
"(",
"[",
"'href'",
"=>",
"$",
"sharee",
"[",
"'{DAV:}href'",
"]",
",",
"'properties'",
"=>",
"$",
"properties",
",",
"'access'",
"=>",
"$",
"access",
",",
"'comment'",
"=>",
"isset",
"(",
"$",
"sharee",
"[",
"$",
"sumElem",
"]",
")",
"?",
"$",
"sharee",
"[",
"$",
"sumElem",
"]",
":",
"null",
",",
"]",
")",
";",
"break",
";",
"case",
"'{'",
".",
"Plugin",
"::",
"NS_CALENDARSERVER",
".",
"'}remove'",
":",
"$",
"sharees",
"[",
"]",
"=",
"new",
"Sharee",
"(",
"[",
"'href'",
"=>",
"$",
"elem",
"[",
"'value'",
"]",
"[",
"'{DAV:}href'",
"]",
",",
"'access'",
"=>",
"\\",
"Sabre",
"\\",
"DAV",
"\\",
"Sharing",
"\\",
"Plugin",
"::",
"ACCESS_NOACCESS",
",",
"]",
")",
";",
"break",
";",
"}",
"}",
"return",
"new",
"self",
"(",
"$",
"sharees",
")",
";",
"}"
] | The deserialize method is called during xml parsing.
This method is called statically, this is because in theory this method
may be used as a type of constructor, or factory method.
Often you want to return an instance of the current class, but you are
free to return other data as well.
You are responsible for advancing the reader to the next element. Not
doing anything will result in a never-ending loop.
If you just want to skip parsing for this element altogether, you can
just call $reader->next();
$reader->parseInnerTree() will parse the entire sub-tree, and advance to
the next element.
@param Reader $reader
@return mixed | [
"The",
"deserialize",
"method",
"is",
"called",
"during",
"xml",
"parsing",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Xml/Request/Share.php#L64-L108 |
sabre-io/dav | lib/DAV/Browser/MapGetToPropFind.php | MapGetToPropFind.httpGet | public function httpGet(RequestInterface $request, ResponseInterface $response)
{
$node = $this->server->tree->getNodeForPath($request->getPath());
if ($node instanceof DAV\IFile) {
return;
}
$subRequest = clone $request;
$subRequest->setMethod('PROPFIND');
$this->server->invokeMethod($subRequest, $response);
return false;
} | php | public function httpGet(RequestInterface $request, ResponseInterface $response)
{
$node = $this->server->tree->getNodeForPath($request->getPath());
if ($node instanceof DAV\IFile) {
return;
}
$subRequest = clone $request;
$subRequest->setMethod('PROPFIND');
$this->server->invokeMethod($subRequest, $response);
return false;
} | [
"public",
"function",
"httpGet",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"request",
"->",
"getPath",
"(",
")",
")",
";",
"if",
"(",
"$",
"node",
"instanceof",
"DAV",
"\\",
"IFile",
")",
"{",
"return",
";",
"}",
"$",
"subRequest",
"=",
"clone",
"$",
"request",
";",
"$",
"subRequest",
"->",
"setMethod",
"(",
"'PROPFIND'",
")",
";",
"$",
"this",
"->",
"server",
"->",
"invokeMethod",
"(",
"$",
"subRequest",
",",
"$",
"response",
")",
";",
"return",
"false",
";",
"}"
] | This method intercepts GET requests to non-files, and changes it into an HTTP PROPFIND request.
@param RequestInterface $request
@param ResponseInterface $response
@return bool | [
"This",
"method",
"intercepts",
"GET",
"requests",
"to",
"non",
"-",
"files",
"and",
"changes",
"it",
"into",
"an",
"HTTP",
"PROPFIND",
"request",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/MapGetToPropFind.php#L49-L62 |
sabre-io/dav | lib/CalDAV/Principal/User.php | User.getChild | public function getChild($name)
{
$principal = $this->principalBackend->getPrincipalByPath($this->getPrincipalURL().'/'.$name);
if (!$principal) {
throw new DAV\Exception\NotFound('Node with name '.$name.' was not found');
}
if ('calendar-proxy-read' === $name) {
return new ProxyRead($this->principalBackend, $this->principalProperties);
}
if ('calendar-proxy-write' === $name) {
return new ProxyWrite($this->principalBackend, $this->principalProperties);
}
throw new DAV\Exception\NotFound('Node with name '.$name.' was not found');
} | php | public function getChild($name)
{
$principal = $this->principalBackend->getPrincipalByPath($this->getPrincipalURL().'/'.$name);
if (!$principal) {
throw new DAV\Exception\NotFound('Node with name '.$name.' was not found');
}
if ('calendar-proxy-read' === $name) {
return new ProxyRead($this->principalBackend, $this->principalProperties);
}
if ('calendar-proxy-write' === $name) {
return new ProxyWrite($this->principalBackend, $this->principalProperties);
}
throw new DAV\Exception\NotFound('Node with name '.$name.' was not found');
} | [
"public",
"function",
"getChild",
"(",
"$",
"name",
")",
"{",
"$",
"principal",
"=",
"$",
"this",
"->",
"principalBackend",
"->",
"getPrincipalByPath",
"(",
"$",
"this",
"->",
"getPrincipalURL",
"(",
")",
".",
"'/'",
".",
"$",
"name",
")",
";",
"if",
"(",
"!",
"$",
"principal",
")",
"{",
"throw",
"new",
"DAV",
"\\",
"Exception",
"\\",
"NotFound",
"(",
"'Node with name '",
".",
"$",
"name",
".",
"' was not found'",
")",
";",
"}",
"if",
"(",
"'calendar-proxy-read'",
"===",
"$",
"name",
")",
"{",
"return",
"new",
"ProxyRead",
"(",
"$",
"this",
"->",
"principalBackend",
",",
"$",
"this",
"->",
"principalProperties",
")",
";",
"}",
"if",
"(",
"'calendar-proxy-write'",
"===",
"$",
"name",
")",
"{",
"return",
"new",
"ProxyWrite",
"(",
"$",
"this",
"->",
"principalBackend",
",",
"$",
"this",
"->",
"principalProperties",
")",
";",
"}",
"throw",
"new",
"DAV",
"\\",
"Exception",
"\\",
"NotFound",
"(",
"'Node with name '",
".",
"$",
"name",
".",
"' was not found'",
")",
";",
"}"
] | Returns a specific child node, referenced by its name.
@param string $name
@return DAV\INode | [
"Returns",
"a",
"specific",
"child",
"node",
"referenced",
"by",
"its",
"name",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Principal/User.php#L55-L70 |
sabre-io/dav | lib/CalDAV/Principal/User.php | User.getChildren | public function getChildren()
{
$r = [];
if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL().'/calendar-proxy-read')) {
$r[] = new ProxyRead($this->principalBackend, $this->principalProperties);
}
if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL().'/calendar-proxy-write')) {
$r[] = new ProxyWrite($this->principalBackend, $this->principalProperties);
}
return $r;
} | php | public function getChildren()
{
$r = [];
if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL().'/calendar-proxy-read')) {
$r[] = new ProxyRead($this->principalBackend, $this->principalProperties);
}
if ($this->principalBackend->getPrincipalByPath($this->getPrincipalURL().'/calendar-proxy-write')) {
$r[] = new ProxyWrite($this->principalBackend, $this->principalProperties);
}
return $r;
} | [
"public",
"function",
"getChildren",
"(",
")",
"{",
"$",
"r",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"principalBackend",
"->",
"getPrincipalByPath",
"(",
"$",
"this",
"->",
"getPrincipalURL",
"(",
")",
".",
"'/calendar-proxy-read'",
")",
")",
"{",
"$",
"r",
"[",
"]",
"=",
"new",
"ProxyRead",
"(",
"$",
"this",
"->",
"principalBackend",
",",
"$",
"this",
"->",
"principalProperties",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"principalBackend",
"->",
"getPrincipalByPath",
"(",
"$",
"this",
"->",
"getPrincipalURL",
"(",
")",
".",
"'/calendar-proxy-write'",
")",
")",
"{",
"$",
"r",
"[",
"]",
"=",
"new",
"ProxyWrite",
"(",
"$",
"this",
"->",
"principalBackend",
",",
"$",
"this",
"->",
"principalProperties",
")",
";",
"}",
"return",
"$",
"r",
";",
"}"
] | Returns an array with all the child nodes.
@return DAV\INode[] | [
"Returns",
"an",
"array",
"with",
"all",
"the",
"child",
"nodes",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Principal/User.php#L77-L88 |
sabre-io/dav | lib/CalDAV/Principal/User.php | User.childExists | public function childExists($name)
{
try {
$this->getChild($name);
return true;
} catch (DAV\Exception\NotFound $e) {
return false;
}
} | php | public function childExists($name)
{
try {
$this->getChild($name);
return true;
} catch (DAV\Exception\NotFound $e) {
return false;
}
} | [
"public",
"function",
"childExists",
"(",
"$",
"name",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"getChild",
"(",
"$",
"name",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"DAV",
"\\",
"Exception",
"\\",
"NotFound",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] | Returns whether or not the child node exists.
@param string $name
@return bool | [
"Returns",
"whether",
"or",
"not",
"the",
"child",
"node",
"exists",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Principal/User.php#L97-L106 |
sabre-io/dav | lib/CalDAV/Principal/User.php | User.getACL | public function getACL()
{
$acl = parent::getACL();
$acl[] = [
'privilege' => '{DAV:}read',
'principal' => $this->principalProperties['uri'].'/calendar-proxy-read',
'protected' => true,
];
$acl[] = [
'privilege' => '{DAV:}read',
'principal' => $this->principalProperties['uri'].'/calendar-proxy-write',
'protected' => true,
];
return $acl;
} | php | public function getACL()
{
$acl = parent::getACL();
$acl[] = [
'privilege' => '{DAV:}read',
'principal' => $this->principalProperties['uri'].'/calendar-proxy-read',
'protected' => true,
];
$acl[] = [
'privilege' => '{DAV:}read',
'principal' => $this->principalProperties['uri'].'/calendar-proxy-write',
'protected' => true,
];
return $acl;
} | [
"public",
"function",
"getACL",
"(",
")",
"{",
"$",
"acl",
"=",
"parent",
"::",
"getACL",
"(",
")",
";",
"$",
"acl",
"[",
"]",
"=",
"[",
"'privilege'",
"=>",
"'{DAV:}read'",
",",
"'principal'",
"=>",
"$",
"this",
"->",
"principalProperties",
"[",
"'uri'",
"]",
".",
"'/calendar-proxy-read'",
",",
"'protected'",
"=>",
"true",
",",
"]",
";",
"$",
"acl",
"[",
"]",
"=",
"[",
"'privilege'",
"=>",
"'{DAV:}read'",
",",
"'principal'",
"=>",
"$",
"this",
"->",
"principalProperties",
"[",
"'uri'",
"]",
".",
"'/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/Principal/User.php#L120-L135 |
sabre-io/dav | lib/DAV/CorePlugin.php | CorePlugin.initialize | public function initialize(Server $server)
{
$this->server = $server;
$server->on('method:GET', [$this, 'httpGet']);
$server->on('method:OPTIONS', [$this, 'httpOptions']);
$server->on('method:HEAD', [$this, 'httpHead']);
$server->on('method:DELETE', [$this, 'httpDelete']);
$server->on('method:PROPFIND', [$this, 'httpPropFind']);
$server->on('method:PROPPATCH', [$this, 'httpPropPatch']);
$server->on('method:PUT', [$this, 'httpPut']);
$server->on('method:MKCOL', [$this, 'httpMkcol']);
$server->on('method:MOVE', [$this, 'httpMove']);
$server->on('method:COPY', [$this, 'httpCopy']);
$server->on('method:REPORT', [$this, 'httpReport']);
$server->on('propPatch', [$this, 'propPatchProtectedPropertyCheck'], 90);
$server->on('propPatch', [$this, 'propPatchNodeUpdate'], 200);
$server->on('propFind', [$this, 'propFind']);
$server->on('propFind', [$this, 'propFindNode'], 120);
$server->on('propFind', [$this, 'propFindLate'], 200);
$server->on('exception', [$this, 'exception']);
} | php | public function initialize(Server $server)
{
$this->server = $server;
$server->on('method:GET', [$this, 'httpGet']);
$server->on('method:OPTIONS', [$this, 'httpOptions']);
$server->on('method:HEAD', [$this, 'httpHead']);
$server->on('method:DELETE', [$this, 'httpDelete']);
$server->on('method:PROPFIND', [$this, 'httpPropFind']);
$server->on('method:PROPPATCH', [$this, 'httpPropPatch']);
$server->on('method:PUT', [$this, 'httpPut']);
$server->on('method:MKCOL', [$this, 'httpMkcol']);
$server->on('method:MOVE', [$this, 'httpMove']);
$server->on('method:COPY', [$this, 'httpCopy']);
$server->on('method:REPORT', [$this, 'httpReport']);
$server->on('propPatch', [$this, 'propPatchProtectedPropertyCheck'], 90);
$server->on('propPatch', [$this, 'propPatchNodeUpdate'], 200);
$server->on('propFind', [$this, 'propFind']);
$server->on('propFind', [$this, 'propFindNode'], 120);
$server->on('propFind', [$this, 'propFindLate'], 200);
$server->on('exception', [$this, 'exception']);
} | [
"public",
"function",
"initialize",
"(",
"Server",
"$",
"server",
")",
"{",
"$",
"this",
"->",
"server",
"=",
"$",
"server",
";",
"$",
"server",
"->",
"on",
"(",
"'method:GET'",
",",
"[",
"$",
"this",
",",
"'httpGet'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'method:OPTIONS'",
",",
"[",
"$",
"this",
",",
"'httpOptions'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'method:HEAD'",
",",
"[",
"$",
"this",
",",
"'httpHead'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'method:DELETE'",
",",
"[",
"$",
"this",
",",
"'httpDelete'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'method:PROPFIND'",
",",
"[",
"$",
"this",
",",
"'httpPropFind'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'method:PROPPATCH'",
",",
"[",
"$",
"this",
",",
"'httpPropPatch'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'method:PUT'",
",",
"[",
"$",
"this",
",",
"'httpPut'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'method:MKCOL'",
",",
"[",
"$",
"this",
",",
"'httpMkcol'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'method:MOVE'",
",",
"[",
"$",
"this",
",",
"'httpMove'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'method:COPY'",
",",
"[",
"$",
"this",
",",
"'httpCopy'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'method:REPORT'",
",",
"[",
"$",
"this",
",",
"'httpReport'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'propPatch'",
",",
"[",
"$",
"this",
",",
"'propPatchProtectedPropertyCheck'",
"]",
",",
"90",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'propPatch'",
",",
"[",
"$",
"this",
",",
"'propPatchNodeUpdate'",
"]",
",",
"200",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'propFind'",
",",
"[",
"$",
"this",
",",
"'propFind'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'propFind'",
",",
"[",
"$",
"this",
",",
"'propFindNode'",
"]",
",",
"120",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'propFind'",
",",
"[",
"$",
"this",
",",
"'propFindLate'",
"]",
",",
"200",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'exception'",
",",
"[",
"$",
"this",
",",
"'exception'",
"]",
")",
";",
"}"
] | Sets up the plugin.
@param Server $server | [
"Sets",
"up",
"the",
"plugin",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L33-L55 |
sabre-io/dav | lib/DAV/CorePlugin.php | CorePlugin.httpGet | public function httpGet(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
$node = $this->server->tree->getNodeForPath($path);
if (!$node instanceof IFile) {
return;
}
if ('HEAD' === $request->getHeader('X-Sabre-Original-Method')) {
$body = '';
} else {
$body = $node->get();
// Converting string into stream, if needed.
if (is_string($body)) {
$stream = fopen('php://temp', 'r+');
fwrite($stream, $body);
rewind($stream);
$body = $stream;
}
}
/*
* TODO: getetag, getlastmodified, getsize should also be used using
* this method
*/
$httpHeaders = $this->server->getHTTPHeaders($path);
/* ContentType needs to get a default, because many webservers will otherwise
* default to text/html, and we don't want this for security reasons.
*/
if (!isset($httpHeaders['Content-Type'])) {
$httpHeaders['Content-Type'] = 'application/octet-stream';
}
if (isset($httpHeaders['Content-Length'])) {
$nodeSize = $httpHeaders['Content-Length'];
// Need to unset Content-Length, because we'll handle that during figuring out the range
unset($httpHeaders['Content-Length']);
} else {
$nodeSize = null;
}
$response->addHeaders($httpHeaders);
$range = $this->server->getHTTPRange();
$ifRange = $request->getHeader('If-Range');
$ignoreRangeHeader = false;
// If ifRange is set, and range is specified, we first need to check
// the precondition.
if ($nodeSize && $range && $ifRange) {
// if IfRange is parsable as a date we'll treat it as a DateTime
// otherwise, we must treat it as an etag.
try {
$ifRangeDate = new \DateTime($ifRange);
// It's a date. We must check if the entity is modified since
// the specified date.
if (!isset($httpHeaders['Last-Modified'])) {
$ignoreRangeHeader = true;
} else {
$modified = new \DateTime($httpHeaders['Last-Modified']);
if ($modified > $ifRangeDate) {
$ignoreRangeHeader = true;
}
}
} catch (\Exception $e) {
// It's an entity. We can do a simple comparison.
if (!isset($httpHeaders['ETag'])) {
$ignoreRangeHeader = true;
} elseif ($httpHeaders['ETag'] !== $ifRange) {
$ignoreRangeHeader = true;
}
}
}
// We're only going to support HTTP ranges if the backend provided a filesize
if (!$ignoreRangeHeader && $nodeSize && $range) {
// Determining the exact byte offsets
if (!is_null($range[0])) {
$start = $range[0];
$end = $range[1] ? $range[1] : $nodeSize - 1;
if ($start >= $nodeSize) {
throw new Exception\RequestedRangeNotSatisfiable('The start offset ('.$range[0].') exceeded the size of the entity ('.$nodeSize.')');
}
if ($end < $start) {
throw new Exception\RequestedRangeNotSatisfiable('The end offset ('.$range[1].') is lower than the start offset ('.$range[0].')');
}
if ($end >= $nodeSize) {
$end = $nodeSize - 1;
}
} else {
$start = $nodeSize - $range[1];
$end = $nodeSize - 1;
if ($start < 0) {
$start = 0;
}
}
// Streams may advertise themselves as seekable, but still not
// actually allow fseek. We'll manually go forward in the stream
// if fseek failed.
if (!stream_get_meta_data($body)['seekable'] || -1 === fseek($body, $start, SEEK_SET)) {
$consumeBlock = 8192;
for ($consumed = 0; $start - $consumed > 0;) {
if (feof($body)) {
throw new Exception\RequestedRangeNotSatisfiable('The start offset ('.$start.') exceeded the size of the entity ('.$consumed.')');
}
$consumed += strlen(fread($body, min($start - $consumed, $consumeBlock)));
}
}
$response->setHeader('Content-Length', $end - $start + 1);
$response->setHeader('Content-Range', 'bytes '.$start.'-'.$end.'/'.$nodeSize);
$response->setStatus(206);
$response->setBody($body);
} else {
if ($nodeSize) {
$response->setHeader('Content-Length', $nodeSize);
}
$response->setStatus(200);
$response->setBody($body);
}
// Sending back false will interrupt the event chain and tell the server
// we've handled this method.
return false;
} | php | public function httpGet(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
$node = $this->server->tree->getNodeForPath($path);
if (!$node instanceof IFile) {
return;
}
if ('HEAD' === $request->getHeader('X-Sabre-Original-Method')) {
$body = '';
} else {
$body = $node->get();
if (is_string($body)) {
$stream = fopen('php:
fwrite($stream, $body);
rewind($stream);
$body = $stream;
}
}
$httpHeaders = $this->server->getHTTPHeaders($path);
if (!isset($httpHeaders['Content-Type'])) {
$httpHeaders['Content-Type'] = 'application/octet-stream';
}
if (isset($httpHeaders['Content-Length'])) {
$nodeSize = $httpHeaders['Content-Length'];
unset($httpHeaders['Content-Length']);
} else {
$nodeSize = null;
}
$response->addHeaders($httpHeaders);
$range = $this->server->getHTTPRange();
$ifRange = $request->getHeader('If-Range');
$ignoreRangeHeader = false;
if ($nodeSize && $range && $ifRange) {
try {
$ifRangeDate = new \DateTime($ifRange);
if (!isset($httpHeaders['Last-Modified'])) {
$ignoreRangeHeader = true;
} else {
$modified = new \DateTime($httpHeaders['Last-Modified']);
if ($modified > $ifRangeDate) {
$ignoreRangeHeader = true;
}
}
} catch (\Exception $e) {
if (!isset($httpHeaders['ETag'])) {
$ignoreRangeHeader = true;
} elseif ($httpHeaders['ETag'] !== $ifRange) {
$ignoreRangeHeader = true;
}
}
}
if (!$ignoreRangeHeader && $nodeSize && $range) {
if (!is_null($range[0])) {
$start = $range[0];
$end = $range[1] ? $range[1] : $nodeSize - 1;
if ($start >= $nodeSize) {
throw new Exception\RequestedRangeNotSatisfiable('The start offset ('.$range[0].') exceeded the size of the entity ('.$nodeSize.')');
}
if ($end < $start) {
throw new Exception\RequestedRangeNotSatisfiable('The end offset ('.$range[1].') is lower than the start offset ('.$range[0].')');
}
if ($end >= $nodeSize) {
$end = $nodeSize - 1;
}
} else {
$start = $nodeSize - $range[1];
$end = $nodeSize - 1;
if ($start < 0) {
$start = 0;
}
}
if (!stream_get_meta_data($body)['seekable'] || -1 === fseek($body, $start, SEEK_SET)) {
$consumeBlock = 8192;
for ($consumed = 0; $start - $consumed > 0;) {
if (feof($body)) {
throw new Exception\RequestedRangeNotSatisfiable('The start offset ('.$start.') exceeded the size of the entity ('.$consumed.')');
}
$consumed += strlen(fread($body, min($start - $consumed, $consumeBlock)));
}
}
$response->setHeader('Content-Length', $end - $start + 1);
$response->setHeader('Content-Range', 'bytes '.$start.'-'.$end.'/'.$nodeSize);
$response->setStatus(206);
$response->setBody($body);
} else {
if ($nodeSize) {
$response->setHeader('Content-Length', $nodeSize);
}
$response->setStatus(200);
$response->setBody($body);
}
return false;
} | [
"public",
"function",
"httpGet",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"path",
"=",
"$",
"request",
"->",
"getPath",
"(",
")",
";",
"$",
"node",
"=",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"$",
"node",
"instanceof",
"IFile",
")",
"{",
"return",
";",
"}",
"if",
"(",
"'HEAD'",
"===",
"$",
"request",
"->",
"getHeader",
"(",
"'X-Sabre-Original-Method'",
")",
")",
"{",
"$",
"body",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"body",
"=",
"$",
"node",
"->",
"get",
"(",
")",
";",
"// Converting string into stream, if needed.",
"if",
"(",
"is_string",
"(",
"$",
"body",
")",
")",
"{",
"$",
"stream",
"=",
"fopen",
"(",
"'php://temp'",
",",
"'r+'",
")",
";",
"fwrite",
"(",
"$",
"stream",
",",
"$",
"body",
")",
";",
"rewind",
"(",
"$",
"stream",
")",
";",
"$",
"body",
"=",
"$",
"stream",
";",
"}",
"}",
"/*\n * TODO: getetag, getlastmodified, getsize should also be used using\n * this method\n */",
"$",
"httpHeaders",
"=",
"$",
"this",
"->",
"server",
"->",
"getHTTPHeaders",
"(",
"$",
"path",
")",
";",
"/* ContentType needs to get a default, because many webservers will otherwise\n * default to text/html, and we don't want this for security reasons.\n */",
"if",
"(",
"!",
"isset",
"(",
"$",
"httpHeaders",
"[",
"'Content-Type'",
"]",
")",
")",
"{",
"$",
"httpHeaders",
"[",
"'Content-Type'",
"]",
"=",
"'application/octet-stream'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"httpHeaders",
"[",
"'Content-Length'",
"]",
")",
")",
"{",
"$",
"nodeSize",
"=",
"$",
"httpHeaders",
"[",
"'Content-Length'",
"]",
";",
"// Need to unset Content-Length, because we'll handle that during figuring out the range",
"unset",
"(",
"$",
"httpHeaders",
"[",
"'Content-Length'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"nodeSize",
"=",
"null",
";",
"}",
"$",
"response",
"->",
"addHeaders",
"(",
"$",
"httpHeaders",
")",
";",
"$",
"range",
"=",
"$",
"this",
"->",
"server",
"->",
"getHTTPRange",
"(",
")",
";",
"$",
"ifRange",
"=",
"$",
"request",
"->",
"getHeader",
"(",
"'If-Range'",
")",
";",
"$",
"ignoreRangeHeader",
"=",
"false",
";",
"// If ifRange is set, and range is specified, we first need to check",
"// the precondition.",
"if",
"(",
"$",
"nodeSize",
"&&",
"$",
"range",
"&&",
"$",
"ifRange",
")",
"{",
"// if IfRange is parsable as a date we'll treat it as a DateTime",
"// otherwise, we must treat it as an etag.",
"try",
"{",
"$",
"ifRangeDate",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"ifRange",
")",
";",
"// It's a date. We must check if the entity is modified since",
"// the specified date.",
"if",
"(",
"!",
"isset",
"(",
"$",
"httpHeaders",
"[",
"'Last-Modified'",
"]",
")",
")",
"{",
"$",
"ignoreRangeHeader",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"modified",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"httpHeaders",
"[",
"'Last-Modified'",
"]",
")",
";",
"if",
"(",
"$",
"modified",
">",
"$",
"ifRangeDate",
")",
"{",
"$",
"ignoreRangeHeader",
"=",
"true",
";",
"}",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// It's an entity. We can do a simple comparison.",
"if",
"(",
"!",
"isset",
"(",
"$",
"httpHeaders",
"[",
"'ETag'",
"]",
")",
")",
"{",
"$",
"ignoreRangeHeader",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"httpHeaders",
"[",
"'ETag'",
"]",
"!==",
"$",
"ifRange",
")",
"{",
"$",
"ignoreRangeHeader",
"=",
"true",
";",
"}",
"}",
"}",
"// We're only going to support HTTP ranges if the backend provided a filesize",
"if",
"(",
"!",
"$",
"ignoreRangeHeader",
"&&",
"$",
"nodeSize",
"&&",
"$",
"range",
")",
"{",
"// Determining the exact byte offsets",
"if",
"(",
"!",
"is_null",
"(",
"$",
"range",
"[",
"0",
"]",
")",
")",
"{",
"$",
"start",
"=",
"$",
"range",
"[",
"0",
"]",
";",
"$",
"end",
"=",
"$",
"range",
"[",
"1",
"]",
"?",
"$",
"range",
"[",
"1",
"]",
":",
"$",
"nodeSize",
"-",
"1",
";",
"if",
"(",
"$",
"start",
">=",
"$",
"nodeSize",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"RequestedRangeNotSatisfiable",
"(",
"'The start offset ('",
".",
"$",
"range",
"[",
"0",
"]",
".",
"') exceeded the size of the entity ('",
".",
"$",
"nodeSize",
".",
"')'",
")",
";",
"}",
"if",
"(",
"$",
"end",
"<",
"$",
"start",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"RequestedRangeNotSatisfiable",
"(",
"'The end offset ('",
".",
"$",
"range",
"[",
"1",
"]",
".",
"') is lower than the start offset ('",
".",
"$",
"range",
"[",
"0",
"]",
".",
"')'",
")",
";",
"}",
"if",
"(",
"$",
"end",
">=",
"$",
"nodeSize",
")",
"{",
"$",
"end",
"=",
"$",
"nodeSize",
"-",
"1",
";",
"}",
"}",
"else",
"{",
"$",
"start",
"=",
"$",
"nodeSize",
"-",
"$",
"range",
"[",
"1",
"]",
";",
"$",
"end",
"=",
"$",
"nodeSize",
"-",
"1",
";",
"if",
"(",
"$",
"start",
"<",
"0",
")",
"{",
"$",
"start",
"=",
"0",
";",
"}",
"}",
"// Streams may advertise themselves as seekable, but still not",
"// actually allow fseek. We'll manually go forward in the stream",
"// if fseek failed.",
"if",
"(",
"!",
"stream_get_meta_data",
"(",
"$",
"body",
")",
"[",
"'seekable'",
"]",
"||",
"-",
"1",
"===",
"fseek",
"(",
"$",
"body",
",",
"$",
"start",
",",
"SEEK_SET",
")",
")",
"{",
"$",
"consumeBlock",
"=",
"8192",
";",
"for",
"(",
"$",
"consumed",
"=",
"0",
";",
"$",
"start",
"-",
"$",
"consumed",
">",
"0",
";",
")",
"{",
"if",
"(",
"feof",
"(",
"$",
"body",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"RequestedRangeNotSatisfiable",
"(",
"'The start offset ('",
".",
"$",
"start",
".",
"') exceeded the size of the entity ('",
".",
"$",
"consumed",
".",
"')'",
")",
";",
"}",
"$",
"consumed",
"+=",
"strlen",
"(",
"fread",
"(",
"$",
"body",
",",
"min",
"(",
"$",
"start",
"-",
"$",
"consumed",
",",
"$",
"consumeBlock",
")",
")",
")",
";",
"}",
"}",
"$",
"response",
"->",
"setHeader",
"(",
"'Content-Length'",
",",
"$",
"end",
"-",
"$",
"start",
"+",
"1",
")",
";",
"$",
"response",
"->",
"setHeader",
"(",
"'Content-Range'",
",",
"'bytes '",
".",
"$",
"start",
".",
"'-'",
".",
"$",
"end",
".",
"'/'",
".",
"$",
"nodeSize",
")",
";",
"$",
"response",
"->",
"setStatus",
"(",
"206",
")",
";",
"$",
"response",
"->",
"setBody",
"(",
"$",
"body",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"nodeSize",
")",
"{",
"$",
"response",
"->",
"setHeader",
"(",
"'Content-Length'",
",",
"$",
"nodeSize",
")",
";",
"}",
"$",
"response",
"->",
"setStatus",
"(",
"200",
")",
";",
"$",
"response",
"->",
"setBody",
"(",
"$",
"body",
")",
";",
"}",
"// Sending back false will interrupt the event chain and tell the server",
"// we've handled this method.",
"return",
"false",
";",
"}"
] | This is the default implementation for the GET method.
@param RequestInterface $request
@param ResponseInterface $response
@return bool | [
"This",
"is",
"the",
"default",
"implementation",
"for",
"the",
"GET",
"method",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L78-L208 |
sabre-io/dav | lib/DAV/CorePlugin.php | CorePlugin.httpOptions | public function httpOptions(RequestInterface $request, ResponseInterface $response)
{
$methods = $this->server->getAllowedMethods($request->getPath());
$response->setHeader('Allow', strtoupper(implode(', ', $methods)));
$features = ['1', '3', 'extended-mkcol'];
foreach ($this->server->getPlugins() as $plugin) {
$features = array_merge($features, $plugin->getFeatures());
}
$response->setHeader('DAV', implode(', ', $features));
$response->setHeader('MS-Author-Via', 'DAV');
$response->setHeader('Accept-Ranges', 'bytes');
$response->setHeader('Content-Length', '0');
$response->setStatus(200);
// Sending back false will interrupt the event chain and tell the server
// we've handled this method.
return false;
} | php | public function httpOptions(RequestInterface $request, ResponseInterface $response)
{
$methods = $this->server->getAllowedMethods($request->getPath());
$response->setHeader('Allow', strtoupper(implode(', ', $methods)));
$features = ['1', '3', 'extended-mkcol'];
foreach ($this->server->getPlugins() as $plugin) {
$features = array_merge($features, $plugin->getFeatures());
}
$response->setHeader('DAV', implode(', ', $features));
$response->setHeader('MS-Author-Via', 'DAV');
$response->setHeader('Accept-Ranges', 'bytes');
$response->setHeader('Content-Length', '0');
$response->setStatus(200);
return false;
} | [
"public",
"function",
"httpOptions",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"methods",
"=",
"$",
"this",
"->",
"server",
"->",
"getAllowedMethods",
"(",
"$",
"request",
"->",
"getPath",
"(",
")",
")",
";",
"$",
"response",
"->",
"setHeader",
"(",
"'Allow'",
",",
"strtoupper",
"(",
"implode",
"(",
"', '",
",",
"$",
"methods",
")",
")",
")",
";",
"$",
"features",
"=",
"[",
"'1'",
",",
"'3'",
",",
"'extended-mkcol'",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"server",
"->",
"getPlugins",
"(",
")",
"as",
"$",
"plugin",
")",
"{",
"$",
"features",
"=",
"array_merge",
"(",
"$",
"features",
",",
"$",
"plugin",
"->",
"getFeatures",
"(",
")",
")",
";",
"}",
"$",
"response",
"->",
"setHeader",
"(",
"'DAV'",
",",
"implode",
"(",
"', '",
",",
"$",
"features",
")",
")",
";",
"$",
"response",
"->",
"setHeader",
"(",
"'MS-Author-Via'",
",",
"'DAV'",
")",
";",
"$",
"response",
"->",
"setHeader",
"(",
"'Accept-Ranges'",
",",
"'bytes'",
")",
";",
"$",
"response",
"->",
"setHeader",
"(",
"'Content-Length'",
",",
"'0'",
")",
";",
"$",
"response",
"->",
"setStatus",
"(",
"200",
")",
";",
"// Sending back false will interrupt the event chain and tell the server",
"// we've handled this method.",
"return",
"false",
";",
"}"
] | HTTP OPTIONS.
@param RequestInterface $request
@param ResponseInterface $response
@return bool | [
"HTTP",
"OPTIONS",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L218-L238 |
sabre-io/dav | lib/DAV/CorePlugin.php | CorePlugin.httpHead | public function httpHead(RequestInterface $request, ResponseInterface $response)
{
// This is implemented by changing the HEAD request to a GET request,
// and telling the request handler that is doesn't need to create the body.
$subRequest = clone $request;
$subRequest->setMethod('GET');
$subRequest->setHeader('X-Sabre-Original-Method', 'HEAD');
try {
$this->server->invokeMethod($subRequest, $response, false);
} catch (Exception\NotImplemented $e) {
// Some clients may do HEAD requests on collections, however, GET
// requests and HEAD requests _may_ not be defined on a collection,
// which would trigger a 501.
// This breaks some clients though, so we're transforming these
// 501s into 200s.
$response->setStatus(200);
$response->setBody('');
$response->setHeader('Content-Type', 'text/plain');
$response->setHeader('X-Sabre-Real-Status', $e->getHTTPCode());
}
// Sending back false will interrupt the event chain and tell the server
// we've handled this method.
return false;
} | php | public function httpHead(RequestInterface $request, ResponseInterface $response)
{
$subRequest = clone $request;
$subRequest->setMethod('GET');
$subRequest->setHeader('X-Sabre-Original-Method', 'HEAD');
try {
$this->server->invokeMethod($subRequest, $response, false);
} catch (Exception\NotImplemented $e) {
$response->setStatus(200);
$response->setBody('');
$response->setHeader('Content-Type', 'text/plain');
$response->setHeader('X-Sabre-Real-Status', $e->getHTTPCode());
}
return false;
} | [
"public",
"function",
"httpHead",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"// This is implemented by changing the HEAD request to a GET request,",
"// and telling the request handler that is doesn't need to create the body.",
"$",
"subRequest",
"=",
"clone",
"$",
"request",
";",
"$",
"subRequest",
"->",
"setMethod",
"(",
"'GET'",
")",
";",
"$",
"subRequest",
"->",
"setHeader",
"(",
"'X-Sabre-Original-Method'",
",",
"'HEAD'",
")",
";",
"try",
"{",
"$",
"this",
"->",
"server",
"->",
"invokeMethod",
"(",
"$",
"subRequest",
",",
"$",
"response",
",",
"false",
")",
";",
"}",
"catch",
"(",
"Exception",
"\\",
"NotImplemented",
"$",
"e",
")",
"{",
"// Some clients may do HEAD requests on collections, however, GET",
"// requests and HEAD requests _may_ not be defined on a collection,",
"// which would trigger a 501.",
"// This breaks some clients though, so we're transforming these",
"// 501s into 200s.",
"$",
"response",
"->",
"setStatus",
"(",
"200",
")",
";",
"$",
"response",
"->",
"setBody",
"(",
"''",
")",
";",
"$",
"response",
"->",
"setHeader",
"(",
"'Content-Type'",
",",
"'text/plain'",
")",
";",
"$",
"response",
"->",
"setHeader",
"(",
"'X-Sabre-Real-Status'",
",",
"$",
"e",
"->",
"getHTTPCode",
"(",
")",
")",
";",
"}",
"// Sending back false will interrupt the event chain and tell the server",
"// we've handled this method.",
"return",
"false",
";",
"}"
] | HTTP HEAD.
This method is normally used to take a peak at a url, and only get the
HTTP response headers, without the body. This is used by clients to
determine if a remote file was changed, so they can use a local cached
version, instead of downloading it again
@param RequestInterface $request
@param ResponseInterface $response
@return bool | [
"HTTP",
"HEAD",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L253-L278 |
sabre-io/dav | lib/DAV/CorePlugin.php | CorePlugin.httpDelete | public function httpDelete(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
if (!$this->server->emit('beforeUnbind', [$path])) {
return false;
}
$this->server->tree->delete($path);
$this->server->emit('afterUnbind', [$path]);
$response->setStatus(204);
$response->setHeader('Content-Length', '0');
// Sending back false will interrupt the event chain and tell the server
// we've handled this method.
return false;
} | php | public function httpDelete(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
if (!$this->server->emit('beforeUnbind', [$path])) {
return false;
}
$this->server->tree->delete($path);
$this->server->emit('afterUnbind', [$path]);
$response->setStatus(204);
$response->setHeader('Content-Length', '0');
return false;
} | [
"public",
"function",
"httpDelete",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"path",
"=",
"$",
"request",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"server",
"->",
"emit",
"(",
"'beforeUnbind'",
",",
"[",
"$",
"path",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"delete",
"(",
"$",
"path",
")",
";",
"$",
"this",
"->",
"server",
"->",
"emit",
"(",
"'afterUnbind'",
",",
"[",
"$",
"path",
"]",
")",
";",
"$",
"response",
"->",
"setStatus",
"(",
"204",
")",
";",
"$",
"response",
"->",
"setHeader",
"(",
"'Content-Length'",
",",
"'0'",
")",
";",
"// Sending back false will interrupt the event chain and tell the server",
"// we've handled this method.",
"return",
"false",
";",
"}"
] | HTTP Delete.
The HTTP delete method, deletes a given uri
@param RequestInterface $request
@param ResponseInterface $response | [
"HTTP",
"Delete",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L288-L304 |
sabre-io/dav | lib/DAV/CorePlugin.php | CorePlugin.httpPropFind | public function httpPropFind(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
$requestBody = $request->getBodyAsString();
if (strlen($requestBody)) {
try {
$propFindXml = $this->server->xml->expect('{DAV:}propfind', $requestBody);
} catch (ParseException $e) {
throw new BadRequest($e->getMessage(), 0, $e);
}
} else {
$propFindXml = new Xml\Request\PropFind();
$propFindXml->allProp = true;
$propFindXml->properties = [];
}
$depth = $this->server->getHTTPDepth(1);
// The only two options for the depth of a propfind is 0 or 1 - as long as depth infinity is not enabled
if (!$this->server->enablePropfindDepthInfinity && 0 != $depth) {
$depth = 1;
}
$newProperties = $this->server->getPropertiesIteratorForPath($path, $propFindXml->properties, $depth);
// This is a multi-status response
$response->setStatus(207);
$response->setHeader('Content-Type', 'application/xml; charset=utf-8');
$response->setHeader('Vary', 'Brief,Prefer');
// Normally this header is only needed for OPTIONS responses, however..
// iCal seems to also depend on these being set for PROPFIND. Since
// this is not harmful, we'll add it.
$features = ['1', '3', 'extended-mkcol'];
foreach ($this->server->getPlugins() as $plugin) {
$features = array_merge($features, $plugin->getFeatures());
}
$response->setHeader('DAV', implode(', ', $features));
$prefer = $this->server->getHTTPPrefer();
$minimal = 'minimal' === $prefer['return'];
$data = $this->server->generateMultiStatus($newProperties, $minimal);
$response->setBody($data);
// Sending back false will interrupt the event chain and tell the server
// we've handled this method.
return false;
} | php | public function httpPropFind(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
$requestBody = $request->getBodyAsString();
if (strlen($requestBody)) {
try {
$propFindXml = $this->server->xml->expect('{DAV:}propfind', $requestBody);
} catch (ParseException $e) {
throw new BadRequest($e->getMessage(), 0, $e);
}
} else {
$propFindXml = new Xml\Request\PropFind();
$propFindXml->allProp = true;
$propFindXml->properties = [];
}
$depth = $this->server->getHTTPDepth(1);
if (!$this->server->enablePropfindDepthInfinity && 0 != $depth) {
$depth = 1;
}
$newProperties = $this->server->getPropertiesIteratorForPath($path, $propFindXml->properties, $depth);
$response->setStatus(207);
$response->setHeader('Content-Type', 'application/xml; charset=utf-8');
$response->setHeader('Vary', 'Brief,Prefer');
$features = ['1', '3', 'extended-mkcol'];
foreach ($this->server->getPlugins() as $plugin) {
$features = array_merge($features, $plugin->getFeatures());
}
$response->setHeader('DAV', implode(', ', $features));
$prefer = $this->server->getHTTPPrefer();
$minimal = 'minimal' === $prefer['return'];
$data = $this->server->generateMultiStatus($newProperties, $minimal);
$response->setBody($data);
return false;
} | [
"public",
"function",
"httpPropFind",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"path",
"=",
"$",
"request",
"->",
"getPath",
"(",
")",
";",
"$",
"requestBody",
"=",
"$",
"request",
"->",
"getBodyAsString",
"(",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"requestBody",
")",
")",
"{",
"try",
"{",
"$",
"propFindXml",
"=",
"$",
"this",
"->",
"server",
"->",
"xml",
"->",
"expect",
"(",
"'{DAV:}propfind'",
",",
"$",
"requestBody",
")",
";",
"}",
"catch",
"(",
"ParseException",
"$",
"e",
")",
"{",
"throw",
"new",
"BadRequest",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"}",
"else",
"{",
"$",
"propFindXml",
"=",
"new",
"Xml",
"\\",
"Request",
"\\",
"PropFind",
"(",
")",
";",
"$",
"propFindXml",
"->",
"allProp",
"=",
"true",
";",
"$",
"propFindXml",
"->",
"properties",
"=",
"[",
"]",
";",
"}",
"$",
"depth",
"=",
"$",
"this",
"->",
"server",
"->",
"getHTTPDepth",
"(",
"1",
")",
";",
"// The only two options for the depth of a propfind is 0 or 1 - as long as depth infinity is not enabled",
"if",
"(",
"!",
"$",
"this",
"->",
"server",
"->",
"enablePropfindDepthInfinity",
"&&",
"0",
"!=",
"$",
"depth",
")",
"{",
"$",
"depth",
"=",
"1",
";",
"}",
"$",
"newProperties",
"=",
"$",
"this",
"->",
"server",
"->",
"getPropertiesIteratorForPath",
"(",
"$",
"path",
",",
"$",
"propFindXml",
"->",
"properties",
",",
"$",
"depth",
")",
";",
"// This is a multi-status response",
"$",
"response",
"->",
"setStatus",
"(",
"207",
")",
";",
"$",
"response",
"->",
"setHeader",
"(",
"'Content-Type'",
",",
"'application/xml; charset=utf-8'",
")",
";",
"$",
"response",
"->",
"setHeader",
"(",
"'Vary'",
",",
"'Brief,Prefer'",
")",
";",
"// Normally this header is only needed for OPTIONS responses, however..",
"// iCal seems to also depend on these being set for PROPFIND. Since",
"// this is not harmful, we'll add it.",
"$",
"features",
"=",
"[",
"'1'",
",",
"'3'",
",",
"'extended-mkcol'",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"server",
"->",
"getPlugins",
"(",
")",
"as",
"$",
"plugin",
")",
"{",
"$",
"features",
"=",
"array_merge",
"(",
"$",
"features",
",",
"$",
"plugin",
"->",
"getFeatures",
"(",
")",
")",
";",
"}",
"$",
"response",
"->",
"setHeader",
"(",
"'DAV'",
",",
"implode",
"(",
"', '",
",",
"$",
"features",
")",
")",
";",
"$",
"prefer",
"=",
"$",
"this",
"->",
"server",
"->",
"getHTTPPrefer",
"(",
")",
";",
"$",
"minimal",
"=",
"'minimal'",
"===",
"$",
"prefer",
"[",
"'return'",
"]",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"server",
"->",
"generateMultiStatus",
"(",
"$",
"newProperties",
",",
"$",
"minimal",
")",
";",
"$",
"response",
"->",
"setBody",
"(",
"$",
"data",
")",
";",
"// Sending back false will interrupt the event chain and tell the server",
"// we've handled this method.",
"return",
"false",
";",
"}"
] | WebDAV PROPFIND.
This WebDAV method requests information about an uri resource, or a list of resources
If a client wants to receive the properties for a single resource it will add an HTTP Depth: header with a 0 value
If the value is 1, it means that it also expects a list of sub-resources (e.g.: files in a directory)
The request body contains an XML data structure that has a list of properties the client understands
The response body is also an xml document, containing information about every uri resource and the requested properties
It has to return a HTTP 207 Multi-status status code
@param RequestInterface $request
@param ResponseInterface $response | [
"WebDAV",
"PROPFIND",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L321-L369 |
sabre-io/dav | lib/DAV/CorePlugin.php | CorePlugin.httpPropPatch | public function httpPropPatch(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
try {
$propPatch = $this->server->xml->expect('{DAV:}propertyupdate', $request->getBody());
} catch (ParseException $e) {
throw new BadRequest($e->getMessage(), 0, $e);
}
$newProperties = $propPatch->properties;
$result = $this->server->updateProperties($path, $newProperties);
$prefer = $this->server->getHTTPPrefer();
$response->setHeader('Vary', 'Brief,Prefer');
if ('minimal' === $prefer['return']) {
// If return-minimal is specified, we only have to check if the
// request was successful, and don't need to return the
// multi-status.
$ok = true;
foreach ($result as $prop => $code) {
if ((int) $code > 299) {
$ok = false;
}
}
if ($ok) {
$response->setStatus(204);
return false;
}
}
$response->setStatus(207);
$response->setHeader('Content-Type', 'application/xml; charset=utf-8');
// Reorganizing the result for generateMultiStatus
$multiStatus = [];
foreach ($result as $propertyName => $code) {
if (isset($multiStatus[$code])) {
$multiStatus[$code][$propertyName] = null;
} else {
$multiStatus[$code] = [$propertyName => null];
}
}
$multiStatus['href'] = $path;
$response->setBody(
$this->server->generateMultiStatus([$multiStatus])
);
// Sending back false will interrupt the event chain and tell the server
// we've handled this method.
return false;
} | php | public function httpPropPatch(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
try {
$propPatch = $this->server->xml->expect('{DAV:}propertyupdate', $request->getBody());
} catch (ParseException $e) {
throw new BadRequest($e->getMessage(), 0, $e);
}
$newProperties = $propPatch->properties;
$result = $this->server->updateProperties($path, $newProperties);
$prefer = $this->server->getHTTPPrefer();
$response->setHeader('Vary', 'Brief,Prefer');
if ('minimal' === $prefer['return']) {
$ok = true;
foreach ($result as $prop => $code) {
if ((int) $code > 299) {
$ok = false;
}
}
if ($ok) {
$response->setStatus(204);
return false;
}
}
$response->setStatus(207);
$response->setHeader('Content-Type', 'application/xml; charset=utf-8');
$multiStatus = [];
foreach ($result as $propertyName => $code) {
if (isset($multiStatus[$code])) {
$multiStatus[$code][$propertyName] = null;
} else {
$multiStatus[$code] = [$propertyName => null];
}
}
$multiStatus['href'] = $path;
$response->setBody(
$this->server->generateMultiStatus([$multiStatus])
);
return false;
} | [
"public",
"function",
"httpPropPatch",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"path",
"=",
"$",
"request",
"->",
"getPath",
"(",
")",
";",
"try",
"{",
"$",
"propPatch",
"=",
"$",
"this",
"->",
"server",
"->",
"xml",
"->",
"expect",
"(",
"'{DAV:}propertyupdate'",
",",
"$",
"request",
"->",
"getBody",
"(",
")",
")",
";",
"}",
"catch",
"(",
"ParseException",
"$",
"e",
")",
"{",
"throw",
"new",
"BadRequest",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"$",
"newProperties",
"=",
"$",
"propPatch",
"->",
"properties",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"server",
"->",
"updateProperties",
"(",
"$",
"path",
",",
"$",
"newProperties",
")",
";",
"$",
"prefer",
"=",
"$",
"this",
"->",
"server",
"->",
"getHTTPPrefer",
"(",
")",
";",
"$",
"response",
"->",
"setHeader",
"(",
"'Vary'",
",",
"'Brief,Prefer'",
")",
";",
"if",
"(",
"'minimal'",
"===",
"$",
"prefer",
"[",
"'return'",
"]",
")",
"{",
"// If return-minimal is specified, we only have to check if the",
"// request was successful, and don't need to return the",
"// multi-status.",
"$",
"ok",
"=",
"true",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"prop",
"=>",
"$",
"code",
")",
"{",
"if",
"(",
"(",
"int",
")",
"$",
"code",
">",
"299",
")",
"{",
"$",
"ok",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"$",
"ok",
")",
"{",
"$",
"response",
"->",
"setStatus",
"(",
"204",
")",
";",
"return",
"false",
";",
"}",
"}",
"$",
"response",
"->",
"setStatus",
"(",
"207",
")",
";",
"$",
"response",
"->",
"setHeader",
"(",
"'Content-Type'",
",",
"'application/xml; charset=utf-8'",
")",
";",
"// Reorganizing the result for generateMultiStatus",
"$",
"multiStatus",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"propertyName",
"=>",
"$",
"code",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"multiStatus",
"[",
"$",
"code",
"]",
")",
")",
"{",
"$",
"multiStatus",
"[",
"$",
"code",
"]",
"[",
"$",
"propertyName",
"]",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"multiStatus",
"[",
"$",
"code",
"]",
"=",
"[",
"$",
"propertyName",
"=>",
"null",
"]",
";",
"}",
"}",
"$",
"multiStatus",
"[",
"'href'",
"]",
"=",
"$",
"path",
";",
"$",
"response",
"->",
"setBody",
"(",
"$",
"this",
"->",
"server",
"->",
"generateMultiStatus",
"(",
"[",
"$",
"multiStatus",
"]",
")",
")",
";",
"// Sending back false will interrupt the event chain and tell the server",
"// we've handled this method.",
"return",
"false",
";",
"}"
] | WebDAV PROPPATCH.
This method is called to update properties on a Node. The request is an XML body with all the mutations.
In this XML body it is specified which properties should be set/updated and/or deleted
@param RequestInterface $request
@param ResponseInterface $response
@return bool | [
"WebDAV",
"PROPPATCH",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L382-L437 |
sabre-io/dav | lib/DAV/CorePlugin.php | CorePlugin.httpPut | public function httpPut(RequestInterface $request, ResponseInterface $response)
{
$body = $request->getBodyAsStream();
$path = $request->getPath();
// Intercepting Content-Range
if ($request->getHeader('Content-Range')) {
/*
An origin server that allows PUT on a given target resource MUST send
a 400 (Bad Request) response to a PUT request that contains a
Content-Range header field.
Reference: http://tools.ietf.org/html/rfc7231#section-4.3.4
*/
throw new Exception\BadRequest('Content-Range on PUT requests are forbidden.');
}
// Intercepting the Finder problem
if (($expected = $request->getHeader('X-Expected-Entity-Length')) && $expected > 0) {
/*
Many webservers will not cooperate well with Finder PUT requests,
because it uses 'Chunked' transfer encoding for the request body.
The symptom of this problem is that Finder sends files to the
server, but they arrive as 0-length files in PHP.
If we don't do anything, the user might think they are uploading
files successfully, but they end up empty on the server. Instead,
we throw back an error if we detect this.
The reason Finder uses Chunked, is because it thinks the files
might change as it's being uploaded, and therefore the
Content-Length can vary.
Instead it sends the X-Expected-Entity-Length header with the size
of the file at the very start of the request. If this header is set,
but we don't get a request body we will fail the request to
protect the end-user.
*/
// Only reading first byte
$firstByte = fread($body, 1);
if (1 !== strlen($firstByte)) {
throw new Exception\Forbidden('This server is not compatible with OS/X finder. Consider using a different WebDAV client or webserver.');
}
// The body needs to stay intact, so we copy everything to a
// temporary stream.
$newBody = fopen('php://temp', 'r+');
fwrite($newBody, $firstByte);
stream_copy_to_stream($body, $newBody);
rewind($newBody);
$body = $newBody;
}
if ($this->server->tree->nodeExists($path)) {
$node = $this->server->tree->getNodeForPath($path);
// If the node is a collection, we'll deny it
if (!($node instanceof IFile)) {
throw new Exception\Conflict('PUT is not allowed on non-files.');
}
if (!$this->server->updateFile($path, $body, $etag)) {
return false;
}
$response->setHeader('Content-Length', '0');
if ($etag) {
$response->setHeader('ETag', $etag);
}
$response->setStatus(204);
} else {
$etag = null;
// If we got here, the resource didn't exist yet.
if (!$this->server->createFile($path, $body, $etag)) {
// For one reason or another the file was not created.
return false;
}
$response->setHeader('Content-Length', '0');
if ($etag) {
$response->setHeader('ETag', $etag);
}
$response->setStatus(201);
}
// Sending back false will interrupt the event chain and tell the server
// we've handled this method.
return false;
} | php | public function httpPut(RequestInterface $request, ResponseInterface $response)
{
$body = $request->getBodyAsStream();
$path = $request->getPath();
if ($request->getHeader('Content-Range')) {
throw new Exception\BadRequest('Content-Range on PUT requests are forbidden.');
}
if (($expected = $request->getHeader('X-Expected-Entity-Length')) && $expected > 0) {
$firstByte = fread($body, 1);
if (1 !== strlen($firstByte)) {
throw new Exception\Forbidden('This server is not compatible with OS/X finder. Consider using a different WebDAV client or webserver.');
}
$newBody = fopen('php:
fwrite($newBody, $firstByte);
stream_copy_to_stream($body, $newBody);
rewind($newBody);
$body = $newBody;
}
if ($this->server->tree->nodeExists($path)) {
$node = $this->server->tree->getNodeForPath($path);
if (!($node instanceof IFile)) {
throw new Exception\Conflict('PUT is not allowed on non-files.');
}
if (!$this->server->updateFile($path, $body, $etag)) {
return false;
}
$response->setHeader('Content-Length', '0');
if ($etag) {
$response->setHeader('ETag', $etag);
}
$response->setStatus(204);
} else {
$etag = null;
if (!$this->server->createFile($path, $body, $etag)) {
return false;
}
$response->setHeader('Content-Length', '0');
if ($etag) {
$response->setHeader('ETag', $etag);
}
$response->setStatus(201);
}
return false;
} | [
"public",
"function",
"httpPut",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"body",
"=",
"$",
"request",
"->",
"getBodyAsStream",
"(",
")",
";",
"$",
"path",
"=",
"$",
"request",
"->",
"getPath",
"(",
")",
";",
"// Intercepting Content-Range",
"if",
"(",
"$",
"request",
"->",
"getHeader",
"(",
"'Content-Range'",
")",
")",
"{",
"/*\n An origin server that allows PUT on a given target resource MUST send\n a 400 (Bad Request) response to a PUT request that contains a\n Content-Range header field.\n\n Reference: http://tools.ietf.org/html/rfc7231#section-4.3.4\n */",
"throw",
"new",
"Exception",
"\\",
"BadRequest",
"(",
"'Content-Range on PUT requests are forbidden.'",
")",
";",
"}",
"// Intercepting the Finder problem",
"if",
"(",
"(",
"$",
"expected",
"=",
"$",
"request",
"->",
"getHeader",
"(",
"'X-Expected-Entity-Length'",
")",
")",
"&&",
"$",
"expected",
">",
"0",
")",
"{",
"/*\n Many webservers will not cooperate well with Finder PUT requests,\n because it uses 'Chunked' transfer encoding for the request body.\n\n The symptom of this problem is that Finder sends files to the\n server, but they arrive as 0-length files in PHP.\n\n If we don't do anything, the user might think they are uploading\n files successfully, but they end up empty on the server. Instead,\n we throw back an error if we detect this.\n\n The reason Finder uses Chunked, is because it thinks the files\n might change as it's being uploaded, and therefore the\n Content-Length can vary.\n\n Instead it sends the X-Expected-Entity-Length header with the size\n of the file at the very start of the request. If this header is set,\n but we don't get a request body we will fail the request to\n protect the end-user.\n */",
"// Only reading first byte",
"$",
"firstByte",
"=",
"fread",
"(",
"$",
"body",
",",
"1",
")",
";",
"if",
"(",
"1",
"!==",
"strlen",
"(",
"$",
"firstByte",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"Forbidden",
"(",
"'This server is not compatible with OS/X finder. Consider using a different WebDAV client or webserver.'",
")",
";",
"}",
"// The body needs to stay intact, so we copy everything to a",
"// temporary stream.",
"$",
"newBody",
"=",
"fopen",
"(",
"'php://temp'",
",",
"'r+'",
")",
";",
"fwrite",
"(",
"$",
"newBody",
",",
"$",
"firstByte",
")",
";",
"stream_copy_to_stream",
"(",
"$",
"body",
",",
"$",
"newBody",
")",
";",
"rewind",
"(",
"$",
"newBody",
")",
";",
"$",
"body",
"=",
"$",
"newBody",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"nodeExists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"path",
")",
";",
"// If the node is a collection, we'll deny it",
"if",
"(",
"!",
"(",
"$",
"node",
"instanceof",
"IFile",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"Conflict",
"(",
"'PUT is not allowed on non-files.'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"server",
"->",
"updateFile",
"(",
"$",
"path",
",",
"$",
"body",
",",
"$",
"etag",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"response",
"->",
"setHeader",
"(",
"'Content-Length'",
",",
"'0'",
")",
";",
"if",
"(",
"$",
"etag",
")",
"{",
"$",
"response",
"->",
"setHeader",
"(",
"'ETag'",
",",
"$",
"etag",
")",
";",
"}",
"$",
"response",
"->",
"setStatus",
"(",
"204",
")",
";",
"}",
"else",
"{",
"$",
"etag",
"=",
"null",
";",
"// If we got here, the resource didn't exist yet.",
"if",
"(",
"!",
"$",
"this",
"->",
"server",
"->",
"createFile",
"(",
"$",
"path",
",",
"$",
"body",
",",
"$",
"etag",
")",
")",
"{",
"// For one reason or another the file was not created.",
"return",
"false",
";",
"}",
"$",
"response",
"->",
"setHeader",
"(",
"'Content-Length'",
",",
"'0'",
")",
";",
"if",
"(",
"$",
"etag",
")",
"{",
"$",
"response",
"->",
"setHeader",
"(",
"'ETag'",
",",
"$",
"etag",
")",
";",
"}",
"$",
"response",
"->",
"setStatus",
"(",
"201",
")",
";",
"}",
"// Sending back false will interrupt the event chain and tell the server",
"// we've handled this method.",
"return",
"false",
";",
"}"
] | HTTP PUT method.
This HTTP method updates a file, or creates a new one.
If a new resource was created, a 201 Created status code should be returned. If an existing resource is updated, it's a 204 No Content
@param RequestInterface $request
@param ResponseInterface $response
@return bool | [
"HTTP",
"PUT",
"method",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L451-L542 |
sabre-io/dav | lib/DAV/CorePlugin.php | CorePlugin.httpMkcol | public function httpMkcol(RequestInterface $request, ResponseInterface $response)
{
$requestBody = $request->getBodyAsString();
$path = $request->getPath();
if ($requestBody) {
$contentType = $request->getHeader('Content-Type');
if (null === $contentType || (0 !== strpos($contentType, 'application/xml') && 0 !== strpos($contentType, 'text/xml'))) {
// We must throw 415 for unsupported mkcol bodies
throw new Exception\UnsupportedMediaType('The request body for the MKCOL request must have an xml Content-Type');
}
try {
$mkcol = $this->server->xml->expect('{DAV:}mkcol', $requestBody);
} catch (\Sabre\Xml\ParseException $e) {
throw new Exception\BadRequest($e->getMessage(), 0, $e);
}
$properties = $mkcol->getProperties();
if (!isset($properties['{DAV:}resourcetype'])) {
throw new Exception\BadRequest('The mkcol request must include a {DAV:}resourcetype property');
}
$resourceType = $properties['{DAV:}resourcetype']->getValue();
unset($properties['{DAV:}resourcetype']);
} else {
$properties = [];
$resourceType = ['{DAV:}collection'];
}
$mkcol = new MkCol($resourceType, $properties);
$result = $this->server->createCollection($path, $mkcol);
if (is_array($result)) {
$response->setStatus(207);
$response->setHeader('Content-Type', 'application/xml; charset=utf-8');
$response->setBody(
$this->server->generateMultiStatus([$result])
);
} else {
$response->setHeader('Content-Length', '0');
$response->setStatus(201);
}
// Sending back false will interrupt the event chain and tell the server
// we've handled this method.
return false;
} | php | public function httpMkcol(RequestInterface $request, ResponseInterface $response)
{
$requestBody = $request->getBodyAsString();
$path = $request->getPath();
if ($requestBody) {
$contentType = $request->getHeader('Content-Type');
if (null === $contentType || (0 !== strpos($contentType, 'application/xml') && 0 !== strpos($contentType, 'text/xml'))) {
throw new Exception\UnsupportedMediaType('The request body for the MKCOL request must have an xml Content-Type');
}
try {
$mkcol = $this->server->xml->expect('{DAV:}mkcol', $requestBody);
} catch (\Sabre\Xml\ParseException $e) {
throw new Exception\BadRequest($e->getMessage(), 0, $e);
}
$properties = $mkcol->getProperties();
if (!isset($properties['{DAV:}resourcetype'])) {
throw new Exception\BadRequest('The mkcol request must include a {DAV:}resourcetype property');
}
$resourceType = $properties['{DAV:}resourcetype']->getValue();
unset($properties['{DAV:}resourcetype']);
} else {
$properties = [];
$resourceType = ['{DAV:}collection'];
}
$mkcol = new MkCol($resourceType, $properties);
$result = $this->server->createCollection($path, $mkcol);
if (is_array($result)) {
$response->setStatus(207);
$response->setHeader('Content-Type', 'application/xml; charset=utf-8');
$response->setBody(
$this->server->generateMultiStatus([$result])
);
} else {
$response->setHeader('Content-Length', '0');
$response->setStatus(201);
}
return false;
} | [
"public",
"function",
"httpMkcol",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"requestBody",
"=",
"$",
"request",
"->",
"getBodyAsString",
"(",
")",
";",
"$",
"path",
"=",
"$",
"request",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"$",
"requestBody",
")",
"{",
"$",
"contentType",
"=",
"$",
"request",
"->",
"getHeader",
"(",
"'Content-Type'",
")",
";",
"if",
"(",
"null",
"===",
"$",
"contentType",
"||",
"(",
"0",
"!==",
"strpos",
"(",
"$",
"contentType",
",",
"'application/xml'",
")",
"&&",
"0",
"!==",
"strpos",
"(",
"$",
"contentType",
",",
"'text/xml'",
")",
")",
")",
"{",
"// We must throw 415 for unsupported mkcol bodies",
"throw",
"new",
"Exception",
"\\",
"UnsupportedMediaType",
"(",
"'The request body for the MKCOL request must have an xml Content-Type'",
")",
";",
"}",
"try",
"{",
"$",
"mkcol",
"=",
"$",
"this",
"->",
"server",
"->",
"xml",
"->",
"expect",
"(",
"'{DAV:}mkcol'",
",",
"$",
"requestBody",
")",
";",
"}",
"catch",
"(",
"\\",
"Sabre",
"\\",
"Xml",
"\\",
"ParseException",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"BadRequest",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"$",
"properties",
"=",
"$",
"mkcol",
"->",
"getProperties",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"properties",
"[",
"'{DAV:}resourcetype'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"BadRequest",
"(",
"'The mkcol request must include a {DAV:}resourcetype property'",
")",
";",
"}",
"$",
"resourceType",
"=",
"$",
"properties",
"[",
"'{DAV:}resourcetype'",
"]",
"->",
"getValue",
"(",
")",
";",
"unset",
"(",
"$",
"properties",
"[",
"'{DAV:}resourcetype'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"properties",
"=",
"[",
"]",
";",
"$",
"resourceType",
"=",
"[",
"'{DAV:}collection'",
"]",
";",
"}",
"$",
"mkcol",
"=",
"new",
"MkCol",
"(",
"$",
"resourceType",
",",
"$",
"properties",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"server",
"->",
"createCollection",
"(",
"$",
"path",
",",
"$",
"mkcol",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"result",
")",
")",
"{",
"$",
"response",
"->",
"setStatus",
"(",
"207",
")",
";",
"$",
"response",
"->",
"setHeader",
"(",
"'Content-Type'",
",",
"'application/xml; charset=utf-8'",
")",
";",
"$",
"response",
"->",
"setBody",
"(",
"$",
"this",
"->",
"server",
"->",
"generateMultiStatus",
"(",
"[",
"$",
"result",
"]",
")",
")",
";",
"}",
"else",
"{",
"$",
"response",
"->",
"setHeader",
"(",
"'Content-Length'",
",",
"'0'",
")",
";",
"$",
"response",
"->",
"setStatus",
"(",
"201",
")",
";",
"}",
"// Sending back false will interrupt the event chain and tell the server",
"// we've handled this method.",
"return",
"false",
";",
"}"
] | WebDAV MKCOL.
The MKCOL method is used to create a new collection (directory) on the server
@param RequestInterface $request
@param ResponseInterface $response
@return bool | [
"WebDAV",
"MKCOL",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L554-L603 |
sabre-io/dav | lib/DAV/CorePlugin.php | CorePlugin.httpMove | public function httpMove(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
$moveInfo = $this->server->getCopyAndMoveInfo($request);
if ($moveInfo['destinationExists']) {
if (!$this->server->emit('beforeUnbind', [$moveInfo['destination']])) {
return false;
}
}
if (!$this->server->emit('beforeUnbind', [$path])) {
return false;
}
if (!$this->server->emit('beforeBind', [$moveInfo['destination']])) {
return false;
}
if (!$this->server->emit('beforeMove', [$path, $moveInfo['destination']])) {
return false;
}
if ($moveInfo['destinationExists']) {
$this->server->tree->delete($moveInfo['destination']);
$this->server->emit('afterUnbind', [$moveInfo['destination']]);
}
$this->server->tree->move($path, $moveInfo['destination']);
// Its important afterMove is called before afterUnbind, because it
// allows systems to transfer data from one path to another.
// PropertyStorage uses this. If afterUnbind was first, it would clean
// up all the properties before it has a chance.
$this->server->emit('afterMove', [$path, $moveInfo['destination']]);
$this->server->emit('afterUnbind', [$path]);
$this->server->emit('afterBind', [$moveInfo['destination']]);
// If a resource was overwritten we should send a 204, otherwise a 201
$response->setHeader('Content-Length', '0');
$response->setStatus($moveInfo['destinationExists'] ? 204 : 201);
// Sending back false will interrupt the event chain and tell the server
// we've handled this method.
return false;
} | php | public function httpMove(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
$moveInfo = $this->server->getCopyAndMoveInfo($request);
if ($moveInfo['destinationExists']) {
if (!$this->server->emit('beforeUnbind', [$moveInfo['destination']])) {
return false;
}
}
if (!$this->server->emit('beforeUnbind', [$path])) {
return false;
}
if (!$this->server->emit('beforeBind', [$moveInfo['destination']])) {
return false;
}
if (!$this->server->emit('beforeMove', [$path, $moveInfo['destination']])) {
return false;
}
if ($moveInfo['destinationExists']) {
$this->server->tree->delete($moveInfo['destination']);
$this->server->emit('afterUnbind', [$moveInfo['destination']]);
}
$this->server->tree->move($path, $moveInfo['destination']);
$this->server->emit('afterMove', [$path, $moveInfo['destination']]);
$this->server->emit('afterUnbind', [$path]);
$this->server->emit('afterBind', [$moveInfo['destination']]);
$response->setHeader('Content-Length', '0');
$response->setStatus($moveInfo['destinationExists'] ? 204 : 201);
return false;
} | [
"public",
"function",
"httpMove",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"path",
"=",
"$",
"request",
"->",
"getPath",
"(",
")",
";",
"$",
"moveInfo",
"=",
"$",
"this",
"->",
"server",
"->",
"getCopyAndMoveInfo",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"moveInfo",
"[",
"'destinationExists'",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"server",
"->",
"emit",
"(",
"'beforeUnbind'",
",",
"[",
"$",
"moveInfo",
"[",
"'destination'",
"]",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"server",
"->",
"emit",
"(",
"'beforeUnbind'",
",",
"[",
"$",
"path",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"server",
"->",
"emit",
"(",
"'beforeBind'",
",",
"[",
"$",
"moveInfo",
"[",
"'destination'",
"]",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"server",
"->",
"emit",
"(",
"'beforeMove'",
",",
"[",
"$",
"path",
",",
"$",
"moveInfo",
"[",
"'destination'",
"]",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"moveInfo",
"[",
"'destinationExists'",
"]",
")",
"{",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"delete",
"(",
"$",
"moveInfo",
"[",
"'destination'",
"]",
")",
";",
"$",
"this",
"->",
"server",
"->",
"emit",
"(",
"'afterUnbind'",
",",
"[",
"$",
"moveInfo",
"[",
"'destination'",
"]",
"]",
")",
";",
"}",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"move",
"(",
"$",
"path",
",",
"$",
"moveInfo",
"[",
"'destination'",
"]",
")",
";",
"// Its important afterMove is called before afterUnbind, because it",
"// allows systems to transfer data from one path to another.",
"// PropertyStorage uses this. If afterUnbind was first, it would clean",
"// up all the properties before it has a chance.",
"$",
"this",
"->",
"server",
"->",
"emit",
"(",
"'afterMove'",
",",
"[",
"$",
"path",
",",
"$",
"moveInfo",
"[",
"'destination'",
"]",
"]",
")",
";",
"$",
"this",
"->",
"server",
"->",
"emit",
"(",
"'afterUnbind'",
",",
"[",
"$",
"path",
"]",
")",
";",
"$",
"this",
"->",
"server",
"->",
"emit",
"(",
"'afterBind'",
",",
"[",
"$",
"moveInfo",
"[",
"'destination'",
"]",
"]",
")",
";",
"// If a resource was overwritten we should send a 204, otherwise a 201",
"$",
"response",
"->",
"setHeader",
"(",
"'Content-Length'",
",",
"'0'",
")",
";",
"$",
"response",
"->",
"setStatus",
"(",
"$",
"moveInfo",
"[",
"'destinationExists'",
"]",
"?",
"204",
":",
"201",
")",
";",
"// Sending back false will interrupt the event chain and tell the server",
"// we've handled this method.",
"return",
"false",
";",
"}"
] | WebDAV HTTP MOVE method.
This method moves one uri to a different uri. A lot of the actual request processing is done in getCopyMoveInfo
@param RequestInterface $request
@param ResponseInterface $response
@return bool | [
"WebDAV",
"HTTP",
"MOVE",
"method",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L615-L658 |
sabre-io/dav | lib/DAV/CorePlugin.php | CorePlugin.httpCopy | public function httpCopy(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
$copyInfo = $this->server->getCopyAndMoveInfo($request);
if (!$this->server->emit('beforeBind', [$copyInfo['destination']])) {
return false;
}
if ($copyInfo['destinationExists']) {
if (!$this->server->emit('beforeUnbind', [$copyInfo['destination']])) {
return false;
}
$this->server->tree->delete($copyInfo['destination']);
}
$this->server->tree->copy($path, $copyInfo['destination']);
$this->server->emit('afterBind', [$copyInfo['destination']]);
// If a resource was overwritten we should send a 204, otherwise a 201
$response->setHeader('Content-Length', '0');
$response->setStatus($copyInfo['destinationExists'] ? 204 : 201);
// Sending back false will interrupt the event chain and tell the server
// we've handled this method.
return false;
} | php | public function httpCopy(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
$copyInfo = $this->server->getCopyAndMoveInfo($request);
if (!$this->server->emit('beforeBind', [$copyInfo['destination']])) {
return false;
}
if ($copyInfo['destinationExists']) {
if (!$this->server->emit('beforeUnbind', [$copyInfo['destination']])) {
return false;
}
$this->server->tree->delete($copyInfo['destination']);
}
$this->server->tree->copy($path, $copyInfo['destination']);
$this->server->emit('afterBind', [$copyInfo['destination']]);
$response->setHeader('Content-Length', '0');
$response->setStatus($copyInfo['destinationExists'] ? 204 : 201);
return false;
} | [
"public",
"function",
"httpCopy",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"path",
"=",
"$",
"request",
"->",
"getPath",
"(",
")",
";",
"$",
"copyInfo",
"=",
"$",
"this",
"->",
"server",
"->",
"getCopyAndMoveInfo",
"(",
"$",
"request",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"server",
"->",
"emit",
"(",
"'beforeBind'",
",",
"[",
"$",
"copyInfo",
"[",
"'destination'",
"]",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"copyInfo",
"[",
"'destinationExists'",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"server",
"->",
"emit",
"(",
"'beforeUnbind'",
",",
"[",
"$",
"copyInfo",
"[",
"'destination'",
"]",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"delete",
"(",
"$",
"copyInfo",
"[",
"'destination'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"copy",
"(",
"$",
"path",
",",
"$",
"copyInfo",
"[",
"'destination'",
"]",
")",
";",
"$",
"this",
"->",
"server",
"->",
"emit",
"(",
"'afterBind'",
",",
"[",
"$",
"copyInfo",
"[",
"'destination'",
"]",
"]",
")",
";",
"// If a resource was overwritten we should send a 204, otherwise a 201",
"$",
"response",
"->",
"setHeader",
"(",
"'Content-Length'",
",",
"'0'",
")",
";",
"$",
"response",
"->",
"setStatus",
"(",
"$",
"copyInfo",
"[",
"'destinationExists'",
"]",
"?",
"204",
":",
"201",
")",
";",
"// Sending back false will interrupt the event chain and tell the server",
"// we've handled this method.",
"return",
"false",
";",
"}"
] | WebDAV HTTP COPY method.
This method copies one uri to a different uri, and works much like the MOVE request
A lot of the actual request processing is done in getCopyMoveInfo
@param RequestInterface $request
@param ResponseInterface $response
@return bool | [
"WebDAV",
"HTTP",
"COPY",
"method",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L671-L697 |
sabre-io/dav | lib/DAV/CorePlugin.php | CorePlugin.httpReport | public function httpReport(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
$result = $this->server->xml->parse(
$request->getBody(),
$request->getUrl(),
$rootElementName
);
if ($this->server->emit('report', [$rootElementName, $result, $path])) {
// If emit returned true, it means the report was not supported
throw new Exception\ReportNotSupported();
}
// Sending back false will interrupt the event chain and tell the server
// we've handled this method.
return false;
} | php | public function httpReport(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
$result = $this->server->xml->parse(
$request->getBody(),
$request->getUrl(),
$rootElementName
);
if ($this->server->emit('report', [$rootElementName, $result, $path])) {
throw new Exception\ReportNotSupported();
}
return false;
} | [
"public",
"function",
"httpReport",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"path",
"=",
"$",
"request",
"->",
"getPath",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"server",
"->",
"xml",
"->",
"parse",
"(",
"$",
"request",
"->",
"getBody",
"(",
")",
",",
"$",
"request",
"->",
"getUrl",
"(",
")",
",",
"$",
"rootElementName",
")",
";",
"if",
"(",
"$",
"this",
"->",
"server",
"->",
"emit",
"(",
"'report'",
",",
"[",
"$",
"rootElementName",
",",
"$",
"result",
",",
"$",
"path",
"]",
")",
")",
"{",
"// If emit returned true, it means the report was not supported",
"throw",
"new",
"Exception",
"\\",
"ReportNotSupported",
"(",
")",
";",
"}",
"// Sending back false will interrupt the event chain and tell the server",
"// we've handled this method.",
"return",
"false",
";",
"}"
] | HTTP REPORT method implementation.
Although the REPORT method is not part of the standard WebDAV spec (it's from rfc3253)
It's used in a lot of extensions, so it made sense to implement it into the core.
@param RequestInterface $request
@param ResponseInterface $response
@return bool | [
"HTTP",
"REPORT",
"method",
"implementation",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L710-L728 |
sabre-io/dav | lib/DAV/CorePlugin.php | CorePlugin.propPatchProtectedPropertyCheck | public function propPatchProtectedPropertyCheck($path, PropPatch $propPatch)
{
// Comparing the mutation list to the list of protected properties.
$mutations = $propPatch->getMutations();
$protected = array_intersect(
$this->server->protectedProperties,
array_keys($mutations)
);
if ($protected) {
$propPatch->setResultCode($protected, 403);
}
} | php | public function propPatchProtectedPropertyCheck($path, PropPatch $propPatch)
{
$mutations = $propPatch->getMutations();
$protected = array_intersect(
$this->server->protectedProperties,
array_keys($mutations)
);
if ($protected) {
$propPatch->setResultCode($protected, 403);
}
} | [
"public",
"function",
"propPatchProtectedPropertyCheck",
"(",
"$",
"path",
",",
"PropPatch",
"$",
"propPatch",
")",
"{",
"// Comparing the mutation list to the list of protected properties.",
"$",
"mutations",
"=",
"$",
"propPatch",
"->",
"getMutations",
"(",
")",
";",
"$",
"protected",
"=",
"array_intersect",
"(",
"$",
"this",
"->",
"server",
"->",
"protectedProperties",
",",
"array_keys",
"(",
"$",
"mutations",
")",
")",
";",
"if",
"(",
"$",
"protected",
")",
"{",
"$",
"propPatch",
"->",
"setResultCode",
"(",
"$",
"protected",
",",
"403",
")",
";",
"}",
"}"
] | This method is called during property updates.
Here we check if a user attempted to update a protected property and
ensure that the process fails if this is the case.
@param string $path
@param PropPatch $propPatch | [
"This",
"method",
"is",
"called",
"during",
"property",
"updates",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L739-L752 |
sabre-io/dav | lib/DAV/CorePlugin.php | CorePlugin.propPatchNodeUpdate | public function propPatchNodeUpdate($path, PropPatch $propPatch)
{
// This should trigger a 404 if the node doesn't exist.
$node = $this->server->tree->getNodeForPath($path);
if ($node instanceof IProperties) {
$node->propPatch($propPatch);
}
} | php | public function propPatchNodeUpdate($path, PropPatch $propPatch)
{
$node = $this->server->tree->getNodeForPath($path);
if ($node instanceof IProperties) {
$node->propPatch($propPatch);
}
} | [
"public",
"function",
"propPatchNodeUpdate",
"(",
"$",
"path",
",",
"PropPatch",
"$",
"propPatch",
")",
"{",
"// This should trigger a 404 if the node doesn't exist.",
"$",
"node",
"=",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"node",
"instanceof",
"IProperties",
")",
"{",
"$",
"node",
"->",
"propPatch",
"(",
"$",
"propPatch",
")",
";",
"}",
"}"
] | This method is called during property updates.
Here we check if a node implements IProperties and let the node handle
updating of (some) properties.
@param string $path
@param PropPatch $propPatch | [
"This",
"method",
"is",
"called",
"during",
"property",
"updates",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L763-L771 |
sabre-io/dav | lib/DAV/CorePlugin.php | CorePlugin.propFind | public function propFind(PropFind $propFind, INode $node)
{
$propFind->handle('{DAV:}getlastmodified', function () use ($node) {
$lm = $node->getLastModified();
if ($lm) {
return new Xml\Property\GetLastModified($lm);
}
});
if ($node instanceof IFile) {
$propFind->handle('{DAV:}getcontentlength', [$node, 'getSize']);
$propFind->handle('{DAV:}getetag', [$node, 'getETag']);
$propFind->handle('{DAV:}getcontenttype', [$node, 'getContentType']);
}
if ($node instanceof IQuota) {
$quotaInfo = null;
$propFind->handle('{DAV:}quota-used-bytes', function () use (&$quotaInfo, $node) {
$quotaInfo = $node->getQuotaInfo();
return $quotaInfo[0];
});
$propFind->handle('{DAV:}quota-available-bytes', function () use (&$quotaInfo, $node) {
if (!$quotaInfo) {
$quotaInfo = $node->getQuotaInfo();
}
return $quotaInfo[1];
});
}
$propFind->handle('{DAV:}supported-report-set', function () use ($propFind) {
$reports = [];
foreach ($this->server->getPlugins() as $plugin) {
$reports = array_merge($reports, $plugin->getSupportedReportSet($propFind->getPath()));
}
return new Xml\Property\SupportedReportSet($reports);
});
$propFind->handle('{DAV:}resourcetype', function () use ($node) {
return new Xml\Property\ResourceType($this->server->getResourceTypeForNode($node));
});
$propFind->handle('{DAV:}supported-method-set', function () use ($propFind) {
return new Xml\Property\SupportedMethodSet(
$this->server->getAllowedMethods($propFind->getPath())
);
});
} | php | public function propFind(PropFind $propFind, INode $node)
{
$propFind->handle('{DAV:}getlastmodified', function () use ($node) {
$lm = $node->getLastModified();
if ($lm) {
return new Xml\Property\GetLastModified($lm);
}
});
if ($node instanceof IFile) {
$propFind->handle('{DAV:}getcontentlength', [$node, 'getSize']);
$propFind->handle('{DAV:}getetag', [$node, 'getETag']);
$propFind->handle('{DAV:}getcontenttype', [$node, 'getContentType']);
}
if ($node instanceof IQuota) {
$quotaInfo = null;
$propFind->handle('{DAV:}quota-used-bytes', function () use (&$quotaInfo, $node) {
$quotaInfo = $node->getQuotaInfo();
return $quotaInfo[0];
});
$propFind->handle('{DAV:}quota-available-bytes', function () use (&$quotaInfo, $node) {
if (!$quotaInfo) {
$quotaInfo = $node->getQuotaInfo();
}
return $quotaInfo[1];
});
}
$propFind->handle('{DAV:}supported-report-set', function () use ($propFind) {
$reports = [];
foreach ($this->server->getPlugins() as $plugin) {
$reports = array_merge($reports, $plugin->getSupportedReportSet($propFind->getPath()));
}
return new Xml\Property\SupportedReportSet($reports);
});
$propFind->handle('{DAV:}resourcetype', function () use ($node) {
return new Xml\Property\ResourceType($this->server->getResourceTypeForNode($node));
});
$propFind->handle('{DAV:}supported-method-set', function () use ($propFind) {
return new Xml\Property\SupportedMethodSet(
$this->server->getAllowedMethods($propFind->getPath())
);
});
} | [
"public",
"function",
"propFind",
"(",
"PropFind",
"$",
"propFind",
",",
"INode",
"$",
"node",
")",
"{",
"$",
"propFind",
"->",
"handle",
"(",
"'{DAV:}getlastmodified'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"node",
")",
"{",
"$",
"lm",
"=",
"$",
"node",
"->",
"getLastModified",
"(",
")",
";",
"if",
"(",
"$",
"lm",
")",
"{",
"return",
"new",
"Xml",
"\\",
"Property",
"\\",
"GetLastModified",
"(",
"$",
"lm",
")",
";",
"}",
"}",
")",
";",
"if",
"(",
"$",
"node",
"instanceof",
"IFile",
")",
"{",
"$",
"propFind",
"->",
"handle",
"(",
"'{DAV:}getcontentlength'",
",",
"[",
"$",
"node",
",",
"'getSize'",
"]",
")",
";",
"$",
"propFind",
"->",
"handle",
"(",
"'{DAV:}getetag'",
",",
"[",
"$",
"node",
",",
"'getETag'",
"]",
")",
";",
"$",
"propFind",
"->",
"handle",
"(",
"'{DAV:}getcontenttype'",
",",
"[",
"$",
"node",
",",
"'getContentType'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"node",
"instanceof",
"IQuota",
")",
"{",
"$",
"quotaInfo",
"=",
"null",
";",
"$",
"propFind",
"->",
"handle",
"(",
"'{DAV:}quota-used-bytes'",
",",
"function",
"(",
")",
"use",
"(",
"&",
"$",
"quotaInfo",
",",
"$",
"node",
")",
"{",
"$",
"quotaInfo",
"=",
"$",
"node",
"->",
"getQuotaInfo",
"(",
")",
";",
"return",
"$",
"quotaInfo",
"[",
"0",
"]",
";",
"}",
")",
";",
"$",
"propFind",
"->",
"handle",
"(",
"'{DAV:}quota-available-bytes'",
",",
"function",
"(",
")",
"use",
"(",
"&",
"$",
"quotaInfo",
",",
"$",
"node",
")",
"{",
"if",
"(",
"!",
"$",
"quotaInfo",
")",
"{",
"$",
"quotaInfo",
"=",
"$",
"node",
"->",
"getQuotaInfo",
"(",
")",
";",
"}",
"return",
"$",
"quotaInfo",
"[",
"1",
"]",
";",
"}",
")",
";",
"}",
"$",
"propFind",
"->",
"handle",
"(",
"'{DAV:}supported-report-set'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"propFind",
")",
"{",
"$",
"reports",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"server",
"->",
"getPlugins",
"(",
")",
"as",
"$",
"plugin",
")",
"{",
"$",
"reports",
"=",
"array_merge",
"(",
"$",
"reports",
",",
"$",
"plugin",
"->",
"getSupportedReportSet",
"(",
"$",
"propFind",
"->",
"getPath",
"(",
")",
")",
")",
";",
"}",
"return",
"new",
"Xml",
"\\",
"Property",
"\\",
"SupportedReportSet",
"(",
"$",
"reports",
")",
";",
"}",
")",
";",
"$",
"propFind",
"->",
"handle",
"(",
"'{DAV:}resourcetype'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"node",
")",
"{",
"return",
"new",
"Xml",
"\\",
"Property",
"\\",
"ResourceType",
"(",
"$",
"this",
"->",
"server",
"->",
"getResourceTypeForNode",
"(",
"$",
"node",
")",
")",
";",
"}",
")",
";",
"$",
"propFind",
"->",
"handle",
"(",
"'{DAV:}supported-method-set'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"propFind",
")",
"{",
"return",
"new",
"Xml",
"\\",
"Property",
"\\",
"SupportedMethodSet",
"(",
"$",
"this",
"->",
"server",
"->",
"getAllowedMethods",
"(",
"$",
"propFind",
"->",
"getPath",
"(",
")",
")",
")",
";",
"}",
")",
";",
"}"
] | This method is called when properties are retrieved.
Here we add all the default properties.
@param PropFind $propFind
@param INode $node | [
"This",
"method",
"is",
"called",
"when",
"properties",
"are",
"retrieved",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L781-L828 |
sabre-io/dav | lib/DAV/CorePlugin.php | CorePlugin.propFindNode | public function propFindNode(PropFind $propFind, INode $node)
{
if ($node instanceof IProperties && $propertyNames = $propFind->get404Properties()) {
$nodeProperties = $node->getProperties($propertyNames);
foreach ($nodeProperties as $propertyName => $propertyValue) {
$propFind->set($propertyName, $propertyValue, 200);
}
}
} | php | public function propFindNode(PropFind $propFind, INode $node)
{
if ($node instanceof IProperties && $propertyNames = $propFind->get404Properties()) {
$nodeProperties = $node->getProperties($propertyNames);
foreach ($nodeProperties as $propertyName => $propertyValue) {
$propFind->set($propertyName, $propertyValue, 200);
}
}
} | [
"public",
"function",
"propFindNode",
"(",
"PropFind",
"$",
"propFind",
",",
"INode",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"IProperties",
"&&",
"$",
"propertyNames",
"=",
"$",
"propFind",
"->",
"get404Properties",
"(",
")",
")",
"{",
"$",
"nodeProperties",
"=",
"$",
"node",
"->",
"getProperties",
"(",
"$",
"propertyNames",
")",
";",
"foreach",
"(",
"$",
"nodeProperties",
"as",
"$",
"propertyName",
"=>",
"$",
"propertyValue",
")",
"{",
"$",
"propFind",
"->",
"set",
"(",
"$",
"propertyName",
",",
"$",
"propertyValue",
",",
"200",
")",
";",
"}",
"}",
"}"
] | Fetches properties for a node.
This event is called a bit later, so plugins have a chance first to
populate the result.
@param PropFind $propFind
@param INode $node | [
"Fetches",
"properties",
"for",
"a",
"node",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L839-L847 |
sabre-io/dav | lib/DAV/CorePlugin.php | CorePlugin.propFindLate | public function propFindLate(PropFind $propFind, INode $node)
{
$propFind->handle('{http://calendarserver.org/ns/}getctag', function () use ($propFind) {
// If we already have a sync-token from the current propFind
// request, we can re-use that.
$val = $propFind->get('{http://sabredav.org/ns}sync-token');
if ($val) {
return $val;
}
$val = $propFind->get('{DAV:}sync-token');
if ($val && is_scalar($val)) {
return $val;
}
if ($val && $val instanceof Xml\Property\Href) {
return substr($val->getHref(), strlen(Sync\Plugin::SYNCTOKEN_PREFIX));
}
// If we got here, the earlier two properties may simply not have
// been part of the earlier request. We're going to fetch them.
$result = $this->server->getProperties($propFind->getPath(), [
'{http://sabredav.org/ns}sync-token',
'{DAV:}sync-token',
]);
if (isset($result['{http://sabredav.org/ns}sync-token'])) {
return $result['{http://sabredav.org/ns}sync-token'];
}
if (isset($result['{DAV:}sync-token'])) {
$val = $result['{DAV:}sync-token'];
if (is_scalar($val)) {
return $val;
} elseif ($val instanceof Xml\Property\Href) {
return substr($val->getHref(), strlen(Sync\Plugin::SYNCTOKEN_PREFIX));
}
}
});
} | php | public function propFindLate(PropFind $propFind, INode $node)
{
$propFind->handle('{http:
$val = $propFind->get('{http:
if ($val) {
return $val;
}
$val = $propFind->get('{DAV:}sync-token');
if ($val && is_scalar($val)) {
return $val;
}
if ($val && $val instanceof Xml\Property\Href) {
return substr($val->getHref(), strlen(Sync\Plugin::SYNCTOKEN_PREFIX));
}
$result = $this->server->getProperties($propFind->getPath(), [
'{http:
'{DAV:}sync-token',
]);
if (isset($result['{http:
return $result['{http:
}
if (isset($result['{DAV:}sync-token'])) {
$val = $result['{DAV:}sync-token'];
if (is_scalar($val)) {
return $val;
} elseif ($val instanceof Xml\Property\Href) {
return substr($val->getHref(), strlen(Sync\Plugin::SYNCTOKEN_PREFIX));
}
}
});
} | [
"public",
"function",
"propFindLate",
"(",
"PropFind",
"$",
"propFind",
",",
"INode",
"$",
"node",
")",
"{",
"$",
"propFind",
"->",
"handle",
"(",
"'{http://calendarserver.org/ns/}getctag'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"propFind",
")",
"{",
"// If we already have a sync-token from the current propFind",
"// request, we can re-use that.",
"$",
"val",
"=",
"$",
"propFind",
"->",
"get",
"(",
"'{http://sabredav.org/ns}sync-token'",
")",
";",
"if",
"(",
"$",
"val",
")",
"{",
"return",
"$",
"val",
";",
"}",
"$",
"val",
"=",
"$",
"propFind",
"->",
"get",
"(",
"'{DAV:}sync-token'",
")",
";",
"if",
"(",
"$",
"val",
"&&",
"is_scalar",
"(",
"$",
"val",
")",
")",
"{",
"return",
"$",
"val",
";",
"}",
"if",
"(",
"$",
"val",
"&&",
"$",
"val",
"instanceof",
"Xml",
"\\",
"Property",
"\\",
"Href",
")",
"{",
"return",
"substr",
"(",
"$",
"val",
"->",
"getHref",
"(",
")",
",",
"strlen",
"(",
"Sync",
"\\",
"Plugin",
"::",
"SYNCTOKEN_PREFIX",
")",
")",
";",
"}",
"// If we got here, the earlier two properties may simply not have",
"// been part of the earlier request. We're going to fetch them.",
"$",
"result",
"=",
"$",
"this",
"->",
"server",
"->",
"getProperties",
"(",
"$",
"propFind",
"->",
"getPath",
"(",
")",
",",
"[",
"'{http://sabredav.org/ns}sync-token'",
",",
"'{DAV:}sync-token'",
",",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"'{http://sabredav.org/ns}sync-token'",
"]",
")",
")",
"{",
"return",
"$",
"result",
"[",
"'{http://sabredav.org/ns}sync-token'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"'{DAV:}sync-token'",
"]",
")",
")",
"{",
"$",
"val",
"=",
"$",
"result",
"[",
"'{DAV:}sync-token'",
"]",
";",
"if",
"(",
"is_scalar",
"(",
"$",
"val",
")",
")",
"{",
"return",
"$",
"val",
";",
"}",
"elseif",
"(",
"$",
"val",
"instanceof",
"Xml",
"\\",
"Property",
"\\",
"Href",
")",
"{",
"return",
"substr",
"(",
"$",
"val",
"->",
"getHref",
"(",
")",
",",
"strlen",
"(",
"Sync",
"\\",
"Plugin",
"::",
"SYNCTOKEN_PREFIX",
")",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
] | This method is called when properties are retrieved.
This specific handler is called very late in the process, because we
want other systems to first have a chance to handle the properties.
@param PropFind $propFind
@param INode $node | [
"This",
"method",
"is",
"called",
"when",
"properties",
"are",
"retrieved",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L858-L895 |
sabre-io/dav | lib/DAV/CorePlugin.php | CorePlugin.exception | public function exception($e)
{
$logLevel = \Psr\Log\LogLevel::CRITICAL;
if ($e instanceof \Sabre\DAV\Exception) {
// If it's a standard sabre/dav exception, it means we have a http
// status code available.
$code = $e->getHTTPCode();
if ($code >= 400 && $code < 500) {
// user error
$logLevel = \Psr\Log\LogLevel::INFO;
} else {
// Server-side error. We mark it's as an error, but it's not
// critical.
$logLevel = \Psr\Log\LogLevel::ERROR;
}
}
$this->server->getLogger()->log(
$logLevel,
'Uncaught exception',
[
'exception' => $e,
]
);
} | php | public function exception($e)
{
$logLevel = \Psr\Log\LogLevel::CRITICAL;
if ($e instanceof \Sabre\DAV\Exception) {
$code = $e->getHTTPCode();
if ($code >= 400 && $code < 500) {
$logLevel = \Psr\Log\LogLevel::INFO;
} else {
$logLevel = \Psr\Log\LogLevel::ERROR;
}
}
$this->server->getLogger()->log(
$logLevel,
'Uncaught exception',
[
'exception' => $e,
]
);
} | [
"public",
"function",
"exception",
"(",
"$",
"e",
")",
"{",
"$",
"logLevel",
"=",
"\\",
"Psr",
"\\",
"Log",
"\\",
"LogLevel",
"::",
"CRITICAL",
";",
"if",
"(",
"$",
"e",
"instanceof",
"\\",
"Sabre",
"\\",
"DAV",
"\\",
"Exception",
")",
"{",
"// If it's a standard sabre/dav exception, it means we have a http",
"// status code available.",
"$",
"code",
"=",
"$",
"e",
"->",
"getHTTPCode",
"(",
")",
";",
"if",
"(",
"$",
"code",
">=",
"400",
"&&",
"$",
"code",
"<",
"500",
")",
"{",
"// user error",
"$",
"logLevel",
"=",
"\\",
"Psr",
"\\",
"Log",
"\\",
"LogLevel",
"::",
"INFO",
";",
"}",
"else",
"{",
"// Server-side error. We mark it's as an error, but it's not",
"// critical.",
"$",
"logLevel",
"=",
"\\",
"Psr",
"\\",
"Log",
"\\",
"LogLevel",
"::",
"ERROR",
";",
"}",
"}",
"$",
"this",
"->",
"server",
"->",
"getLogger",
"(",
")",
"->",
"log",
"(",
"$",
"logLevel",
",",
"'Uncaught exception'",
",",
"[",
"'exception'",
"=>",
"$",
"e",
",",
"]",
")",
";",
"}"
] | Listens for exception events, and automatically logs them.
@param Exception $e | [
"Listens",
"for",
"exception",
"events",
"and",
"automatically",
"logs",
"them",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L902-L927 |
sabre-io/dav | lib/CalDAV/Xml/Filter/CalendarData.php | CalendarData.xmlDeserialize | public static function xmlDeserialize(Reader $reader)
{
$result = [
'contentType' => $reader->getAttribute('content-type') ?: 'text/calendar',
'version' => $reader->getAttribute('version') ?: '2.0',
];
$elems = (array) $reader->parseInnerTree();
foreach ($elems as $elem) {
switch ($elem['name']) {
case '{'.Plugin::NS_CALDAV.'}expand':
$result['expand'] = [
'start' => isset($elem['attributes']['start']) ? DateTimeParser::parseDateTime($elem['attributes']['start']) : null,
'end' => isset($elem['attributes']['end']) ? DateTimeParser::parseDateTime($elem['attributes']['end']) : null,
];
if (!$result['expand']['start'] || !$result['expand']['end']) {
throw new BadRequest('The "start" and "end" attributes are required when expanding calendar-data');
}
if ($result['expand']['end'] <= $result['expand']['start']) {
throw new BadRequest('The end-date must be larger than the start-date when expanding calendar-data');
}
break;
}
}
return $result;
} | php | public static function xmlDeserialize(Reader $reader)
{
$result = [
'contentType' => $reader->getAttribute('content-type') ?: 'text/calendar',
'version' => $reader->getAttribute('version') ?: '2.0',
];
$elems = (array) $reader->parseInnerTree();
foreach ($elems as $elem) {
switch ($elem['name']) {
case '{'.Plugin::NS_CALDAV.'}expand':
$result['expand'] = [
'start' => isset($elem['attributes']['start']) ? DateTimeParser::parseDateTime($elem['attributes']['start']) : null,
'end' => isset($elem['attributes']['end']) ? DateTimeParser::parseDateTime($elem['attributes']['end']) : null,
];
if (!$result['expand']['start'] || !$result['expand']['end']) {
throw new BadRequest('The "start" and "end" attributes are required when expanding calendar-data');
}
if ($result['expand']['end'] <= $result['expand']['start']) {
throw new BadRequest('The end-date must be larger than the start-date when expanding calendar-data');
}
break;
}
}
return $result;
} | [
"public",
"static",
"function",
"xmlDeserialize",
"(",
"Reader",
"$",
"reader",
")",
"{",
"$",
"result",
"=",
"[",
"'contentType'",
"=>",
"$",
"reader",
"->",
"getAttribute",
"(",
"'content-type'",
")",
"?",
":",
"'text/calendar'",
",",
"'version'",
"=>",
"$",
"reader",
"->",
"getAttribute",
"(",
"'version'",
")",
"?",
":",
"'2.0'",
",",
"]",
";",
"$",
"elems",
"=",
"(",
"array",
")",
"$",
"reader",
"->",
"parseInnerTree",
"(",
")",
";",
"foreach",
"(",
"$",
"elems",
"as",
"$",
"elem",
")",
"{",
"switch",
"(",
"$",
"elem",
"[",
"'name'",
"]",
")",
"{",
"case",
"'{'",
".",
"Plugin",
"::",
"NS_CALDAV",
".",
"'}expand'",
":",
"$",
"result",
"[",
"'expand'",
"]",
"=",
"[",
"'start'",
"=>",
"isset",
"(",
"$",
"elem",
"[",
"'attributes'",
"]",
"[",
"'start'",
"]",
")",
"?",
"DateTimeParser",
"::",
"parseDateTime",
"(",
"$",
"elem",
"[",
"'attributes'",
"]",
"[",
"'start'",
"]",
")",
":",
"null",
",",
"'end'",
"=>",
"isset",
"(",
"$",
"elem",
"[",
"'attributes'",
"]",
"[",
"'end'",
"]",
")",
"?",
"DateTimeParser",
"::",
"parseDateTime",
"(",
"$",
"elem",
"[",
"'attributes'",
"]",
"[",
"'end'",
"]",
")",
":",
"null",
",",
"]",
";",
"if",
"(",
"!",
"$",
"result",
"[",
"'expand'",
"]",
"[",
"'start'",
"]",
"||",
"!",
"$",
"result",
"[",
"'expand'",
"]",
"[",
"'end'",
"]",
")",
"{",
"throw",
"new",
"BadRequest",
"(",
"'The \"start\" and \"end\" attributes are required when expanding calendar-data'",
")",
";",
"}",
"if",
"(",
"$",
"result",
"[",
"'expand'",
"]",
"[",
"'end'",
"]",
"<=",
"$",
"result",
"[",
"'expand'",
"]",
"[",
"'start'",
"]",
")",
"{",
"throw",
"new",
"BadRequest",
"(",
"'The end-date must be larger than the start-date when expanding calendar-data'",
")",
";",
"}",
"break",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | The deserialize method is called during xml parsing.
This method is called statically, this is because in theory this method
may be used as a type of constructor, or factory method.
Often you want to return an instance of the current class, but you are
free to return other data as well.
You are responsible for advancing the reader to the next element. Not
doing anything will result in a never-ending loop.
If you just want to skip parsing for this element altogether, you can
just call $reader->next();
$reader->parseInnerTree() will parse the entire sub-tree, and advance to
the next element.
@param Reader $reader
@return mixed | [
"The",
"deserialize",
"method",
"is",
"called",
"during",
"xml",
"parsing",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Xml/Filter/CalendarData.php#L54-L82 |
sabre-io/dav | lib/DAV/Xml/Property/SupportedReportSet.php | SupportedReportSet.addReport | public function addReport($report)
{
$report = (array) $report;
foreach ($report as $r) {
if (!preg_match('/^{([^}]*)}(.*)$/', $r)) {
throw new DAV\Exception('Reportname must be in clark-notation');
}
$this->reports[] = $r;
}
} | php | public function addReport($report)
{
$report = (array) $report;
foreach ($report as $r) {
if (!preg_match('/^{([^}]*)}(.*)$/', $r)) {
throw new DAV\Exception('Reportname must be in clark-notation');
}
$this->reports[] = $r;
}
} | [
"public",
"function",
"addReport",
"(",
"$",
"report",
")",
"{",
"$",
"report",
"=",
"(",
"array",
")",
"$",
"report",
";",
"foreach",
"(",
"$",
"report",
"as",
"$",
"r",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'/^{([^}]*)}(.*)$/'",
",",
"$",
"r",
")",
")",
"{",
"throw",
"new",
"DAV",
"\\",
"Exception",
"(",
"'Reportname must be in clark-notation'",
")",
";",
"}",
"$",
"this",
"->",
"reports",
"[",
"]",
"=",
"$",
"r",
";",
"}",
"}"
] | Adds a report to this property.
The report must be a string in clark-notation.
Multiple reports can be specified as an array.
@param mixed $report | [
"Adds",
"a",
"report",
"to",
"this",
"property",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Property/SupportedReportSet.php#L60-L70 |
sabre-io/dav | lib/DAV/Xml/Property/SupportedReportSet.php | SupportedReportSet.xmlSerialize | public function xmlSerialize(Writer $writer)
{
foreach ($this->getValue() as $val) {
$writer->startElement('{DAV:}supported-report');
$writer->startElement('{DAV:}report');
$writer->writeElement($val);
$writer->endElement();
$writer->endElement();
}
} | php | public function xmlSerialize(Writer $writer)
{
foreach ($this->getValue() as $val) {
$writer->startElement('{DAV:}supported-report');
$writer->startElement('{DAV:}report');
$writer->writeElement($val);
$writer->endElement();
$writer->endElement();
}
} | [
"public",
"function",
"xmlSerialize",
"(",
"Writer",
"$",
"writer",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getValue",
"(",
")",
"as",
"$",
"val",
")",
"{",
"$",
"writer",
"->",
"startElement",
"(",
"'{DAV:}supported-report'",
")",
";",
"$",
"writer",
"->",
"startElement",
"(",
"'{DAV:}report'",
")",
";",
"$",
"writer",
"->",
"writeElement",
"(",
"$",
"val",
")",
";",
"$",
"writer",
"->",
"endElement",
"(",
")",
";",
"$",
"writer",
"->",
"endElement",
"(",
")",
";",
"}",
"}"
] | The xmlSerialize method is called during xml writing.
Use the $writer argument to write its own xml serialization.
An important note: do _not_ create a parent element. Any element
implementing XmlSerializable should only ever write what's considered
its 'inner xml'.
The parent of the current element is responsible for writing a
containing element.
This allows serializers to be re-used for different element names.
If you are opening new elements, you must also close them again.
@param Writer $writer | [
"The",
"xmlSerialize",
"method",
"is",
"called",
"during",
"xml",
"writing",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Property/SupportedReportSet.php#L115-L124 |
sabre-io/dav | lib/CardDAV/Backend/PDO.php | PDO.getAddressBooksForUser | public function getAddressBooksForUser($principalUri)
{
$stmt = $this->pdo->prepare('SELECT id, uri, displayname, principaluri, description, synctoken FROM '.$this->addressBooksTableName.' WHERE principaluri = ?');
$stmt->execute([$principalUri]);
$addressBooks = [];
foreach ($stmt->fetchAll() as $row) {
$addressBooks[] = [
'id' => $row['id'],
'uri' => $row['uri'],
'principaluri' => $row['principaluri'],
'{DAV:}displayname' => $row['displayname'],
'{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description' => $row['description'],
'{http://calendarserver.org/ns/}getctag' => $row['synctoken'],
'{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0',
];
}
return $addressBooks;
} | php | public function getAddressBooksForUser($principalUri)
{
$stmt = $this->pdo->prepare('SELECT id, uri, displayname, principaluri, description, synctoken FROM '.$this->addressBooksTableName.' WHERE principaluri = ?');
$stmt->execute([$principalUri]);
$addressBooks = [];
foreach ($stmt->fetchAll() as $row) {
$addressBooks[] = [
'id' => $row['id'],
'uri' => $row['uri'],
'principaluri' => $row['principaluri'],
'{DAV:}displayname' => $row['displayname'],
'{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description' => $row['description'],
'{http:
'{http:
];
}
return $addressBooks;
} | [
"public",
"function",
"getAddressBooksForUser",
"(",
"$",
"principalUri",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"'SELECT id, uri, displayname, principaluri, description, synctoken FROM '",
".",
"$",
"this",
"->",
"addressBooksTableName",
".",
"' WHERE principaluri = ?'",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"[",
"$",
"principalUri",
"]",
")",
";",
"$",
"addressBooks",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"stmt",
"->",
"fetchAll",
"(",
")",
"as",
"$",
"row",
")",
"{",
"$",
"addressBooks",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"row",
"[",
"'id'",
"]",
",",
"'uri'",
"=>",
"$",
"row",
"[",
"'uri'",
"]",
",",
"'principaluri'",
"=>",
"$",
"row",
"[",
"'principaluri'",
"]",
",",
"'{DAV:}displayname'",
"=>",
"$",
"row",
"[",
"'displayname'",
"]",
",",
"'{'",
".",
"CardDAV",
"\\",
"Plugin",
"::",
"NS_CARDDAV",
".",
"'}addressbook-description'",
"=>",
"$",
"row",
"[",
"'description'",
"]",
",",
"'{http://calendarserver.org/ns/}getctag'",
"=>",
"$",
"row",
"[",
"'synctoken'",
"]",
",",
"'{http://sabredav.org/ns}sync-token'",
"=>",
"$",
"row",
"[",
"'synctoken'",
"]",
"?",
"$",
"row",
"[",
"'synctoken'",
"]",
":",
"'0'",
",",
"]",
";",
"}",
"return",
"$",
"addressBooks",
";",
"}"
] | Returns the list of addressbooks for a specific user.
@param string $principalUri
@return array | [
"Returns",
"the",
"list",
"of",
"addressbooks",
"for",
"a",
"specific",
"user",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L62-L82 |