repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
yajra/laravel-oci8
src/Oci8/Query/Processors/OracleProcessor.php
OracleProcessor.prepareStatement
private function prepareStatement(Builder $query, $sql) { /** @var \Yajra\Oci8\Oci8Connection $connection */ $connection = $query->getConnection(); $pdo = $connection->getPdo(); return $pdo->prepare($sql); }
php
private function prepareStatement(Builder $query, $sql) { /** @var \Yajra\Oci8\Oci8Connection $connection */ $connection = $query->getConnection(); $pdo = $connection->getPdo(); return $pdo->prepare($sql); }
[ "private", "function", "prepareStatement", "(", "Builder", "$", "query", ",", "$", "sql", ")", "{", "/** @var \\Yajra\\Oci8\\Oci8Connection $connection */", "$", "connection", "=", "$", "query", "->", "getConnection", "(", ")", ";", "$", "pdo", "=", "$", "connec...
Get prepared statement. @param Builder $query @param string $sql @return \PDOStatement|\Yajra\Pdo\Oci8
[ "Get", "prepared", "statement", "." ]
0318976c23e06f20212f57ac162b4ec8af963c6c
https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Query/Processors/OracleProcessor.php#L42-L49
train
yajra/laravel-oci8
src/Oci8/Query/Processors/OracleProcessor.php
OracleProcessor.bindValues
private function bindValues(&$values, $statement, $parameter) { $count = count($values); for ($i = 0; $i < $count; $i++) { if (is_object($values[$i])) { if ($values[$i] instanceof DateTime) { $values[$i] = $values[$i]->format('Y-m-d H:i:s'); } else { $values[$i] = (string) $values[$i]; } } $type = $this->getPdoType($values[$i]); $statement->bindParam($parameter, $values[$i], $type); $parameter++; } return $parameter; }
php
private function bindValues(&$values, $statement, $parameter) { $count = count($values); for ($i = 0; $i < $count; $i++) { if (is_object($values[$i])) { if ($values[$i] instanceof DateTime) { $values[$i] = $values[$i]->format('Y-m-d H:i:s'); } else { $values[$i] = (string) $values[$i]; } } $type = $this->getPdoType($values[$i]); $statement->bindParam($parameter, $values[$i], $type); $parameter++; } return $parameter; }
[ "private", "function", "bindValues", "(", "&", "$", "values", ",", "$", "statement", ",", "$", "parameter", ")", "{", "$", "count", "=", "count", "(", "$", "values", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";...
Bind values to PDO statement. @param array $values @param \PDOStatement $statement @param int $parameter @return int
[ "Bind", "values", "to", "PDO", "statement", "." ]
0318976c23e06f20212f57ac162b4ec8af963c6c
https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Query/Processors/OracleProcessor.php#L86-L103
train
yajra/laravel-oci8
src/Oci8/Query/Processors/OracleProcessor.php
OracleProcessor.saveLob
public function saveLob(Builder $query, $sql, array $values, array $binaries) { $id = 0; $parameter = 0; $statement = $this->prepareStatement($query, $sql); $parameter = $this->bindValues($values, $statement, $parameter); $countBinary = count($binaries); for ($i = 0; $i < $countBinary; $i++) { $statement->bindParam($parameter, $binaries[$i], PDO::PARAM_LOB, -1); $parameter++; } // bind output param for the returning clause. $statement->bindParam($parameter, $id, PDO::PARAM_INT, 10); if (! $statement->execute()) { return false; } return (int) $id; }
php
public function saveLob(Builder $query, $sql, array $values, array $binaries) { $id = 0; $parameter = 0; $statement = $this->prepareStatement($query, $sql); $parameter = $this->bindValues($values, $statement, $parameter); $countBinary = count($binaries); for ($i = 0; $i < $countBinary; $i++) { $statement->bindParam($parameter, $binaries[$i], PDO::PARAM_LOB, -1); $parameter++; } // bind output param for the returning clause. $statement->bindParam($parameter, $id, PDO::PARAM_INT, 10); if (! $statement->execute()) { return false; } return (int) $id; }
[ "public", "function", "saveLob", "(", "Builder", "$", "query", ",", "$", "sql", ",", "array", "$", "values", ",", "array", "$", "binaries", ")", "{", "$", "id", "=", "0", ";", "$", "parameter", "=", "0", ";", "$", "statement", "=", "$", "this", "...
Save Query with Blob returning primary key value. @param Builder $query @param string $sql @param array $values @param array $binaries @return int
[ "Save", "Query", "with", "Blob", "returning", "primary", "key", "value", "." ]
0318976c23e06f20212f57ac162b4ec8af963c6c
https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Query/Processors/OracleProcessor.php#L137-L159
train
yajra/laravel-oci8
src/Oci8/Schema/Trigger.php
Trigger.autoIncrement
public function autoIncrement($table, $column, $triggerName, $sequenceName) { if (! $table || ! $column || ! $triggerName || ! $sequenceName) { return false; } if ($this->connection->getConfig('prefix_schema')) { $table = $this->connection->getConfig('prefix_schema') . '.' . $table; $triggerName = $this->connection->getConfig('prefix_schema') . '.' . $triggerName; $sequenceName = $this->connection->getConfig('prefix_schema') . '.' . $sequenceName; } $table = $this->wrapValue($table); $column = $this->wrapValue($column); return $this->connection->statement(" create trigger $triggerName before insert on {$table} for each row begin if :new.{$column} is null then select {$sequenceName}.nextval into :new.{$column} from dual; end if; end;"); }
php
public function autoIncrement($table, $column, $triggerName, $sequenceName) { if (! $table || ! $column || ! $triggerName || ! $sequenceName) { return false; } if ($this->connection->getConfig('prefix_schema')) { $table = $this->connection->getConfig('prefix_schema') . '.' . $table; $triggerName = $this->connection->getConfig('prefix_schema') . '.' . $triggerName; $sequenceName = $this->connection->getConfig('prefix_schema') . '.' . $sequenceName; } $table = $this->wrapValue($table); $column = $this->wrapValue($column); return $this->connection->statement(" create trigger $triggerName before insert on {$table} for each row begin if :new.{$column} is null then select {$sequenceName}.nextval into :new.{$column} from dual; end if; end;"); }
[ "public", "function", "autoIncrement", "(", "$", "table", ",", "$", "column", ",", "$", "triggerName", ",", "$", "sequenceName", ")", "{", "if", "(", "!", "$", "table", "||", "!", "$", "column", "||", "!", "$", "triggerName", "||", "!", "$", "sequenc...
Function to create auto increment trigger for a table. @param string $table @param string $column @param string $triggerName @param string $sequenceName @return bool
[ "Function", "to", "create", "auto", "increment", "trigger", "for", "a", "table", "." ]
0318976c23e06f20212f57ac162b4ec8af963c6c
https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Schema/Trigger.php#L35-L59
train
yajra/laravel-oci8
src/Oci8/Schema/Trigger.php
Trigger.wrapValue
protected function wrapValue($value) { $value = Str::upper($value); return $this->isReserved($value) ? '"' . $value . '"' : $value; }
php
protected function wrapValue($value) { $value = Str::upper($value); return $this->isReserved($value) ? '"' . $value . '"' : $value; }
[ "protected", "function", "wrapValue", "(", "$", "value", ")", "{", "$", "value", "=", "Str", "::", "upper", "(", "$", "value", ")", ";", "return", "$", "this", "->", "isReserved", "(", "$", "value", ")", "?", "'\"'", ".", "$", "value", ".", "'\"'",...
Wrap value if reserved word. @param string $value @return string
[ "Wrap", "value", "if", "reserved", "word", "." ]
0318976c23e06f20212f57ac162b4ec8af963c6c
https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Schema/Trigger.php#L67-L72
train
yajra/laravel-oci8
src/Oci8/Connectors/OracleConnector.php
OracleConnector.parseConfig
protected function parseConfig(array $config) { $config = $this->setHost($config); $config = $this->setPort($config); $config = $this->setProtocol($config); $config = $this->setServiceId($config); $config = $this->setTNS($config); $config = $this->setCharset($config); return $config; }
php
protected function parseConfig(array $config) { $config = $this->setHost($config); $config = $this->setPort($config); $config = $this->setProtocol($config); $config = $this->setServiceId($config); $config = $this->setTNS($config); $config = $this->setCharset($config); return $config; }
[ "protected", "function", "parseConfig", "(", "array", "$", "config", ")", "{", "$", "config", "=", "$", "this", "->", "setHost", "(", "$", "config", ")", ";", "$", "config", "=", "$", "this", "->", "setPort", "(", "$", "config", ")", ";", "$", "con...
Parse configurations. @param array $config @return array
[ "Parse", "configurations", "." ]
0318976c23e06f20212f57ac162b4ec8af963c6c
https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Connectors/OracleConnector.php#L74-L84
train
yajra/laravel-oci8
src/Oci8/Connectors/OracleConnector.php
OracleConnector.setServiceId
protected function setServiceId(array $config) { $config['service'] = empty($config['service_name']) ? $service_param = 'SID = ' . $config['database'] : $service_param = 'SERVICE_NAME = ' . $config['service_name']; return $config; }
php
protected function setServiceId(array $config) { $config['service'] = empty($config['service_name']) ? $service_param = 'SID = ' . $config['database'] : $service_param = 'SERVICE_NAME = ' . $config['service_name']; return $config; }
[ "protected", "function", "setServiceId", "(", "array", "$", "config", ")", "{", "$", "config", "[", "'service'", "]", "=", "empty", "(", "$", "config", "[", "'service_name'", "]", ")", "?", "$", "service_param", "=", "'SID = '", ".", "$", "config", "[", ...
Set service id from config. @param array $config @return array
[ "Set", "service", "id", "from", "config", "." ]
0318976c23e06f20212f57ac162b4ec8af963c6c
https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Connectors/OracleConnector.php#L131-L138
train
yajra/laravel-oci8
src/Oci8/Connectors/OracleConnector.php
OracleConnector.checkMultipleHostDsn
protected function checkMultipleHostDsn(array $config) { $host = is_array($config['host']) ? $config['host'] : explode(',', $config['host']); $count = count($host); if ($count > 1) { $address = ''; for ($i = 0; $i < $count; $i++) { $address .= '(ADDRESS = (PROTOCOL = ' . $config['protocol'] . ')(HOST = ' . trim($host[$i]) . ')(PORT = ' . $config['port'] . '))'; } // create a tns with multiple address connection $config['tns'] = "(DESCRIPTION = {$address} (LOAD_BALANCE = yes) (FAILOVER = on) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = {$config['database']})))"; } return $config; }
php
protected function checkMultipleHostDsn(array $config) { $host = is_array($config['host']) ? $config['host'] : explode(',', $config['host']); $count = count($host); if ($count > 1) { $address = ''; for ($i = 0; $i < $count; $i++) { $address .= '(ADDRESS = (PROTOCOL = ' . $config['protocol'] . ')(HOST = ' . trim($host[$i]) . ')(PORT = ' . $config['port'] . '))'; } // create a tns with multiple address connection $config['tns'] = "(DESCRIPTION = {$address} (LOAD_BALANCE = yes) (FAILOVER = on) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = {$config['database']})))"; } return $config; }
[ "protected", "function", "checkMultipleHostDsn", "(", "array", "$", "config", ")", "{", "$", "host", "=", "is_array", "(", "$", "config", "[", "'host'", "]", ")", "?", "$", "config", "[", "'host'", "]", ":", "explode", "(", "','", ",", "$", "config", ...
Set DSN host from config. @param array $config @return array
[ "Set", "DSN", "host", "from", "config", "." ]
0318976c23e06f20212f57ac162b4ec8af963c6c
https://github.com/yajra/laravel-oci8/blob/0318976c23e06f20212f57ac162b4ec8af963c6c/src/Oci8/Connectors/OracleConnector.php#L174-L190
train
sabre-io/dav
lib/DAV/Browser/PropFindAll.php
PropFindAll.get
public function get($propertyName) { return isset($this->result[$propertyName]) ? $this->result[$propertyName][1] : null; }
php
public function get($propertyName) { return isset($this->result[$propertyName]) ? $this->result[$propertyName][1] : null; }
[ "public", "function", "get", "(", "$", "propertyName", ")", "{", "return", "isset", "(", "$", "this", "->", "result", "[", "$", "propertyName", "]", ")", "?", "$", "this", "->", "result", "[", "$", "propertyName", "]", "[", "1", "]", ":", "null", "...
Returns the current value for a property. @param string $propertyName @return mixed
[ "Returns", "the", "current", "value", "for", "a", "property", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/PropFindAll.php#L87-L90
train
sabre-io/dav
lib/DAV/Browser/PropFindAll.php
PropFindAll.get404Properties
public function get404Properties() { $result = []; foreach ($this->result as $propertyName => $stuff) { if (404 === $stuff[0]) { $result[] = $propertyName; } } // If there's nothing in this list, we're adding one fictional item. if (!$result) { $result[] = '{http://sabredav.org/ns}idk'; } return $result; }
php
public function get404Properties() { $result = []; foreach ($this->result as $propertyName => $stuff) { if (404 === $stuff[0]) { $result[] = $propertyName; } } // If there's nothing in this list, we're adding one fictional item. if (!$result) { $result[] = '{http://sabredav.org/ns}idk'; } return $result; }
[ "public", "function", "get404Properties", "(", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "result", "as", "$", "propertyName", "=>", "$", "stuff", ")", "{", "if", "(", "404", "===", "$", "stuff", "[", "0", "]", ...
Returns all propertynames that have a 404 status, and thus don't have a value yet. @return array
[ "Returns", "all", "propertynames", "that", "have", "a", "404", "status", "and", "thus", "don", "t", "have", "a", "value", "yet", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/PropFindAll.php#L113-L127
train
sabre-io/dav
lib/DAV/Sync/Plugin.php
Plugin.sendSyncCollectionResponse
protected function sendSyncCollectionResponse($syncToken, $collectionUrl, array $added, array $modified, array $deleted, array $properties) { $fullPaths = []; // Pre-fetching children, if this is possible. foreach (array_merge($added, $modified) as $item) { $fullPath = $collectionUrl.'/'.$item; $fullPaths[] = $fullPath; } $responses = []; foreach ($this->server->getPropertiesForMultiplePaths($fullPaths, $properties) as $fullPath => $props) { // The 'Property_Response' class is responsible for generating a // single {DAV:}response xml element. $responses[] = new DAV\Xml\Element\Response($fullPath, $props); } // Deleted items also show up as 'responses'. They have no properties, // and a single {DAV:}status element set as 'HTTP/1.1 404 Not Found'. foreach ($deleted as $item) { $fullPath = $collectionUrl.'/'.$item; $responses[] = new DAV\Xml\Element\Response($fullPath, [], 404); } $multiStatus = new DAV\Xml\Response\MultiStatus($responses, self::SYNCTOKEN_PREFIX.$syncToken); $this->server->httpResponse->setStatus(207); $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); $this->server->httpResponse->setBody( $this->server->xml->write('{DAV:}multistatus', $multiStatus, $this->server->getBaseUri()) ); }
php
protected function sendSyncCollectionResponse($syncToken, $collectionUrl, array $added, array $modified, array $deleted, array $properties) { $fullPaths = []; // Pre-fetching children, if this is possible. foreach (array_merge($added, $modified) as $item) { $fullPath = $collectionUrl.'/'.$item; $fullPaths[] = $fullPath; } $responses = []; foreach ($this->server->getPropertiesForMultiplePaths($fullPaths, $properties) as $fullPath => $props) { // The 'Property_Response' class is responsible for generating a // single {DAV:}response xml element. $responses[] = new DAV\Xml\Element\Response($fullPath, $props); } // Deleted items also show up as 'responses'. They have no properties, // and a single {DAV:}status element set as 'HTTP/1.1 404 Not Found'. foreach ($deleted as $item) { $fullPath = $collectionUrl.'/'.$item; $responses[] = new DAV\Xml\Element\Response($fullPath, [], 404); } $multiStatus = new DAV\Xml\Response\MultiStatus($responses, self::SYNCTOKEN_PREFIX.$syncToken); $this->server->httpResponse->setStatus(207); $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); $this->server->httpResponse->setBody( $this->server->xml->write('{DAV:}multistatus', $multiStatus, $this->server->getBaseUri()) ); }
[ "protected", "function", "sendSyncCollectionResponse", "(", "$", "syncToken", ",", "$", "collectionUrl", ",", "array", "$", "added", ",", "array", "$", "modified", ",", "array", "$", "deleted", ",", "array", "$", "properties", ")", "{", "$", "fullPaths", "="...
Sends the response to a sync-collection request. @param string $syncToken @param string $collectionUrl @param array $added @param array $modified @param array $deleted @param array $properties
[ "Sends", "the", "response", "to", "a", "sync", "-", "collection", "request", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Sync/Plugin.php#L151-L181
train
sabre-io/dav
lib/DAV/Client.php
Client.propFind
public function propFind($url, array $properties, $depth = 0) { $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->formatOutput = true; $root = $dom->createElementNS('DAV:', 'd:propfind'); $prop = $dom->createElement('d:prop'); foreach ($properties as $property) { list( $namespace, $elementName ) = \Sabre\Xml\Service::parseClarkNotation($property); if ('DAV:' === $namespace) { $element = $dom->createElement('d:'.$elementName); } else { $element = $dom->createElementNS($namespace, 'x:'.$elementName); } $prop->appendChild($element); } $dom->appendChild($root)->appendChild($prop); $body = $dom->saveXML(); $url = $this->getAbsoluteUrl($url); $request = new HTTP\Request('PROPFIND', $url, [ 'Depth' => $depth, 'Content-Type' => 'application/xml', ], $body); $response = $this->send($request); if ((int) $response->getStatus() >= 400) { throw new HTTP\ClientHttpException($response); } $result = $this->parseMultiStatus($response->getBodyAsString()); // If depth was 0, we only return the top item if (0 === $depth) { reset($result); $result = current($result); return isset($result[200]) ? $result[200] : []; } $newResult = []; foreach ($result as $href => $statusList) { $newResult[$href] = isset($statusList[200]) ? $statusList[200] : []; } return $newResult; }
php
public function propFind($url, array $properties, $depth = 0) { $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->formatOutput = true; $root = $dom->createElementNS('DAV:', 'd:propfind'); $prop = $dom->createElement('d:prop'); foreach ($properties as $property) { list( $namespace, $elementName ) = \Sabre\Xml\Service::parseClarkNotation($property); if ('DAV:' === $namespace) { $element = $dom->createElement('d:'.$elementName); } else { $element = $dom->createElementNS($namespace, 'x:'.$elementName); } $prop->appendChild($element); } $dom->appendChild($root)->appendChild($prop); $body = $dom->saveXML(); $url = $this->getAbsoluteUrl($url); $request = new HTTP\Request('PROPFIND', $url, [ 'Depth' => $depth, 'Content-Type' => 'application/xml', ], $body); $response = $this->send($request); if ((int) $response->getStatus() >= 400) { throw new HTTP\ClientHttpException($response); } $result = $this->parseMultiStatus($response->getBodyAsString()); // If depth was 0, we only return the top item if (0 === $depth) { reset($result); $result = current($result); return isset($result[200]) ? $result[200] : []; } $newResult = []; foreach ($result as $href => $statusList) { $newResult[$href] = isset($statusList[200]) ? $statusList[200] : []; } return $newResult; }
[ "public", "function", "propFind", "(", "$", "url", ",", "array", "$", "properties", ",", "$", "depth", "=", "0", ")", "{", "$", "dom", "=", "new", "\\", "DOMDocument", "(", "'1.0'", ",", "'UTF-8'", ")", ";", "$", "dom", "->", "formatOutput", "=", "...
Does a PROPFIND request. The list of requested properties must be specified as an array, in clark notation. The returned array will contain a list of filenames as keys, and properties as values. The properties array will contain the list of properties. Only properties that are actually returned from the server (without error) will be returned, anything else is discarded. Depth should be either 0 or 1. A depth of 1 will cause a request to be made to the server to also return all child resources. @param string $url @param array $properties @param int $depth @return array
[ "Does", "a", "PROPFIND", "request", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Client.php#L200-L254
train
sabre-io/dav
lib/DAV/Client.php
Client.propPatch
public function propPatch($url, array $properties) { $propPatch = new Xml\Request\PropPatch(); $propPatch->properties = $properties; $xml = $this->xml->write( '{DAV:}propertyupdate', $propPatch ); $url = $this->getAbsoluteUrl($url); $request = new HTTP\Request('PROPPATCH', $url, [ 'Content-Type' => 'application/xml', ], $xml); $response = $this->send($request); if ($response->getStatus() >= 400) { throw new HTTP\ClientHttpException($response); } if (207 === $response->getStatus()) { // If it's a 207, the request could still have failed, but the // information is hidden in the response body. $result = $this->parseMultiStatus($response->getBodyAsString()); $errorProperties = []; foreach ($result as $href => $statusList) { foreach ($statusList as $status => $properties) { if ($status >= 400) { foreach ($properties as $propName => $propValue) { $errorProperties[] = $propName.' ('.$status.')'; } } } } if ($errorProperties) { throw new HTTP\ClientException('PROPPATCH failed. The following properties errored: '.implode(', ', $errorProperties)); } } return true; }
php
public function propPatch($url, array $properties) { $propPatch = new Xml\Request\PropPatch(); $propPatch->properties = $properties; $xml = $this->xml->write( '{DAV:}propertyupdate', $propPatch ); $url = $this->getAbsoluteUrl($url); $request = new HTTP\Request('PROPPATCH', $url, [ 'Content-Type' => 'application/xml', ], $xml); $response = $this->send($request); if ($response->getStatus() >= 400) { throw new HTTP\ClientHttpException($response); } if (207 === $response->getStatus()) { // If it's a 207, the request could still have failed, but the // information is hidden in the response body. $result = $this->parseMultiStatus($response->getBodyAsString()); $errorProperties = []; foreach ($result as $href => $statusList) { foreach ($statusList as $status => $properties) { if ($status >= 400) { foreach ($properties as $propName => $propValue) { $errorProperties[] = $propName.' ('.$status.')'; } } } } if ($errorProperties) { throw new HTTP\ClientException('PROPPATCH failed. The following properties errored: '.implode(', ', $errorProperties)); } } return true; }
[ "public", "function", "propPatch", "(", "$", "url", ",", "array", "$", "properties", ")", "{", "$", "propPatch", "=", "new", "Xml", "\\", "Request", "\\", "PropPatch", "(", ")", ";", "$", "propPatch", "->", "properties", "=", "$", "properties", ";", "$...
Updates a list of properties on the server. The list of properties must have clark-notation properties for the keys, and the actual (string) value for the value. If the value is null, an attempt is made to delete the property. @param string $url @param array $properties @return bool
[ "Updates", "a", "list", "of", "properties", "on", "the", "server", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Client.php#L268-L308
train
sabre-io/dav
lib/DAV/Client.php
Client.options
public function options() { $request = new HTTP\Request('OPTIONS', $this->getAbsoluteUrl('')); $response = $this->send($request); $dav = $response->getHeader('Dav'); if (!$dav) { return []; } $features = explode(',', $dav); foreach ($features as &$v) { $v = trim($v); } return $features; }
php
public function options() { $request = new HTTP\Request('OPTIONS', $this->getAbsoluteUrl('')); $response = $this->send($request); $dav = $response->getHeader('Dav'); if (!$dav) { return []; } $features = explode(',', $dav); foreach ($features as &$v) { $v = trim($v); } return $features; }
[ "public", "function", "options", "(", ")", "{", "$", "request", "=", "new", "HTTP", "\\", "Request", "(", "'OPTIONS'", ",", "$", "this", "->", "getAbsoluteUrl", "(", "''", ")", ")", ";", "$", "response", "=", "$", "this", "->", "send", "(", "$", "r...
Performs an HTTP options request. This method returns all the features from the 'DAV:' header as an array. If there was no DAV header, or no contents this method will return an empty array. @return array
[ "Performs", "an", "HTTP", "options", "request", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Client.php#L319-L335
train
sabre-io/dav
lib/DAV/Client.php
Client.request
public function request($method, $url = '', $body = null, array $headers = []) { $url = $this->getAbsoluteUrl($url); $response = $this->send(new HTTP\Request($method, $url, $headers, $body)); return [ 'body' => $response->getBodyAsString(), 'statusCode' => (int) $response->getStatus(), 'headers' => array_change_key_case($response->getHeaders()), ]; }
php
public function request($method, $url = '', $body = null, array $headers = []) { $url = $this->getAbsoluteUrl($url); $response = $this->send(new HTTP\Request($method, $url, $headers, $body)); return [ 'body' => $response->getBodyAsString(), 'statusCode' => (int) $response->getStatus(), 'headers' => array_change_key_case($response->getHeaders()), ]; }
[ "public", "function", "request", "(", "$", "method", ",", "$", "url", "=", "''", ",", "$", "body", "=", "null", ",", "array", "$", "headers", "=", "[", "]", ")", "{", "$", "url", "=", "$", "this", "->", "getAbsoluteUrl", "(", "$", "url", ")", "...
Performs an actual HTTP request, and returns the result. If the specified url is relative, it will be expanded based on the base url. The returned array contains 3 keys: * body - the response body * httpCode - a HTTP code (200, 404, etc) * headers - a list of response http headers. The header names have been lowercased. For large uploads, it's highly recommended to specify body as a stream resource. You can easily do this by simply passing the result of fopen(..., 'r'). This method will throw an exception if an HTTP error was received. Any HTTP status code above 399 is considered an error. Note that it is no longer recommended to use this method, use the send() method instead. @param string $method @param string $url @param string|resource|null $body @param array $headers @throws clientException, in case a curl error occurred @return array
[ "Performs", "an", "actual", "HTTP", "request", "and", "returns", "the", "result", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Client.php#L368-L379
train
sabre-io/dav
lib/DAV/Client.php
Client.parseMultiStatus
public function parseMultiStatus($body) { $multistatus = $this->xml->expect('{DAV:}multistatus', $body); $result = []; foreach ($multistatus->getResponses() as $response) { $result[$response->getHref()] = $response->getResponseProperties(); } return $result; }
php
public function parseMultiStatus($body) { $multistatus = $this->xml->expect('{DAV:}multistatus', $body); $result = []; foreach ($multistatus->getResponses() as $response) { $result[$response->getHref()] = $response->getResponseProperties(); } return $result; }
[ "public", "function", "parseMultiStatus", "(", "$", "body", ")", "{", "$", "multistatus", "=", "$", "this", "->", "xml", "->", "expect", "(", "'{DAV:}multistatus'", ",", "$", "body", ")", ";", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "...
Parses a WebDAV multistatus response body. This method returns an array with the following structure [ 'url/to/resource' => [ '200' => [ '{DAV:}property1' => 'value1', '{DAV:}property2' => 'value2', ], '404' => [ '{DAV:}property1' => null, '{DAV:}property2' => null, ], ], 'url/to/resource2' => [ .. etc .. ] ] @param string $body xml body @return array
[ "Parses", "a", "WebDAV", "multistatus", "response", "body", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Client.php#L423-L434
train
sabre-io/dav
lib/CardDAV/AddressBook.php
AddressBook.getChild
public function getChild($name) { $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name); if (!$obj) { throw new DAV\Exception\NotFound('Card not found'); } return new Card($this->carddavBackend, $this->addressBookInfo, $obj); }
php
public function getChild($name) { $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name); if (!$obj) { throw new DAV\Exception\NotFound('Card not found'); } return new Card($this->carddavBackend, $this->addressBookInfo, $obj); }
[ "public", "function", "getChild", "(", "$", "name", ")", "{", "$", "obj", "=", "$", "this", "->", "carddavBackend", "->", "getCard", "(", "$", "this", "->", "addressBookInfo", "[", "'id'", "]", ",", "$", "name", ")", ";", "if", "(", "!", "$", "obj"...
Returns a card. @param string $name @return Card
[ "Returns", "a", "card", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/AddressBook.php#L66-L74
train
sabre-io/dav
lib/CardDAV/AddressBook.php
AddressBook.getChildren
public function getChildren() { $objs = $this->carddavBackend->getCards($this->addressBookInfo['id']); $children = []; foreach ($objs as $obj) { $obj['acl'] = $this->getChildACL(); $children[] = new Card($this->carddavBackend, $this->addressBookInfo, $obj); } return $children; }
php
public function getChildren() { $objs = $this->carddavBackend->getCards($this->addressBookInfo['id']); $children = []; foreach ($objs as $obj) { $obj['acl'] = $this->getChildACL(); $children[] = new Card($this->carddavBackend, $this->addressBookInfo, $obj); } return $children; }
[ "public", "function", "getChildren", "(", ")", "{", "$", "objs", "=", "$", "this", "->", "carddavBackend", "->", "getCards", "(", "$", "this", "->", "addressBookInfo", "[", "'id'", "]", ")", ";", "$", "children", "=", "[", "]", ";", "foreach", "(", "...
Returns the full list of cards. @return array
[ "Returns", "the", "full", "list", "of", "cards", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/AddressBook.php#L81-L91
train
sabre-io/dav
lib/CalDAV/CalendarHome.php
CalendarHome.getChild
public function getChild($name) { // Special nodes if ('inbox' === $name && $this->caldavBackend instanceof Backend\SchedulingSupport) { return new Schedule\Inbox($this->caldavBackend, $this->principalInfo['uri']); } if ('outbox' === $name && $this->caldavBackend instanceof Backend\SchedulingSupport) { return new Schedule\Outbox($this->principalInfo['uri']); } if ('notifications' === $name && $this->caldavBackend instanceof Backend\NotificationSupport) { return new Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); } // Calendars foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) { if ($calendar['uri'] === $name) { if ($this->caldavBackend instanceof Backend\SharingSupport) { return new SharedCalendar($this->caldavBackend, $calendar); } else { return new Calendar($this->caldavBackend, $calendar); } } } if ($this->caldavBackend instanceof Backend\SubscriptionSupport) { foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { if ($subscription['uri'] === $name) { return new Subscriptions\Subscription($this->caldavBackend, $subscription); } } } throw new NotFound('Node with name \''.$name.'\' could not be found'); }
php
public function getChild($name) { // Special nodes if ('inbox' === $name && $this->caldavBackend instanceof Backend\SchedulingSupport) { return new Schedule\Inbox($this->caldavBackend, $this->principalInfo['uri']); } if ('outbox' === $name && $this->caldavBackend instanceof Backend\SchedulingSupport) { return new Schedule\Outbox($this->principalInfo['uri']); } if ('notifications' === $name && $this->caldavBackend instanceof Backend\NotificationSupport) { return new Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); } // Calendars foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) { if ($calendar['uri'] === $name) { if ($this->caldavBackend instanceof Backend\SharingSupport) { return new SharedCalendar($this->caldavBackend, $calendar); } else { return new Calendar($this->caldavBackend, $calendar); } } } if ($this->caldavBackend instanceof Backend\SubscriptionSupport) { foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { if ($subscription['uri'] === $name) { return new Subscriptions\Subscription($this->caldavBackend, $subscription); } } } throw new NotFound('Node with name \''.$name.'\' could not be found'); }
[ "public", "function", "getChild", "(", "$", "name", ")", "{", "// Special nodes", "if", "(", "'inbox'", "===", "$", "name", "&&", "$", "this", "->", "caldavBackend", "instanceof", "Backend", "\\", "SchedulingSupport", ")", "{", "return", "new", "Schedule", "...
Returns a single calendar, by name. @param string $name @return Calendar
[ "Returns", "a", "single", "calendar", "by", "name", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/CalendarHome.php#L127-L160
train
sabre-io/dav
lib/CalDAV/CalendarHome.php
CalendarHome.getChildren
public function getChildren() { $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']); $objs = []; foreach ($calendars as $calendar) { if ($this->caldavBackend instanceof Backend\SharingSupport) { $objs[] = new SharedCalendar($this->caldavBackend, $calendar); } else { $objs[] = new Calendar($this->caldavBackend, $calendar); } } if ($this->caldavBackend instanceof Backend\SchedulingSupport) { $objs[] = new Schedule\Inbox($this->caldavBackend, $this->principalInfo['uri']); $objs[] = new Schedule\Outbox($this->principalInfo['uri']); } // We're adding a notifications node, if it's supported by the backend. if ($this->caldavBackend instanceof Backend\NotificationSupport) { $objs[] = new Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); } // If the backend supports subscriptions, we'll add those as well, if ($this->caldavBackend instanceof Backend\SubscriptionSupport) { foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { $objs[] = new Subscriptions\Subscription($this->caldavBackend, $subscription); } } return $objs; }
php
public function getChildren() { $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']); $objs = []; foreach ($calendars as $calendar) { if ($this->caldavBackend instanceof Backend\SharingSupport) { $objs[] = new SharedCalendar($this->caldavBackend, $calendar); } else { $objs[] = new Calendar($this->caldavBackend, $calendar); } } if ($this->caldavBackend instanceof Backend\SchedulingSupport) { $objs[] = new Schedule\Inbox($this->caldavBackend, $this->principalInfo['uri']); $objs[] = new Schedule\Outbox($this->principalInfo['uri']); } // We're adding a notifications node, if it's supported by the backend. if ($this->caldavBackend instanceof Backend\NotificationSupport) { $objs[] = new Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); } // If the backend supports subscriptions, we'll add those as well, if ($this->caldavBackend instanceof Backend\SubscriptionSupport) { foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { $objs[] = new Subscriptions\Subscription($this->caldavBackend, $subscription); } } return $objs; }
[ "public", "function", "getChildren", "(", ")", "{", "$", "calendars", "=", "$", "this", "->", "caldavBackend", "->", "getCalendarsForUser", "(", "$", "this", "->", "principalInfo", "[", "'uri'", "]", ")", ";", "$", "objs", "=", "[", "]", ";", "foreach", ...
Returns a list of calendars. @return array
[ "Returns", "a", "list", "of", "calendars", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/CalendarHome.php#L183-L213
train
sabre-io/dav
lib/CalDAV/CalendarHome.php
CalendarHome.createExtendedCollection
public function createExtendedCollection($name, MkCol $mkCol) { $isCalendar = false; $isSubscription = false; foreach ($mkCol->getResourceType() as $rt) { switch ($rt) { case '{DAV:}collection': case '{http://calendarserver.org/ns/}shared-owner': // ignore break; case '{urn:ietf:params:xml:ns:caldav}calendar': $isCalendar = true; break; case '{http://calendarserver.org/ns/}subscribed': $isSubscription = true; break; default: throw new DAV\Exception\InvalidResourceType('Unknown resourceType: '.$rt); } } $properties = $mkCol->getRemainingValues(); $mkCol->setRemainingResultCode(201); if ($isSubscription) { if (!$this->caldavBackend instanceof Backend\SubscriptionSupport) { throw new DAV\Exception\InvalidResourceType('This backend does not support subscriptions'); } $this->caldavBackend->createSubscription($this->principalInfo['uri'], $name, $properties); } elseif ($isCalendar) { $this->caldavBackend->createCalendar($this->principalInfo['uri'], $name, $properties); } else { throw new DAV\Exception\InvalidResourceType('You can only create calendars and subscriptions in this collection'); } }
php
public function createExtendedCollection($name, MkCol $mkCol) { $isCalendar = false; $isSubscription = false; foreach ($mkCol->getResourceType() as $rt) { switch ($rt) { case '{DAV:}collection': case '{http://calendarserver.org/ns/}shared-owner': // ignore break; case '{urn:ietf:params:xml:ns:caldav}calendar': $isCalendar = true; break; case '{http://calendarserver.org/ns/}subscribed': $isSubscription = true; break; default: throw new DAV\Exception\InvalidResourceType('Unknown resourceType: '.$rt); } } $properties = $mkCol->getRemainingValues(); $mkCol->setRemainingResultCode(201); if ($isSubscription) { if (!$this->caldavBackend instanceof Backend\SubscriptionSupport) { throw new DAV\Exception\InvalidResourceType('This backend does not support subscriptions'); } $this->caldavBackend->createSubscription($this->principalInfo['uri'], $name, $properties); } elseif ($isCalendar) { $this->caldavBackend->createCalendar($this->principalInfo['uri'], $name, $properties); } else { throw new DAV\Exception\InvalidResourceType('You can only create calendars and subscriptions in this collection'); } }
[ "public", "function", "createExtendedCollection", "(", "$", "name", ",", "MkCol", "$", "mkCol", ")", "{", "$", "isCalendar", "=", "false", ";", "$", "isSubscription", "=", "false", ";", "foreach", "(", "$", "mkCol", "->", "getResourceType", "(", ")", "as",...
Creates a new calendar or subscription. @param string $name @param MkCol $mkCol @throws DAV\Exception\InvalidResourceType
[ "Creates", "a", "new", "calendar", "or", "subscription", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/CalendarHome.php#L223-L257
train
sabre-io/dav
lib/CalDAV/CalendarHome.php
CalendarHome.shareReply
public function shareReply($href, $status, $calendarUri, $inReplyTo, $summary = null) { if (!$this->caldavBackend instanceof Backend\SharingSupport) { throw new DAV\Exception\NotImplemented('Sharing support is not implemented by this backend.'); } return $this->caldavBackend->shareReply($href, $status, $calendarUri, $inReplyTo, $summary); }
php
public function shareReply($href, $status, $calendarUri, $inReplyTo, $summary = null) { if (!$this->caldavBackend instanceof Backend\SharingSupport) { throw new DAV\Exception\NotImplemented('Sharing support is not implemented by this backend.'); } return $this->caldavBackend->shareReply($href, $status, $calendarUri, $inReplyTo, $summary); }
[ "public", "function", "shareReply", "(", "$", "href", ",", "$", "status", ",", "$", "calendarUri", ",", "$", "inReplyTo", ",", "$", "summary", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "caldavBackend", "instanceof", "Backend", "\\", "Sh...
This method is called when a user replied to a request to share. This method should return the url of the newly created calendar if the share was accepted. @param string $href The sharee who is replying (often a mailto: address) @param int $status One of the SharingPlugin::STATUS_* constants @param string $calendarUri The url to the calendar thats being shared @param string $inReplyTo The unique id this message is a response to @param string $summary A description of the reply @return string|null
[ "This", "method", "is", "called", "when", "a", "user", "replied", "to", "a", "request", "to", "share", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/CalendarHome.php#L326-L333
train
sabre-io/dav
lib/DAV/Mount/Plugin.php
Plugin.httpGet
public function httpGet(RequestInterface $request, ResponseInterface $response) { $queryParams = $request->getQueryParameters(); if (!array_key_exists('mount', $queryParams)) { return; } $currentUri = $request->getAbsoluteUrl(); // Stripping off everything after the ? list($currentUri) = explode('?', $currentUri); $this->davMount($response, $currentUri); // Returning false to break the event chain return false; }
php
public function httpGet(RequestInterface $request, ResponseInterface $response) { $queryParams = $request->getQueryParameters(); if (!array_key_exists('mount', $queryParams)) { return; } $currentUri = $request->getAbsoluteUrl(); // Stripping off everything after the ? list($currentUri) = explode('?', $currentUri); $this->davMount($response, $currentUri); // Returning false to break the event chain return false; }
[ "public", "function", "httpGet", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "queryParams", "=", "$", "request", "->", "getQueryParameters", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "'mount'...
'beforeMethod' event handles. This event handles intercepts GET requests ending with ?mount. @param RequestInterface $request @param ResponseInterface $response @return bool
[ "beforeMethod", "event", "handles", ".", "This", "event", "handles", "intercepts", "GET", "requests", "ending", "with", "?mount", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Mount/Plugin.php#L49-L65
train
sabre-io/dav
lib/DAV/Mount/Plugin.php
Plugin.davMount
public function davMount(ResponseInterface $response, $uri) { $response->setStatus(200); $response->setHeader('Content-Type', 'application/davmount+xml'); ob_start(); echo '<?xml version="1.0"?>', "\n"; echo "<dm:mount xmlns:dm=\"http://purl.org/NET/webdav/mount\">\n"; echo ' <dm:url>', htmlspecialchars($uri, ENT_NOQUOTES, 'UTF-8'), "</dm:url>\n"; echo '</dm:mount>'; $response->setBody(ob_get_clean()); }
php
public function davMount(ResponseInterface $response, $uri) { $response->setStatus(200); $response->setHeader('Content-Type', 'application/davmount+xml'); ob_start(); echo '<?xml version="1.0"?>', "\n"; echo "<dm:mount xmlns:dm=\"http://purl.org/NET/webdav/mount\">\n"; echo ' <dm:url>', htmlspecialchars($uri, ENT_NOQUOTES, 'UTF-8'), "</dm:url>\n"; echo '</dm:mount>'; $response->setBody(ob_get_clean()); }
[ "public", "function", "davMount", "(", "ResponseInterface", "$", "response", ",", "$", "uri", ")", "{", "$", "response", "->", "setStatus", "(", "200", ")", ";", "$", "response", "->", "setHeader", "(", "'Content-Type'", ",", "'application/davmount+xml'", ")",...
Generates the davmount response. @param ResponseInterface $response @param string $uri absolute uri
[ "Generates", "the", "davmount", "response", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Mount/Plugin.php#L73-L83
train
sabre-io/dav
lib/DAVACL/FS/HomeCollection.php
HomeCollection.getChildForPrincipal
public function getChildForPrincipal(array $principalInfo) { $owner = $principalInfo['uri']; $acl = [ [ 'privilege' => '{DAV:}all', 'principal' => '{DAV:}owner', 'protected' => true, ], ]; list(, $principalBaseName) = Uri\split($owner); $path = $this->storagePath.'/'.$principalBaseName; if (!is_dir($path)) { mkdir($path, 0777, true); } return new Collection( $path, $acl, $owner ); }
php
public function getChildForPrincipal(array $principalInfo) { $owner = $principalInfo['uri']; $acl = [ [ 'privilege' => '{DAV:}all', 'principal' => '{DAV:}owner', 'protected' => true, ], ]; list(, $principalBaseName) = Uri\split($owner); $path = $this->storagePath.'/'.$principalBaseName; if (!is_dir($path)) { mkdir($path, 0777, true); } return new Collection( $path, $acl, $owner ); }
[ "public", "function", "getChildForPrincipal", "(", "array", "$", "principalInfo", ")", "{", "$", "owner", "=", "$", "principalInfo", "[", "'uri'", "]", ";", "$", "acl", "=", "[", "[", "'privilege'", "=>", "'{DAV:}all'", ",", "'principal'", "=>", "'{DAV:}owne...
Returns a principals' collection of files. The passed array contains principal information, and is guaranteed to at least contain a uri item. Other properties may or may not be supplied by the authentication backend. @param array $principalInfo @return \Sabre\DAV\INode
[ "Returns", "a", "principals", "collection", "of", "files", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/FS/HomeCollection.php#L78-L102
train
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)) { // 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; }
[ "public", "function", "getPrincipalsByPrefix", "(", "$", "prefixPath", ")", "{", "$", "fields", "=", "[", "'uri'", ",", "]", ";", "foreach", "(", "$", "this", "->", "fieldMap", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "fields", "[", "]", ...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/PrincipalBackend/PDO.php#L93-L125
train
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", "[",...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/PrincipalBackend/PDO.php#L136-L165
train
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", "...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/PrincipalBackend/PDO.php#L182-L209
train
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", "\\", "Excepti...
Returns the list of members for a group-principal. @param string $principal @return array
[ "Returns", "the", "list", "of", "members", "for", "a", "group", "-", "principal", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/PrincipalBackend/PDO.php#L344-L359
train
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) { // 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]); } }
[ "public", "function", "setGroupMemberSet", "(", "$", "principal", ",", "array", "$", "members", ")", "{", "// Grabbing the list of principal id's.", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'SELECT id, uri FROM '", ".", "$", "this", "->...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/PrincipalBackend/PDO.php#L393-L420
train
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 (?)'", ")", ";"...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/PrincipalBackend/PDO.php#L432-L437
train
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'", "]", ")", ";", "$", "s...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/TemporaryFileFilterPlugin.php#L96-L101
train
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", "(", ")", "...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/TemporaryFileFilterPlugin.php#L114-L132
train
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", ")", ")", "{", "$", "...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/TemporaryFileFilterPlugin.php#L148-L159
train
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", "->"...
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", ...
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/TemporaryFileFilterPlugin.php#L195-L208
train
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...
This method handles the PUT method. @param RequestInterface $request @param ResponseInterface $hR @param string $tempLocation @return bool
[ "This", "method", "handles", "the", "PUT", "method", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/TemporaryFileFilterPlugin.php#L219-L233
train
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", "(",...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/TemporaryFileFilterPlugin.php#L247-L258
train
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", ...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/TemporaryFileFilterPlugin.php#L273-L297
train
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'); } // 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); }
[ "public", "function", "shareResource", "(", "$", "path", ",", "array", "$", "sharees", ")", "{", "$", "node", "=", "$", "this", "->", "server", "->", "tree", "->", "getNodeForPath", "(", "$", "path", ")", ";", "if", "(", "!", "$", "node", "instanceof...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Sharing/Plugin.php#L112-L136
train
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", "(", ")",...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Sharing/Plugin.php#L146-L159
train
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; } // 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'); } }
[ "public", "function", "httpPost", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "path", "=", "$", "request", "->", "getPath", "(", ")", ";", "$", "contentType", "=", "$", "request", "->", "getHeader", "(...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Sharing/Plugin.php#L169-L203
train
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:user@example.org"/><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)) { // 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:user@example.org"/><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", "->"...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Sharing/Plugin.php#L254-L281
train
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'", "]", ...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Sharing/Plugin.php#L291-L324
train
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", "->", "baseU...
Returns the base responding uri. @return string
[ "Returns", "the", "base", "responding", "uri", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L332-L339
train
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 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 '/'; }
[ "public", "function", "guessBaseUri", "(", ")", "{", "$", "pathInfo", "=", "$", "this", "->", "httpRequest", "->", "getRawServerValue", "(", "'PATH_INFO'", ")", ";", "$", "uri", "=", "$", "this", "->", "httpRequest", "->", "getRawServerValue", "(", "'REQUEST...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L349-L380
train
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L389-L393
train
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L404-L411
train
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.'; } // 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]); } }
[ "public", "function", "invokeMethod", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ",", "$", "sendResponse", "=", "true", ")", "{", "$", "method", "=", "$", "request", "->", "getMethod", "(", ")", ";", "if", "(", "!",...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L444-L485
train
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', ]; // 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; }
[ "public", "function", "getAllowedMethods", "(", "$", "path", ")", "{", "$", "methods", "=", "[", "'OPTIONS'", ",", "'GET'", ",", "'HEAD'", ",", "'DELETE'", ",", "'PROPFIND'", ",", "'PUT'", ",", "'PROPPATCH'", ",", "'COPY'", ",", "'MOVE'", ",", "'REPORT'", ...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L496-L525
train
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))), '/'); // 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().')'); } }
[ "public", "function", "calculateUri", "(", "$", "uri", ")", "{", "if", "(", "''", "!=", "$", "uri", "&&", "'/'", "!=", "$", "uri", "[", "0", "]", "&&", "strpos", "(", "$", "uri", ",", "'://'", ")", ")", "{", "$", "uri", "=", "parse_url", "(", ...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L551-L570
train
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) { // 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; }
[ "public", "function", "getHTTPDepth", "(", "$", "default", "=", "self", "::", "DEPTH_INFINITY", ")", "{", "// If its not set, we'll grab the default", "$", "depth", "=", "$", "this", "->", "httpRequest", "->", "getHeader", "(", "'Depth'", ")", ";", "if", "(", ...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L582-L601
train
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; } // 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, ]; }
[ "public", "function", "getHTTPRange", "(", ")", "{", "$", "range", "=", "$", "this", "->", "httpRequest", "->", "getHeader", "(", "'range'", ")", ";", "if", "(", "is_null", "(", "$", "range", ")", ")", "{", "return", "null", ";", "}", "// Matching \"Ra...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L617-L638
train
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 = [ // 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; }
[ "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.", ...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L666-L689
train
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) { // 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, ]; }
[ "public", "function", "getCopyAndMoveInfo", "(", "RequestInterface", "$", "request", ")", "{", "// Collecting the relevant HTTP headers", "if", "(", "!", "$", "request", "->", "getHeader", "(", "'Destination'", ")", ")", "{", "throw", "new", "Exception", "\\", "Ba...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L715-L774
train
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", "(", "$", ...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L792-L800
train
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) { // Skipping the parent path if (0 === $k) { continue; } $result[$row['href']] = $row[200]; } return $result; }
[ "public", "function", "getPropertiesForChildren", "(", "$", "path", ",", "$", "propertyNames", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getPropertiesForPath", "(", "$", "path", ",", "$", "propertyNames", ",", "1", ...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L815-L828
train
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]; // GetLastModified gets special cased } 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'", ",", ...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L843-L870
train
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", "=", "$", ...
Small helper to support PROPFIND with DEPTH_INFINITY. @param PropFind $propFind @param array $yieldFirst @return \Traversable
[ "Small", "helper", "to", "support", "PROPFIND", "with", "DEPTH_INFINITY", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L880-L914
train
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", "("...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L1012-L1034
train
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'); } // 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; }
[ "public", "function", "createFile", "(", "$", "uri", ",", "$", "data", ",", "&", "$", "etag", "=", "null", ")", "{", "list", "(", "$", "dir", ",", "$", "name", ")", "=", "Uri", "\\", "split", "(", "$", "uri", ")", ";", "if", "(", "!", "$", ...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L1071-L1106
train
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); // 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; }
[ "public", "function", "updateFile", "(", "$", "uri", ",", "$", "data", ",", "&", "$", "etag", "=", "null", ")", "{", "$", "node", "=", "$", "this", "->", "tree", "->", "getNodeForPath", "(", "$", "uri", ")", ";", "// It is possible for an event handler t...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L1119-L1140
train
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); // 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]); }
[ "public", "function", "createCollection", "(", "$", "uri", ",", "MkCol", "$", "mkCol", ")", "{", "list", "(", "$", "parentUri", ",", "$", "newName", ")", "=", "Uri", "\\", "split", "(", "$", "uri", ")", ";", "// Making sure the parent exists", "try", "{"...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L1160-L1237
train
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", ",...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L1257-L1264
train
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", "(", "$",...
Returns an array with resourcetypes for a node. @param INode $node @return array
[ "Returns", "an", "array", "with", "resourcetypes", "for", "a", "node", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L1615-L1625
train
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", ...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Server.php#L1640-L1667
train
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", "(", "...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Browser/MapGetToPropFind.php#L49-L62
train
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", ")", "{", "retur...
Returns whether or not the child node exists. @param string $name @return bool
[ "Returns", "whether", "or", "not", "the", "child", "node", "exists", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Principal/User.php#L97-L106
train
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); // Sending back false will interrupt the event chain and tell the server // we've handled this method. return false; }
[ "public", "function", "httpOptions", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "methods", "=", "$", "this", "->", "server", "->", "getAllowedMethods", "(", "$", "request", "->", "getPath", "(", ")", ")...
HTTP OPTIONS. @param RequestInterface $request @param ResponseInterface $response @return bool
[ "HTTP", "OPTIONS", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L218-L238
train
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) { // 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; }
[ "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.", "$", ...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L253-L278
train
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'); // Sending back false will interrupt the event chain and tell the server // we've handled this method. return false; }
[ "public", "function", "httpDelete", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "path", "=", "$", "request", "->", "getPath", "(", ")", ";", "if", "(", "!", "$", "this", "->", "server", "->", "emit",...
HTTP Delete. The HTTP delete method, deletes a given uri @param RequestInterface $request @param ResponseInterface $response
[ "HTTP", "Delete", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L288-L304
train
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); // 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; }
[ "public", "function", "httpPropFind", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "path", "=", "$", "request", "->", "getPath", "(", ")", ";", "$", "requestBody", "=", "$", "request", "->", "getBodyAsStr...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L321-L369
train
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']) { // 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; }
[ "public", "function", "httpPropPatch", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "path", "=", "$", "request", "->", "getPath", "(", ")", ";", "try", "{", "$", "propPatch", "=", "$", "this", "->", "...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L382-L437
train
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(); // 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; }
[ "public", "function", "httpPut", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "body", "=", "$", "request", "->", "getBodyAsStream", "(", ")", ";", "$", "path", "=", "$", "request", "->", "getPath", "(",...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L451-L542
train
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'))) { // 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; }
[ "public", "function", "httpMkcol", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "requestBody", "=", "$", "request", "->", "getBodyAsString", "(", ")", ";", "$", "path", "=", "$", "request", "->", "getPath...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L554-L603
train
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']); // 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; }
[ "public", "function", "httpMove", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "path", "=", "$", "request", "->", "getPath", "(", ")", ";", "$", "moveInfo", "=", "$", "this", "->", "server", "->", "ge...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L615-L658
train
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']]); // 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; }
[ "public", "function", "httpCopy", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "path", "=", "$", "request", "->", "getPath", "(", ")", ";", "$", "copyInfo", "=", "$", "this", "->", "server", "->", "ge...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L671-L697
train
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])) { // 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; }
[ "public", "function", "httpReport", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "path", "=", "$", "request", "->", "getPath", "(", ")", ";", "$", "result", "=", "$", "this", "->", "server", "->", "xm...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L710-L728
train
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", "(", ")", ")", "{"...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L839-L847
train
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) { // 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, ] ); }
[ "public", "function", "exception", "(", "$", "e", ")", "{", "$", "logLevel", "=", "\\", "Psr", "\\", "Log", "\\", "LogLevel", "::", "CRITICAL", ";", "if", "(", "$", "e", "instanceof", "\\", "Sabre", "\\", "DAV", "\\", "Exception", ")", "{", "// If it...
Listens for exception events, and automatically logs them. @param Exception $e
[ "Listens", "for", "exception", "events", "and", "automatically", "logs", "them", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/CorePlugin.php#L902-L927
train
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", "(", "'/^{([^}]*)}(.*)$/'", ",", "$", ...
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", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Property/SupportedReportSet.php#L60-L70
train
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://calendarserver.org/ns/}getctag' => $row['synctoken'], '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', ]; } return $addressBooks; }
[ "public", "function", "getAddressBooksForUser", "(", "$", "principalUri", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'SELECT id, uri, displayname, principaluri, description, synctoken FROM '", ".", "$", "this", "->", "addressBooksTableN...
Returns the list of addressbooks for a specific user. @param string $principalUri @return array
[ "Returns", "the", "list", "of", "addressbooks", "for", "a", "specific", "user", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L62-L82
train
sabre-io/dav
lib/CardDAV/Backend/PDO.php
PDO.updateAddressBook
public function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch) { $supportedProperties = [ '{DAV:}displayname', '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description', ]; $propPatch->handle($supportedProperties, function ($mutations) use ($addressBookId) { $updates = []; foreach ($mutations as $property => $newValue) { switch ($property) { case '{DAV:}displayname': $updates['displayname'] = $newValue; break; case '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description': $updates['description'] = $newValue; break; } } $query = 'UPDATE '.$this->addressBooksTableName.' SET '; $first = true; foreach ($updates as $key => $value) { if ($first) { $first = false; } else { $query .= ', '; } $query .= ' '.$key.' = :'.$key.' '; } $query .= ' WHERE id = :addressbookid'; $stmt = $this->pdo->prepare($query); $updates['addressbookid'] = $addressBookId; $stmt->execute($updates); $this->addChange($addressBookId, '', 2); return true; }); }
php
public function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch) { $supportedProperties = [ '{DAV:}displayname', '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description', ]; $propPatch->handle($supportedProperties, function ($mutations) use ($addressBookId) { $updates = []; foreach ($mutations as $property => $newValue) { switch ($property) { case '{DAV:}displayname': $updates['displayname'] = $newValue; break; case '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description': $updates['description'] = $newValue; break; } } $query = 'UPDATE '.$this->addressBooksTableName.' SET '; $first = true; foreach ($updates as $key => $value) { if ($first) { $first = false; } else { $query .= ', '; } $query .= ' '.$key.' = :'.$key.' '; } $query .= ' WHERE id = :addressbookid'; $stmt = $this->pdo->prepare($query); $updates['addressbookid'] = $addressBookId; $stmt->execute($updates); $this->addChange($addressBookId, '', 2); return true; }); }
[ "public", "function", "updateAddressBook", "(", "$", "addressBookId", ",", "\\", "Sabre", "\\", "DAV", "\\", "PropPatch", "$", "propPatch", ")", "{", "$", "supportedProperties", "=", "[", "'{DAV:}displayname'", ",", "'{'", ".", "CardDAV", "\\", "Plugin", "::",...
Updates properties for an address book. 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 $addressBookId @param \Sabre\DAV\PropPatch $propPatch
[ "Updates", "properties", "for", "an", "address", "book", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L99-L139
train
sabre-io/dav
lib/CardDAV/Backend/PDO.php
PDO.deleteAddressBook
public function deleteAddressBook($addressBookId) { $stmt = $this->pdo->prepare('DELETE FROM '.$this->cardsTableName.' WHERE addressbookid = ?'); $stmt->execute([$addressBookId]); $stmt = $this->pdo->prepare('DELETE FROM '.$this->addressBooksTableName.' WHERE id = ?'); $stmt->execute([$addressBookId]); $stmt = $this->pdo->prepare('DELETE FROM '.$this->addressBookChangesTableName.' WHERE addressbookid = ?'); $stmt->execute([$addressBookId]); }
php
public function deleteAddressBook($addressBookId) { $stmt = $this->pdo->prepare('DELETE FROM '.$this->cardsTableName.' WHERE addressbookid = ?'); $stmt->execute([$addressBookId]); $stmt = $this->pdo->prepare('DELETE FROM '.$this->addressBooksTableName.' WHERE id = ?'); $stmt->execute([$addressBookId]); $stmt = $this->pdo->prepare('DELETE FROM '.$this->addressBookChangesTableName.' WHERE addressbookid = ?'); $stmt->execute([$addressBookId]); }
[ "public", "function", "deleteAddressBook", "(", "$", "addressBookId", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'DELETE FROM '", ".", "$", "this", "->", "cardsTableName", ".", "' WHERE addressbookid = ?'", ")", ";", "$", "s...
Deletes an entire addressbook and all its contents. @param int $addressBookId
[ "Deletes", "an", "entire", "addressbook", "and", "all", "its", "contents", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L186-L196
train
sabre-io/dav
lib/CardDAV/Backend/PDO.php
PDO.getCards
public function getCards($addressbookId) { $stmt = $this->pdo->prepare('SELECT id, uri, lastmodified, etag, size FROM '.$this->cardsTableName.' WHERE addressbookid = ?'); $stmt->execute([$addressbookId]); $result = []; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $row['etag'] = '"'.$row['etag'].'"'; $row['lastmodified'] = (int) $row['lastmodified']; $result[] = $row; } return $result; }
php
public function getCards($addressbookId) { $stmt = $this->pdo->prepare('SELECT id, uri, lastmodified, etag, size FROM '.$this->cardsTableName.' WHERE addressbookid = ?'); $stmt->execute([$addressbookId]); $result = []; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $row['etag'] = '"'.$row['etag'].'"'; $row['lastmodified'] = (int) $row['lastmodified']; $result[] = $row; } return $result; }
[ "public", "function", "getCards", "(", "$", "addressbookId", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'SELECT id, uri, lastmodified, etag, size FROM '", ".", "$", "this", "->", "cardsTableName", ".", "' WHERE addressbookid = ?'", ...
Returns all cards for a specific addressbook id. This method should return the following properties for each card: * carddata - raw vcard data * uri - Some unique url * lastmodified - A unix timestamp It's recommended to also return the following properties: * etag - A unique etag. This must change every time the card changes. * size - The size of the card in bytes. If these last two properties are provided, less time will be spent calculating them. If they are specified, you can also ommit carddata. This may speed up certain requests, especially with large cards. @param mixed $addressbookId @return array
[ "Returns", "all", "cards", "for", "a", "specific", "addressbook", "id", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L218-L231
train
sabre-io/dav
lib/CardDAV/Backend/PDO.php
PDO.getCard
public function getCard($addressBookId, $cardUri) { $stmt = $this->pdo->prepare('SELECT id, carddata, uri, lastmodified, etag, size FROM '.$this->cardsTableName.' WHERE addressbookid = ? AND uri = ? LIMIT 1'); $stmt->execute([$addressBookId, $cardUri]); $result = $stmt->fetch(\PDO::FETCH_ASSOC); if (!$result) { return false; } $result['etag'] = '"'.$result['etag'].'"'; $result['lastmodified'] = (int) $result['lastmodified']; return $result; }
php
public function getCard($addressBookId, $cardUri) { $stmt = $this->pdo->prepare('SELECT id, carddata, uri, lastmodified, etag, size FROM '.$this->cardsTableName.' WHERE addressbookid = ? AND uri = ? LIMIT 1'); $stmt->execute([$addressBookId, $cardUri]); $result = $stmt->fetch(\PDO::FETCH_ASSOC); if (!$result) { return false; } $result['etag'] = '"'.$result['etag'].'"'; $result['lastmodified'] = (int) $result['lastmodified']; return $result; }
[ "public", "function", "getCard", "(", "$", "addressBookId", ",", "$", "cardUri", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'SELECT id, carddata, uri, lastmodified, etag, size FROM '", ".", "$", "this", "->", "cardsTableName", "...
Returns a specific card. The same set of properties must be returned as with getCards. The only exception is that 'carddata' is absolutely required. If the card does not exist, you must return false. @param mixed $addressBookId @param string $cardUri @return array
[ "Returns", "a", "specific", "card", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L246-L261
train
sabre-io/dav
lib/CardDAV/Backend/PDO.php
PDO.createCard
public function createCard($addressBookId, $cardUri, $cardData) { $stmt = $this->pdo->prepare('INSERT INTO '.$this->cardsTableName.' (carddata, uri, lastmodified, addressbookid, size, etag) VALUES (?, ?, ?, ?, ?, ?)'); $etag = md5($cardData); $stmt->execute([ $cardData, $cardUri, time(), $addressBookId, strlen($cardData), $etag, ]); $this->addChange($addressBookId, $cardUri, 1); return '"'.$etag.'"'; }
php
public function createCard($addressBookId, $cardUri, $cardData) { $stmt = $this->pdo->prepare('INSERT INTO '.$this->cardsTableName.' (carddata, uri, lastmodified, addressbookid, size, etag) VALUES (?, ?, ?, ?, ?, ?)'); $etag = md5($cardData); $stmt->execute([ $cardData, $cardUri, time(), $addressBookId, strlen($cardData), $etag, ]); $this->addChange($addressBookId, $cardUri, 1); return '"'.$etag.'"'; }
[ "public", "function", "createCard", "(", "$", "addressBookId", ",", "$", "cardUri", ",", "$", "cardData", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'INSERT INTO '", ".", "$", "this", "->", "cardsTableName", ".", "' (car...
Creates a new card. The addressbook id will be passed as the first argument. This is the same id as it is returned from the getAddressBooksForUser method. The cardUri is a base uri, and doesn't include the full path. The cardData argument is the vcard body, and is passed as a string. It is possible to return an ETag from this method. This ETag is for the newly created resource, and must be enclosed with double quotes (that is, the string itself must contain the double quotes). You should only return the ETag if you store the carddata as-is. If a subsequent GET request on the same card does not have the same body, byte-by-byte and you did return an ETag here, clients tend to get confused. If you don't return an ETag, you can just return null. @param mixed $addressBookId @param string $cardUri @param string $cardData @return string|null
[ "Creates", "a", "new", "card", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L321-L339
train
sabre-io/dav
lib/CardDAV/Backend/PDO.php
PDO.deleteCard
public function deleteCard($addressBookId, $cardUri) { $stmt = $this->pdo->prepare('DELETE FROM '.$this->cardsTableName.' WHERE addressbookid = ? AND uri = ?'); $stmt->execute([$addressBookId, $cardUri]); $this->addChange($addressBookId, $cardUri, 3); return 1 === $stmt->rowCount(); }
php
public function deleteCard($addressBookId, $cardUri) { $stmt = $this->pdo->prepare('DELETE FROM '.$this->cardsTableName.' WHERE addressbookid = ? AND uri = ?'); $stmt->execute([$addressBookId, $cardUri]); $this->addChange($addressBookId, $cardUri, 3); return 1 === $stmt->rowCount(); }
[ "public", "function", "deleteCard", "(", "$", "addressBookId", ",", "$", "cardUri", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'DELETE FROM '", ".", "$", "this", "->", "cardsTableName", ".", "' WHERE addressbookid = ? AND uri ...
Deletes a card. @param mixed $addressBookId @param string $cardUri @return bool
[ "Deletes", "a", "card", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L394-L402
train
sabre-io/dav
lib/CardDAV/Backend/PDO.php
PDO.getChangesForAddressBook
public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, $limit = null) { // Current synctoken $stmt = $this->pdo->prepare('SELECT synctoken FROM '.$this->addressBooksTableName.' WHERE id = ?'); $stmt->execute([$addressBookId]); $currentToken = $stmt->fetchColumn(0); if (is_null($currentToken)) { return null; } $result = [ 'syncToken' => $currentToken, 'added' => [], 'modified' => [], 'deleted' => [], ]; if ($syncToken) { $query = 'SELECT uri, operation FROM '.$this->addressBookChangesTableName.' WHERE synctoken >= ? AND synctoken < ? AND addressbookid = ? ORDER BY synctoken'; if ($limit > 0) { $query .= ' LIMIT '.(int) $limit; } // Fetching all changes $stmt = $this->pdo->prepare($query); $stmt->execute([$syncToken, $currentToken, $addressBookId]); $changes = []; // This loop ensures that any duplicates are overwritten, only the // last change on a node is relevant. while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $changes[$row['uri']] = $row['operation']; } foreach ($changes as $uri => $operation) { switch ($operation) { case 1: $result['added'][] = $uri; break; case 2: $result['modified'][] = $uri; break; case 3: $result['deleted'][] = $uri; break; } } } else { // No synctoken supplied, this is the initial sync. $query = 'SELECT uri FROM '.$this->cardsTableName.' WHERE addressbookid = ?'; $stmt = $this->pdo->prepare($query); $stmt->execute([$addressBookId]); $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); } return $result; }
php
public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel, $limit = null) { // Current synctoken $stmt = $this->pdo->prepare('SELECT synctoken FROM '.$this->addressBooksTableName.' WHERE id = ?'); $stmt->execute([$addressBookId]); $currentToken = $stmt->fetchColumn(0); if (is_null($currentToken)) { return null; } $result = [ 'syncToken' => $currentToken, 'added' => [], 'modified' => [], 'deleted' => [], ]; if ($syncToken) { $query = 'SELECT uri, operation FROM '.$this->addressBookChangesTableName.' WHERE synctoken >= ? AND synctoken < ? AND addressbookid = ? ORDER BY synctoken'; if ($limit > 0) { $query .= ' LIMIT '.(int) $limit; } // Fetching all changes $stmt = $this->pdo->prepare($query); $stmt->execute([$syncToken, $currentToken, $addressBookId]); $changes = []; // This loop ensures that any duplicates are overwritten, only the // last change on a node is relevant. while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $changes[$row['uri']] = $row['operation']; } foreach ($changes as $uri => $operation) { switch ($operation) { case 1: $result['added'][] = $uri; break; case 2: $result['modified'][] = $uri; break; case 3: $result['deleted'][] = $uri; break; } } } else { // No synctoken supplied, this is the initial sync. $query = 'SELECT uri FROM '.$this->cardsTableName.' WHERE addressbookid = ?'; $stmt = $this->pdo->prepare($query); $stmt->execute([$addressBookId]); $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); } return $result; }
[ "public", "function", "getChangesForAddressBook", "(", "$", "addressBookId", ",", "$", "syncToken", ",", "$", "syncLevel", ",", "$", "limit", "=", "null", ")", "{", "// Current synctoken", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "...
The getChanges method returns all the changes that have happened, since the specified syncToken in the specified address book. This function should return an array, such as the following: [ 'syncToken' => 'The current synctoken', 'added' => [ 'new.txt', ], 'modified' => [ 'updated.txt', ], 'deleted' => [ 'foo.php.bak', 'old.txt' ] ]; The returned syncToken property should reflect the *current* syncToken of the addressbook, as reported in the {http://sabredav.org/ns}sync-token property. This is needed here too, to ensure the operation is atomic. If the $syncToken argument is specified as null, this is an initial sync, and all members should be reported. The modified property is an array of nodenames that have changed since the last token. The deleted property is an array with nodenames, that have been deleted from collection. The $syncLevel argument is basically the 'depth' of the report. If it's 1, you only have to report changes that happened only directly in immediate descendants. If it's 2, it should also include changes from the nodes below the child collections. (grandchildren) The $limit argument allows a client to specify how many results should be returned at most. If the limit is not specified, it should be treated as infinite. If the limit (infinite or not) is higher than you're willing to return, you should throw a Sabre\DAV\Exception\TooMuchMatches() exception. If the syncToken is expired (due to data cleanup) or unknown, you must return null. The limit is 'suggestive'. You are free to ignore it. @param string $addressBookId @param string $syncToken @param int $syncLevel @param int $limit @return array
[ "The", "getChanges", "method", "returns", "all", "the", "changes", "that", "have", "happened", "since", "the", "specified", "syncToken", "in", "the", "specified", "address", "book", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L461-L520
train
sabre-io/dav
lib/CardDAV/Backend/PDO.php
PDO.addChange
protected function addChange($addressBookId, $objectUri, $operation) { $stmt = $this->pdo->prepare('INSERT INTO '.$this->addressBookChangesTableName.' (uri, synctoken, addressbookid, operation) SELECT ?, synctoken, ?, ? FROM '.$this->addressBooksTableName.' WHERE id = ?'); $stmt->execute([ $objectUri, $addressBookId, $operation, $addressBookId, ]); $stmt = $this->pdo->prepare('UPDATE '.$this->addressBooksTableName.' SET synctoken = synctoken + 1 WHERE id = ?'); $stmt->execute([ $addressBookId, ]); }
php
protected function addChange($addressBookId, $objectUri, $operation) { $stmt = $this->pdo->prepare('INSERT INTO '.$this->addressBookChangesTableName.' (uri, synctoken, addressbookid, operation) SELECT ?, synctoken, ?, ? FROM '.$this->addressBooksTableName.' WHERE id = ?'); $stmt->execute([ $objectUri, $addressBookId, $operation, $addressBookId, ]); $stmt = $this->pdo->prepare('UPDATE '.$this->addressBooksTableName.' SET synctoken = synctoken + 1 WHERE id = ?'); $stmt->execute([ $addressBookId, ]); }
[ "protected", "function", "addChange", "(", "$", "addressBookId", ",", "$", "objectUri", ",", "$", "operation", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'INSERT INTO '", ".", "$", "this", "->", "addressBookChangesTableName"...
Adds a change record to the addressbookchanges table. @param mixed $addressBookId @param string $objectUri @param int $operation 1 = add, 2 = modify, 3 = delete
[ "Adds", "a", "change", "record", "to", "the", "addressbookchanges", "table", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L529-L542
train
sabre-io/dav
lib/CalDAV/Backend/SimplePDO.php
SimplePDO.updateCalendarObject
public function updateCalendarObject($calendarId, $objectUri, $calendarData) { $stmt = $this->pdo->prepare('UPDATE simple_calendarobjects SET calendardata = ? WHERE calendarid = ? AND uri = ?'); $stmt->execute([$calendarData, $calendarId, $objectUri]); return '"'.md5($calendarData).'"'; }
php
public function updateCalendarObject($calendarId, $objectUri, $calendarData) { $stmt = $this->pdo->prepare('UPDATE simple_calendarobjects SET calendardata = ? WHERE calendarid = ? AND uri = ?'); $stmt->execute([$calendarData, $calendarId, $objectUri]); return '"'.md5($calendarData).'"'; }
[ "public", "function", "updateCalendarObject", "(", "$", "calendarId", ",", "$", "objectUri", ",", "$", "calendarData", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'UPDATE simple_calendarobjects SET calendardata = ? WHERE calendarid = ?...
Updates an existing calendarobject, based on it's uri. The object uri is only the basename, or filename and not a full path. It is possible return an etag from this function, which will be used in the response to this PUT request. Note that the ETag must be surrounded by double-quotes. However, you should only really return this ETag if you don't mangle the calendar-data. If the result of a subsequent GET to this object is not the exact same as this request body, you should omit the ETag. @param mixed $calendarId @param string $objectUri @param string $calendarData @return string|null
[ "Updates", "an", "existing", "calendarobject", "based", "on", "it", "s", "uri", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/SimplePDO.php#L271-L277
train
sabre-io/dav
lib/DAV/Locks/Plugin.php
Plugin.propFind
public function propFind(DAV\PropFind $propFind, DAV\INode $node) { $propFind->handle('{DAV:}supportedlock', function () { return new DAV\Xml\Property\SupportedLock(); }); $propFind->handle('{DAV:}lockdiscovery', function () use ($propFind) { return new DAV\Xml\Property\LockDiscovery( $this->getLocks($propFind->getPath()) ); }); }
php
public function propFind(DAV\PropFind $propFind, DAV\INode $node) { $propFind->handle('{DAV:}supportedlock', function () { return new DAV\Xml\Property\SupportedLock(); }); $propFind->handle('{DAV:}lockdiscovery', function () use ($propFind) { return new DAV\Xml\Property\LockDiscovery( $this->getLocks($propFind->getPath()) ); }); }
[ "public", "function", "propFind", "(", "DAV", "\\", "PropFind", "$", "propFind", ",", "DAV", "\\", "INode", "$", "node", ")", "{", "$", "propFind", "->", "handle", "(", "'{DAV:}supportedlock'", ",", "function", "(", ")", "{", "return", "new", "DAV", "\\"...
This method is called after most properties have been found it allows us to add in any Lock-related properties. @param DAV\PropFind $propFind @param DAV\INode $node
[ "This", "method", "is", "called", "after", "most", "properties", "have", "been", "found", "it", "allows", "us", "to", "add", "in", "any", "Lock", "-", "related", "properties", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Plugin.php#L91-L101
train
sabre-io/dav
lib/DAV/Locks/Plugin.php
Plugin.httpLock
public function httpLock(RequestInterface $request, ResponseInterface $response) { $uri = $request->getPath(); $existingLocks = $this->getLocks($uri); if ($body = $request->getBodyAsString()) { // This is a new lock request $existingLock = null; // Checking if there's already non-shared locks on the uri. foreach ($existingLocks as $existingLock) { if (LockInfo::EXCLUSIVE === $existingLock->scope) { throw new DAV\Exception\ConflictingLock($existingLock); } } $lockInfo = $this->parseLockRequest($body); $lockInfo->depth = $this->server->getHTTPDepth(); $lockInfo->uri = $uri; if ($existingLock && LockInfo::SHARED != $lockInfo->scope) { throw new DAV\Exception\ConflictingLock($existingLock); } } else { // Gonna check if this was a lock refresh. $existingLocks = $this->getLocks($uri); $conditions = $this->server->getIfConditions($request); $found = null; foreach ($existingLocks as $existingLock) { foreach ($conditions as $condition) { foreach ($condition['tokens'] as $token) { if ($token['token'] === 'opaquelocktoken:'.$existingLock->token) { $found = $existingLock; break 3; } } } } // If none were found, this request is in error. if (is_null($found)) { if ($existingLocks) { throw new DAV\Exception\Locked(reset($existingLocks)); } else { throw new DAV\Exception\BadRequest('An xml body is required for lock requests'); } } // This must have been a lock refresh $lockInfo = $found; // The resource could have been locked through another uri. if ($uri != $lockInfo->uri) { $uri = $lockInfo->uri; } } if ($timeout = $this->getTimeoutHeader()) { $lockInfo->timeout = $timeout; } $newFile = false; // If we got this far.. we should go check if this node actually exists. If this is not the case, we need to create it first try { $this->server->tree->getNodeForPath($uri); // We need to call the beforeWriteContent event for RFC3744 // Edit: looks like this is not used, and causing problems now. // // See Issue 222 // $this->server->emit('beforeWriteContent',array($uri)); } catch (DAV\Exception\NotFound $e) { // It didn't, lets create it $this->server->createFile($uri, fopen('php://memory', 'r')); $newFile = true; } $this->lockNode($uri, $lockInfo); $response->setHeader('Content-Type', 'application/xml; charset=utf-8'); $response->setHeader('Lock-Token', '<opaquelocktoken:'.$lockInfo->token.'>'); $response->setStatus($newFile ? 201 : 200); $response->setBody($this->generateLockResponse($lockInfo)); // Returning false will interrupt the event chain and mark this method // as 'handled'. return false; }
php
public function httpLock(RequestInterface $request, ResponseInterface $response) { $uri = $request->getPath(); $existingLocks = $this->getLocks($uri); if ($body = $request->getBodyAsString()) { // This is a new lock request $existingLock = null; // Checking if there's already non-shared locks on the uri. foreach ($existingLocks as $existingLock) { if (LockInfo::EXCLUSIVE === $existingLock->scope) { throw new DAV\Exception\ConflictingLock($existingLock); } } $lockInfo = $this->parseLockRequest($body); $lockInfo->depth = $this->server->getHTTPDepth(); $lockInfo->uri = $uri; if ($existingLock && LockInfo::SHARED != $lockInfo->scope) { throw new DAV\Exception\ConflictingLock($existingLock); } } else { // Gonna check if this was a lock refresh. $existingLocks = $this->getLocks($uri); $conditions = $this->server->getIfConditions($request); $found = null; foreach ($existingLocks as $existingLock) { foreach ($conditions as $condition) { foreach ($condition['tokens'] as $token) { if ($token['token'] === 'opaquelocktoken:'.$existingLock->token) { $found = $existingLock; break 3; } } } } // If none were found, this request is in error. if (is_null($found)) { if ($existingLocks) { throw new DAV\Exception\Locked(reset($existingLocks)); } else { throw new DAV\Exception\BadRequest('An xml body is required for lock requests'); } } // This must have been a lock refresh $lockInfo = $found; // The resource could have been locked through another uri. if ($uri != $lockInfo->uri) { $uri = $lockInfo->uri; } } if ($timeout = $this->getTimeoutHeader()) { $lockInfo->timeout = $timeout; } $newFile = false; // If we got this far.. we should go check if this node actually exists. If this is not the case, we need to create it first try { $this->server->tree->getNodeForPath($uri); // We need to call the beforeWriteContent event for RFC3744 // Edit: looks like this is not used, and causing problems now. // // See Issue 222 // $this->server->emit('beforeWriteContent',array($uri)); } catch (DAV\Exception\NotFound $e) { // It didn't, lets create it $this->server->createFile($uri, fopen('php://memory', 'r')); $newFile = true; } $this->lockNode($uri, $lockInfo); $response->setHeader('Content-Type', 'application/xml; charset=utf-8'); $response->setHeader('Lock-Token', '<opaquelocktoken:'.$lockInfo->token.'>'); $response->setStatus($newFile ? 201 : 200); $response->setBody($this->generateLockResponse($lockInfo)); // Returning false will interrupt the event chain and mark this method // as 'handled'. return false; }
[ "public", "function", "httpLock", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "uri", "=", "$", "request", "->", "getPath", "(", ")", ";", "$", "existingLocks", "=", "$", "this", "->", "getLocks", "(", ...
Locks an uri. The WebDAV lock request can be operated to either create a new lock on a file, or to refresh an existing lock If a new lock is created, a full XML body should be supplied, containing information about the lock such as the type of lock (shared or exclusive) and the owner of the lock If a lock is to be refreshed, no body should be supplied and there should be a valid If header containing the lock Additionally, a lock can be requested for a non-existent file. In these case we're obligated to create an empty file as per RFC4918:S7.3 @param RequestInterface $request @param ResponseInterface $response @return bool
[ "Locks", "an", "uri", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Plugin.php#L167-L256
train
sabre-io/dav
lib/DAV/Locks/Plugin.php
Plugin.getTimeoutHeader
public function getTimeoutHeader() { $header = $this->server->httpRequest->getHeader('Timeout'); if ($header) { if (0 === stripos($header, 'second-')) { $header = (int) (substr($header, 7)); } elseif (0 === stripos($header, 'infinite')) { $header = LockInfo::TIMEOUT_INFINITE; } else { throw new DAV\Exception\BadRequest('Invalid HTTP timeout header'); } } else { $header = 0; } return $header; }
php
public function getTimeoutHeader() { $header = $this->server->httpRequest->getHeader('Timeout'); if ($header) { if (0 === stripos($header, 'second-')) { $header = (int) (substr($header, 7)); } elseif (0 === stripos($header, 'infinite')) { $header = LockInfo::TIMEOUT_INFINITE; } else { throw new DAV\Exception\BadRequest('Invalid HTTP timeout header'); } } else { $header = 0; } return $header; }
[ "public", "function", "getTimeoutHeader", "(", ")", "{", "$", "header", "=", "$", "this", "->", "server", "->", "httpRequest", "->", "getHeader", "(", "'Timeout'", ")", ";", "if", "(", "$", "header", ")", "{", "if", "(", "0", "===", "stripos", "(", "...
Returns the contents of the HTTP Timeout header. The method formats the header into an integer. @return int
[ "Returns", "the", "contents", "of", "the", "HTTP", "Timeout", "header", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Plugin.php#L361-L378
train
sabre-io/dav
lib/DAV/Locks/Plugin.php
Plugin.generateLockResponse
protected function generateLockResponse(LockInfo $lockInfo) { return $this->server->xml->write('{DAV:}prop', [ '{DAV:}lockdiscovery' => new DAV\Xml\Property\LockDiscovery([$lockInfo]), ]); }
php
protected function generateLockResponse(LockInfo $lockInfo) { return $this->server->xml->write('{DAV:}prop', [ '{DAV:}lockdiscovery' => new DAV\Xml\Property\LockDiscovery([$lockInfo]), ]); }
[ "protected", "function", "generateLockResponse", "(", "LockInfo", "$", "lockInfo", ")", "{", "return", "$", "this", "->", "server", "->", "xml", "->", "write", "(", "'{DAV:}prop'", ",", "[", "'{DAV:}lockdiscovery'", "=>", "new", "DAV", "\\", "Xml", "\\", "Pr...
Generates the response for successful LOCK requests. @param LockInfo $lockInfo @return string
[ "Generates", "the", "response", "for", "successful", "LOCK", "requests", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Plugin.php#L387-L392
train
sabre-io/dav
lib/DAV/Locks/Plugin.php
Plugin.parseLockRequest
protected function parseLockRequest($body) { $result = $this->server->xml->expect( '{DAV:}lockinfo', $body ); $lockInfo = new LockInfo(); $lockInfo->owner = $result->owner; $lockInfo->token = DAV\UUIDUtil::getUUID(); $lockInfo->scope = $result->scope; return $lockInfo; }
php
protected function parseLockRequest($body) { $result = $this->server->xml->expect( '{DAV:}lockinfo', $body ); $lockInfo = new LockInfo(); $lockInfo->owner = $result->owner; $lockInfo->token = DAV\UUIDUtil::getUUID(); $lockInfo->scope = $result->scope; return $lockInfo; }
[ "protected", "function", "parseLockRequest", "(", "$", "body", ")", "{", "$", "result", "=", "$", "this", "->", "server", "->", "xml", "->", "expect", "(", "'{DAV:}lockinfo'", ",", "$", "body", ")", ";", "$", "lockInfo", "=", "new", "LockInfo", "(", ")...
Parses a webdav lock xml body, and returns a new Sabre\DAV\Locks\LockInfo object. @param string $body @return LockInfo
[ "Parses", "a", "webdav", "lock", "xml", "body", "and", "returns", "a", "new", "Sabre", "\\", "DAV", "\\", "Locks", "\\", "LockInfo", "object", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Plugin.php#L529-L543
train
sabre-io/dav
lib/DAV/FS/File.php
File.getETag
public function getETag() { return '"'.sha1( fileinode($this->path). filesize($this->path). filemtime($this->path) ).'"'; }
php
public function getETag() { return '"'.sha1( fileinode($this->path). filesize($this->path). filemtime($this->path) ).'"'; }
[ "public", "function", "getETag", "(", ")", "{", "return", "'\"'", ".", "sha1", "(", "fileinode", "(", "$", "this", "->", "path", ")", ".", "filesize", "(", "$", "this", "->", "path", ")", ".", "filemtime", "(", "$", "this", "->", "path", ")", ")", ...
Returns the ETag for a file. An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change. The ETag is an arbitrary string, but MUST be surrounded by double-quotes. Return null if the ETag can not effectively be determined @return mixed
[ "Returns", "the", "ETag", "for", "a", "file", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/FS/File.php#L67-L74
train
sabre-io/dav
lib/CalDAV/CalendarObject.php
CalendarObject.put
public function put($calendarData) { if (is_resource($calendarData)) { $calendarData = stream_get_contents($calendarData); } $etag = $this->caldavBackend->updateCalendarObject($this->calendarInfo['id'], $this->objectData['uri'], $calendarData); $this->objectData['calendardata'] = $calendarData; $this->objectData['etag'] = $etag; return $etag; }
php
public function put($calendarData) { if (is_resource($calendarData)) { $calendarData = stream_get_contents($calendarData); } $etag = $this->caldavBackend->updateCalendarObject($this->calendarInfo['id'], $this->objectData['uri'], $calendarData); $this->objectData['calendardata'] = $calendarData; $this->objectData['etag'] = $etag; return $etag; }
[ "public", "function", "put", "(", "$", "calendarData", ")", "{", "if", "(", "is_resource", "(", "$", "calendarData", ")", ")", "{", "$", "calendarData", "=", "stream_get_contents", "(", "$", "calendarData", ")", ";", "}", "$", "etag", "=", "$", "this", ...
Updates the ICalendar-formatted object. @param string|resource $calendarData @return string
[ "Updates", "the", "ICalendar", "-", "formatted", "object", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/CalendarObject.php#L102-L112
train
sabre-io/dav
lib/CalDAV/CalendarObject.php
CalendarObject.getContentType
public function getContentType() { $mime = 'text/calendar; charset=utf-8'; if (isset($this->objectData['component']) && $this->objectData['component']) { $mime .= '; component='.$this->objectData['component']; } return $mime; }
php
public function getContentType() { $mime = 'text/calendar; charset=utf-8'; if (isset($this->objectData['component']) && $this->objectData['component']) { $mime .= '; component='.$this->objectData['component']; } return $mime; }
[ "public", "function", "getContentType", "(", ")", "{", "$", "mime", "=", "'text/calendar; charset=utf-8'", ";", "if", "(", "isset", "(", "$", "this", "->", "objectData", "[", "'component'", "]", ")", "&&", "$", "this", "->", "objectData", "[", "'component'",...
Returns the mime content-type. @return string
[ "Returns", "the", "mime", "content", "-", "type", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/CalendarObject.php#L127-L135
train
sabre-io/dav
lib/CalDAV/Notifications/Collection.php
Collection.getChildren
public function getChildren() { $children = []; $notifications = $this->caldavBackend->getNotificationsForPrincipal($this->principalUri); foreach ($notifications as $notification) { $children[] = new Node( $this->caldavBackend, $this->principalUri, $notification ); } return $children; }
php
public function getChildren() { $children = []; $notifications = $this->caldavBackend->getNotificationsForPrincipal($this->principalUri); foreach ($notifications as $notification) { $children[] = new Node( $this->caldavBackend, $this->principalUri, $notification ); } return $children; }
[ "public", "function", "getChildren", "(", ")", "{", "$", "children", "=", "[", "]", ";", "$", "notifications", "=", "$", "this", "->", "caldavBackend", "->", "getNotificationsForPrincipal", "(", "$", "this", "->", "principalUri", ")", ";", "foreach", "(", ...
Returns all notifications for a principal. @return array
[ "Returns", "all", "notifications", "for", "a", "principal", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Notifications/Collection.php#L60-L74
train
sabre-io/dav
lib/DAV/StringUtil.php
StringUtil.textMatch
public static function textMatch($haystack, $needle, $collation, $matchType = 'contains') { switch ($collation) { case 'i;ascii-casemap': // default strtolower takes locale into consideration // we don't want this. $haystack = str_replace(range('a', 'z'), range('A', 'Z'), $haystack); $needle = str_replace(range('a', 'z'), range('A', 'Z'), $needle); break; case 'i;octet': // Do nothing break; case 'i;unicode-casemap': $haystack = mb_strtoupper($haystack, 'UTF-8'); $needle = mb_strtoupper($needle, 'UTF-8'); break; default: throw new Exception\BadRequest('Collation type: '.$collation.' is not supported'); } switch ($matchType) { case 'contains': return false !== strpos($haystack, $needle); case 'equals': return $haystack === $needle; case 'starts-with': return 0 === strpos($haystack, $needle); case 'ends-with': return strrpos($haystack, $needle) === strlen($haystack) - strlen($needle); default: throw new Exception\BadRequest('Match-type: '.$matchType.' is not supported'); } }
php
public static function textMatch($haystack, $needle, $collation, $matchType = 'contains') { switch ($collation) { case 'i;ascii-casemap': // default strtolower takes locale into consideration // we don't want this. $haystack = str_replace(range('a', 'z'), range('A', 'Z'), $haystack); $needle = str_replace(range('a', 'z'), range('A', 'Z'), $needle); break; case 'i;octet': // Do nothing break; case 'i;unicode-casemap': $haystack = mb_strtoupper($haystack, 'UTF-8'); $needle = mb_strtoupper($needle, 'UTF-8'); break; default: throw new Exception\BadRequest('Collation type: '.$collation.' is not supported'); } switch ($matchType) { case 'contains': return false !== strpos($haystack, $needle); case 'equals': return $haystack === $needle; case 'starts-with': return 0 === strpos($haystack, $needle); case 'ends-with': return strrpos($haystack, $needle) === strlen($haystack) - strlen($needle); default: throw new Exception\BadRequest('Match-type: '.$matchType.' is not supported'); } }
[ "public", "static", "function", "textMatch", "(", "$", "haystack", ",", "$", "needle", ",", "$", "collation", ",", "$", "matchType", "=", "'contains'", ")", "{", "switch", "(", "$", "collation", ")", "{", "case", "'i;ascii-casemap'", ":", "// default strtolo...
Checks if a needle occurs in a haystack ;). @param string $haystack @param string $needle @param string $collation @param string $matchType @return bool
[ "Checks", "if", "a", "needle", "occurs", "in", "a", "haystack", ";", ")", "." ]
44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/StringUtil.php#L30-L65
train