repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
39
1.84M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
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", "::", "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", ";", "}", ")", ";", "}" ]
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", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L99-L139
sabre-io/dav
lib/CardDAV/Backend/PDO.php
PDO.createAddressBook
public function createAddressBook($principalUri, $url, array $properties) { $values = [ 'displayname' => null, 'description' => null, 'principaluri' => $principalUri, 'uri' => $url, ]; foreach ($properties as $property => $newValue) { switch ($property) { case '{DAV:}displayname': $values['displayname'] = $newValue; break; case '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description': $values['description'] = $newValue; break; default: throw new DAV\Exception\BadRequest('Unknown property: '.$property); } } $query = 'INSERT INTO '.$this->addressBooksTableName.' (uri, displayname, description, principaluri, synctoken) VALUES (:uri, :displayname, :description, :principaluri, 1)'; $stmt = $this->pdo->prepare($query); $stmt->execute($values); return $this->pdo->lastInsertId( $this->addressBooksTableName.'_id_seq' ); }
php
public function createAddressBook($principalUri, $url, array $properties) { $values = [ 'displayname' => null, 'description' => null, 'principaluri' => $principalUri, 'uri' => $url, ]; foreach ($properties as $property => $newValue) { switch ($property) { case '{DAV:}displayname': $values['displayname'] = $newValue; break; case '{'.CardDAV\Plugin::NS_CARDDAV.'}addressbook-description': $values['description'] = $newValue; break; default: throw new DAV\Exception\BadRequest('Unknown property: '.$property); } } $query = 'INSERT INTO '.$this->addressBooksTableName.' (uri, displayname, description, principaluri, synctoken) VALUES (:uri, :displayname, :description, :principaluri, 1)'; $stmt = $this->pdo->prepare($query); $stmt->execute($values); return $this->pdo->lastInsertId( $this->addressBooksTableName.'_id_seq' ); }
[ "public", "function", "createAddressBook", "(", "$", "principalUri", ",", "$", "url", ",", "array", "$", "properties", ")", "{", "$", "values", "=", "[", "'displayname'", "=>", "null", ",", "'description'", "=>", "null", ",", "'principaluri'", "=>", "$", "principalUri", ",", "'uri'", "=>", "$", "url", ",", "]", ";", "foreach", "(", "$", "properties", "as", "$", "property", "=>", "$", "newValue", ")", "{", "switch", "(", "$", "property", ")", "{", "case", "'{DAV:}displayname'", ":", "$", "values", "[", "'displayname'", "]", "=", "$", "newValue", ";", "break", ";", "case", "'{'", ".", "CardDAV", "\\", "Plugin", "::", "NS_CARDDAV", ".", "'}addressbook-description'", ":", "$", "values", "[", "'description'", "]", "=", "$", "newValue", ";", "break", ";", "default", ":", "throw", "new", "DAV", "\\", "Exception", "\\", "BadRequest", "(", "'Unknown property: '", ".", "$", "property", ")", ";", "}", "}", "$", "query", "=", "'INSERT INTO '", ".", "$", "this", "->", "addressBooksTableName", ".", "' (uri, displayname, description, principaluri, synctoken) VALUES (:uri, :displayname, :description, :principaluri, 1)'", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "$", "query", ")", ";", "$", "stmt", "->", "execute", "(", "$", "values", ")", ";", "return", "$", "this", "->", "pdo", "->", "lastInsertId", "(", "$", "this", "->", "addressBooksTableName", ".", "'_id_seq'", ")", ";", "}" ]
Creates a new address book. @param string $principalUri @param string $url just the 'basename' of the url @param array $properties @return int Last insert id
[ "Creates", "a", "new", "address", "book", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L150-L179
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 = ?'", ")", ";", "$", "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", "]", ")", ";", "}" ]
Deletes an entire addressbook and all its contents. @param int $addressBookId
[ "Deletes", "an", "entire", "addressbook", "and", "all", "its", "contents", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L186-L196
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 = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "addressbookId", "]", ")", ";", "$", "result", "=", "[", "]", ";", "while", "(", "$", "row", "=", "$", "stmt", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ")", "{", "$", "row", "[", "'etag'", "]", "=", "'\"'", ".", "$", "row", "[", "'etag'", "]", ".", "'\"'", ";", "$", "row", "[", "'lastmodified'", "]", "=", "(", "int", ")", "$", "row", "[", "'lastmodified'", "]", ";", "$", "result", "[", "]", "=", "$", "row", ";", "}", "return", "$", "result", ";", "}" ]
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", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L218-L231
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", ".", "' 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", ";", "}" ]
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", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L246-L261
sabre-io/dav
lib/CardDAV/Backend/PDO.php
PDO.getMultipleCards
public function getMultipleCards($addressBookId, array $uris) { $query = 'SELECT id, uri, lastmodified, etag, size, carddata FROM '.$this->cardsTableName.' WHERE addressbookid = ? AND uri IN ('; // Inserting a whole bunch of question marks $query .= implode(',', array_fill(0, count($uris), '?')); $query .= ')'; $stmt = $this->pdo->prepare($query); $stmt->execute(array_merge([$addressBookId], $uris)); $result = []; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $row['etag'] = '"'.$row['etag'].'"'; $row['lastmodified'] = (int) $row['lastmodified']; $result[] = $row; } return $result; }
php
public function getMultipleCards($addressBookId, array $uris) { $query = 'SELECT id, uri, lastmodified, etag, size, carddata FROM '.$this->cardsTableName.' WHERE addressbookid = ? AND uri IN ('; $query .= implode(',', array_fill(0, count($uris), '?')); $query .= ')'; $stmt = $this->pdo->prepare($query); $stmt->execute(array_merge([$addressBookId], $uris)); $result = []; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $row['etag'] = '"'.$row['etag'].'"'; $row['lastmodified'] = (int) $row['lastmodified']; $result[] = $row; } return $result; }
[ "public", "function", "getMultipleCards", "(", "$", "addressBookId", ",", "array", "$", "uris", ")", "{", "$", "query", "=", "'SELECT id, uri, lastmodified, etag, size, carddata FROM '", ".", "$", "this", "->", "cardsTableName", ".", "' WHERE addressbookid = ? AND uri IN ('", ";", "// Inserting a whole bunch of question marks", "$", "query", ".=", "implode", "(", "','", ",", "array_fill", "(", "0", ",", "count", "(", "$", "uris", ")", ",", "'?'", ")", ")", ";", "$", "query", ".=", "')'", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "$", "query", ")", ";", "$", "stmt", "->", "execute", "(", "array_merge", "(", "[", "$", "addressBookId", "]", ",", "$", "uris", ")", ")", ";", "$", "result", "=", "[", "]", ";", "while", "(", "$", "row", "=", "$", "stmt", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ")", "{", "$", "row", "[", "'etag'", "]", "=", "'\"'", ".", "$", "row", "[", "'etag'", "]", ".", "'\"'", ";", "$", "row", "[", "'lastmodified'", "]", "=", "(", "int", ")", "$", "row", "[", "'lastmodified'", "]", ";", "$", "result", "[", "]", "=", "$", "row", ";", "}", "return", "$", "result", ";", "}" ]
Returns a list of cards. This method should work identical to getCard, but instead return all the cards in the list as an array. If the backend supports this, it may allow for some speed-ups. @param mixed $addressBookId @param array $uris @return array
[ "Returns", "a", "list", "of", "cards", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L276-L293
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", ".", "' (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", ".", "'\"'", ";", "}" ]
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", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L321-L339
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 = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "addressBookId", ",", "$", "cardUri", "]", ")", ";", "$", "this", "->", "addChange", "(", "$", "addressBookId", ",", "$", "cardUri", ",", "3", ")", ";", "return", "1", "===", "$", "stmt", "->", "rowCount", "(", ")", ";", "}" ]
Deletes a card. @param mixed $addressBookId @param string $cardUri @return bool
[ "Deletes", "a", "card", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L394-L402
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) { $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; } $stmt = $this->pdo->prepare($query); $stmt->execute([$syncToken, $currentToken, $addressBookId]); $changes = []; 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 { $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", "(", "'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", ";", "}" ]
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", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L461-L520
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", ".", "' (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", ",", "]", ")", ";", "}" ]
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", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Backend/PDO.php#L529-L542
sabre-io/dav
lib/CalDAV/Backend/SimplePDO.php
SimplePDO.getCalendarsForUser
public function getCalendarsForUser($principalUri) { // Making fields a comma-delimited list $stmt = $this->pdo->prepare('SELECT id, uri FROM simple_calendars WHERE principaluri = ? ORDER BY id ASC'); $stmt->execute([$principalUri]); $calendars = []; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $calendars[] = [ 'id' => $row['id'], 'uri' => $row['uri'], 'principaluri' => $principalUri, ]; } return $calendars; }
php
public function getCalendarsForUser($principalUri) { $stmt = $this->pdo->prepare('SELECT id, uri FROM simple_calendars WHERE principaluri = ? ORDER BY id ASC'); $stmt->execute([$principalUri]); $calendars = []; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $calendars[] = [ 'id' => $row['id'], 'uri' => $row['uri'], 'principaluri' => $principalUri, ]; } return $calendars; }
[ "public", "function", "getCalendarsForUser", "(", "$", "principalUri", ")", "{", "// Making fields a comma-delimited list", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'SELECT id, uri FROM simple_calendars WHERE principaluri = ? ORDER BY id ASC'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "principalUri", "]", ")", ";", "$", "calendars", "=", "[", "]", ";", "while", "(", "$", "row", "=", "$", "stmt", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ")", "{", "$", "calendars", "[", "]", "=", "[", "'id'", "=>", "$", "row", "[", "'id'", "]", ",", "'uri'", "=>", "$", "row", "[", "'uri'", "]", ",", "'principaluri'", "=>", "$", "principalUri", ",", "]", ";", "}", "return", "$", "calendars", ";", "}" ]
Returns a list of calendars for a principal. Every project is an array with the following keys: * id, a unique id that will be used by other functions to modify the calendar. This can be the same as the uri or a database key. * uri. This is just the 'base uri' or 'filename' of the calendar. * principaluri. The owner of the calendar. Almost always the same as principalUri passed to this method. Furthermore it can contain webdav properties in clark notation. A very common one is '{DAV:}displayname'. Many clients also require: {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set For this property, you can just return an instance of Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet. If you return {http://sabredav.org/ns}read-only and set the value to 1, ACL will automatically be put in read-only mode. @param string $principalUri @return array
[ "Returns", "a", "list", "of", "calendars", "for", "a", "principal", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/SimplePDO.php#L80-L96
sabre-io/dav
lib/CalDAV/Backend/SimplePDO.php
SimplePDO.createCalendar
public function createCalendar($principalUri, $calendarUri, array $properties) { $stmt = $this->pdo->prepare('INSERT INTO simple_calendars (principaluri, uri) VALUES (?, ?)'); $stmt->execute([$principalUri, $calendarUri]); return $this->pdo->lastInsertId(); }
php
public function createCalendar($principalUri, $calendarUri, array $properties) { $stmt = $this->pdo->prepare('INSERT INTO simple_calendars (principaluri, uri) VALUES (?, ?)'); $stmt->execute([$principalUri, $calendarUri]); return $this->pdo->lastInsertId(); }
[ "public", "function", "createCalendar", "(", "$", "principalUri", ",", "$", "calendarUri", ",", "array", "$", "properties", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'INSERT INTO simple_calendars (principaluri, uri) VALUES (?, ?)'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "principalUri", ",", "$", "calendarUri", "]", ")", ";", "return", "$", "this", "->", "pdo", "->", "lastInsertId", "(", ")", ";", "}" ]
Creates a new calendar for a principal. If the creation was a success, an id must be returned that can be used to reference this calendar in other methods, such as updateCalendar. @param string $principalUri @param string $calendarUri @param array $properties @return string
[ "Creates", "a", "new", "calendar", "for", "a", "principal", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/SimplePDO.php#L110-L116
sabre-io/dav
lib/CalDAV/Backend/SimplePDO.php
SimplePDO.deleteCalendar
public function deleteCalendar($calendarId) { $stmt = $this->pdo->prepare('DELETE FROM simple_calendarobjects WHERE calendarid = ?'); $stmt->execute([$calendarId]); $stmt = $this->pdo->prepare('DELETE FROM simple_calendars WHERE id = ?'); $stmt->execute([$calendarId]); }
php
public function deleteCalendar($calendarId) { $stmt = $this->pdo->prepare('DELETE FROM simple_calendarobjects WHERE calendarid = ?'); $stmt->execute([$calendarId]); $stmt = $this->pdo->prepare('DELETE FROM simple_calendars WHERE id = ?'); $stmt->execute([$calendarId]); }
[ "public", "function", "deleteCalendar", "(", "$", "calendarId", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'DELETE FROM simple_calendarobjects WHERE calendarid = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "calendarId", "]", ")", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'DELETE FROM simple_calendars WHERE id = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "calendarId", "]", ")", ";", "}" ]
Delete a calendar and all it's objects. @param string $calendarId
[ "Delete", "a", "calendar", "and", "all", "it", "s", "objects", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/SimplePDO.php#L123-L130
sabre-io/dav
lib/CalDAV/Backend/SimplePDO.php
SimplePDO.getCalendarObjects
public function getCalendarObjects($calendarId) { $stmt = $this->pdo->prepare('SELECT id, uri, calendardata FROM simple_calendarobjects WHERE calendarid = ?'); $stmt->execute([$calendarId]); $result = []; foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { $result[] = [ 'id' => $row['id'], 'uri' => $row['uri'], 'etag' => '"'.md5($row['calendardata']).'"', 'calendarid' => $calendarId, 'size' => strlen($row['calendardata']), 'calendardata' => $row['calendardata'], ]; } return $result; }
php
public function getCalendarObjects($calendarId) { $stmt = $this->pdo->prepare('SELECT id, uri, calendardata FROM simple_calendarobjects WHERE calendarid = ?'); $stmt->execute([$calendarId]); $result = []; foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { $result[] = [ 'id' => $row['id'], 'uri' => $row['uri'], 'etag' => '"'.md5($row['calendardata']).'"', 'calendarid' => $calendarId, 'size' => strlen($row['calendardata']), 'calendardata' => $row['calendardata'], ]; } return $result; }
[ "public", "function", "getCalendarObjects", "(", "$", "calendarId", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'SELECT id, uri, calendardata FROM simple_calendarobjects WHERE calendarid = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "calendarId", "]", ")", ";", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "stmt", "->", "fetchAll", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", "as", "$", "row", ")", "{", "$", "result", "[", "]", "=", "[", "'id'", "=>", "$", "row", "[", "'id'", "]", ",", "'uri'", "=>", "$", "row", "[", "'uri'", "]", ",", "'etag'", "=>", "'\"'", ".", "md5", "(", "$", "row", "[", "'calendardata'", "]", ")", ".", "'\"'", ",", "'calendarid'", "=>", "$", "calendarId", ",", "'size'", "=>", "strlen", "(", "$", "row", "[", "'calendardata'", "]", ")", ",", "'calendardata'", "=>", "$", "row", "[", "'calendardata'", "]", ",", "]", ";", "}", "return", "$", "result", ";", "}" ]
Returns all calendar objects within a calendar. Every item contains an array with the following keys: * calendardata - The iCalendar-compatible calendar data * uri - a unique key which will be used to construct the uri. This can be any arbitrary string, but making sure it ends with '.ics' is a good idea. This is only the basename, or filename, not the full path. * lastmodified - a timestamp of the last modification time * etag - An arbitrary string, surrounded by double-quotes. (e.g.: ' "abcdef"') * size - The size of the calendar objects, in bytes. * component - optional, a string containing the type of object, such as 'vevent' or 'vtodo'. If specified, this will be used to populate the Content-Type header. Note that the etag is optional, but it's highly encouraged to return for speed reasons. The calendardata is also optional. If it's not returned 'getCalendarObject' will be called later, which *is* expected to return calendardata. If neither etag or size are specified, the calendardata will be used/fetched to determine these numbers. If both are specified the amount of times this is needed is reduced by a great degree. @param string $calendarId @return array
[ "Returns", "all", "calendar", "objects", "within", "a", "calendar", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/SimplePDO.php#L164-L182
sabre-io/dav
lib/CalDAV/Backend/SimplePDO.php
SimplePDO.getCalendarObject
public function getCalendarObject($calendarId, $objectUri) { $stmt = $this->pdo->prepare('SELECT id, uri, calendardata FROM simple_calendarobjects WHERE calendarid = ? AND uri = ?'); $stmt->execute([$calendarId, $objectUri]); $row = $stmt->fetch(\PDO::FETCH_ASSOC); if (!$row) { return null; } return [ 'id' => $row['id'], 'uri' => $row['uri'], 'etag' => '"'.md5($row['calendardata']).'"', 'calendarid' => $calendarId, 'size' => strlen($row['calendardata']), 'calendardata' => $row['calendardata'], ]; }
php
public function getCalendarObject($calendarId, $objectUri) { $stmt = $this->pdo->prepare('SELECT id, uri, calendardata FROM simple_calendarobjects WHERE calendarid = ? AND uri = ?'); $stmt->execute([$calendarId, $objectUri]); $row = $stmt->fetch(\PDO::FETCH_ASSOC); if (!$row) { return null; } return [ 'id' => $row['id'], 'uri' => $row['uri'], 'etag' => '"'.md5($row['calendardata']).'"', 'calendarid' => $calendarId, 'size' => strlen($row['calendardata']), 'calendardata' => $row['calendardata'], ]; }
[ "public", "function", "getCalendarObject", "(", "$", "calendarId", ",", "$", "objectUri", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'SELECT id, uri, calendardata FROM simple_calendarobjects WHERE calendarid = ? AND uri = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "calendarId", ",", "$", "objectUri", "]", ")", ";", "$", "row", "=", "$", "stmt", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ";", "if", "(", "!", "$", "row", ")", "{", "return", "null", ";", "}", "return", "[", "'id'", "=>", "$", "row", "[", "'id'", "]", ",", "'uri'", "=>", "$", "row", "[", "'uri'", "]", ",", "'etag'", "=>", "'\"'", ".", "md5", "(", "$", "row", "[", "'calendardata'", "]", ")", ".", "'\"'", ",", "'calendarid'", "=>", "$", "calendarId", ",", "'size'", "=>", "strlen", "(", "$", "row", "[", "'calendardata'", "]", ")", ",", "'calendardata'", "=>", "$", "row", "[", "'calendardata'", "]", ",", "]", ";", "}" ]
Returns information from a single calendar object, based on it's object uri. The object uri is only the basename, or filename and not a full path. The returned array must have the same keys as getCalendarObjects. The 'calendardata' object is required here though, while it's not required for getCalendarObjects. This method must return null if the object did not exist. @param string $calendarId @param string $objectUri @return array|null
[ "Returns", "information", "from", "a", "single", "calendar", "object", "based", "on", "it", "s", "object", "uri", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/SimplePDO.php#L201-L219
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 = ? AND uri = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "calendarData", ",", "$", "calendarId", ",", "$", "objectUri", "]", ")", ";", "return", "'\"'", ".", "md5", "(", "$", "calendarData", ")", ".", "'\"'", ";", "}" ]
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", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/SimplePDO.php#L271-L277
sabre-io/dav
lib/CalDAV/Backend/SimplePDO.php
SimplePDO.deleteCalendarObject
public function deleteCalendarObject($calendarId, $objectUri) { $stmt = $this->pdo->prepare('DELETE FROM simple_calendarobjects WHERE calendarid = ? AND uri = ?'); $stmt->execute([$calendarId, $objectUri]); }
php
public function deleteCalendarObject($calendarId, $objectUri) { $stmt = $this->pdo->prepare('DELETE FROM simple_calendarobjects WHERE calendarid = ? AND uri = ?'); $stmt->execute([$calendarId, $objectUri]); }
[ "public", "function", "deleteCalendarObject", "(", "$", "calendarId", ",", "$", "objectUri", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'DELETE FROM simple_calendarobjects WHERE calendarid = ? AND uri = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "calendarId", ",", "$", "objectUri", "]", ")", ";", "}" ]
Deletes an existing calendar object. The object uri is only the basename, or filename and not a full path. @param string $calendarId @param string $objectUri
[ "Deletes", "an", "existing", "calendar", "object", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/SimplePDO.php#L287-L291
sabre-io/dav
lib/DAV/Auth/Backend/AbstractDigest.php
AbstractDigest.check
public function check(RequestInterface $request, ResponseInterface $response) { $digest = new HTTP\Auth\Digest( $this->realm, $request, $response ); $digest->init(); $username = $digest->getUsername(); // No username was given if (!$username) { return [false, "No 'Authorization: Digest' header found. Either the client didn't send one, or the server is misconfigured"]; } $hash = $this->getDigestHash($this->realm, $username); // If this was false, the user account didn't exist if (false === $hash || is_null($hash)) { return [false, 'Username or password was incorrect']; } if (!is_string($hash)) { throw new DAV\Exception('The returned value from getDigestHash must be a string or null'); } // If this was false, the password or part of the hash was incorrect. if (!$digest->validateA1($hash)) { return [false, 'Username or password was incorrect']; } return [true, $this->principalPrefix.$username]; }
php
public function check(RequestInterface $request, ResponseInterface $response) { $digest = new HTTP\Auth\Digest( $this->realm, $request, $response ); $digest->init(); $username = $digest->getUsername(); if (!$username) { return [false, "No 'Authorization: Digest' header found. Either the client didn't send one, or the server is misconfigured"]; } $hash = $this->getDigestHash($this->realm, $username); if (false === $hash || is_null($hash)) { return [false, 'Username or password was incorrect']; } if (!is_string($hash)) { throw new DAV\Exception('The returned value from getDigestHash must be a string or null'); } if (!$digest->validateA1($hash)) { return [false, 'Username or password was incorrect']; } return [true, $this->principalPrefix.$username]; }
[ "public", "function", "check", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "digest", "=", "new", "HTTP", "\\", "Auth", "\\", "Digest", "(", "$", "this", "->", "realm", ",", "$", "request", ",", "$", "response", ")", ";", "$", "digest", "->", "init", "(", ")", ";", "$", "username", "=", "$", "digest", "->", "getUsername", "(", ")", ";", "// No username was given", "if", "(", "!", "$", "username", ")", "{", "return", "[", "false", ",", "\"No 'Authorization: Digest' header found. Either the client didn't send one, or the server is misconfigured\"", "]", ";", "}", "$", "hash", "=", "$", "this", "->", "getDigestHash", "(", "$", "this", "->", "realm", ",", "$", "username", ")", ";", "// If this was false, the user account didn't exist", "if", "(", "false", "===", "$", "hash", "||", "is_null", "(", "$", "hash", ")", ")", "{", "return", "[", "false", ",", "'Username or password was incorrect'", "]", ";", "}", "if", "(", "!", "is_string", "(", "$", "hash", ")", ")", "{", "throw", "new", "DAV", "\\", "Exception", "(", "'The returned value from getDigestHash must be a string or null'", ")", ";", "}", "// If this was false, the password or part of the hash was incorrect.", "if", "(", "!", "$", "digest", "->", "validateA1", "(", "$", "hash", ")", ")", "{", "return", "[", "false", ",", "'Username or password was incorrect'", "]", ";", "}", "return", "[", "true", ",", "$", "this", "->", "principalPrefix", ".", "$", "username", "]", ";", "}" ]
When this method is called, the backend must check if authentication was successful. The returned value must be one of the following [true, "principals/username"] [false, "reason for failure"] If authentication was successful, it's expected that the authentication backend returns a so-called principal url. Examples of a principal url: principals/admin principals/user1 principals/users/joe principals/uid/123457 If you don't use WebDAV ACL (RFC3744) we recommend that you simply return a string such as: principals/users/[username] @param RequestInterface $request @param ResponseInterface $response @return array
[ "When", "this", "method", "is", "called", "the", "backend", "must", "check", "if", "authentication", "was", "successful", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Auth/Backend/AbstractDigest.php#L97-L128
sabre-io/dav
lib/DAV/Auth/Backend/AbstractDigest.php
AbstractDigest.challenge
public function challenge(RequestInterface $request, ResponseInterface $response) { $auth = new HTTP\Auth\Digest( $this->realm, $request, $response ); $auth->init(); $oldStatus = $response->getStatus() ?: 200; $auth->requireLogin(); // Preventing the digest utility from modifying the http status code, // this should be handled by the main plugin. $response->setStatus($oldStatus); }
php
public function challenge(RequestInterface $request, ResponseInterface $response) { $auth = new HTTP\Auth\Digest( $this->realm, $request, $response ); $auth->init(); $oldStatus = $response->getStatus() ?: 200; $auth->requireLogin(); $response->setStatus($oldStatus); }
[ "public", "function", "challenge", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "auth", "=", "new", "HTTP", "\\", "Auth", "\\", "Digest", "(", "$", "this", "->", "realm", ",", "$", "request", ",", "$", "response", ")", ";", "$", "auth", "->", "init", "(", ")", ";", "$", "oldStatus", "=", "$", "response", "->", "getStatus", "(", ")", "?", ":", "200", ";", "$", "auth", "->", "requireLogin", "(", ")", ";", "// Preventing the digest utility from modifying the http status code,", "// this should be handled by the main plugin.", "$", "response", "->", "setStatus", "(", "$", "oldStatus", ")", ";", "}" ]
This method is called when a user could not be authenticated, and authentication was required for the current request. This gives you the opportunity to set authentication headers. The 401 status code will already be set. In this case of Basic Auth, this would for example mean that the following header needs to be set: $response->addHeader('WWW-Authenticate', 'Basic realm=SabreDAV'); Keep in mind that in the case of multiple authentication backends, other WWW-Authenticate headers may already have been set, and you'll want to append your own WWW-Authenticate header instead of overwriting the existing one. @param RequestInterface $request @param ResponseInterface $response
[ "This", "method", "is", "called", "when", "a", "user", "could", "not", "be", "authenticated", "and", "authentication", "was", "required", "for", "the", "current", "request", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Auth/Backend/AbstractDigest.php#L150-L165
sabre-io/dav
lib/DAV/Locks/Plugin.php
Plugin.initialize
public function initialize(DAV\Server $server) { $this->server = $server; $this->server->xml->elementMap['{DAV:}lockinfo'] = 'Sabre\\DAV\\Xml\\Request\\Lock'; $server->on('method:LOCK', [$this, 'httpLock']); $server->on('method:UNLOCK', [$this, 'httpUnlock']); $server->on('validateTokens', [$this, 'validateTokens']); $server->on('propFind', [$this, 'propFind']); $server->on('afterUnbind', [$this, 'afterUnbind']); }
php
public function initialize(DAV\Server $server) { $this->server = $server; $this->server->xml->elementMap['{DAV:}lockinfo'] = 'Sabre\\DAV\\Xml\\Request\\Lock'; $server->on('method:LOCK', [$this, 'httpLock']); $server->on('method:UNLOCK', [$this, 'httpUnlock']); $server->on('validateTokens', [$this, 'validateTokens']); $server->on('propFind', [$this, 'propFind']); $server->on('afterUnbind', [$this, 'afterUnbind']); }
[ "public", "function", "initialize", "(", "DAV", "\\", "Server", "$", "server", ")", "{", "$", "this", "->", "server", "=", "$", "server", ";", "$", "this", "->", "server", "->", "xml", "->", "elementMap", "[", "'{DAV:}lockinfo'", "]", "=", "'Sabre\\\\DAV\\\\Xml\\\\Request\\\\Lock'", ";", "$", "server", "->", "on", "(", "'method:LOCK'", ",", "[", "$", "this", ",", "'httpLock'", "]", ")", ";", "$", "server", "->", "on", "(", "'method:UNLOCK'", ",", "[", "$", "this", ",", "'httpUnlock'", "]", ")", ";", "$", "server", "->", "on", "(", "'validateTokens'", ",", "[", "$", "this", ",", "'validateTokens'", "]", ")", ";", "$", "server", "->", "on", "(", "'propFind'", ",", "[", "$", "this", ",", "'propFind'", "]", ")", ";", "$", "server", "->", "on", "(", "'afterUnbind'", ",", "[", "$", "this", ",", "'afterUnbind'", "]", ")", ";", "}" ]
Initializes the plugin. This method is automatically called by the Server class after addPlugin. @param DAV\Server $server
[ "Initializes", "the", "plugin", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Plugin.php#L58-L69
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", "\\", "Xml", "\\", "Property", "\\", "SupportedLock", "(", ")", ";", "}", ")", ";", "$", "propFind", "->", "handle", "(", "'{DAV:}lockdiscovery'", ",", "function", "(", ")", "use", "(", "$", "propFind", ")", "{", "return", "new", "DAV", "\\", "Xml", "\\", "Property", "\\", "LockDiscovery", "(", "$", "this", "->", "getLocks", "(", "$", "propFind", "->", "getPath", "(", ")", ")", ")", ";", "}", ")", ";", "}" ]
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", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Plugin.php#L91-L101
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()) { $existingLock = null; 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 { $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 (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'); } } $lockInfo = $found; if ($uri != $lockInfo->uri) { $uri = $lockInfo->uri; } } if ($timeout = $this->getTimeoutHeader()) { $lockInfo->timeout = $timeout; } $newFile = false; try { $this->server->tree->getNodeForPath($uri); } catch (DAV\Exception\NotFound $e) { $this->server->createFile($uri, fopen('php: $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)); return false; }
[ "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", ";", "}" ]
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", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Plugin.php#L167-L256
sabre-io/dav
lib/DAV/Locks/Plugin.php
Plugin.httpUnlock
public function httpUnlock(RequestInterface $request, ResponseInterface $response) { $lockToken = $request->getHeader('Lock-Token'); // If the locktoken header is not supplied, we need to throw a bad request exception if (!$lockToken) { throw new DAV\Exception\BadRequest('No lock token was supplied'); } $path = $request->getPath(); $locks = $this->getLocks($path); // Windows sometimes forgets to include < and > in the Lock-Token // header if ('<' !== $lockToken[0]) { $lockToken = '<'.$lockToken.'>'; } foreach ($locks as $lock) { if ('<opaquelocktoken:'.$lock->token.'>' == $lockToken) { $this->unlockNode($path, $lock); $response->setHeader('Content-Length', '0'); $response->setStatus(204); // Returning false will break the method chain, and mark the // method as 'handled'. return false; } } // If we got here, it means the locktoken was invalid throw new DAV\Exception\LockTokenMatchesRequestUri(); }
php
public function httpUnlock(RequestInterface $request, ResponseInterface $response) { $lockToken = $request->getHeader('Lock-Token'); if (!$lockToken) { throw new DAV\Exception\BadRequest('No lock token was supplied'); } $path = $request->getPath(); $locks = $this->getLocks($path); if ('<' !== $lockToken[0]) { $lockToken = '<'.$lockToken.'>'; } foreach ($locks as $lock) { if ('<opaquelocktoken:'.$lock->token.'>' == $lockToken) { $this->unlockNode($path, $lock); $response->setHeader('Content-Length', '0'); $response->setStatus(204); return false; } } throw new DAV\Exception\LockTokenMatchesRequestUri(); }
[ "public", "function", "httpUnlock", "(", "RequestInterface", "$", "request", ",", "ResponseInterface", "$", "response", ")", "{", "$", "lockToken", "=", "$", "request", "->", "getHeader", "(", "'Lock-Token'", ")", ";", "// If the locktoken header is not supplied, we need to throw a bad request exception", "if", "(", "!", "$", "lockToken", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "BadRequest", "(", "'No lock token was supplied'", ")", ";", "}", "$", "path", "=", "$", "request", "->", "getPath", "(", ")", ";", "$", "locks", "=", "$", "this", "->", "getLocks", "(", "$", "path", ")", ";", "// Windows sometimes forgets to include < and > in the Lock-Token", "// header", "if", "(", "'<'", "!==", "$", "lockToken", "[", "0", "]", ")", "{", "$", "lockToken", "=", "'<'", ".", "$", "lockToken", ".", "'>'", ";", "}", "foreach", "(", "$", "locks", "as", "$", "lock", ")", "{", "if", "(", "'<opaquelocktoken:'", ".", "$", "lock", "->", "token", ".", "'>'", "==", "$", "lockToken", ")", "{", "$", "this", "->", "unlockNode", "(", "$", "path", ",", "$", "lock", ")", ";", "$", "response", "->", "setHeader", "(", "'Content-Length'", ",", "'0'", ")", ";", "$", "response", "->", "setStatus", "(", "204", ")", ";", "// Returning false will break the method chain, and mark the", "// method as 'handled'.", "return", "false", ";", "}", "}", "// If we got here, it means the locktoken was invalid", "throw", "new", "DAV", "\\", "Exception", "\\", "LockTokenMatchesRequestUri", "(", ")", ";", "}" ]
Unlocks a uri. This WebDAV method allows you to remove a lock from a node. The client should provide a valid locktoken through the Lock-token http header The server should return 204 (No content) on success @param RequestInterface $request @param ResponseInterface $response
[ "Unlocks", "a", "uri", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Plugin.php#L267-L298
sabre-io/dav
lib/DAV/Locks/Plugin.php
Plugin.afterUnbind
public function afterUnbind($path) { $locks = $this->getLocks($path, $includeChildren = true); foreach ($locks as $lock) { $this->unlockNode($path, $lock); } }
php
public function afterUnbind($path) { $locks = $this->getLocks($path, $includeChildren = true); foreach ($locks as $lock) { $this->unlockNode($path, $lock); } }
[ "public", "function", "afterUnbind", "(", "$", "path", ")", "{", "$", "locks", "=", "$", "this", "->", "getLocks", "(", "$", "path", ",", "$", "includeChildren", "=", "true", ")", ";", "foreach", "(", "$", "locks", "as", "$", "lock", ")", "{", "$", "this", "->", "unlockNode", "(", "$", "path", ",", "$", "lock", ")", ";", "}", "}" ]
This method is called after a node is deleted. We use this event to clean up any locks that still exist on the node. @param string $path
[ "This", "method", "is", "called", "after", "a", "node", "is", "deleted", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Plugin.php#L307-L313
sabre-io/dav
lib/DAV/Locks/Plugin.php
Plugin.lockNode
public function lockNode($uri, LockInfo $lockInfo) { if (!$this->server->emit('beforeLock', [$uri, $lockInfo])) { return; } return $this->locksBackend->lock($uri, $lockInfo); }
php
public function lockNode($uri, LockInfo $lockInfo) { if (!$this->server->emit('beforeLock', [$uri, $lockInfo])) { return; } return $this->locksBackend->lock($uri, $lockInfo); }
[ "public", "function", "lockNode", "(", "$", "uri", ",", "LockInfo", "$", "lockInfo", ")", "{", "if", "(", "!", "$", "this", "->", "server", "->", "emit", "(", "'beforeLock'", ",", "[", "$", "uri", ",", "$", "lockInfo", "]", ")", ")", "{", "return", ";", "}", "return", "$", "this", "->", "locksBackend", "->", "lock", "(", "$", "uri", ",", "$", "lockInfo", ")", ";", "}" ]
Locks a uri. All the locking information is supplied in the lockInfo object. The object has a suggested timeout, but this can be safely ignored It is important that if the existing timeout is ignored, the property is overwritten, as this needs to be sent back to the client @param string $uri @param LockInfo $lockInfo @return bool
[ "Locks", "a", "uri", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Plugin.php#L326-L333
sabre-io/dav
lib/DAV/Locks/Plugin.php
Plugin.unlockNode
public function unlockNode($uri, LockInfo $lockInfo) { if (!$this->server->emit('beforeUnlock', [$uri, $lockInfo])) { return; } return $this->locksBackend->unlock($uri, $lockInfo); }
php
public function unlockNode($uri, LockInfo $lockInfo) { if (!$this->server->emit('beforeUnlock', [$uri, $lockInfo])) { return; } return $this->locksBackend->unlock($uri, $lockInfo); }
[ "public", "function", "unlockNode", "(", "$", "uri", ",", "LockInfo", "$", "lockInfo", ")", "{", "if", "(", "!", "$", "this", "->", "server", "->", "emit", "(", "'beforeUnlock'", ",", "[", "$", "uri", ",", "$", "lockInfo", "]", ")", ")", "{", "return", ";", "}", "return", "$", "this", "->", "locksBackend", "->", "unlock", "(", "$", "uri", ",", "$", "lockInfo", ")", ";", "}" ]
Unlocks a uri. This method removes a lock from a uri. It is assumed all the supplied information is correct and verified @param string $uri @param LockInfo $lockInfo @return bool
[ "Unlocks", "a", "uri", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Plugin.php#L345-L352
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", "(", "$", "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", ";", "}" ]
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", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Plugin.php#L361-L378
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", "\\", "Property", "\\", "LockDiscovery", "(", "[", "$", "lockInfo", "]", ")", ",", "]", ")", ";", "}" ]
Generates the response for successful LOCK requests. @param LockInfo $lockInfo @return string
[ "Generates", "the", "response", "for", "successful", "LOCK", "requests", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Plugin.php#L387-L392
sabre-io/dav
lib/DAV/Locks/Plugin.php
Plugin.validateTokens
public function validateTokens(RequestInterface $request, &$conditions) { // First we need to gather a list of locks that must be satisfied. $mustLocks = []; $method = $request->getMethod(); // Methods not in that list are operations that doesn't alter any // resources, and we don't need to check the lock-states for. switch ($method) { case 'DELETE': $mustLocks = array_merge($mustLocks, $this->getLocks( $request->getPath(), true )); break; case 'MKCOL': case 'MKCALENDAR': case 'PROPPATCH': case 'PUT': case 'PATCH': $mustLocks = array_merge($mustLocks, $this->getLocks( $request->getPath(), false )); break; case 'MOVE': $mustLocks = array_merge($mustLocks, $this->getLocks( $request->getPath(), true )); $mustLocks = array_merge($mustLocks, $this->getLocks( $this->server->calculateUri($request->getHeader('Destination')), false )); break; case 'COPY': $mustLocks = array_merge($mustLocks, $this->getLocks( $this->server->calculateUri($request->getHeader('Destination')), false )); break; case 'LOCK': //Temporary measure.. figure out later why this is needed // Here we basically ignore all incoming tokens... foreach ($conditions as $ii => $condition) { foreach ($condition['tokens'] as $jj => $token) { $conditions[$ii]['tokens'][$jj]['validToken'] = true; } } return; } // It's possible that there's identical locks, because of shared // parents. We're removing the duplicates here. $tmp = []; foreach ($mustLocks as $lock) { $tmp[$lock->token] = $lock; } $mustLocks = array_values($tmp); foreach ($conditions as $kk => $condition) { foreach ($condition['tokens'] as $ii => $token) { // Lock tokens always start with opaquelocktoken: if ('opaquelocktoken:' !== substr($token['token'], 0, 16)) { continue; } $checkToken = substr($token['token'], 16); // Looping through our list with locks. foreach ($mustLocks as $jj => $mustLock) { if ($mustLock->token == $checkToken) { // We have a match! // Removing this one from mustlocks unset($mustLocks[$jj]); // Marking the condition as valid. $conditions[$kk]['tokens'][$ii]['validToken'] = true; // Advancing to the next token continue 2; } } // If we got here, it means that there was a // lock-token, but it was not in 'mustLocks'. // // This is an edge-case, as it could mean that token // was specified with a url that was not 'required' to // check. So we're doing one extra lookup to make sure // we really don't know this token. // // This also gets triggered when the user specified a // lock-token that was expired. $oddLocks = $this->getLocks($condition['uri']); foreach ($oddLocks as $oddLock) { if ($oddLock->token === $checkToken) { // We have a hit! $conditions[$kk]['tokens'][$ii]['validToken'] = true; continue 2; } } // If we get all the way here, the lock-token was // really unknown. } } // If there's any locks left in the 'mustLocks' array, it means that // the resource was locked and we must block it. if ($mustLocks) { throw new DAV\Exception\Locked(reset($mustLocks)); } }
php
public function validateTokens(RequestInterface $request, &$conditions) { $mustLocks = []; $method = $request->getMethod(); switch ($method) { case 'DELETE': $mustLocks = array_merge($mustLocks, $this->getLocks( $request->getPath(), true )); break; case 'MKCOL': case 'MKCALENDAR': case 'PROPPATCH': case 'PUT': case 'PATCH': $mustLocks = array_merge($mustLocks, $this->getLocks( $request->getPath(), false )); break; case 'MOVE': $mustLocks = array_merge($mustLocks, $this->getLocks( $request->getPath(), true )); $mustLocks = array_merge($mustLocks, $this->getLocks( $this->server->calculateUri($request->getHeader('Destination')), false )); break; case 'COPY': $mustLocks = array_merge($mustLocks, $this->getLocks( $this->server->calculateUri($request->getHeader('Destination')), false )); break; case 'LOCK': foreach ($conditions as $ii => $condition) { foreach ($condition['tokens'] as $jj => $token) { $conditions[$ii]['tokens'][$jj]['validToken'] = true; } } return; } $tmp = []; foreach ($mustLocks as $lock) { $tmp[$lock->token] = $lock; } $mustLocks = array_values($tmp); foreach ($conditions as $kk => $condition) { foreach ($condition['tokens'] as $ii => $token) { if ('opaquelocktoken:' !== substr($token['token'], 0, 16)) { continue; } $checkToken = substr($token['token'], 16); foreach ($mustLocks as $jj => $mustLock) { if ($mustLock->token == $checkToken) { unset($mustLocks[$jj]); $conditions[$kk]['tokens'][$ii]['validToken'] = true; continue 2; } } $oddLocks = $this->getLocks($condition['uri']); foreach ($oddLocks as $oddLock) { if ($oddLock->token === $checkToken) { $conditions[$kk]['tokens'][$ii]['validToken'] = true; continue 2; } } } } if ($mustLocks) { throw new DAV\Exception\Locked(reset($mustLocks)); } }
[ "public", "function", "validateTokens", "(", "RequestInterface", "$", "request", ",", "&", "$", "conditions", ")", "{", "// First we need to gather a list of locks that must be satisfied.", "$", "mustLocks", "=", "[", "]", ";", "$", "method", "=", "$", "request", "->", "getMethod", "(", ")", ";", "// Methods not in that list are operations that doesn't alter any", "// resources, and we don't need to check the lock-states for.", "switch", "(", "$", "method", ")", "{", "case", "'DELETE'", ":", "$", "mustLocks", "=", "array_merge", "(", "$", "mustLocks", ",", "$", "this", "->", "getLocks", "(", "$", "request", "->", "getPath", "(", ")", ",", "true", ")", ")", ";", "break", ";", "case", "'MKCOL'", ":", "case", "'MKCALENDAR'", ":", "case", "'PROPPATCH'", ":", "case", "'PUT'", ":", "case", "'PATCH'", ":", "$", "mustLocks", "=", "array_merge", "(", "$", "mustLocks", ",", "$", "this", "->", "getLocks", "(", "$", "request", "->", "getPath", "(", ")", ",", "false", ")", ")", ";", "break", ";", "case", "'MOVE'", ":", "$", "mustLocks", "=", "array_merge", "(", "$", "mustLocks", ",", "$", "this", "->", "getLocks", "(", "$", "request", "->", "getPath", "(", ")", ",", "true", ")", ")", ";", "$", "mustLocks", "=", "array_merge", "(", "$", "mustLocks", ",", "$", "this", "->", "getLocks", "(", "$", "this", "->", "server", "->", "calculateUri", "(", "$", "request", "->", "getHeader", "(", "'Destination'", ")", ")", ",", "false", ")", ")", ";", "break", ";", "case", "'COPY'", ":", "$", "mustLocks", "=", "array_merge", "(", "$", "mustLocks", ",", "$", "this", "->", "getLocks", "(", "$", "this", "->", "server", "->", "calculateUri", "(", "$", "request", "->", "getHeader", "(", "'Destination'", ")", ")", ",", "false", ")", ")", ";", "break", ";", "case", "'LOCK'", ":", "//Temporary measure.. figure out later why this is needed", "// Here we basically ignore all incoming tokens...", "foreach", "(", "$", "conditions", "as", "$", "ii", "=>", "$", "condition", ")", "{", "foreach", "(", "$", "condition", "[", "'tokens'", "]", "as", "$", "jj", "=>", "$", "token", ")", "{", "$", "conditions", "[", "$", "ii", "]", "[", "'tokens'", "]", "[", "$", "jj", "]", "[", "'validToken'", "]", "=", "true", ";", "}", "}", "return", ";", "}", "// It's possible that there's identical locks, because of shared", "// parents. We're removing the duplicates here.", "$", "tmp", "=", "[", "]", ";", "foreach", "(", "$", "mustLocks", "as", "$", "lock", ")", "{", "$", "tmp", "[", "$", "lock", "->", "token", "]", "=", "$", "lock", ";", "}", "$", "mustLocks", "=", "array_values", "(", "$", "tmp", ")", ";", "foreach", "(", "$", "conditions", "as", "$", "kk", "=>", "$", "condition", ")", "{", "foreach", "(", "$", "condition", "[", "'tokens'", "]", "as", "$", "ii", "=>", "$", "token", ")", "{", "// Lock tokens always start with opaquelocktoken:", "if", "(", "'opaquelocktoken:'", "!==", "substr", "(", "$", "token", "[", "'token'", "]", ",", "0", ",", "16", ")", ")", "{", "continue", ";", "}", "$", "checkToken", "=", "substr", "(", "$", "token", "[", "'token'", "]", ",", "16", ")", ";", "// Looping through our list with locks.", "foreach", "(", "$", "mustLocks", "as", "$", "jj", "=>", "$", "mustLock", ")", "{", "if", "(", "$", "mustLock", "->", "token", "==", "$", "checkToken", ")", "{", "// We have a match!", "// Removing this one from mustlocks", "unset", "(", "$", "mustLocks", "[", "$", "jj", "]", ")", ";", "// Marking the condition as valid.", "$", "conditions", "[", "$", "kk", "]", "[", "'tokens'", "]", "[", "$", "ii", "]", "[", "'validToken'", "]", "=", "true", ";", "// Advancing to the next token", "continue", "2", ";", "}", "}", "// If we got here, it means that there was a", "// lock-token, but it was not in 'mustLocks'.", "//", "// This is an edge-case, as it could mean that token", "// was specified with a url that was not 'required' to", "// check. So we're doing one extra lookup to make sure", "// we really don't know this token.", "//", "// This also gets triggered when the user specified a", "// lock-token that was expired.", "$", "oddLocks", "=", "$", "this", "->", "getLocks", "(", "$", "condition", "[", "'uri'", "]", ")", ";", "foreach", "(", "$", "oddLocks", "as", "$", "oddLock", ")", "{", "if", "(", "$", "oddLock", "->", "token", "===", "$", "checkToken", ")", "{", "// We have a hit!", "$", "conditions", "[", "$", "kk", "]", "[", "'tokens'", "]", "[", "$", "ii", "]", "[", "'validToken'", "]", "=", "true", ";", "continue", "2", ";", "}", "}", "// If we get all the way here, the lock-token was", "// really unknown.", "}", "}", "// If there's any locks left in the 'mustLocks' array, it means that", "// the resource was locked and we must block it.", "if", "(", "$", "mustLocks", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "Locked", "(", "reset", "(", "$", "mustLocks", ")", ")", ";", "}", "}" ]
The validateTokens event is triggered before every request. It's a moment where this plugin can check all the supplied lock tokens in the If: header, and check if they are valid. In addition, it will also ensure that it checks any missing lokens that must be present in the request, and reject requests without the proper tokens. @param RequestInterface $request @param mixed $conditions
[ "The", "validateTokens", "event", "is", "triggered", "before", "every", "request", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Plugin.php#L407-L520
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", "(", ")", ";", "$", "lockInfo", "->", "owner", "=", "$", "result", "->", "owner", ";", "$", "lockInfo", "->", "token", "=", "DAV", "\\", "UUIDUtil", "::", "getUUID", "(", ")", ";", "$", "lockInfo", "->", "scope", "=", "$", "result", "->", "scope", ";", "return", "$", "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", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Plugin.php#L529-L543
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", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/FS/File.php#L67-L74
sabre-io/dav
lib/DAVACL/FS/Collection.php
Collection.getChild
public function getChild($name) { $path = $this->path.'/'.$name; if (!file_exists($path)) { throw new NotFound('File could not be located'); } if ('.' == $name || '..' == $name) { throw new Forbidden('Permission denied to . and ..'); } if (is_dir($path)) { return new self($path, $this->acl, $this->owner); } else { return new File($path, $this->acl, $this->owner); } }
php
public function getChild($name) { $path = $this->path.'/'.$name; if (!file_exists($path)) { throw new NotFound('File could not be located'); } if ('.' == $name || '..' == $name) { throw new Forbidden('Permission denied to . and ..'); } if (is_dir($path)) { return new self($path, $this->acl, $this->owner); } else { return new File($path, $this->acl, $this->owner); } }
[ "public", "function", "getChild", "(", "$", "name", ")", "{", "$", "path", "=", "$", "this", "->", "path", ".", "'/'", ".", "$", "name", ";", "if", "(", "!", "file_exists", "(", "$", "path", ")", ")", "{", "throw", "new", "NotFound", "(", "'File could not be located'", ")", ";", "}", "if", "(", "'.'", "==", "$", "name", "||", "'..'", "==", "$", "name", ")", "{", "throw", "new", "Forbidden", "(", "'Permission denied to . and ..'", ")", ";", "}", "if", "(", "is_dir", "(", "$", "path", ")", ")", "{", "return", "new", "self", "(", "$", "path", ",", "$", "this", "->", "acl", ",", "$", "this", "->", "owner", ")", ";", "}", "else", "{", "return", "new", "File", "(", "$", "path", ",", "$", "this", "->", "acl", ",", "$", "this", "->", "owner", ")", ";", "}", "}" ]
Returns a specific child node, referenced by its name. This method must throw Sabre\DAV\Exception\NotFound if the node does not exist. @param string $name @throws NotFound @return \Sabre\DAV\INode
[ "Returns", "a", "specific", "child", "node", "referenced", "by", "its", "name", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/FS/Collection.php#L64-L79
sabre-io/dav
lib/CalDAV/Xml/Property/Invite.php
Invite.xmlSerialize
public function xmlSerialize(Writer $writer) { $cs = '{'.Plugin::NS_CALENDARSERVER.'}'; foreach ($this->sharees as $sharee) { if (DAV\Sharing\Plugin::ACCESS_SHAREDOWNER === $sharee->access) { $writer->startElement($cs.'organizer'); } else { $writer->startElement($cs.'user'); switch ($sharee->inviteStatus) { case DAV\Sharing\Plugin::INVITE_ACCEPTED: $writer->writeElement($cs.'invite-accepted'); break; case DAV\Sharing\Plugin::INVITE_DECLINED: $writer->writeElement($cs.'invite-declined'); break; case DAV\Sharing\Plugin::INVITE_NORESPONSE: $writer->writeElement($cs.'invite-noresponse'); break; case DAV\Sharing\Plugin::INVITE_INVALID: $writer->writeElement($cs.'invite-invalid'); break; } $writer->startElement($cs.'access'); switch ($sharee->access) { case DAV\Sharing\Plugin::ACCESS_READWRITE: $writer->writeElement($cs.'read-write'); break; case DAV\Sharing\Plugin::ACCESS_READ: $writer->writeElement($cs.'read'); break; } $writer->endElement(); // access } $href = new DAV\Xml\Property\Href($sharee->href); $href->xmlSerialize($writer); if (isset($sharee->properties['{DAV:}displayname'])) { $writer->writeElement($cs.'common-name', $sharee->properties['{DAV:}displayname']); } if ($sharee->comment) { $writer->writeElement($cs.'summary', $sharee->comment); } $writer->endElement(); // organizer or user } }
php
public function xmlSerialize(Writer $writer) { $cs = '{'.Plugin::NS_CALENDARSERVER.'}'; foreach ($this->sharees as $sharee) { if (DAV\Sharing\Plugin::ACCESS_SHAREDOWNER === $sharee->access) { $writer->startElement($cs.'organizer'); } else { $writer->startElement($cs.'user'); switch ($sharee->inviteStatus) { case DAV\Sharing\Plugin::INVITE_ACCEPTED: $writer->writeElement($cs.'invite-accepted'); break; case DAV\Sharing\Plugin::INVITE_DECLINED: $writer->writeElement($cs.'invite-declined'); break; case DAV\Sharing\Plugin::INVITE_NORESPONSE: $writer->writeElement($cs.'invite-noresponse'); break; case DAV\Sharing\Plugin::INVITE_INVALID: $writer->writeElement($cs.'invite-invalid'); break; } $writer->startElement($cs.'access'); switch ($sharee->access) { case DAV\Sharing\Plugin::ACCESS_READWRITE: $writer->writeElement($cs.'read-write'); break; case DAV\Sharing\Plugin::ACCESS_READ: $writer->writeElement($cs.'read'); break; } $writer->endElement(); } $href = new DAV\Xml\Property\Href($sharee->href); $href->xmlSerialize($writer); if (isset($sharee->properties['{DAV:}displayname'])) { $writer->writeElement($cs.'common-name', $sharee->properties['{DAV:}displayname']); } if ($sharee->comment) { $writer->writeElement($cs.'summary', $sharee->comment); } $writer->endElement(); } }
[ "public", "function", "xmlSerialize", "(", "Writer", "$", "writer", ")", "{", "$", "cs", "=", "'{'", ".", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}'", ";", "foreach", "(", "$", "this", "->", "sharees", "as", "$", "sharee", ")", "{", "if", "(", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "ACCESS_SHAREDOWNER", "===", "$", "sharee", "->", "access", ")", "{", "$", "writer", "->", "startElement", "(", "$", "cs", ".", "'organizer'", ")", ";", "}", "else", "{", "$", "writer", "->", "startElement", "(", "$", "cs", ".", "'user'", ")", ";", "switch", "(", "$", "sharee", "->", "inviteStatus", ")", "{", "case", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "INVITE_ACCEPTED", ":", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'invite-accepted'", ")", ";", "break", ";", "case", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "INVITE_DECLINED", ":", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'invite-declined'", ")", ";", "break", ";", "case", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "INVITE_NORESPONSE", ":", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'invite-noresponse'", ")", ";", "break", ";", "case", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "INVITE_INVALID", ":", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'invite-invalid'", ")", ";", "break", ";", "}", "$", "writer", "->", "startElement", "(", "$", "cs", ".", "'access'", ")", ";", "switch", "(", "$", "sharee", "->", "access", ")", "{", "case", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "ACCESS_READWRITE", ":", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'read-write'", ")", ";", "break", ";", "case", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "ACCESS_READ", ":", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'read'", ")", ";", "break", ";", "}", "$", "writer", "->", "endElement", "(", ")", ";", "// access", "}", "$", "href", "=", "new", "DAV", "\\", "Xml", "\\", "Property", "\\", "Href", "(", "$", "sharee", "->", "href", ")", ";", "$", "href", "->", "xmlSerialize", "(", "$", "writer", ")", ";", "if", "(", "isset", "(", "$", "sharee", "->", "properties", "[", "'{DAV:}displayname'", "]", ")", ")", "{", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'common-name'", ",", "$", "sharee", "->", "properties", "[", "'{DAV:}displayname'", "]", ")", ";", "}", "if", "(", "$", "sharee", "->", "comment", ")", "{", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'summary'", ",", "$", "sharee", "->", "comment", ")", ";", "}", "$", "writer", "->", "endElement", "(", ")", ";", "// organizer or user", "}", "}" ]
The xmlSerialize method is called during xml writing. Use the $writer argument to write its own xml serialization. An important note: do _not_ create a parent element. Any element implementing XmlSerializable should only ever write what's considered its 'inner xml'. The parent of the current element is responsible for writing a containing element. This allows serializers to be re-used for different element names. If you are opening new elements, you must also close them again. @param Writer $writer
[ "The", "xmlSerialize", "method", "is", "called", "during", "xml", "writing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Xml/Property/Invite.php#L73-L121
sabre-io/dav
lib/CalDAV/CalendarObject.php
CalendarObject.get
public function get() { // Pre-populating the 'calendardata' is optional, if we don't have it // already we fetch it from the backend. if (!isset($this->objectData['calendardata'])) { $this->objectData = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $this->objectData['uri']); } return $this->objectData['calendardata']; }
php
public function get() { if (!isset($this->objectData['calendardata'])) { $this->objectData = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $this->objectData['uri']); } return $this->objectData['calendardata']; }
[ "public", "function", "get", "(", ")", "{", "// Pre-populating the 'calendardata' is optional, if we don't have it", "// already we fetch it from the backend.", "if", "(", "!", "isset", "(", "$", "this", "->", "objectData", "[", "'calendardata'", "]", ")", ")", "{", "$", "this", "->", "objectData", "=", "$", "this", "->", "caldavBackend", "->", "getCalendarObject", "(", "$", "this", "->", "calendarInfo", "[", "'id'", "]", ",", "$", "this", "->", "objectData", "[", "'uri'", "]", ")", ";", "}", "return", "$", "this", "->", "objectData", "[", "'calendardata'", "]", ";", "}" ]
Returns the ICalendar-formatted object. @return string
[ "Returns", "the", "ICalendar", "-", "formatted", "object", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/CalendarObject.php#L84-L93
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", "->", "caldavBackend", "->", "updateCalendarObject", "(", "$", "this", "->", "calendarInfo", "[", "'id'", "]", ",", "$", "this", "->", "objectData", "[", "'uri'", "]", ",", "$", "calendarData", ")", ";", "$", "this", "->", "objectData", "[", "'calendardata'", "]", "=", "$", "calendarData", ";", "$", "this", "->", "objectData", "[", "'etag'", "]", "=", "$", "etag", ";", "return", "$", "etag", ";", "}" ]
Updates the ICalendar-formatted object. @param string|resource $calendarData @return string
[ "Updates", "the", "ICalendar", "-", "formatted", "object", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/CalendarObject.php#L102-L112
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'", "]", ")", "{", "$", "mime", ".=", "'; component='", ".", "$", "this", "->", "objectData", "[", "'component'", "]", ";", "}", "return", "$", "mime", ";", "}" ]
Returns the mime content-type. @return string
[ "Returns", "the", "mime", "content", "-", "type", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/CalendarObject.php#L127-L135
sabre-io/dav
lib/CalDAV/CalendarObject.php
CalendarObject.getACL
public function getACL() { // An alternative acl may be specified in the object data. if (isset($this->objectData['acl'])) { return $this->objectData['acl']; } // The default ACL return [ [ 'privilege' => '{DAV:}all', 'principal' => $this->calendarInfo['principaluri'], 'protected' => true, ], [ 'privilege' => '{DAV:}all', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write', 'protected' => true, ], [ 'privilege' => '{DAV:}read', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-read', 'protected' => true, ], ]; }
php
public function getACL() { if (isset($this->objectData['acl'])) { return $this->objectData['acl']; } return [ [ 'privilege' => '{DAV:}all', 'principal' => $this->calendarInfo['principaluri'], 'protected' => true, ], [ 'privilege' => '{DAV:}all', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write', 'protected' => true, ], [ 'privilege' => '{DAV:}read', 'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-read', 'protected' => true, ], ]; }
[ "public", "function", "getACL", "(", ")", "{", "// An alternative acl may be specified in the object data.", "if", "(", "isset", "(", "$", "this", "->", "objectData", "[", "'acl'", "]", ")", ")", "{", "return", "$", "this", "->", "objectData", "[", "'acl'", "]", ";", "}", "// The default ACL", "return", "[", "[", "'privilege'", "=>", "'{DAV:}all'", ",", "'principal'", "=>", "$", "this", "->", "calendarInfo", "[", "'principaluri'", "]", ",", "'protected'", "=>", "true", ",", "]", ",", "[", "'privilege'", "=>", "'{DAV:}all'", ",", "'principal'", "=>", "$", "this", "->", "calendarInfo", "[", "'principaluri'", "]", ".", "'/calendar-proxy-write'", ",", "'protected'", "=>", "true", ",", "]", ",", "[", "'privilege'", "=>", "'{DAV:}read'", ",", "'principal'", "=>", "$", "this", "->", "calendarInfo", "[", "'principaluri'", "]", ".", "'/calendar-proxy-read'", ",", "'protected'", "=>", "true", ",", "]", ",", "]", ";", "}" ]
Returns a list of ACE's for this node. Each ACE has the following properties: * 'privilege', a string such as {DAV:}read or {DAV:}write. These are currently the only supported privileges * 'principal', a url to the principal who owns the node * 'protected' (optional), indicating that this ACE is not allowed to be updated. @return array
[ "Returns", "a", "list", "of", "ACE", "s", "for", "this", "node", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/CalendarObject.php#L201-L226
sabre-io/dav
lib/CardDAV/Xml/Filter/ParamFilter.php
ParamFilter.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { $result = [ 'name' => null, 'is-not-defined' => false, 'text-match' => null, ]; $att = $reader->parseAttributes(); $result['name'] = $att['name']; $elems = $reader->parseInnerTree(); if (is_array($elems)) { foreach ($elems as $elem) { switch ($elem['name']) { case '{'.Plugin::NS_CARDDAV.'}is-not-defined': $result['is-not-defined'] = true; break; case '{'.Plugin::NS_CARDDAV.'}text-match': $matchType = isset($elem['attributes']['match-type']) ? $elem['attributes']['match-type'] : 'contains'; if (!in_array($matchType, ['contains', 'equals', 'starts-with', 'ends-with'])) { throw new BadRequest('Unknown match-type: '.$matchType); } $result['text-match'] = [ 'negate-condition' => isset($elem['attributes']['negate-condition']) && 'yes' === $elem['attributes']['negate-condition'], 'collation' => isset($elem['attributes']['collation']) ? $elem['attributes']['collation'] : 'i;unicode-casemap', 'value' => $elem['value'], 'match-type' => $matchType, ]; break; } } } return $result; }
php
public static function xmlDeserialize(Reader $reader) { $result = [ 'name' => null, 'is-not-defined' => false, 'text-match' => null, ]; $att = $reader->parseAttributes(); $result['name'] = $att['name']; $elems = $reader->parseInnerTree(); if (is_array($elems)) { foreach ($elems as $elem) { switch ($elem['name']) { case '{'.Plugin::NS_CARDDAV.'}is-not-defined': $result['is-not-defined'] = true; break; case '{'.Plugin::NS_CARDDAV.'}text-match': $matchType = isset($elem['attributes']['match-type']) ? $elem['attributes']['match-type'] : 'contains'; if (!in_array($matchType, ['contains', 'equals', 'starts-with', 'ends-with'])) { throw new BadRequest('Unknown match-type: '.$matchType); } $result['text-match'] = [ 'negate-condition' => isset($elem['attributes']['negate-condition']) && 'yes' === $elem['attributes']['negate-condition'], 'collation' => isset($elem['attributes']['collation']) ? $elem['attributes']['collation'] : 'i;unicode-casemap', 'value' => $elem['value'], 'match-type' => $matchType, ]; break; } } } return $result; }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "$", "result", "=", "[", "'name'", "=>", "null", ",", "'is-not-defined'", "=>", "false", ",", "'text-match'", "=>", "null", ",", "]", ";", "$", "att", "=", "$", "reader", "->", "parseAttributes", "(", ")", ";", "$", "result", "[", "'name'", "]", "=", "$", "att", "[", "'name'", "]", ";", "$", "elems", "=", "$", "reader", "->", "parseInnerTree", "(", ")", ";", "if", "(", "is_array", "(", "$", "elems", ")", ")", "{", "foreach", "(", "$", "elems", "as", "$", "elem", ")", "{", "switch", "(", "$", "elem", "[", "'name'", "]", ")", "{", "case", "'{'", ".", "Plugin", "::", "NS_CARDDAV", ".", "'}is-not-defined'", ":", "$", "result", "[", "'is-not-defined'", "]", "=", "true", ";", "break", ";", "case", "'{'", ".", "Plugin", "::", "NS_CARDDAV", ".", "'}text-match'", ":", "$", "matchType", "=", "isset", "(", "$", "elem", "[", "'attributes'", "]", "[", "'match-type'", "]", ")", "?", "$", "elem", "[", "'attributes'", "]", "[", "'match-type'", "]", ":", "'contains'", ";", "if", "(", "!", "in_array", "(", "$", "matchType", ",", "[", "'contains'", ",", "'equals'", ",", "'starts-with'", ",", "'ends-with'", "]", ")", ")", "{", "throw", "new", "BadRequest", "(", "'Unknown match-type: '", ".", "$", "matchType", ")", ";", "}", "$", "result", "[", "'text-match'", "]", "=", "[", "'negate-condition'", "=>", "isset", "(", "$", "elem", "[", "'attributes'", "]", "[", "'negate-condition'", "]", ")", "&&", "'yes'", "===", "$", "elem", "[", "'attributes'", "]", "[", "'negate-condition'", "]", ",", "'collation'", "=>", "isset", "(", "$", "elem", "[", "'attributes'", "]", "[", "'collation'", "]", ")", "?", "$", "elem", "[", "'attributes'", "]", "[", "'collation'", "]", ":", "'i;unicode-casemap'", ",", "'value'", "=>", "$", "elem", "[", "'value'", "]", ",", "'match-type'", "=>", "$", "matchType", ",", "]", ";", "break", ";", "}", "}", "}", "return", "$", "result", ";", "}" ]
The deserialize method is called during xml parsing. This method is called statically, this is because in theory this method may be used as a type of constructor, or factory method. Often you want to return an instance of the current class, but you are free to return other data as well. You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop. If you just want to skip parsing for this element altogether, you can just call $reader->next(); $reader->parseInnerTree() will parse the entire sub-tree, and advance to the next element. @param Reader $reader @return mixed
[ "The", "deserialize", "method", "is", "called", "during", "xml", "parsing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Xml/Filter/ParamFilter.php#L50-L87
sabre-io/dav
lib/DAV/Xml/Property/Complex.php
Complex.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { $xml = $reader->readInnerXml(); if (Reader::ELEMENT === $reader->nodeType && $reader->isEmptyElement) { // Easy! $reader->next(); return null; } // Now we have a copy of the inner xml, we need to traverse it to get // all the strings. If there's no non-string data, we just return the // string, otherwise we return an instance of this class. $reader->read(); $nonText = false; $text = ''; while (true) { switch ($reader->nodeType) { case Reader::ELEMENT: $nonText = true; $reader->next(); continue 2; case Reader::TEXT: case Reader::CDATA: $text .= $reader->value; break; case Reader::END_ELEMENT: break 2; } $reader->read(); } // Make sure we advance the cursor one step further. $reader->read(); if ($nonText) { $new = new self($xml); return $new; } else { return $text; } }
php
public static function xmlDeserialize(Reader $reader) { $xml = $reader->readInnerXml(); if (Reader::ELEMENT === $reader->nodeType && $reader->isEmptyElement) { $reader->next(); return null; } $reader->read(); $nonText = false; $text = ''; while (true) { switch ($reader->nodeType) { case Reader::ELEMENT: $nonText = true; $reader->next(); continue 2; case Reader::TEXT: case Reader::CDATA: $text .= $reader->value; break; case Reader::END_ELEMENT: break 2; } $reader->read(); } $reader->read(); if ($nonText) { $new = new self($xml); return $new; } else { return $text; } }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "$", "xml", "=", "$", "reader", "->", "readInnerXml", "(", ")", ";", "if", "(", "Reader", "::", "ELEMENT", "===", "$", "reader", "->", "nodeType", "&&", "$", "reader", "->", "isEmptyElement", ")", "{", "// Easy!", "$", "reader", "->", "next", "(", ")", ";", "return", "null", ";", "}", "// Now we have a copy of the inner xml, we need to traverse it to get", "// all the strings. If there's no non-string data, we just return the", "// string, otherwise we return an instance of this class.", "$", "reader", "->", "read", "(", ")", ";", "$", "nonText", "=", "false", ";", "$", "text", "=", "''", ";", "while", "(", "true", ")", "{", "switch", "(", "$", "reader", "->", "nodeType", ")", "{", "case", "Reader", "::", "ELEMENT", ":", "$", "nonText", "=", "true", ";", "$", "reader", "->", "next", "(", ")", ";", "continue", "2", ";", "case", "Reader", "::", "TEXT", ":", "case", "Reader", "::", "CDATA", ":", "$", "text", ".=", "$", "reader", "->", "value", ";", "break", ";", "case", "Reader", "::", "END_ELEMENT", ":", "break", "2", ";", "}", "$", "reader", "->", "read", "(", ")", ";", "}", "// Make sure we advance the cursor one step further.", "$", "reader", "->", "read", "(", ")", ";", "if", "(", "$", "nonText", ")", "{", "$", "new", "=", "new", "self", "(", "$", "xml", ")", ";", "return", "$", "new", ";", "}", "else", "{", "return", "$", "text", ";", "}", "}" ]
The deserialize method is called during xml parsing. This method is called statically, this is because in theory this method may be used as a type of constructor, or factory method. Often you want to return an instance of the current class, but you are free to return other data as well. You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop. If you just want to skip parsing for this element altogether, you can just call $reader->next(); $reader->parseInnerTree() will parse the entire sub-tree, and advance to the next element. @param Reader $reader @return mixed
[ "The", "deserialize", "method", "is", "called", "during", "xml", "parsing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Property/Complex.php#L44-L88
sabre-io/dav
lib/DAV/Exception/PreconditionFailed.php
PreconditionFailed.serialize
public function serialize(DAV\Server $server, \DOMElement $errorNode) { if ($this->header) { $prop = $errorNode->ownerDocument->createElement('s:header'); $prop->nodeValue = $this->header; $errorNode->appendChild($prop); } }
php
public function serialize(DAV\Server $server, \DOMElement $errorNode) { if ($this->header) { $prop = $errorNode->ownerDocument->createElement('s:header'); $prop->nodeValue = $this->header; $errorNode->appendChild($prop); } }
[ "public", "function", "serialize", "(", "DAV", "\\", "Server", "$", "server", ",", "\\", "DOMElement", "$", "errorNode", ")", "{", "if", "(", "$", "this", "->", "header", ")", "{", "$", "prop", "=", "$", "errorNode", "->", "ownerDocument", "->", "createElement", "(", "'s:header'", ")", ";", "$", "prop", "->", "nodeValue", "=", "$", "this", "->", "header", ";", "$", "errorNode", "->", "appendChild", "(", "$", "prop", ")", ";", "}", "}" ]
This method allows the exception to include additional information into the WebDAV error response. @param DAV\Server $server @param \DOMElement $errorNode
[ "This", "method", "allows", "the", "exception", "to", "include", "additional", "information", "into", "the", "WebDAV", "error", "response", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Exception/PreconditionFailed.php#L60-L67
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", "(", "$", "notifications", "as", "$", "notification", ")", "{", "$", "children", "[", "]", "=", "new", "Node", "(", "$", "this", "->", "caldavBackend", ",", "$", "this", "->", "principalUri", ",", "$", "notification", ")", ";", "}", "return", "$", "children", ";", "}" ]
Returns all notifications for a principal. @return array
[ "Returns", "all", "notifications", "for", "a", "principal", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Notifications/Collection.php#L60-L74
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': $haystack = str_replace(range('a', 'z'), range('A', 'Z'), $haystack); $needle = str_replace(range('a', 'z'), range('A', 'Z'), $needle); break; case 'i;octet': 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 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'", ")", ";", "}", "}" ]
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", ";", ")", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/StringUtil.php#L30-L65
sabre-io/dav
lib/DAV/StringUtil.php
StringUtil.ensureUTF8
public static function ensureUTF8($input) { $encoding = mb_detect_encoding($input, ['UTF-8', 'ISO-8859-1'], true); if ('ISO-8859-1' === $encoding) { return utf8_encode($input); } else { return $input; } }
php
public static function ensureUTF8($input) { $encoding = mb_detect_encoding($input, ['UTF-8', 'ISO-8859-1'], true); if ('ISO-8859-1' === $encoding) { return utf8_encode($input); } else { return $input; } }
[ "public", "static", "function", "ensureUTF8", "(", "$", "input", ")", "{", "$", "encoding", "=", "mb_detect_encoding", "(", "$", "input", ",", "[", "'UTF-8'", ",", "'ISO-8859-1'", "]", ",", "true", ")", ";", "if", "(", "'ISO-8859-1'", "===", "$", "encoding", ")", "{", "return", "utf8_encode", "(", "$", "input", ")", ";", "}", "else", "{", "return", "$", "input", ";", "}", "}" ]
This method takes an input string, checks if it's not valid UTF-8 and attempts to convert it to UTF-8 if it's not. Note that currently this can only convert ISO-8859-1 to UTF-8 (latin-1), anything else will likely fail. @param string $input @return string
[ "This", "method", "takes", "an", "input", "string", "checks", "if", "it", "s", "not", "valid", "UTF", "-", "8", "and", "attempts", "to", "convert", "it", "to", "UTF", "-", "8", "if", "it", "s", "not", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/StringUtil.php#L78-L87
sabre-io/dav
lib/CalDAV/Schedule/SchedulingObject.php
SchedulingObject.get
public function get() { // Pre-populating the 'calendardata' is optional, if we don't have it // already we fetch it from the backend. if (!isset($this->objectData['calendardata'])) { $this->objectData = $this->caldavBackend->getSchedulingObject($this->objectData['principaluri'], $this->objectData['uri']); } return $this->objectData['calendardata']; }
php
public function get() { if (!isset($this->objectData['calendardata'])) { $this->objectData = $this->caldavBackend->getSchedulingObject($this->objectData['principaluri'], $this->objectData['uri']); } return $this->objectData['calendardata']; }
[ "public", "function", "get", "(", ")", "{", "// Pre-populating the 'calendardata' is optional, if we don't have it", "// already we fetch it from the backend.", "if", "(", "!", "isset", "(", "$", "this", "->", "objectData", "[", "'calendardata'", "]", ")", ")", "{", "$", "this", "->", "objectData", "=", "$", "this", "->", "caldavBackend", "->", "getSchedulingObject", "(", "$", "this", "->", "objectData", "[", "'principaluri'", "]", ",", "$", "this", "->", "objectData", "[", "'uri'", "]", ")", ";", "}", "return", "$", "this", "->", "objectData", "[", "'calendardata'", "]", ";", "}" ]
Returns the ICalendar-formatted object. @return string
[ "Returns", "the", "ICalendar", "-", "formatted", "object", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/SchedulingObject.php#L50-L59
sabre-io/dav
lib/CalDAV/Schedule/SchedulingObject.php
SchedulingObject.getACL
public function getACL() { // An alternative acl may be specified in the object data. // if (isset($this->objectData['acl'])) { return $this->objectData['acl']; } // The default ACL return [ [ 'privilege' => '{DAV:}all', 'principal' => '{DAV:}owner', 'protected' => true, ], [ 'privilege' => '{DAV:}all', 'principal' => $this->objectData['principaluri'].'/calendar-proxy-write', 'protected' => true, ], [ 'privilege' => '{DAV:}read', 'principal' => $this->objectData['principaluri'].'/calendar-proxy-read', 'protected' => true, ], ]; }
php
public function getACL() { if (isset($this->objectData['acl'])) { return $this->objectData['acl']; } return [ [ 'privilege' => '{DAV:}all', 'principal' => '{DAV:}owner', 'protected' => true, ], [ 'privilege' => '{DAV:}all', 'principal' => $this->objectData['principaluri'].'/calendar-proxy-write', 'protected' => true, ], [ 'privilege' => '{DAV:}read', 'principal' => $this->objectData['principaluri'].'/calendar-proxy-read', 'protected' => true, ], ]; }
[ "public", "function", "getACL", "(", ")", "{", "// An alternative acl may be specified in the object data.", "//", "if", "(", "isset", "(", "$", "this", "->", "objectData", "[", "'acl'", "]", ")", ")", "{", "return", "$", "this", "->", "objectData", "[", "'acl'", "]", ";", "}", "// The default ACL", "return", "[", "[", "'privilege'", "=>", "'{DAV:}all'", ",", "'principal'", "=>", "'{DAV:}owner'", ",", "'protected'", "=>", "true", ",", "]", ",", "[", "'privilege'", "=>", "'{DAV:}all'", ",", "'principal'", "=>", "$", "this", "->", "objectData", "[", "'principaluri'", "]", ".", "'/calendar-proxy-write'", ",", "'protected'", "=>", "true", ",", "]", ",", "[", "'privilege'", "=>", "'{DAV:}read'", ",", "'principal'", "=>", "$", "this", "->", "objectData", "[", "'principaluri'", "]", ".", "'/calendar-proxy-read'", ",", "'protected'", "=>", "true", ",", "]", ",", "]", ";", "}" ]
Returns a list of ACE's for this node. Each ACE has the following properties: * 'privilege', a string such as {DAV:}read or {DAV:}write. These are currently the only supported privileges * 'principal', a url to the principal who owns the node * 'protected' (optional), indicating that this ACE is not allowed to be updated. @return array
[ "Returns", "a", "list", "of", "ACE", "s", "for", "this", "node", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/SchedulingObject.php#L105-L132
sabre-io/dav
lib/DAV/Locks/Backend/File.php
File.getLocks
public function getLocks($uri, $returnChildLocks) { $newLocks = []; $locks = $this->getData(); foreach ($locks as $lock) { if ($lock->uri === $uri || //deep locks on parents (0 != $lock->depth && 0 === strpos($uri, $lock->uri.'/')) || // locks on children ($returnChildLocks && (0 === strpos($lock->uri, $uri.'/')))) { $newLocks[] = $lock; } } // Checking if we can remove any of these locks foreach ($newLocks as $k => $lock) { if (time() > $lock->timeout + $lock->created) { unset($newLocks[$k]); } } return $newLocks; }
php
public function getLocks($uri, $returnChildLocks) { $newLocks = []; $locks = $this->getData(); foreach ($locks as $lock) { if ($lock->uri === $uri || (0 != $lock->depth && 0 === strpos($uri, $lock->uri.'/')) || ($returnChildLocks && (0 === strpos($lock->uri, $uri.'/')))) { $newLocks[] = $lock; } } foreach ($newLocks as $k => $lock) { if (time() > $lock->timeout + $lock->created) { unset($newLocks[$k]); } } return $newLocks; }
[ "public", "function", "getLocks", "(", "$", "uri", ",", "$", "returnChildLocks", ")", "{", "$", "newLocks", "=", "[", "]", ";", "$", "locks", "=", "$", "this", "->", "getData", "(", ")", ";", "foreach", "(", "$", "locks", "as", "$", "lock", ")", "{", "if", "(", "$", "lock", "->", "uri", "===", "$", "uri", "||", "//deep locks on parents", "(", "0", "!=", "$", "lock", "->", "depth", "&&", "0", "===", "strpos", "(", "$", "uri", ",", "$", "lock", "->", "uri", ".", "'/'", ")", ")", "||", "// locks on children", "(", "$", "returnChildLocks", "&&", "(", "0", "===", "strpos", "(", "$", "lock", "->", "uri", ",", "$", "uri", ".", "'/'", ")", ")", ")", ")", "{", "$", "newLocks", "[", "]", "=", "$", "lock", ";", "}", "}", "// Checking if we can remove any of these locks", "foreach", "(", "$", "newLocks", "as", "$", "k", "=>", "$", "lock", ")", "{", "if", "(", "time", "(", ")", ">", "$", "lock", "->", "timeout", "+", "$", "lock", "->", "created", ")", "{", "unset", "(", "$", "newLocks", "[", "$", "k", "]", ")", ";", "}", "}", "return", "$", "newLocks", ";", "}" ]
Returns a list of Sabre\DAV\Locks\LockInfo objects. This method should return all the locks for a particular uri, including locks that might be set on a parent uri. If returnChildLocks is set to true, this method should also look for any locks in the subtree of the uri for locks. @param string $uri @param bool $returnChildLocks @return array
[ "Returns", "a", "list", "of", "Sabre", "\\", "DAV", "\\", "Locks", "\\", "LockInfo", "objects", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Backend/File.php#L55-L80
sabre-io/dav
lib/DAV/Locks/Backend/File.php
File.lock
public function lock($uri, LockInfo $lockInfo) { // We're making the lock timeout 30 minutes $lockInfo->timeout = 1800; $lockInfo->created = time(); $lockInfo->uri = $uri; $locks = $this->getData(); foreach ($locks as $k => $lock) { if ( ($lock->token == $lockInfo->token) || (time() > $lock->timeout + $lock->created) ) { unset($locks[$k]); } } $locks[] = $lockInfo; $this->putData($locks); return true; }
php
public function lock($uri, LockInfo $lockInfo) { $lockInfo->timeout = 1800; $lockInfo->created = time(); $lockInfo->uri = $uri; $locks = $this->getData(); foreach ($locks as $k => $lock) { if ( ($lock->token == $lockInfo->token) || (time() > $lock->timeout + $lock->created) ) { unset($locks[$k]); } } $locks[] = $lockInfo; $this->putData($locks); return true; }
[ "public", "function", "lock", "(", "$", "uri", ",", "LockInfo", "$", "lockInfo", ")", "{", "// We're making the lock timeout 30 minutes", "$", "lockInfo", "->", "timeout", "=", "1800", ";", "$", "lockInfo", "->", "created", "=", "time", "(", ")", ";", "$", "lockInfo", "->", "uri", "=", "$", "uri", ";", "$", "locks", "=", "$", "this", "->", "getData", "(", ")", ";", "foreach", "(", "$", "locks", "as", "$", "k", "=>", "$", "lock", ")", "{", "if", "(", "(", "$", "lock", "->", "token", "==", "$", "lockInfo", "->", "token", ")", "||", "(", "time", "(", ")", ">", "$", "lock", "->", "timeout", "+", "$", "lock", "->", "created", ")", ")", "{", "unset", "(", "$", "locks", "[", "$", "k", "]", ")", ";", "}", "}", "$", "locks", "[", "]", "=", "$", "lockInfo", ";", "$", "this", "->", "putData", "(", "$", "locks", ")", ";", "return", "true", ";", "}" ]
Locks a uri. @param string $uri @param LockInfo $lockInfo @return bool
[ "Locks", "a", "uri", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Backend/File.php#L90-L111
sabre-io/dav
lib/DAV/Locks/Backend/File.php
File.unlock
public function unlock($uri, LockInfo $lockInfo) { $locks = $this->getData(); foreach ($locks as $k => $lock) { if ($lock->token == $lockInfo->token) { unset($locks[$k]); $this->putData($locks); return true; } } return false; }
php
public function unlock($uri, LockInfo $lockInfo) { $locks = $this->getData(); foreach ($locks as $k => $lock) { if ($lock->token == $lockInfo->token) { unset($locks[$k]); $this->putData($locks); return true; } } return false; }
[ "public", "function", "unlock", "(", "$", "uri", ",", "LockInfo", "$", "lockInfo", ")", "{", "$", "locks", "=", "$", "this", "->", "getData", "(", ")", ";", "foreach", "(", "$", "locks", "as", "$", "k", "=>", "$", "lock", ")", "{", "if", "(", "$", "lock", "->", "token", "==", "$", "lockInfo", "->", "token", ")", "{", "unset", "(", "$", "locks", "[", "$", "k", "]", ")", ";", "$", "this", "->", "putData", "(", "$", "locks", ")", ";", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Removes a lock from a uri. @param string $uri @param LockInfo $lockInfo @return bool
[ "Removes", "a", "lock", "from", "a", "uri", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Backend/File.php#L121-L134
sabre-io/dav
lib/DAV/Locks/Backend/File.php
File.getData
protected function getData() { if (!file_exists($this->locksFile)) { return []; } // opening up the file, and creating a shared lock $handle = fopen($this->locksFile, 'r'); flock($handle, LOCK_SH); // Reading data until the eof $data = stream_get_contents($handle); // We're all good flock($handle, LOCK_UN); fclose($handle); // Unserializing and checking if the resource file contains data for this file $data = unserialize($data); if (!$data) { return []; } return $data; }
php
protected function getData() { if (!file_exists($this->locksFile)) { return []; } $handle = fopen($this->locksFile, 'r'); flock($handle, LOCK_SH); $data = stream_get_contents($handle); flock($handle, LOCK_UN); fclose($handle); $data = unserialize($data); if (!$data) { return []; } return $data; }
[ "protected", "function", "getData", "(", ")", "{", "if", "(", "!", "file_exists", "(", "$", "this", "->", "locksFile", ")", ")", "{", "return", "[", "]", ";", "}", "// opening up the file, and creating a shared lock", "$", "handle", "=", "fopen", "(", "$", "this", "->", "locksFile", ",", "'r'", ")", ";", "flock", "(", "$", "handle", ",", "LOCK_SH", ")", ";", "// Reading data until the eof", "$", "data", "=", "stream_get_contents", "(", "$", "handle", ")", ";", "// We're all good", "flock", "(", "$", "handle", ",", "LOCK_UN", ")", ";", "fclose", "(", "$", "handle", ")", ";", "// Unserializing and checking if the resource file contains data for this file", "$", "data", "=", "unserialize", "(", "$", "data", ")", ";", "if", "(", "!", "$", "data", ")", "{", "return", "[", "]", ";", "}", "return", "$", "data", ";", "}" ]
Loads the lockdata from the filesystem. @return array
[ "Loads", "the", "lockdata", "from", "the", "filesystem", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Backend/File.php#L141-L165
sabre-io/dav
lib/DAV/Locks/Backend/File.php
File.putData
protected function putData(array $newData) { // opening up the file, and creating an exclusive lock $handle = fopen($this->locksFile, 'a+'); flock($handle, LOCK_EX); // We can only truncate and rewind once the lock is acquired. ftruncate($handle, 0); rewind($handle); fwrite($handle, serialize($newData)); flock($handle, LOCK_UN); fclose($handle); }
php
protected function putData(array $newData) { $handle = fopen($this->locksFile, 'a+'); flock($handle, LOCK_EX); ftruncate($handle, 0); rewind($handle); fwrite($handle, serialize($newData)); flock($handle, LOCK_UN); fclose($handle); }
[ "protected", "function", "putData", "(", "array", "$", "newData", ")", "{", "// opening up the file, and creating an exclusive lock", "$", "handle", "=", "fopen", "(", "$", "this", "->", "locksFile", ",", "'a+'", ")", ";", "flock", "(", "$", "handle", ",", "LOCK_EX", ")", ";", "// We can only truncate and rewind once the lock is acquired.", "ftruncate", "(", "$", "handle", ",", "0", ")", ";", "rewind", "(", "$", "handle", ")", ";", "fwrite", "(", "$", "handle", ",", "serialize", "(", "$", "newData", ")", ")", ";", "flock", "(", "$", "handle", ",", "LOCK_UN", ")", ";", "fclose", "(", "$", "handle", ")", ";", "}" ]
Saves the lockdata. @param array $newData
[ "Saves", "the", "lockdata", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Locks/Backend/File.php#L172-L185
sabre-io/dav
lib/DAVACL/PrincipalBackend/AbstractBackend.php
AbstractBackend.findByUri
public function findByUri($uri, $principalPrefix) { // Note that the default implementation here is a bit slow and could // likely be optimized. if ('mailto:' !== substr($uri, 0, 7)) { return; } $result = $this->searchPrincipals( $principalPrefix, ['{http://sabredav.org/ns}email-address' => substr($uri, 7)] ); if ($result) { return $result[0]; } }
php
public function findByUri($uri, $principalPrefix) { if ('mailto:' !== substr($uri, 0, 7)) { return; } $result = $this->searchPrincipals( $principalPrefix, ['{http: ); if ($result) { return $result[0]; } }
[ "public", "function", "findByUri", "(", "$", "uri", ",", "$", "principalPrefix", ")", "{", "// Note that the default implementation here is a bit slow and could", "// likely be optimized.", "if", "(", "'mailto:'", "!==", "substr", "(", "$", "uri", ",", "0", ",", "7", ")", ")", "{", "return", ";", "}", "$", "result", "=", "$", "this", "->", "searchPrincipals", "(", "$", "principalPrefix", ",", "[", "'{http://sabredav.org/ns}email-address'", "=>", "substr", "(", "$", "uri", ",", "7", ")", "]", ")", ";", "if", "(", "$", "result", ")", "{", "return", "$", "result", "[", "0", "]", ";", "}", "}" ]
Finds a principal by its URI. This method may receive any type of uri, but mailto: addresses will be the most common. Implementation of this API is optional. It is currently used by the CalDAV system to find principals based on their email addresses. If this API is not implemented, some features may not work correctly. This method must return a relative principal path, or null, if the principal was not found or you refuse to find it. @param string $uri @param string $principalPrefix @return string
[ "Finds", "a", "principal", "by", "its", "URI", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/PrincipalBackend/AbstractBackend.php#L38-L53
sabre-io/dav
lib/DAVACL/AbstractPrincipalCollection.php
AbstractPrincipalCollection.getChildren
public function getChildren() { if ($this->disableListing) { throw new DAV\Exception\MethodNotAllowed('Listing members of this collection is disabled'); } $children = []; foreach ($this->principalBackend->getPrincipalsByPrefix($this->principalPrefix) as $principalInfo) { $children[] = $this->getChildForPrincipal($principalInfo); } return $children; }
php
public function getChildren() { if ($this->disableListing) { throw new DAV\Exception\MethodNotAllowed('Listing members of this collection is disabled'); } $children = []; foreach ($this->principalBackend->getPrincipalsByPrefix($this->principalPrefix) as $principalInfo) { $children[] = $this->getChildForPrincipal($principalInfo); } return $children; }
[ "public", "function", "getChildren", "(", ")", "{", "if", "(", "$", "this", "->", "disableListing", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "MethodNotAllowed", "(", "'Listing members of this collection is disabled'", ")", ";", "}", "$", "children", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "principalBackend", "->", "getPrincipalsByPrefix", "(", "$", "this", "->", "principalPrefix", ")", "as", "$", "principalInfo", ")", "{", "$", "children", "[", "]", "=", "$", "this", "->", "getChildForPrincipal", "(", "$", "principalInfo", ")", ";", "}", "return", "$", "children", ";", "}" ]
Return the list of users. @return array
[ "Return", "the", "list", "of", "users", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/AbstractPrincipalCollection.php#L94-L105
sabre-io/dav
lib/DAVACL/AbstractPrincipalCollection.php
AbstractPrincipalCollection.getChild
public function getChild($name) { $principalInfo = $this->principalBackend->getPrincipalByPath($this->principalPrefix.'/'.$name); if (!$principalInfo) { throw new DAV\Exception\NotFound('Principal with name '.$name.' not found'); } return $this->getChildForPrincipal($principalInfo); }
php
public function getChild($name) { $principalInfo = $this->principalBackend->getPrincipalByPath($this->principalPrefix.'/'.$name); if (!$principalInfo) { throw new DAV\Exception\NotFound('Principal with name '.$name.' not found'); } return $this->getChildForPrincipal($principalInfo); }
[ "public", "function", "getChild", "(", "$", "name", ")", "{", "$", "principalInfo", "=", "$", "this", "->", "principalBackend", "->", "getPrincipalByPath", "(", "$", "this", "->", "principalPrefix", ".", "'/'", ".", "$", "name", ")", ";", "if", "(", "!", "$", "principalInfo", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "NotFound", "(", "'Principal with name '", ".", "$", "name", ".", "' not found'", ")", ";", "}", "return", "$", "this", "->", "getChildForPrincipal", "(", "$", "principalInfo", ")", ";", "}" ]
Returns a child object, by its name. @param string $name @throws DAV\Exception\NotFound @return DAV\INode
[ "Returns", "a", "child", "object", "by", "its", "name", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/AbstractPrincipalCollection.php#L116-L124
sabre-io/dav
lib/DAVACL/AbstractPrincipalCollection.php
AbstractPrincipalCollection.searchPrincipals
public function searchPrincipals(array $searchProperties, $test = 'allof') { $result = $this->principalBackend->searchPrincipals($this->principalPrefix, $searchProperties, $test); $r = []; foreach ($result as $row) { list(, $r[]) = Uri\split($row); } return $r; }
php
public function searchPrincipals(array $searchProperties, $test = 'allof') { $result = $this->principalBackend->searchPrincipals($this->principalPrefix, $searchProperties, $test); $r = []; foreach ($result as $row) { list(, $r[]) = Uri\split($row); } return $r; }
[ "public", "function", "searchPrincipals", "(", "array", "$", "searchProperties", ",", "$", "test", "=", "'allof'", ")", "{", "$", "result", "=", "$", "this", "->", "principalBackend", "->", "searchPrincipals", "(", "$", "this", "->", "principalPrefix", ",", "$", "searchProperties", ",", "$", "test", ")", ";", "$", "r", "=", "[", "]", ";", "foreach", "(", "$", "result", "as", "$", "row", ")", "{", "list", "(", ",", "$", "r", "[", "]", ")", "=", "Uri", "\\", "split", "(", "$", "row", ")", ";", "}", "return", "$", "r", ";", "}" ]
This method is used to search for principals matching a set of properties. This search is specifically used by RFC3744's principal-property-search REPORT. You should at least allow searching on http://sabredav.org/ns}email-address. The actual search should be a unicode-non-case-sensitive search. The keys in searchProperties are the WebDAV property names, while the values are the property values to search on. By default, if multiple properties are submitted to this method, the various properties should be combined with 'AND'. If $test is set to 'anyof', it should be combined using 'OR'. This method should simply return a list of 'child names', which may be used to call $this->getChild in the future. @param array $searchProperties @param string $test @return array
[ "This", "method", "is", "used", "to", "search", "for", "principals", "matching", "a", "set", "of", "properties", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/AbstractPrincipalCollection.php#L150-L160
sabre-io/dav
lib/DAV/Xml/Property/ResourceType.php
ResourceType.add
public function add($type) { $this->value[] = $type; $this->value = array_unique($this->value); }
php
public function add($type) { $this->value[] = $type; $this->value = array_unique($this->value); }
[ "public", "function", "add", "(", "$", "type", ")", "{", "$", "this", "->", "value", "[", "]", "=", "$", "type", ";", "$", "this", "->", "value", "=", "array_unique", "(", "$", "this", "->", "value", ")", ";", "}" ]
Adds a resourcetype value to this property. @param string $type
[ "Adds", "a", "resourcetype", "value", "to", "this", "property", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/Xml/Property/ResourceType.php#L69-L73
sabre-io/dav
lib/DAVACL/Xml/Request/PrincipalSearchPropertySetReport.php
PrincipalSearchPropertySetReport.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { if (!$reader->isEmptyElement) { throw new BadRequest('The {DAV:}principal-search-property-set element must be empty'); } // The element is actually empty, so there's not much to do. $reader->next(); $self = new self(); return $self; }
php
public static function xmlDeserialize(Reader $reader) { if (!$reader->isEmptyElement) { throw new BadRequest('The {DAV:}principal-search-property-set element must be empty'); } $reader->next(); $self = new self(); return $self; }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "if", "(", "!", "$", "reader", "->", "isEmptyElement", ")", "{", "throw", "new", "BadRequest", "(", "'The {DAV:}principal-search-property-set element must be empty'", ")", ";", "}", "// The element is actually empty, so there's not much to do.", "$", "reader", "->", "next", "(", ")", ";", "$", "self", "=", "new", "self", "(", ")", ";", "return", "$", "self", ";", "}" ]
The deserialize method is called during xml parsing. This method is called statically, this is because in theory this method may be used as a type of constructor, or factory method. Often you want to return an instance of the current class, but you are free to return other data as well. You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop. If you just want to skip parsing for this element altogether, you can just call $reader->next(); $reader->parseInnerTree() will parse the entire sub-tree, and advance to the next element. @param Reader $reader @return mixed
[ "The", "deserialize", "method", "is", "called", "during", "xml", "parsing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Xml/Request/PrincipalSearchPropertySetReport.php#L47-L59
sabre-io/dav
lib/CalDAV/Xml/Notification/Invite.php
Invite.xmlSerializeFull
public function xmlSerializeFull(Writer $writer) { $cs = '{'.CalDAV\Plugin::NS_CALENDARSERVER.'}'; $this->dtStamp->setTimezone(new \DateTimeZone('GMT')); $writer->writeElement($cs.'dtstamp', $this->dtStamp->format('Ymd\\THis\\Z')); $writer->startElement($cs.'invite-notification'); $writer->writeElement($cs.'uid', $this->id); $writer->writeElement('{DAV:}href', $this->href); switch ($this->type) { case DAV\Sharing\Plugin::INVITE_ACCEPTED: $writer->writeElement($cs.'invite-accepted'); break; case DAV\Sharing\Plugin::INVITE_NORESPONSE: $writer->writeElement($cs.'invite-noresponse'); break; } $writer->writeElement($cs.'hosturl', [ '{DAV:}href' => $writer->contextUri.$this->hostUrl, ]); if ($this->summary) { $writer->writeElement($cs.'summary', $this->summary); } $writer->startElement($cs.'access'); if ($this->readOnly) { $writer->writeElement($cs.'read'); } else { $writer->writeElement($cs.'read-write'); } $writer->endElement(); // access $writer->startElement($cs.'organizer'); // If the organizer contains a 'mailto:' part, it means it should be // treated as absolute. if ('mailto:' === strtolower(substr($this->organizer, 0, 7))) { $writer->writeElement('{DAV:}href', $this->organizer); } else { $writer->writeElement('{DAV:}href', $writer->contextUri.$this->organizer); } if ($this->commonName) { $writer->writeElement($cs.'common-name', $this->commonName); } if ($this->firstName) { $writer->writeElement($cs.'first-name', $this->firstName); } if ($this->lastName) { $writer->writeElement($cs.'last-name', $this->lastName); } $writer->endElement(); // organizer if ($this->commonName) { $writer->writeElement($cs.'organizer-cn', $this->commonName); } if ($this->firstName) { $writer->writeElement($cs.'organizer-first', $this->firstName); } if ($this->lastName) { $writer->writeElement($cs.'organizer-last', $this->lastName); } if ($this->supportedComponents) { $writer->writeElement('{'.CalDAV\Plugin::NS_CALDAV.'}supported-calendar-component-set', $this->supportedComponents); } $writer->endElement(); // invite-notification }
php
public function xmlSerializeFull(Writer $writer) { $cs = '{'.CalDAV\Plugin::NS_CALENDARSERVER.'}'; $this->dtStamp->setTimezone(new \DateTimeZone('GMT')); $writer->writeElement($cs.'dtstamp', $this->dtStamp->format('Ymd\\THis\\Z')); $writer->startElement($cs.'invite-notification'); $writer->writeElement($cs.'uid', $this->id); $writer->writeElement('{DAV:}href', $this->href); switch ($this->type) { case DAV\Sharing\Plugin::INVITE_ACCEPTED: $writer->writeElement($cs.'invite-accepted'); break; case DAV\Sharing\Plugin::INVITE_NORESPONSE: $writer->writeElement($cs.'invite-noresponse'); break; } $writer->writeElement($cs.'hosturl', [ '{DAV:}href' => $writer->contextUri.$this->hostUrl, ]); if ($this->summary) { $writer->writeElement($cs.'summary', $this->summary); } $writer->startElement($cs.'access'); if ($this->readOnly) { $writer->writeElement($cs.'read'); } else { $writer->writeElement($cs.'read-write'); } $writer->endElement(); $writer->startElement($cs.'organizer'); if ('mailto:' === strtolower(substr($this->organizer, 0, 7))) { $writer->writeElement('{DAV:}href', $this->organizer); } else { $writer->writeElement('{DAV:}href', $writer->contextUri.$this->organizer); } if ($this->commonName) { $writer->writeElement($cs.'common-name', $this->commonName); } if ($this->firstName) { $writer->writeElement($cs.'first-name', $this->firstName); } if ($this->lastName) { $writer->writeElement($cs.'last-name', $this->lastName); } $writer->endElement(); if ($this->commonName) { $writer->writeElement($cs.'organizer-cn', $this->commonName); } if ($this->firstName) { $writer->writeElement($cs.'organizer-first', $this->firstName); } if ($this->lastName) { $writer->writeElement($cs.'organizer-last', $this->lastName); } if ($this->supportedComponents) { $writer->writeElement('{'.CalDAV\Plugin::NS_CALDAV.'}supported-calendar-component-set', $this->supportedComponents); } $writer->endElement(); }
[ "public", "function", "xmlSerializeFull", "(", "Writer", "$", "writer", ")", "{", "$", "cs", "=", "'{'", ".", "CalDAV", "\\", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}'", ";", "$", "this", "->", "dtStamp", "->", "setTimezone", "(", "new", "\\", "DateTimeZone", "(", "'GMT'", ")", ")", ";", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'dtstamp'", ",", "$", "this", "->", "dtStamp", "->", "format", "(", "'Ymd\\\\THis\\\\Z'", ")", ")", ";", "$", "writer", "->", "startElement", "(", "$", "cs", ".", "'invite-notification'", ")", ";", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'uid'", ",", "$", "this", "->", "id", ")", ";", "$", "writer", "->", "writeElement", "(", "'{DAV:}href'", ",", "$", "this", "->", "href", ")", ";", "switch", "(", "$", "this", "->", "type", ")", "{", "case", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "INVITE_ACCEPTED", ":", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'invite-accepted'", ")", ";", "break", ";", "case", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "INVITE_NORESPONSE", ":", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'invite-noresponse'", ")", ";", "break", ";", "}", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'hosturl'", ",", "[", "'{DAV:}href'", "=>", "$", "writer", "->", "contextUri", ".", "$", "this", "->", "hostUrl", ",", "]", ")", ";", "if", "(", "$", "this", "->", "summary", ")", "{", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'summary'", ",", "$", "this", "->", "summary", ")", ";", "}", "$", "writer", "->", "startElement", "(", "$", "cs", ".", "'access'", ")", ";", "if", "(", "$", "this", "->", "readOnly", ")", "{", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'read'", ")", ";", "}", "else", "{", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'read-write'", ")", ";", "}", "$", "writer", "->", "endElement", "(", ")", ";", "// access", "$", "writer", "->", "startElement", "(", "$", "cs", ".", "'organizer'", ")", ";", "// If the organizer contains a 'mailto:' part, it means it should be", "// treated as absolute.", "if", "(", "'mailto:'", "===", "strtolower", "(", "substr", "(", "$", "this", "->", "organizer", ",", "0", ",", "7", ")", ")", ")", "{", "$", "writer", "->", "writeElement", "(", "'{DAV:}href'", ",", "$", "this", "->", "organizer", ")", ";", "}", "else", "{", "$", "writer", "->", "writeElement", "(", "'{DAV:}href'", ",", "$", "writer", "->", "contextUri", ".", "$", "this", "->", "organizer", ")", ";", "}", "if", "(", "$", "this", "->", "commonName", ")", "{", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'common-name'", ",", "$", "this", "->", "commonName", ")", ";", "}", "if", "(", "$", "this", "->", "firstName", ")", "{", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'first-name'", ",", "$", "this", "->", "firstName", ")", ";", "}", "if", "(", "$", "this", "->", "lastName", ")", "{", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'last-name'", ",", "$", "this", "->", "lastName", ")", ";", "}", "$", "writer", "->", "endElement", "(", ")", ";", "// organizer", "if", "(", "$", "this", "->", "commonName", ")", "{", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'organizer-cn'", ",", "$", "this", "->", "commonName", ")", ";", "}", "if", "(", "$", "this", "->", "firstName", ")", "{", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'organizer-first'", ",", "$", "this", "->", "firstName", ")", ";", "}", "if", "(", "$", "this", "->", "lastName", ")", "{", "$", "writer", "->", "writeElement", "(", "$", "cs", ".", "'organizer-last'", ",", "$", "this", "->", "lastName", ")", ";", "}", "if", "(", "$", "this", "->", "supportedComponents", ")", "{", "$", "writer", "->", "writeElement", "(", "'{'", ".", "CalDAV", "\\", "Plugin", "::", "NS_CALDAV", ".", "'}supported-calendar-component-set'", ",", "$", "this", "->", "supportedComponents", ")", ";", "}", "$", "writer", "->", "endElement", "(", ")", ";", "// invite-notification", "}" ]
This method serializes the entire notification, as it is used in the response body. @param Writer $writer
[ "This", "method", "serializes", "the", "entire", "notification", "as", "it", "is", "used", "in", "the", "response", "body", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Xml/Notification/Invite.php#L198-L268
sabre-io/dav
lib/CalDAV/Schedule/IMipPlugin.php
IMipPlugin.schedule
public function schedule(ITip\Message $iTipMessage) { // Not sending any emails if the system considers the update // insignificant. if (!$iTipMessage->significantChange) { if (!$iTipMessage->scheduleStatus) { $iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email'; } return; } $summary = $iTipMessage->message->VEVENT->SUMMARY; if ('mailto' !== parse_url($iTipMessage->sender, PHP_URL_SCHEME)) { return; } if ('mailto' !== parse_url($iTipMessage->recipient, PHP_URL_SCHEME)) { return; } $sender = substr($iTipMessage->sender, 7); $recipient = substr($iTipMessage->recipient, 7); if ($iTipMessage->senderName) { $sender = $iTipMessage->senderName.' <'.$sender.'>'; } if ($iTipMessage->recipientName) { $recipient = $iTipMessage->recipientName.' <'.$recipient.'>'; } $subject = 'SabreDAV iTIP message'; switch (strtoupper($iTipMessage->method)) { case 'REPLY': $subject = 'Re: '.$summary; break; case 'REQUEST': $subject = $summary; break; case 'CANCEL': $subject = 'Cancelled: '.$summary; break; } $headers = [ 'Reply-To: '.$sender, 'From: '.$this->senderEmail, 'Content-Type: text/calendar; charset=UTF-8; method='.$iTipMessage->method, ]; if (DAV\Server::$exposeVersion) { $headers[] = 'X-Sabre-Version: '.DAV\Version::VERSION; } $this->mail( $recipient, $subject, $iTipMessage->message->serialize(), $headers ); $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip'; }
php
public function schedule(ITip\Message $iTipMessage) { if (!$iTipMessage->significantChange) { if (!$iTipMessage->scheduleStatus) { $iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email'; } return; } $summary = $iTipMessage->message->VEVENT->SUMMARY; if ('mailto' !== parse_url($iTipMessage->sender, PHP_URL_SCHEME)) { return; } if ('mailto' !== parse_url($iTipMessage->recipient, PHP_URL_SCHEME)) { return; } $sender = substr($iTipMessage->sender, 7); $recipient = substr($iTipMessage->recipient, 7); if ($iTipMessage->senderName) { $sender = $iTipMessage->senderName.' <'.$sender.'>'; } if ($iTipMessage->recipientName) { $recipient = $iTipMessage->recipientName.' <'.$recipient.'>'; } $subject = 'SabreDAV iTIP message'; switch (strtoupper($iTipMessage->method)) { case 'REPLY': $subject = 'Re: '.$summary; break; case 'REQUEST': $subject = $summary; break; case 'CANCEL': $subject = 'Cancelled: '.$summary; break; } $headers = [ 'Reply-To: '.$sender, 'From: '.$this->senderEmail, 'Content-Type: text/calendar; charset=UTF-8; method='.$iTipMessage->method, ]; if (DAV\Server::$exposeVersion) { $headers[] = 'X-Sabre-Version: '.DAV\Version::VERSION; } $this->mail( $recipient, $subject, $iTipMessage->message->serialize(), $headers ); $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip'; }
[ "public", "function", "schedule", "(", "ITip", "\\", "Message", "$", "iTipMessage", ")", "{", "// Not sending any emails if the system considers the update", "// insignificant.", "if", "(", "!", "$", "iTipMessage", "->", "significantChange", ")", "{", "if", "(", "!", "$", "iTipMessage", "->", "scheduleStatus", ")", "{", "$", "iTipMessage", "->", "scheduleStatus", "=", "'1.0;We got the message, but it\\'s not significant enough to warrant an email'", ";", "}", "return", ";", "}", "$", "summary", "=", "$", "iTipMessage", "->", "message", "->", "VEVENT", "->", "SUMMARY", ";", "if", "(", "'mailto'", "!==", "parse_url", "(", "$", "iTipMessage", "->", "sender", ",", "PHP_URL_SCHEME", ")", ")", "{", "return", ";", "}", "if", "(", "'mailto'", "!==", "parse_url", "(", "$", "iTipMessage", "->", "recipient", ",", "PHP_URL_SCHEME", ")", ")", "{", "return", ";", "}", "$", "sender", "=", "substr", "(", "$", "iTipMessage", "->", "sender", ",", "7", ")", ";", "$", "recipient", "=", "substr", "(", "$", "iTipMessage", "->", "recipient", ",", "7", ")", ";", "if", "(", "$", "iTipMessage", "->", "senderName", ")", "{", "$", "sender", "=", "$", "iTipMessage", "->", "senderName", ".", "' <'", ".", "$", "sender", ".", "'>'", ";", "}", "if", "(", "$", "iTipMessage", "->", "recipientName", ")", "{", "$", "recipient", "=", "$", "iTipMessage", "->", "recipientName", ".", "' <'", ".", "$", "recipient", ".", "'>'", ";", "}", "$", "subject", "=", "'SabreDAV iTIP message'", ";", "switch", "(", "strtoupper", "(", "$", "iTipMessage", "->", "method", ")", ")", "{", "case", "'REPLY'", ":", "$", "subject", "=", "'Re: '", ".", "$", "summary", ";", "break", ";", "case", "'REQUEST'", ":", "$", "subject", "=", "$", "summary", ";", "break", ";", "case", "'CANCEL'", ":", "$", "subject", "=", "'Cancelled: '", ".", "$", "summary", ";", "break", ";", "}", "$", "headers", "=", "[", "'Reply-To: '", ".", "$", "sender", ",", "'From: '", ".", "$", "this", "->", "senderEmail", ",", "'Content-Type: text/calendar; charset=UTF-8; method='", ".", "$", "iTipMessage", "->", "method", ",", "]", ";", "if", "(", "DAV", "\\", "Server", "::", "$", "exposeVersion", ")", "{", "$", "headers", "[", "]", "=", "'X-Sabre-Version: '", ".", "DAV", "\\", "Version", "::", "VERSION", ";", "}", "$", "this", "->", "mail", "(", "$", "recipient", ",", "$", "subject", ",", "$", "iTipMessage", "->", "message", "->", "serialize", "(", ")", ",", "$", "headers", ")", ";", "$", "iTipMessage", "->", "scheduleStatus", "=", "'1.1; Scheduling message is sent via iMip'", ";", "}" ]
Event handler for the 'schedule' event. @param ITip\Message $iTipMessage
[ "Event", "handler", "for", "the", "schedule", "event", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/IMipPlugin.php#L87-L147
sabre-io/dav
lib/CalDAV/Schedule/IMipPlugin.php
IMipPlugin.mail
protected function mail($to, $subject, $body, array $headers) { mail($to, $subject, $body, implode("\r\n", $headers)); }
php
protected function mail($to, $subject, $body, array $headers) { mail($to, $subject, $body, implode("\r\n", $headers)); }
[ "protected", "function", "mail", "(", "$", "to", ",", "$", "subject", ",", "$", "body", ",", "array", "$", "headers", ")", "{", "mail", "(", "$", "to", ",", "$", "subject", ",", "$", "body", ",", "implode", "(", "\"\\r\\n\"", ",", "$", "headers", ")", ")", ";", "}" ]
This function is responsible for sending the actual email. @param string $to Recipient email address @param string $subject Subject of the email @param string $body iCalendar body @param array $headers List of headers
[ "This", "function", "is", "responsible", "for", "sending", "the", "actual", "email", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/IMipPlugin.php#L160-L163
sabre-io/dav
lib/DAVACL/Xml/Property/Acl.php
Acl.xmlSerialize
public function xmlSerialize(Writer $writer) { foreach ($this->privileges as $ace) { $this->serializeAce($writer, $ace); } }
php
public function xmlSerialize(Writer $writer) { foreach ($this->privileges as $ace) { $this->serializeAce($writer, $ace); } }
[ "public", "function", "xmlSerialize", "(", "Writer", "$", "writer", ")", "{", "foreach", "(", "$", "this", "->", "privileges", "as", "$", "ace", ")", "{", "$", "this", "->", "serializeAce", "(", "$", "writer", ",", "$", "ace", ")", ";", "}", "}" ]
The xmlSerialize method is called during xml writing. Use the $writer argument to write its own xml serialization. An important note: do _not_ create a parent element. Any element implementing XmlSerializable should only ever write what's considered its 'inner xml'. The parent of the current element is responsible for writing a containing element. This allows serializers to be re-used for different element names. If you are opening new elements, you must also close them again. @param Writer $writer
[ "The", "xmlSerialize", "method", "is", "called", "during", "xml", "writing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Xml/Property/Acl.php#L98-L103
sabre-io/dav
lib/DAVACL/Xml/Property/Acl.php
Acl.toHtml
public function toHtml(HtmlOutputHelper $html) { ob_start(); echo '<table>'; echo '<tr><th>Principal</th><th>Privilege</th><th></th></tr>'; foreach ($this->privileges as $privilege) { echo '<tr>'; // if it starts with a {, it's a special principal if ('{' === $privilege['principal'][0]) { echo '<td>', $html->xmlName($privilege['principal']), '</td>'; } else { echo '<td>', $html->link($privilege['principal']), '</td>'; } echo '<td>', $html->xmlName($privilege['privilege']), '</td>'; echo '<td>'; if (!empty($privilege['protected'])) { echo '(protected)'; } echo '</td>'; echo '</tr>'; } echo '</table>'; return ob_get_clean(); }
php
public function toHtml(HtmlOutputHelper $html) { ob_start(); echo '<table>'; echo '<tr><th>Principal</th><th>Privilege</th><th></th></tr>'; foreach ($this->privileges as $privilege) { echo '<tr>'; if ('{' === $privilege['principal'][0]) { echo '<td>', $html->xmlName($privilege['principal']), '</td>'; } else { echo '<td>', $html->link($privilege['principal']), '</td>'; } echo '<td>', $html->xmlName($privilege['privilege']), '</td>'; echo '<td>'; if (!empty($privilege['protected'])) { echo '(protected)'; } echo '</td>'; echo '</tr>'; } echo '</table>'; return ob_get_clean(); }
[ "public", "function", "toHtml", "(", "HtmlOutputHelper", "$", "html", ")", "{", "ob_start", "(", ")", ";", "echo", "'<table>'", ";", "echo", "'<tr><th>Principal</th><th>Privilege</th><th></th></tr>'", ";", "foreach", "(", "$", "this", "->", "privileges", "as", "$", "privilege", ")", "{", "echo", "'<tr>'", ";", "// if it starts with a {, it's a special principal", "if", "(", "'{'", "===", "$", "privilege", "[", "'principal'", "]", "[", "0", "]", ")", "{", "echo", "'<td>'", ",", "$", "html", "->", "xmlName", "(", "$", "privilege", "[", "'principal'", "]", ")", ",", "'</td>'", ";", "}", "else", "{", "echo", "'<td>'", ",", "$", "html", "->", "link", "(", "$", "privilege", "[", "'principal'", "]", ")", ",", "'</td>'", ";", "}", "echo", "'<td>'", ",", "$", "html", "->", "xmlName", "(", "$", "privilege", "[", "'privilege'", "]", ")", ",", "'</td>'", ";", "echo", "'<td>'", ";", "if", "(", "!", "empty", "(", "$", "privilege", "[", "'protected'", "]", ")", ")", "{", "echo", "'(protected)'", ";", "}", "echo", "'</td>'", ";", "echo", "'</tr>'", ";", "}", "echo", "'</table>'", ";", "return", "ob_get_clean", "(", ")", ";", "}" ]
Generate html representation for this value. The html output is 100% trusted, and no effort is being made to sanitize it. It's up to the implementor to sanitize user provided values. The output must be in UTF-8. The baseUri parameter is a url to the root of the application, and can be used to construct local links. @param HtmlOutputHelper $html @return string
[ "Generate", "html", "representation", "for", "this", "value", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Xml/Property/Acl.php#L120-L144
sabre-io/dav
lib/DAVACL/Xml/Property/Acl.php
Acl.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { $elementMap = [ '{DAV:}ace' => 'Sabre\Xml\Element\KeyValue', '{DAV:}privilege' => 'Sabre\Xml\Element\Elements', '{DAV:}principal' => 'Sabre\DAVACL\Xml\Property\Principal', ]; $privileges = []; foreach ((array) $reader->parseInnerTree($elementMap) as $element) { if ('{DAV:}ace' !== $element['name']) { continue; } $ace = $element['value']; if (empty($ace['{DAV:}principal'])) { throw new DAV\Exception\BadRequest('Each {DAV:}ace element must have one {DAV:}principal element'); } $principal = $ace['{DAV:}principal']; switch ($principal->getType()) { case Principal::HREF: $principal = $principal->getHref(); break; case Principal::AUTHENTICATED: $principal = '{DAV:}authenticated'; break; case Principal::UNAUTHENTICATED: $principal = '{DAV:}unauthenticated'; break; case Principal::ALL: $principal = '{DAV:}all'; break; } $protected = array_key_exists('{DAV:}protected', $ace); if (!isset($ace['{DAV:}grant'])) { throw new DAV\Exception\NotImplemented('Every {DAV:}ace element must have a {DAV:}grant element. {DAV:}deny is not yet supported'); } foreach ($ace['{DAV:}grant'] as $elem) { if ('{DAV:}privilege' !== $elem['name']) { continue; } foreach ($elem['value'] as $priv) { $privileges[] = [ 'principal' => $principal, 'protected' => $protected, 'privilege' => $priv, ]; } } } return new self($privileges); }
php
public static function xmlDeserialize(Reader $reader) { $elementMap = [ '{DAV:}ace' => 'Sabre\Xml\Element\KeyValue', '{DAV:}privilege' => 'Sabre\Xml\Element\Elements', '{DAV:}principal' => 'Sabre\DAVACL\Xml\Property\Principal', ]; $privileges = []; foreach ((array) $reader->parseInnerTree($elementMap) as $element) { if ('{DAV:}ace' !== $element['name']) { continue; } $ace = $element['value']; if (empty($ace['{DAV:}principal'])) { throw new DAV\Exception\BadRequest('Each {DAV:}ace element must have one {DAV:}principal element'); } $principal = $ace['{DAV:}principal']; switch ($principal->getType()) { case Principal::HREF: $principal = $principal->getHref(); break; case Principal::AUTHENTICATED: $principal = '{DAV:}authenticated'; break; case Principal::UNAUTHENTICATED: $principal = '{DAV:}unauthenticated'; break; case Principal::ALL: $principal = '{DAV:}all'; break; } $protected = array_key_exists('{DAV:}protected', $ace); if (!isset($ace['{DAV:}grant'])) { throw new DAV\Exception\NotImplemented('Every {DAV:}ace element must have a {DAV:}grant element. {DAV:}deny is not yet supported'); } foreach ($ace['{DAV:}grant'] as $elem) { if ('{DAV:}privilege' !== $elem['name']) { continue; } foreach ($elem['value'] as $priv) { $privileges[] = [ 'principal' => $principal, 'protected' => $protected, 'privilege' => $priv, ]; } } } return new self($privileges); }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "$", "elementMap", "=", "[", "'{DAV:}ace'", "=>", "'Sabre\\Xml\\Element\\KeyValue'", ",", "'{DAV:}privilege'", "=>", "'Sabre\\Xml\\Element\\Elements'", ",", "'{DAV:}principal'", "=>", "'Sabre\\DAVACL\\Xml\\Property\\Principal'", ",", "]", ";", "$", "privileges", "=", "[", "]", ";", "foreach", "(", "(", "array", ")", "$", "reader", "->", "parseInnerTree", "(", "$", "elementMap", ")", "as", "$", "element", ")", "{", "if", "(", "'{DAV:}ace'", "!==", "$", "element", "[", "'name'", "]", ")", "{", "continue", ";", "}", "$", "ace", "=", "$", "element", "[", "'value'", "]", ";", "if", "(", "empty", "(", "$", "ace", "[", "'{DAV:}principal'", "]", ")", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "BadRequest", "(", "'Each {DAV:}ace element must have one {DAV:}principal element'", ")", ";", "}", "$", "principal", "=", "$", "ace", "[", "'{DAV:}principal'", "]", ";", "switch", "(", "$", "principal", "->", "getType", "(", ")", ")", "{", "case", "Principal", "::", "HREF", ":", "$", "principal", "=", "$", "principal", "->", "getHref", "(", ")", ";", "break", ";", "case", "Principal", "::", "AUTHENTICATED", ":", "$", "principal", "=", "'{DAV:}authenticated'", ";", "break", ";", "case", "Principal", "::", "UNAUTHENTICATED", ":", "$", "principal", "=", "'{DAV:}unauthenticated'", ";", "break", ";", "case", "Principal", "::", "ALL", ":", "$", "principal", "=", "'{DAV:}all'", ";", "break", ";", "}", "$", "protected", "=", "array_key_exists", "(", "'{DAV:}protected'", ",", "$", "ace", ")", ";", "if", "(", "!", "isset", "(", "$", "ace", "[", "'{DAV:}grant'", "]", ")", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "NotImplemented", "(", "'Every {DAV:}ace element must have a {DAV:}grant element. {DAV:}deny is not yet supported'", ")", ";", "}", "foreach", "(", "$", "ace", "[", "'{DAV:}grant'", "]", "as", "$", "elem", ")", "{", "if", "(", "'{DAV:}privilege'", "!==", "$", "elem", "[", "'name'", "]", ")", "{", "continue", ";", "}", "foreach", "(", "$", "elem", "[", "'value'", "]", "as", "$", "priv", ")", "{", "$", "privileges", "[", "]", "=", "[", "'principal'", "=>", "$", "principal", ",", "'protected'", "=>", "$", "protected", ",", "'privilege'", "=>", "$", "priv", ",", "]", ";", "}", "}", "}", "return", "new", "self", "(", "$", "privileges", ")", ";", "}" ]
The deserialize method is called during xml parsing. This method is called statically, this is because in theory this method may be used as a type of constructor, or factory method. Often you want to return an instance of the current class, but you are free to return other data as well. Important note 2: You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop. If you just want to skip parsing for this element altogether, you can just call $reader->next(); $reader->parseInnerTree() will parse the entire sub-tree, and advance to the next element. @param Reader $reader @return mixed
[ "The", "deserialize", "method", "is", "called", "during", "xml", "parsing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Xml/Property/Acl.php#L168-L225
sabre-io/dav
lib/DAVACL/Xml/Property/Acl.php
Acl.serializeAce
private function serializeAce(Writer $writer, array $ace) { $writer->startElement('{DAV:}ace'); switch ($ace['principal']) { case '{DAV:}authenticated': $principal = new Principal(Principal::AUTHENTICATED); break; case '{DAV:}unauthenticated': $principal = new Principal(Principal::UNAUTHENTICATED); break; case '{DAV:}all': $principal = new Principal(Principal::ALL); break; default: $principal = new Principal(Principal::HREF, $ace['principal']); break; } $writer->writeElement('{DAV:}principal', $principal); $writer->startElement('{DAV:}grant'); $writer->startElement('{DAV:}privilege'); $writer->writeElement($ace['privilege']); $writer->endElement(); // privilege $writer->endElement(); // grant if (!empty($ace['protected'])) { $writer->writeElement('{DAV:}protected'); } $writer->endElement(); // ace }
php
private function serializeAce(Writer $writer, array $ace) { $writer->startElement('{DAV:}ace'); switch ($ace['principal']) { case '{DAV:}authenticated': $principal = new Principal(Principal::AUTHENTICATED); break; case '{DAV:}unauthenticated': $principal = new Principal(Principal::UNAUTHENTICATED); break; case '{DAV:}all': $principal = new Principal(Principal::ALL); break; default: $principal = new Principal(Principal::HREF, $ace['principal']); break; } $writer->writeElement('{DAV:}principal', $principal); $writer->startElement('{DAV:}grant'); $writer->startElement('{DAV:}privilege'); $writer->writeElement($ace['privilege']); $writer->endElement(); $writer->endElement(); if (!empty($ace['protected'])) { $writer->writeElement('{DAV:}protected'); } $writer->endElement(); }
[ "private", "function", "serializeAce", "(", "Writer", "$", "writer", ",", "array", "$", "ace", ")", "{", "$", "writer", "->", "startElement", "(", "'{DAV:}ace'", ")", ";", "switch", "(", "$", "ace", "[", "'principal'", "]", ")", "{", "case", "'{DAV:}authenticated'", ":", "$", "principal", "=", "new", "Principal", "(", "Principal", "::", "AUTHENTICATED", ")", ";", "break", ";", "case", "'{DAV:}unauthenticated'", ":", "$", "principal", "=", "new", "Principal", "(", "Principal", "::", "UNAUTHENTICATED", ")", ";", "break", ";", "case", "'{DAV:}all'", ":", "$", "principal", "=", "new", "Principal", "(", "Principal", "::", "ALL", ")", ";", "break", ";", "default", ":", "$", "principal", "=", "new", "Principal", "(", "Principal", "::", "HREF", ",", "$", "ace", "[", "'principal'", "]", ")", ";", "break", ";", "}", "$", "writer", "->", "writeElement", "(", "'{DAV:}principal'", ",", "$", "principal", ")", ";", "$", "writer", "->", "startElement", "(", "'{DAV:}grant'", ")", ";", "$", "writer", "->", "startElement", "(", "'{DAV:}privilege'", ")", ";", "$", "writer", "->", "writeElement", "(", "$", "ace", "[", "'privilege'", "]", ")", ";", "$", "writer", "->", "endElement", "(", ")", ";", "// privilege", "$", "writer", "->", "endElement", "(", ")", ";", "// grant", "if", "(", "!", "empty", "(", "$", "ace", "[", "'protected'", "]", ")", ")", "{", "$", "writer", "->", "writeElement", "(", "'{DAV:}protected'", ")", ";", "}", "$", "writer", "->", "endElement", "(", ")", ";", "// ace", "}" ]
Serializes a single access control entry. @param Writer $writer @param array $ace
[ "Serializes", "a", "single", "access", "control", "entry", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAVACL/Xml/Property/Acl.php#L233-L266
sabre-io/dav
lib/CardDAV/Xml/Request/AddressBookQueryReport.php
AddressBookQueryReport.xmlDeserialize
public static function xmlDeserialize(Reader $reader) { $elems = (array) $reader->parseInnerTree([ '{urn:ietf:params:xml:ns:carddav}prop-filter' => 'Sabre\\CardDAV\\Xml\\Filter\\PropFilter', '{urn:ietf:params:xml:ns:carddav}param-filter' => 'Sabre\\CardDAV\\Xml\\Filter\\ParamFilter', '{urn:ietf:params:xml:ns:carddav}address-data' => 'Sabre\\CardDAV\\Xml\\Filter\\AddressData', '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', ]); $newProps = [ 'filters' => null, 'properties' => [], 'test' => 'anyof', 'limit' => null, ]; if (!is_array($elems)) { $elems = []; } foreach ($elems as $elem) { switch ($elem['name']) { case '{DAV:}prop': $newProps['properties'] = array_keys($elem['value']); if (isset($elem['value']['{'.Plugin::NS_CARDDAV.'}address-data'])) { $newProps += $elem['value']['{'.Plugin::NS_CARDDAV.'}address-data']; } break; case '{'.Plugin::NS_CARDDAV.'}filter': if (!is_null($newProps['filters'])) { throw new BadRequest('You can only include 1 {'.Plugin::NS_CARDDAV.'}filter element'); } if (isset($elem['attributes']['test'])) { $newProps['test'] = $elem['attributes']['test']; if ('allof' !== $newProps['test'] && 'anyof' !== $newProps['test']) { throw new BadRequest('The "test" attribute must be one of "allof" or "anyof"'); } } $newProps['filters'] = []; foreach ((array) $elem['value'] as $subElem) { if ($subElem['name'] === '{'.Plugin::NS_CARDDAV.'}prop-filter') { $newProps['filters'][] = $subElem['value']; } } break; case '{'.Plugin::NS_CARDDAV.'}limit': foreach ($elem['value'] as $child) { if ($child['name'] === '{'.Plugin::NS_CARDDAV.'}nresults') { $newProps['limit'] = (int) $child['value']; } } break; } } if (is_null($newProps['filters'])) { /* * We are supposed to throw this error, but KDE sometimes does not * include the filter element, and we need to treat it as if no * filters are supplied */ //throw new BadRequest('The {' . Plugin::NS_CARDDAV . '}filter element is required for this request'); $newProps['filters'] = []; } $obj = new self(); foreach ($newProps as $key => $value) { $obj->$key = $value; } return $obj; }
php
public static function xmlDeserialize(Reader $reader) { $elems = (array) $reader->parseInnerTree([ '{urn:ietf:params:xml:ns:carddav}prop-filter' => 'Sabre\\CardDAV\\Xml\\Filter\\PropFilter', '{urn:ietf:params:xml:ns:carddav}param-filter' => 'Sabre\\CardDAV\\Xml\\Filter\\ParamFilter', '{urn:ietf:params:xml:ns:carddav}address-data' => 'Sabre\\CardDAV\\Xml\\Filter\\AddressData', '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', ]); $newProps = [ 'filters' => null, 'properties' => [], 'test' => 'anyof', 'limit' => null, ]; if (!is_array($elems)) { $elems = []; } foreach ($elems as $elem) { switch ($elem['name']) { case '{DAV:}prop': $newProps['properties'] = array_keys($elem['value']); if (isset($elem['value']['{'.Plugin::NS_CARDDAV.'}address-data'])) { $newProps += $elem['value']['{'.Plugin::NS_CARDDAV.'}address-data']; } break; case '{'.Plugin::NS_CARDDAV.'}filter': if (!is_null($newProps['filters'])) { throw new BadRequest('You can only include 1 {'.Plugin::NS_CARDDAV.'}filter element'); } if (isset($elem['attributes']['test'])) { $newProps['test'] = $elem['attributes']['test']; if ('allof' !== $newProps['test'] && 'anyof' !== $newProps['test']) { throw new BadRequest('The "test" attribute must be one of "allof" or "anyof"'); } } $newProps['filters'] = []; foreach ((array) $elem['value'] as $subElem) { if ($subElem['name'] === '{'.Plugin::NS_CARDDAV.'}prop-filter') { $newProps['filters'][] = $subElem['value']; } } break; case '{'.Plugin::NS_CARDDAV.'}limit': foreach ($elem['value'] as $child) { if ($child['name'] === '{'.Plugin::NS_CARDDAV.'}nresults') { $newProps['limit'] = (int) $child['value']; } } break; } } if (is_null($newProps['filters'])) { $newProps['filters'] = []; } $obj = new self(); foreach ($newProps as $key => $value) { $obj->$key = $value; } return $obj; }
[ "public", "static", "function", "xmlDeserialize", "(", "Reader", "$", "reader", ")", "{", "$", "elems", "=", "(", "array", ")", "$", "reader", "->", "parseInnerTree", "(", "[", "'{urn:ietf:params:xml:ns:carddav}prop-filter'", "=>", "'Sabre\\\\CardDAV\\\\Xml\\\\Filter\\\\PropFilter'", ",", "'{urn:ietf:params:xml:ns:carddav}param-filter'", "=>", "'Sabre\\\\CardDAV\\\\Xml\\\\Filter\\\\ParamFilter'", ",", "'{urn:ietf:params:xml:ns:carddav}address-data'", "=>", "'Sabre\\\\CardDAV\\\\Xml\\\\Filter\\\\AddressData'", ",", "'{DAV:}prop'", "=>", "'Sabre\\\\Xml\\\\Element\\\\KeyValue'", ",", "]", ")", ";", "$", "newProps", "=", "[", "'filters'", "=>", "null", ",", "'properties'", "=>", "[", "]", ",", "'test'", "=>", "'anyof'", ",", "'limit'", "=>", "null", ",", "]", ";", "if", "(", "!", "is_array", "(", "$", "elems", ")", ")", "{", "$", "elems", "=", "[", "]", ";", "}", "foreach", "(", "$", "elems", "as", "$", "elem", ")", "{", "switch", "(", "$", "elem", "[", "'name'", "]", ")", "{", "case", "'{DAV:}prop'", ":", "$", "newProps", "[", "'properties'", "]", "=", "array_keys", "(", "$", "elem", "[", "'value'", "]", ")", ";", "if", "(", "isset", "(", "$", "elem", "[", "'value'", "]", "[", "'{'", ".", "Plugin", "::", "NS_CARDDAV", ".", "'}address-data'", "]", ")", ")", "{", "$", "newProps", "+=", "$", "elem", "[", "'value'", "]", "[", "'{'", ".", "Plugin", "::", "NS_CARDDAV", ".", "'}address-data'", "]", ";", "}", "break", ";", "case", "'{'", ".", "Plugin", "::", "NS_CARDDAV", ".", "'}filter'", ":", "if", "(", "!", "is_null", "(", "$", "newProps", "[", "'filters'", "]", ")", ")", "{", "throw", "new", "BadRequest", "(", "'You can only include 1 {'", ".", "Plugin", "::", "NS_CARDDAV", ".", "'}filter element'", ")", ";", "}", "if", "(", "isset", "(", "$", "elem", "[", "'attributes'", "]", "[", "'test'", "]", ")", ")", "{", "$", "newProps", "[", "'test'", "]", "=", "$", "elem", "[", "'attributes'", "]", "[", "'test'", "]", ";", "if", "(", "'allof'", "!==", "$", "newProps", "[", "'test'", "]", "&&", "'anyof'", "!==", "$", "newProps", "[", "'test'", "]", ")", "{", "throw", "new", "BadRequest", "(", "'The \"test\" attribute must be one of \"allof\" or \"anyof\"'", ")", ";", "}", "}", "$", "newProps", "[", "'filters'", "]", "=", "[", "]", ";", "foreach", "(", "(", "array", ")", "$", "elem", "[", "'value'", "]", "as", "$", "subElem", ")", "{", "if", "(", "$", "subElem", "[", "'name'", "]", "===", "'{'", ".", "Plugin", "::", "NS_CARDDAV", ".", "'}prop-filter'", ")", "{", "$", "newProps", "[", "'filters'", "]", "[", "]", "=", "$", "subElem", "[", "'value'", "]", ";", "}", "}", "break", ";", "case", "'{'", ".", "Plugin", "::", "NS_CARDDAV", ".", "'}limit'", ":", "foreach", "(", "$", "elem", "[", "'value'", "]", "as", "$", "child", ")", "{", "if", "(", "$", "child", "[", "'name'", "]", "===", "'{'", ".", "Plugin", "::", "NS_CARDDAV", ".", "'}nresults'", ")", "{", "$", "newProps", "[", "'limit'", "]", "=", "(", "int", ")", "$", "child", "[", "'value'", "]", ";", "}", "}", "break", ";", "}", "}", "if", "(", "is_null", "(", "$", "newProps", "[", "'filters'", "]", ")", ")", "{", "/*\n * We are supposed to throw this error, but KDE sometimes does not\n * include the filter element, and we need to treat it as if no\n * filters are supplied\n */", "//throw new BadRequest('The {' . Plugin::NS_CARDDAV . '}filter element is required for this request');", "$", "newProps", "[", "'filters'", "]", "=", "[", "]", ";", "}", "$", "obj", "=", "new", "self", "(", ")", ";", "foreach", "(", "$", "newProps", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "obj", "->", "$", "key", "=", "$", "value", ";", "}", "return", "$", "obj", ";", "}" ]
The deserialize method is called during xml parsing. This method is called statically, this is because in theory this method may be used as a type of constructor, or factory method. Often you want to return an instance of the current class, but you are free to return other data as well. You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop. If you just want to skip parsing for this element altogether, you can just call $reader->next(); $reader->parseInnerTree() will parse the entire sub-tree, and advance to the next element. @param Reader $reader @return mixed
[ "The", "deserialize", "method", "is", "called", "during", "xml", "parsing", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CardDAV/Xml/Request/AddressBookQueryReport.php#L122-L195
sabre-io/dav
lib/DAV/FS/Node.php
Node.getName
public function getName() { if ($this->overrideName) { return $this->overrideName; } list(, $name) = Uri\split($this->path); return $name; }
php
public function getName() { if ($this->overrideName) { return $this->overrideName; } list(, $name) = Uri\split($this->path); return $name; }
[ "public", "function", "getName", "(", ")", "{", "if", "(", "$", "this", "->", "overrideName", ")", "{", "return", "$", "this", "->", "overrideName", ";", "}", "list", "(", ",", "$", "name", ")", "=", "Uri", "\\", "split", "(", "$", "this", "->", "path", ")", ";", "return", "$", "name", ";", "}" ]
Returns the name of the node. @return string
[ "Returns", "the", "name", "of", "the", "node", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/FS/Node.php#L56-L65
sabre-io/dav
lib/DAV/FS/Node.php
Node.setName
public function setName($name) { if ($this->overrideName) { throw new Forbidden('This node cannot be renamed'); } list($parentPath) = Uri\split($this->path); list(, $newName) = Uri\split($name); $newPath = $parentPath.'/'.$newName; rename($this->path, $newPath); $this->path = $newPath; }
php
public function setName($name) { if ($this->overrideName) { throw new Forbidden('This node cannot be renamed'); } list($parentPath) = Uri\split($this->path); list(, $newName) = Uri\split($name); $newPath = $parentPath.'/'.$newName; rename($this->path, $newPath); $this->path = $newPath; }
[ "public", "function", "setName", "(", "$", "name", ")", "{", "if", "(", "$", "this", "->", "overrideName", ")", "{", "throw", "new", "Forbidden", "(", "'This node cannot be renamed'", ")", ";", "}", "list", "(", "$", "parentPath", ")", "=", "Uri", "\\", "split", "(", "$", "this", "->", "path", ")", ";", "list", "(", ",", "$", "newName", ")", "=", "Uri", "\\", "split", "(", "$", "name", ")", ";", "$", "newPath", "=", "$", "parentPath", ".", "'/'", ".", "$", "newName", ";", "rename", "(", "$", "this", "->", "path", ",", "$", "newPath", ")", ";", "$", "this", "->", "path", "=", "$", "newPath", ";", "}" ]
Renames the node. @param string $name The new name
[ "Renames", "the", "node", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/FS/Node.php#L72-L85
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.getCalendarsForUser
public function getCalendarsForUser($principalUri) { $fields = array_values($this->propertyMap); $fields[] = 'calendarid'; $fields[] = 'uri'; $fields[] = 'synctoken'; $fields[] = 'components'; $fields[] = 'principaluri'; $fields[] = 'transparent'; $fields[] = 'access'; // Making fields a comma-delimited list $fields = implode(', ', $fields); $stmt = $this->pdo->prepare(<<<SQL SELECT {$this->calendarInstancesTableName}.id as id, $fields FROM {$this->calendarInstancesTableName} LEFT JOIN {$this->calendarTableName} ON {$this->calendarInstancesTableName}.calendarid = {$this->calendarTableName}.id WHERE principaluri = ? ORDER BY calendarorder ASC SQL ); $stmt->execute([$principalUri]); $calendars = []; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $components = []; if ($row['components']) { $components = explode(',', $row['components']); } $calendar = [ 'id' => [(int) $row['calendarid'], (int) $row['id']], 'uri' => $row['uri'], 'principaluri' => $row['principaluri'], '{'.CalDAV\Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', '{'.CalDAV\Plugin::NS_CALDAV.'}supported-calendar-component-set' => new CalDAV\Xml\Property\SupportedCalendarComponentSet($components), '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-calendar-transp' => new CalDAV\Xml\Property\ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), 'share-resource-uri' => '/ns/share/'.$row['calendarid'], ]; $calendar['share-access'] = (int) $row['access']; // 1 = owner, 2 = readonly, 3 = readwrite if ($row['access'] > 1) { // We need to find more information about the original owner. //$stmt2 = $this->pdo->prepare('SELECT principaluri FROM ' . $this->calendarInstancesTableName . ' WHERE access = 1 AND id = ?'); //$stmt2->execute([$row['id']]); // read-only is for backwards compatbility. Might go away in // the future. $calendar['read-only'] = \Sabre\DAV\Sharing\Plugin::ACCESS_READ === (int) $row['access']; } foreach ($this->propertyMap as $xmlName => $dbName) { $calendar[$xmlName] = $row[$dbName]; } $calendars[] = $calendar; } return $calendars; }
php
public function getCalendarsForUser($principalUri) { $fields = array_values($this->propertyMap); $fields[] = 'calendarid'; $fields[] = 'uri'; $fields[] = 'synctoken'; $fields[] = 'components'; $fields[] = 'principaluri'; $fields[] = 'transparent'; $fields[] = 'access'; $fields = implode(', ', $fields); $stmt = $this->pdo->prepare(<<<SQL SELECT {$this->calendarInstancesTableName}.id as id, $fields FROM {$this->calendarInstancesTableName} LEFT JOIN {$this->calendarTableName} ON {$this->calendarInstancesTableName}.calendarid = {$this->calendarTableName}.id WHERE principaluri = ? ORDER BY calendarorder ASC SQL ); $stmt->execute([$principalUri]); $calendars = []; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $components = []; if ($row['components']) { $components = explode(',', $row['components']); } $calendar = [ 'id' => [(int) $row['calendarid'], (int) $row['id']], 'uri' => $row['uri'], 'principaluri' => $row['principaluri'], '{'.CalDAV\Plugin::NS_CALENDARSERVER.'}getctag' => 'http: '{http: '{'.CalDAV\Plugin::NS_CALDAV.'}supported-calendar-component-set' => new CalDAV\Xml\Property\SupportedCalendarComponentSet($components), '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-calendar-transp' => new CalDAV\Xml\Property\ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), 'share-resource-uri' => '/ns/share/'.$row['calendarid'], ]; $calendar['share-access'] = (int) $row['access']; if ($row['access'] > 1) { $calendar['read-only'] = \Sabre\DAV\Sharing\Plugin::ACCESS_READ === (int) $row['access']; } foreach ($this->propertyMap as $xmlName => $dbName) { $calendar[$xmlName] = $row[$dbName]; } $calendars[] = $calendar; } return $calendars; }
[ "public", "function", "getCalendarsForUser", "(", "$", "principalUri", ")", "{", "$", "fields", "=", "array_values", "(", "$", "this", "->", "propertyMap", ")", ";", "$", "fields", "[", "]", "=", "'calendarid'", ";", "$", "fields", "[", "]", "=", "'uri'", ";", "$", "fields", "[", "]", "=", "'synctoken'", ";", "$", "fields", "[", "]", "=", "'components'", ";", "$", "fields", "[", "]", "=", "'principaluri'", ";", "$", "fields", "[", "]", "=", "'transparent'", ";", "$", "fields", "[", "]", "=", "'access'", ";", "// Making fields a comma-delimited list", "$", "fields", "=", "implode", "(", "', '", ",", "$", "fields", ")", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "<<<SQL\nSELECT {$this->calendarInstancesTableName}.id as id, $fields FROM {$this->calendarInstancesTableName}\n LEFT JOIN {$this->calendarTableName} ON\n {$this->calendarInstancesTableName}.calendarid = {$this->calendarTableName}.id\nWHERE principaluri = ? ORDER BY calendarorder ASC\nSQL", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "principalUri", "]", ")", ";", "$", "calendars", "=", "[", "]", ";", "while", "(", "$", "row", "=", "$", "stmt", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ")", "{", "$", "components", "=", "[", "]", ";", "if", "(", "$", "row", "[", "'components'", "]", ")", "{", "$", "components", "=", "explode", "(", "','", ",", "$", "row", "[", "'components'", "]", ")", ";", "}", "$", "calendar", "=", "[", "'id'", "=>", "[", "(", "int", ")", "$", "row", "[", "'calendarid'", "]", ",", "(", "int", ")", "$", "row", "[", "'id'", "]", "]", ",", "'uri'", "=>", "$", "row", "[", "'uri'", "]", ",", "'principaluri'", "=>", "$", "row", "[", "'principaluri'", "]", ",", "'{'", ".", "CalDAV", "\\", "Plugin", "::", "NS_CALENDARSERVER", ".", "'}getctag'", "=>", "'http://sabre.io/ns/sync/'", ".", "(", "$", "row", "[", "'synctoken'", "]", "?", "$", "row", "[", "'synctoken'", "]", ":", "'0'", ")", ",", "'{http://sabredav.org/ns}sync-token'", "=>", "$", "row", "[", "'synctoken'", "]", "?", "$", "row", "[", "'synctoken'", "]", ":", "'0'", ",", "'{'", ".", "CalDAV", "\\", "Plugin", "::", "NS_CALDAV", ".", "'}supported-calendar-component-set'", "=>", "new", "CalDAV", "\\", "Xml", "\\", "Property", "\\", "SupportedCalendarComponentSet", "(", "$", "components", ")", ",", "'{'", ".", "CalDAV", "\\", "Plugin", "::", "NS_CALDAV", ".", "'}schedule-calendar-transp'", "=>", "new", "CalDAV", "\\", "Xml", "\\", "Property", "\\", "ScheduleCalendarTransp", "(", "$", "row", "[", "'transparent'", "]", "?", "'transparent'", ":", "'opaque'", ")", ",", "'share-resource-uri'", "=>", "'/ns/share/'", ".", "$", "row", "[", "'calendarid'", "]", ",", "]", ";", "$", "calendar", "[", "'share-access'", "]", "=", "(", "int", ")", "$", "row", "[", "'access'", "]", ";", "// 1 = owner, 2 = readonly, 3 = readwrite", "if", "(", "$", "row", "[", "'access'", "]", ">", "1", ")", "{", "// We need to find more information about the original owner.", "//$stmt2 = $this->pdo->prepare('SELECT principaluri FROM ' . $this->calendarInstancesTableName . ' WHERE access = 1 AND id = ?');", "//$stmt2->execute([$row['id']]);", "// read-only is for backwards compatbility. Might go away in", "// the future.", "$", "calendar", "[", "'read-only'", "]", "=", "\\", "Sabre", "\\", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "ACCESS_READ", "===", "(", "int", ")", "$", "row", "[", "'access'", "]", ";", "}", "foreach", "(", "$", "this", "->", "propertyMap", "as", "$", "xmlName", "=>", "$", "dbName", ")", "{", "$", "calendar", "[", "$", "xmlName", "]", "=", "$", "row", "[", "$", "dbName", "]", ";", "}", "$", "calendars", "[", "]", "=", "$", "calendar", ";", "}", "return", "$", "calendars", ";", "}" ]
Returns a list of calendars for a principal. Every project is an array with the following keys: * id, a unique id that will be used by other functions to modify the calendar. This can be the same as the uri or a database key. * uri. This is just the 'base uri' or 'filename' of the calendar. * principaluri. The owner of the calendar. Almost always the same as principalUri passed to this method. Furthermore it can contain webdav properties in clark notation. A very common one is '{DAV:}displayname'. Many clients also require: {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set For this property, you can just return an instance of Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet. If you return {http://sabredav.org/ns}read-only and set the value to 1, ACL will automatically be put in read-only mode. @param string $principalUri @return array
[ "Returns", "a", "list", "of", "calendars", "for", "a", "principal", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L153-L213
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.createCalendar
public function createCalendar($principalUri, $calendarUri, array $properties) { $fieldNames = [ 'principaluri', 'uri', 'transparent', 'calendarid', ]; $values = [ ':principaluri' => $principalUri, ':uri' => $calendarUri, ':transparent' => 0, ]; $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; if (!isset($properties[$sccs])) { // Default value $components = 'VEVENT,VTODO'; } else { if (!($properties[$sccs] instanceof CalDAV\Xml\Property\SupportedCalendarComponentSet)) { throw new DAV\Exception('The '.$sccs.' property must be of type: \Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet'); } $components = implode(',', $properties[$sccs]->getValue()); } $transp = '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-calendar-transp'; if (isset($properties[$transp])) { $values[':transparent'] = 'transparent' === $properties[$transp]->getValue() ? 1 : 0; } $stmt = $this->pdo->prepare('INSERT INTO '.$this->calendarTableName.' (synctoken, components) VALUES (1, ?)'); $stmt->execute([$components]); $calendarId = $this->pdo->lastInsertId( $this->calendarTableName.'_id_seq' ); $values[':calendarid'] = $calendarId; foreach ($this->propertyMap as $xmlName => $dbName) { if (isset($properties[$xmlName])) { $values[':'.$dbName] = $properties[$xmlName]; $fieldNames[] = $dbName; } } $stmt = $this->pdo->prepare('INSERT INTO '.$this->calendarInstancesTableName.' ('.implode(', ', $fieldNames).') VALUES ('.implode(', ', array_keys($values)).')'); $stmt->execute($values); return [ $calendarId, $this->pdo->lastInsertId($this->calendarInstancesTableName.'_id_seq'), ]; }
php
public function createCalendar($principalUri, $calendarUri, array $properties) { $fieldNames = [ 'principaluri', 'uri', 'transparent', 'calendarid', ]; $values = [ ':principaluri' => $principalUri, ':uri' => $calendarUri, ':transparent' => 0, ]; $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; if (!isset($properties[$sccs])) { $components = 'VEVENT,VTODO'; } else { if (!($properties[$sccs] instanceof CalDAV\Xml\Property\SupportedCalendarComponentSet)) { throw new DAV\Exception('The '.$sccs.' property must be of type: \Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet'); } $components = implode(',', $properties[$sccs]->getValue()); } $transp = '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-calendar-transp'; if (isset($properties[$transp])) { $values[':transparent'] = 'transparent' === $properties[$transp]->getValue() ? 1 : 0; } $stmt = $this->pdo->prepare('INSERT INTO '.$this->calendarTableName.' (synctoken, components) VALUES (1, ?)'); $stmt->execute([$components]); $calendarId = $this->pdo->lastInsertId( $this->calendarTableName.'_id_seq' ); $values[':calendarid'] = $calendarId; foreach ($this->propertyMap as $xmlName => $dbName) { if (isset($properties[$xmlName])) { $values[':'.$dbName] = $properties[$xmlName]; $fieldNames[] = $dbName; } } $stmt = $this->pdo->prepare('INSERT INTO '.$this->calendarInstancesTableName.' ('.implode(', ', $fieldNames).') VALUES ('.implode(', ', array_keys($values)).')'); $stmt->execute($values); return [ $calendarId, $this->pdo->lastInsertId($this->calendarInstancesTableName.'_id_seq'), ]; }
[ "public", "function", "createCalendar", "(", "$", "principalUri", ",", "$", "calendarUri", ",", "array", "$", "properties", ")", "{", "$", "fieldNames", "=", "[", "'principaluri'", ",", "'uri'", ",", "'transparent'", ",", "'calendarid'", ",", "]", ";", "$", "values", "=", "[", "':principaluri'", "=>", "$", "principalUri", ",", "':uri'", "=>", "$", "calendarUri", ",", "':transparent'", "=>", "0", ",", "]", ";", "$", "sccs", "=", "'{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'", ";", "if", "(", "!", "isset", "(", "$", "properties", "[", "$", "sccs", "]", ")", ")", "{", "// Default value", "$", "components", "=", "'VEVENT,VTODO'", ";", "}", "else", "{", "if", "(", "!", "(", "$", "properties", "[", "$", "sccs", "]", "instanceof", "CalDAV", "\\", "Xml", "\\", "Property", "\\", "SupportedCalendarComponentSet", ")", ")", "{", "throw", "new", "DAV", "\\", "Exception", "(", "'The '", ".", "$", "sccs", ".", "' property must be of type: \\Sabre\\CalDAV\\Xml\\Property\\SupportedCalendarComponentSet'", ")", ";", "}", "$", "components", "=", "implode", "(", "','", ",", "$", "properties", "[", "$", "sccs", "]", "->", "getValue", "(", ")", ")", ";", "}", "$", "transp", "=", "'{'", ".", "CalDAV", "\\", "Plugin", "::", "NS_CALDAV", ".", "'}schedule-calendar-transp'", ";", "if", "(", "isset", "(", "$", "properties", "[", "$", "transp", "]", ")", ")", "{", "$", "values", "[", "':transparent'", "]", "=", "'transparent'", "===", "$", "properties", "[", "$", "transp", "]", "->", "getValue", "(", ")", "?", "1", ":", "0", ";", "}", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'INSERT INTO '", ".", "$", "this", "->", "calendarTableName", ".", "' (synctoken, components) VALUES (1, ?)'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "components", "]", ")", ";", "$", "calendarId", "=", "$", "this", "->", "pdo", "->", "lastInsertId", "(", "$", "this", "->", "calendarTableName", ".", "'_id_seq'", ")", ";", "$", "values", "[", "':calendarid'", "]", "=", "$", "calendarId", ";", "foreach", "(", "$", "this", "->", "propertyMap", "as", "$", "xmlName", "=>", "$", "dbName", ")", "{", "if", "(", "isset", "(", "$", "properties", "[", "$", "xmlName", "]", ")", ")", "{", "$", "values", "[", "':'", ".", "$", "dbName", "]", "=", "$", "properties", "[", "$", "xmlName", "]", ";", "$", "fieldNames", "[", "]", "=", "$", "dbName", ";", "}", "}", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'INSERT INTO '", ".", "$", "this", "->", "calendarInstancesTableName", ".", "' ('", ".", "implode", "(", "', '", ",", "$", "fieldNames", ")", ".", "') VALUES ('", ".", "implode", "(", "', '", ",", "array_keys", "(", "$", "values", ")", ")", ".", "')'", ")", ";", "$", "stmt", "->", "execute", "(", "$", "values", ")", ";", "return", "[", "$", "calendarId", ",", "$", "this", "->", "pdo", "->", "lastInsertId", "(", "$", "this", "->", "calendarInstancesTableName", ".", "'_id_seq'", ")", ",", "]", ";", "}" ]
Creates a new calendar for a principal. If the creation was a success, an id must be returned that can be used to reference this calendar in other methods, such as updateCalendar. @param string $principalUri @param string $calendarUri @param array $properties @return string
[ "Creates", "a", "new", "calendar", "for", "a", "principal", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L227-L279
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.updateCalendar
public function updateCalendar($calendarId, \Sabre\DAV\PropPatch $propPatch) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; $supportedProperties = array_keys($this->propertyMap); $supportedProperties[] = '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-calendar-transp'; $propPatch->handle($supportedProperties, function ($mutations) use ($calendarId, $instanceId) { $newValues = []; foreach ($mutations as $propertyName => $propertyValue) { switch ($propertyName) { case '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-calendar-transp': $fieldName = 'transparent'; $newValues[$fieldName] = 'transparent' === $propertyValue->getValue(); break; default: $fieldName = $this->propertyMap[$propertyName]; $newValues[$fieldName] = $propertyValue; break; } } $valuesSql = []; foreach ($newValues as $fieldName => $value) { $valuesSql[] = $fieldName.' = ?'; } $stmt = $this->pdo->prepare('UPDATE '.$this->calendarInstancesTableName.' SET '.implode(', ', $valuesSql).' WHERE id = ?'); $newValues['id'] = $instanceId; $stmt->execute(array_values($newValues)); $this->addChange($calendarId, '', 2); return true; }); }
php
public function updateCalendar($calendarId, \Sabre\DAV\PropPatch $propPatch) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; $supportedProperties = array_keys($this->propertyMap); $supportedProperties[] = '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-calendar-transp'; $propPatch->handle($supportedProperties, function ($mutations) use ($calendarId, $instanceId) { $newValues = []; foreach ($mutations as $propertyName => $propertyValue) { switch ($propertyName) { case '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-calendar-transp': $fieldName = 'transparent'; $newValues[$fieldName] = 'transparent' === $propertyValue->getValue(); break; default: $fieldName = $this->propertyMap[$propertyName]; $newValues[$fieldName] = $propertyValue; break; } } $valuesSql = []; foreach ($newValues as $fieldName => $value) { $valuesSql[] = $fieldName.' = ?'; } $stmt = $this->pdo->prepare('UPDATE '.$this->calendarInstancesTableName.' SET '.implode(', ', $valuesSql).' WHERE id = ?'); $newValues['id'] = $instanceId; $stmt->execute(array_values($newValues)); $this->addChange($calendarId, '', 2); return true; }); }
[ "public", "function", "updateCalendar", "(", "$", "calendarId", ",", "\\", "Sabre", "\\", "DAV", "\\", "PropPatch", "$", "propPatch", ")", "{", "if", "(", "!", "is_array", "(", "$", "calendarId", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'", ")", ";", "}", "list", "(", "$", "calendarId", ",", "$", "instanceId", ")", "=", "$", "calendarId", ";", "$", "supportedProperties", "=", "array_keys", "(", "$", "this", "->", "propertyMap", ")", ";", "$", "supportedProperties", "[", "]", "=", "'{'", ".", "CalDAV", "\\", "Plugin", "::", "NS_CALDAV", ".", "'}schedule-calendar-transp'", ";", "$", "propPatch", "->", "handle", "(", "$", "supportedProperties", ",", "function", "(", "$", "mutations", ")", "use", "(", "$", "calendarId", ",", "$", "instanceId", ")", "{", "$", "newValues", "=", "[", "]", ";", "foreach", "(", "$", "mutations", "as", "$", "propertyName", "=>", "$", "propertyValue", ")", "{", "switch", "(", "$", "propertyName", ")", "{", "case", "'{'", ".", "CalDAV", "\\", "Plugin", "::", "NS_CALDAV", ".", "'}schedule-calendar-transp'", ":", "$", "fieldName", "=", "'transparent'", ";", "$", "newValues", "[", "$", "fieldName", "]", "=", "'transparent'", "===", "$", "propertyValue", "->", "getValue", "(", ")", ";", "break", ";", "default", ":", "$", "fieldName", "=", "$", "this", "->", "propertyMap", "[", "$", "propertyName", "]", ";", "$", "newValues", "[", "$", "fieldName", "]", "=", "$", "propertyValue", ";", "break", ";", "}", "}", "$", "valuesSql", "=", "[", "]", ";", "foreach", "(", "$", "newValues", "as", "$", "fieldName", "=>", "$", "value", ")", "{", "$", "valuesSql", "[", "]", "=", "$", "fieldName", ".", "' = ?'", ";", "}", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'UPDATE '", ".", "$", "this", "->", "calendarInstancesTableName", ".", "' SET '", ".", "implode", "(", "', '", ",", "$", "valuesSql", ")", ".", "' WHERE id = ?'", ")", ";", "$", "newValues", "[", "'id'", "]", "=", "$", "instanceId", ";", "$", "stmt", "->", "execute", "(", "array_values", "(", "$", "newValues", ")", ")", ";", "$", "this", "->", "addChange", "(", "$", "calendarId", ",", "''", ",", "2", ")", ";", "return", "true", ";", "}", ")", ";", "}" ]
Updates properties for a calendar. 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 mixed $calendarId @param \Sabre\DAV\PropPatch $propPatch
[ "Updates", "properties", "for", "a", "calendar", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L296-L333
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.deleteCalendar
public function deleteCalendar($calendarId) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; $stmt = $this->pdo->prepare('SELECT access FROM '.$this->calendarInstancesTableName.' where id = ?'); $stmt->execute([$instanceId]); $access = (int) $stmt->fetchColumn(); if (\Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER === $access) { /** * If the user is the owner of the calendar, we delete all data and all * instances. **/ $stmt = $this->pdo->prepare('DELETE FROM '.$this->calendarObjectTableName.' WHERE calendarid = ?'); $stmt->execute([$calendarId]); $stmt = $this->pdo->prepare('DELETE FROM '.$this->calendarChangesTableName.' WHERE calendarid = ?'); $stmt->execute([$calendarId]); $stmt = $this->pdo->prepare('DELETE FROM '.$this->calendarInstancesTableName.' WHERE calendarid = ?'); $stmt->execute([$calendarId]); $stmt = $this->pdo->prepare('DELETE FROM '.$this->calendarTableName.' WHERE id = ?'); $stmt->execute([$calendarId]); } else { /** * If it was an instance of a shared calendar, we only delete that * instance. */ $stmt = $this->pdo->prepare('DELETE FROM '.$this->calendarInstancesTableName.' WHERE id = ?'); $stmt->execute([$instanceId]); } }
php
public function deleteCalendar($calendarId) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; $stmt = $this->pdo->prepare('SELECT access FROM '.$this->calendarInstancesTableName.' where id = ?'); $stmt->execute([$instanceId]); $access = (int) $stmt->fetchColumn(); if (\Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER === $access) { $stmt = $this->pdo->prepare('DELETE FROM '.$this->calendarObjectTableName.' WHERE calendarid = ?'); $stmt->execute([$calendarId]); $stmt = $this->pdo->prepare('DELETE FROM '.$this->calendarChangesTableName.' WHERE calendarid = ?'); $stmt->execute([$calendarId]); $stmt = $this->pdo->prepare('DELETE FROM '.$this->calendarInstancesTableName.' WHERE calendarid = ?'); $stmt->execute([$calendarId]); $stmt = $this->pdo->prepare('DELETE FROM '.$this->calendarTableName.' WHERE id = ?'); $stmt->execute([$calendarId]); } else { $stmt = $this->pdo->prepare('DELETE FROM '.$this->calendarInstancesTableName.' WHERE id = ?'); $stmt->execute([$instanceId]); } }
[ "public", "function", "deleteCalendar", "(", "$", "calendarId", ")", "{", "if", "(", "!", "is_array", "(", "$", "calendarId", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'", ")", ";", "}", "list", "(", "$", "calendarId", ",", "$", "instanceId", ")", "=", "$", "calendarId", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'SELECT access FROM '", ".", "$", "this", "->", "calendarInstancesTableName", ".", "' where id = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "instanceId", "]", ")", ";", "$", "access", "=", "(", "int", ")", "$", "stmt", "->", "fetchColumn", "(", ")", ";", "if", "(", "\\", "Sabre", "\\", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "ACCESS_SHAREDOWNER", "===", "$", "access", ")", "{", "/**\n * If the user is the owner of the calendar, we delete all data and all\n * instances.\n **/", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'DELETE FROM '", ".", "$", "this", "->", "calendarObjectTableName", ".", "' WHERE calendarid = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "calendarId", "]", ")", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'DELETE FROM '", ".", "$", "this", "->", "calendarChangesTableName", ".", "' WHERE calendarid = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "calendarId", "]", ")", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'DELETE FROM '", ".", "$", "this", "->", "calendarInstancesTableName", ".", "' WHERE calendarid = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "calendarId", "]", ")", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'DELETE FROM '", ".", "$", "this", "->", "calendarTableName", ".", "' WHERE id = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "calendarId", "]", ")", ";", "}", "else", "{", "/**\n * If it was an instance of a shared calendar, we only delete that\n * instance.\n */", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'DELETE FROM '", ".", "$", "this", "->", "calendarInstancesTableName", ".", "' WHERE id = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "instanceId", "]", ")", ";", "}", "}" ]
Delete a calendar and all it's objects. @param mixed $calendarId
[ "Delete", "a", "calendar", "and", "all", "it", "s", "objects", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L340-L375
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.getCalendarObjects
public function getCalendarObjects($calendarId) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; $stmt = $this->pdo->prepare('SELECT id, uri, lastmodified, etag, calendarid, size, componenttype FROM '.$this->calendarObjectTableName.' WHERE calendarid = ?'); $stmt->execute([$calendarId]); $result = []; foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { $result[] = [ 'id' => $row['id'], 'uri' => $row['uri'], 'lastmodified' => (int) $row['lastmodified'], 'etag' => '"'.$row['etag'].'"', 'size' => (int) $row['size'], 'component' => strtolower($row['componenttype']), ]; } return $result; }
php
public function getCalendarObjects($calendarId) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; $stmt = $this->pdo->prepare('SELECT id, uri, lastmodified, etag, calendarid, size, componenttype FROM '.$this->calendarObjectTableName.' WHERE calendarid = ?'); $stmt->execute([$calendarId]); $result = []; foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { $result[] = [ 'id' => $row['id'], 'uri' => $row['uri'], 'lastmodified' => (int) $row['lastmodified'], 'etag' => '"'.$row['etag'].'"', 'size' => (int) $row['size'], 'component' => strtolower($row['componenttype']), ]; } return $result; }
[ "public", "function", "getCalendarObjects", "(", "$", "calendarId", ")", "{", "if", "(", "!", "is_array", "(", "$", "calendarId", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'", ")", ";", "}", "list", "(", "$", "calendarId", ",", "$", "instanceId", ")", "=", "$", "calendarId", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'SELECT id, uri, lastmodified, etag, calendarid, size, componenttype FROM '", ".", "$", "this", "->", "calendarObjectTableName", ".", "' WHERE calendarid = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "calendarId", "]", ")", ";", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "stmt", "->", "fetchAll", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", "as", "$", "row", ")", "{", "$", "result", "[", "]", "=", "[", "'id'", "=>", "$", "row", "[", "'id'", "]", ",", "'uri'", "=>", "$", "row", "[", "'uri'", "]", ",", "'lastmodified'", "=>", "(", "int", ")", "$", "row", "[", "'lastmodified'", "]", ",", "'etag'", "=>", "'\"'", ".", "$", "row", "[", "'etag'", "]", ".", "'\"'", ",", "'size'", "=>", "(", "int", ")", "$", "row", "[", "'size'", "]", ",", "'component'", "=>", "strtolower", "(", "$", "row", "[", "'componenttype'", "]", ")", ",", "]", ";", "}", "return", "$", "result", ";", "}" ]
Returns all calendar objects within a calendar. Every item contains an array with the following keys: * calendardata - The iCalendar-compatible calendar data * uri - a unique key which will be used to construct the uri. This can be any arbitrary string, but making sure it ends with '.ics' is a good idea. This is only the basename, or filename, not the full path. * lastmodified - a timestamp of the last modification time * etag - An arbitrary string, surrounded by double-quotes. (e.g.: ' "abcdef"') * size - The size of the calendar objects, in bytes. * component - optional, a string containing the type of object, such as 'vevent' or 'vtodo'. If specified, this will be used to populate the Content-Type header. Note that the etag is optional, but it's highly encouraged to return for speed reasons. The calendardata is also optional. If it's not returned 'getCalendarObject' will be called later, which *is* expected to return calendardata. If neither etag or size are specified, the calendardata will be used/fetched to determine these numbers. If both are specified the amount of times this is needed is reduced by a great degree. @param mixed $calendarId @return array
[ "Returns", "all", "calendar", "objects", "within", "a", "calendar", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L409-L432
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.getCalendarObject
public function getCalendarObject($calendarId, $objectUri) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; $stmt = $this->pdo->prepare('SELECT id, uri, lastmodified, etag, calendarid, size, calendardata, componenttype FROM '.$this->calendarObjectTableName.' WHERE calendarid = ? AND uri = ?'); $stmt->execute([$calendarId, $objectUri]); $row = $stmt->fetch(\PDO::FETCH_ASSOC); if (!$row) { return null; } return [ 'id' => $row['id'], 'uri' => $row['uri'], 'lastmodified' => (int) $row['lastmodified'], 'etag' => '"'.$row['etag'].'"', 'size' => (int) $row['size'], 'calendardata' => $row['calendardata'], 'component' => strtolower($row['componenttype']), ]; }
php
public function getCalendarObject($calendarId, $objectUri) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; $stmt = $this->pdo->prepare('SELECT id, uri, lastmodified, etag, calendarid, size, calendardata, componenttype FROM '.$this->calendarObjectTableName.' WHERE calendarid = ? AND uri = ?'); $stmt->execute([$calendarId, $objectUri]); $row = $stmt->fetch(\PDO::FETCH_ASSOC); if (!$row) { return null; } return [ 'id' => $row['id'], 'uri' => $row['uri'], 'lastmodified' => (int) $row['lastmodified'], 'etag' => '"'.$row['etag'].'"', 'size' => (int) $row['size'], 'calendardata' => $row['calendardata'], 'component' => strtolower($row['componenttype']), ]; }
[ "public", "function", "getCalendarObject", "(", "$", "calendarId", ",", "$", "objectUri", ")", "{", "if", "(", "!", "is_array", "(", "$", "calendarId", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'", ")", ";", "}", "list", "(", "$", "calendarId", ",", "$", "instanceId", ")", "=", "$", "calendarId", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'SELECT id, uri, lastmodified, etag, calendarid, size, calendardata, componenttype FROM '", ".", "$", "this", "->", "calendarObjectTableName", ".", "' WHERE calendarid = ? AND uri = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "calendarId", ",", "$", "objectUri", "]", ")", ";", "$", "row", "=", "$", "stmt", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ";", "if", "(", "!", "$", "row", ")", "{", "return", "null", ";", "}", "return", "[", "'id'", "=>", "$", "row", "[", "'id'", "]", ",", "'uri'", "=>", "$", "row", "[", "'uri'", "]", ",", "'lastmodified'", "=>", "(", "int", ")", "$", "row", "[", "'lastmodified'", "]", ",", "'etag'", "=>", "'\"'", ".", "$", "row", "[", "'etag'", "]", ".", "'\"'", ",", "'size'", "=>", "(", "int", ")", "$", "row", "[", "'size'", "]", ",", "'calendardata'", "=>", "$", "row", "[", "'calendardata'", "]", ",", "'component'", "=>", "strtolower", "(", "$", "row", "[", "'componenttype'", "]", ")", ",", "]", ";", "}" ]
Returns information from a single calendar object, based on it's object uri. The object uri is only the basename, or filename and not a full path. The returned array must have the same keys as getCalendarObjects. The 'calendardata' object is required here though, while it's not required for getCalendarObjects. This method must return null if the object did not exist. @param mixed $calendarId @param string $objectUri @return array|null
[ "Returns", "information", "from", "a", "single", "calendar", "object", "based", "on", "it", "s", "object", "uri", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L451-L475
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.getMultipleCalendarObjects
public function getMultipleCalendarObjects($calendarId, array $uris) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; $result = []; foreach (array_chunk($uris, 900) as $chunk) { $query = 'SELECT id, uri, lastmodified, etag, calendarid, size, calendardata, componenttype FROM '.$this->calendarObjectTableName.' WHERE calendarid = ? AND uri IN ('; // Inserting a whole bunch of question marks $query .= implode(',', array_fill(0, count($chunk), '?')); $query .= ')'; $stmt = $this->pdo->prepare($query); $stmt->execute(array_merge([$calendarId], $chunk)); while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $result[] = [ 'id' => $row['id'], 'uri' => $row['uri'], 'lastmodified' => (int) $row['lastmodified'], 'etag' => '"'.$row['etag'].'"', 'size' => (int) $row['size'], 'calendardata' => $row['calendardata'], 'component' => strtolower($row['componenttype']), ]; } } return $result; }
php
public function getMultipleCalendarObjects($calendarId, array $uris) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; $result = []; foreach (array_chunk($uris, 900) as $chunk) { $query = 'SELECT id, uri, lastmodified, etag, calendarid, size, calendardata, componenttype FROM '.$this->calendarObjectTableName.' WHERE calendarid = ? AND uri IN ('; $query .= implode(',', array_fill(0, count($chunk), '?')); $query .= ')'; $stmt = $this->pdo->prepare($query); $stmt->execute(array_merge([$calendarId], $chunk)); while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $result[] = [ 'id' => $row['id'], 'uri' => $row['uri'], 'lastmodified' => (int) $row['lastmodified'], 'etag' => '"'.$row['etag'].'"', 'size' => (int) $row['size'], 'calendardata' => $row['calendardata'], 'component' => strtolower($row['componenttype']), ]; } } return $result; }
[ "public", "function", "getMultipleCalendarObjects", "(", "$", "calendarId", ",", "array", "$", "uris", ")", "{", "if", "(", "!", "is_array", "(", "$", "calendarId", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'", ")", ";", "}", "list", "(", "$", "calendarId", ",", "$", "instanceId", ")", "=", "$", "calendarId", ";", "$", "result", "=", "[", "]", ";", "foreach", "(", "array_chunk", "(", "$", "uris", ",", "900", ")", "as", "$", "chunk", ")", "{", "$", "query", "=", "'SELECT id, uri, lastmodified, etag, calendarid, size, calendardata, componenttype FROM '", ".", "$", "this", "->", "calendarObjectTableName", ".", "' WHERE calendarid = ? AND uri IN ('", ";", "// Inserting a whole bunch of question marks", "$", "query", ".=", "implode", "(", "','", ",", "array_fill", "(", "0", ",", "count", "(", "$", "chunk", ")", ",", "'?'", ")", ")", ";", "$", "query", ".=", "')'", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "$", "query", ")", ";", "$", "stmt", "->", "execute", "(", "array_merge", "(", "[", "$", "calendarId", "]", ",", "$", "chunk", ")", ")", ";", "while", "(", "$", "row", "=", "$", "stmt", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ")", "{", "$", "result", "[", "]", "=", "[", "'id'", "=>", "$", "row", "[", "'id'", "]", ",", "'uri'", "=>", "$", "row", "[", "'uri'", "]", ",", "'lastmodified'", "=>", "(", "int", ")", "$", "row", "[", "'lastmodified'", "]", ",", "'etag'", "=>", "'\"'", ".", "$", "row", "[", "'etag'", "]", ".", "'\"'", ",", "'size'", "=>", "(", "int", ")", "$", "row", "[", "'size'", "]", ",", "'calendardata'", "=>", "$", "row", "[", "'calendardata'", "]", ",", "'component'", "=>", "strtolower", "(", "$", "row", "[", "'componenttype'", "]", ")", ",", "]", ";", "}", "}", "return", "$", "result", ";", "}" ]
Returns a list of calendar objects. This method should work identical to getCalendarObject, but instead return all the calendar objects in the list as an array. If the backend supports this, it may allow for some speed-ups. @param mixed $calendarId @param array $uris @return array
[ "Returns", "a", "list", "of", "calendar", "objects", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L490-L521
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.createCalendarObject
public function createCalendarObject($calendarId, $objectUri, $calendarData) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; $extraData = $this->getDenormalizedData($calendarData); $stmt = $this->pdo->prepare('INSERT INTO '.$this->calendarObjectTableName.' (calendarid, uri, calendardata, lastmodified, etag, size, componenttype, firstoccurence, lastoccurence, uid) VALUES (?,?,?,?,?,?,?,?,?,?)'); $stmt->execute([ $calendarId, $objectUri, $calendarData, time(), $extraData['etag'], $extraData['size'], $extraData['componentType'], $extraData['firstOccurence'], $extraData['lastOccurence'], $extraData['uid'], ]); $this->addChange($calendarId, $objectUri, 1); return '"'.$extraData['etag'].'"'; }
php
public function createCalendarObject($calendarId, $objectUri, $calendarData) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; $extraData = $this->getDenormalizedData($calendarData); $stmt = $this->pdo->prepare('INSERT INTO '.$this->calendarObjectTableName.' (calendarid, uri, calendardata, lastmodified, etag, size, componenttype, firstoccurence, lastoccurence, uid) VALUES (?,?,?,?,?,?,?,?,?,?)'); $stmt->execute([ $calendarId, $objectUri, $calendarData, time(), $extraData['etag'], $extraData['size'], $extraData['componentType'], $extraData['firstOccurence'], $extraData['lastOccurence'], $extraData['uid'], ]); $this->addChange($calendarId, $objectUri, 1); return '"'.$extraData['etag'].'"'; }
[ "public", "function", "createCalendarObject", "(", "$", "calendarId", ",", "$", "objectUri", ",", "$", "calendarData", ")", "{", "if", "(", "!", "is_array", "(", "$", "calendarId", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'", ")", ";", "}", "list", "(", "$", "calendarId", ",", "$", "instanceId", ")", "=", "$", "calendarId", ";", "$", "extraData", "=", "$", "this", "->", "getDenormalizedData", "(", "$", "calendarData", ")", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'INSERT INTO '", ".", "$", "this", "->", "calendarObjectTableName", ".", "' (calendarid, uri, calendardata, lastmodified, etag, size, componenttype, firstoccurence, lastoccurence, uid) VALUES (?,?,?,?,?,?,?,?,?,?)'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "calendarId", ",", "$", "objectUri", ",", "$", "calendarData", ",", "time", "(", ")", ",", "$", "extraData", "[", "'etag'", "]", ",", "$", "extraData", "[", "'size'", "]", ",", "$", "extraData", "[", "'componentType'", "]", ",", "$", "extraData", "[", "'firstOccurence'", "]", ",", "$", "extraData", "[", "'lastOccurence'", "]", ",", "$", "extraData", "[", "'uid'", "]", ",", "]", ")", ";", "$", "this", "->", "addChange", "(", "$", "calendarId", ",", "$", "objectUri", ",", "1", ")", ";", "return", "'\"'", ".", "$", "extraData", "[", "'etag'", "]", ".", "'\"'", ";", "}" ]
Creates a new calendar object. 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
[ "Creates", "a", "new", "calendar", "object", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L542-L567
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.getDenormalizedData
protected function getDenormalizedData($calendarData) { $vObject = VObject\Reader::read($calendarData); $componentType = null; $component = null; $firstOccurence = null; $lastOccurence = null; $uid = null; foreach ($vObject->getComponents() as $component) { if ('VTIMEZONE' !== $component->name) { $componentType = $component->name; $uid = (string) $component->UID; break; } } if (!$componentType) { throw new \Sabre\DAV\Exception\BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component'); } if ('VEVENT' === $componentType) { $firstOccurence = $component->DTSTART->getDateTime()->getTimeStamp(); // Finding the last occurence is a bit harder if (!isset($component->RRULE)) { if (isset($component->DTEND)) { $lastOccurence = $component->DTEND->getDateTime()->getTimeStamp(); } elseif (isset($component->DURATION)) { $endDate = clone $component->DTSTART->getDateTime(); $endDate = $endDate->add(VObject\DateTimeParser::parse($component->DURATION->getValue())); $lastOccurence = $endDate->getTimeStamp(); } elseif (!$component->DTSTART->hasTime()) { $endDate = clone $component->DTSTART->getDateTime(); $endDate = $endDate->modify('+1 day'); $lastOccurence = $endDate->getTimeStamp(); } else { $lastOccurence = $firstOccurence; } } else { $it = new VObject\Recur\EventIterator($vObject, (string) $component->UID); $maxDate = new \DateTime(self::MAX_DATE); if ($it->isInfinite()) { $lastOccurence = $maxDate->getTimeStamp(); } else { $end = $it->getDtEnd(); while ($it->valid() && $end < $maxDate) { $end = $it->getDtEnd(); $it->next(); } $lastOccurence = $end->getTimeStamp(); } } // Ensure Occurence values are positive if ($firstOccurence < 0) { $firstOccurence = 0; } if ($lastOccurence < 0) { $lastOccurence = 0; } } // Destroy circular references to PHP will GC the object. $vObject->destroy(); return [ 'etag' => md5($calendarData), 'size' => strlen($calendarData), 'componentType' => $componentType, 'firstOccurence' => $firstOccurence, 'lastOccurence' => $lastOccurence, 'uid' => $uid, ]; }
php
protected function getDenormalizedData($calendarData) { $vObject = VObject\Reader::read($calendarData); $componentType = null; $component = null; $firstOccurence = null; $lastOccurence = null; $uid = null; foreach ($vObject->getComponents() as $component) { if ('VTIMEZONE' !== $component->name) { $componentType = $component->name; $uid = (string) $component->UID; break; } } if (!$componentType) { throw new \Sabre\DAV\Exception\BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component'); } if ('VEVENT' === $componentType) { $firstOccurence = $component->DTSTART->getDateTime()->getTimeStamp(); if (!isset($component->RRULE)) { if (isset($component->DTEND)) { $lastOccurence = $component->DTEND->getDateTime()->getTimeStamp(); } elseif (isset($component->DURATION)) { $endDate = clone $component->DTSTART->getDateTime(); $endDate = $endDate->add(VObject\DateTimeParser::parse($component->DURATION->getValue())); $lastOccurence = $endDate->getTimeStamp(); } elseif (!$component->DTSTART->hasTime()) { $endDate = clone $component->DTSTART->getDateTime(); $endDate = $endDate->modify('+1 day'); $lastOccurence = $endDate->getTimeStamp(); } else { $lastOccurence = $firstOccurence; } } else { $it = new VObject\Recur\EventIterator($vObject, (string) $component->UID); $maxDate = new \DateTime(self::MAX_DATE); if ($it->isInfinite()) { $lastOccurence = $maxDate->getTimeStamp(); } else { $end = $it->getDtEnd(); while ($it->valid() && $end < $maxDate) { $end = $it->getDtEnd(); $it->next(); } $lastOccurence = $end->getTimeStamp(); } } if ($firstOccurence < 0) { $firstOccurence = 0; } if ($lastOccurence < 0) { $lastOccurence = 0; } } $vObject->destroy(); return [ 'etag' => md5($calendarData), 'size' => strlen($calendarData), 'componentType' => $componentType, 'firstOccurence' => $firstOccurence, 'lastOccurence' => $lastOccurence, 'uid' => $uid, ]; }
[ "protected", "function", "getDenormalizedData", "(", "$", "calendarData", ")", "{", "$", "vObject", "=", "VObject", "\\", "Reader", "::", "read", "(", "$", "calendarData", ")", ";", "$", "componentType", "=", "null", ";", "$", "component", "=", "null", ";", "$", "firstOccurence", "=", "null", ";", "$", "lastOccurence", "=", "null", ";", "$", "uid", "=", "null", ";", "foreach", "(", "$", "vObject", "->", "getComponents", "(", ")", "as", "$", "component", ")", "{", "if", "(", "'VTIMEZONE'", "!==", "$", "component", "->", "name", ")", "{", "$", "componentType", "=", "$", "component", "->", "name", ";", "$", "uid", "=", "(", "string", ")", "$", "component", "->", "UID", ";", "break", ";", "}", "}", "if", "(", "!", "$", "componentType", ")", "{", "throw", "new", "\\", "Sabre", "\\", "DAV", "\\", "Exception", "\\", "BadRequest", "(", "'Calendar objects must have a VJOURNAL, VEVENT or VTODO component'", ")", ";", "}", "if", "(", "'VEVENT'", "===", "$", "componentType", ")", "{", "$", "firstOccurence", "=", "$", "component", "->", "DTSTART", "->", "getDateTime", "(", ")", "->", "getTimeStamp", "(", ")", ";", "// Finding the last occurence is a bit harder", "if", "(", "!", "isset", "(", "$", "component", "->", "RRULE", ")", ")", "{", "if", "(", "isset", "(", "$", "component", "->", "DTEND", ")", ")", "{", "$", "lastOccurence", "=", "$", "component", "->", "DTEND", "->", "getDateTime", "(", ")", "->", "getTimeStamp", "(", ")", ";", "}", "elseif", "(", "isset", "(", "$", "component", "->", "DURATION", ")", ")", "{", "$", "endDate", "=", "clone", "$", "component", "->", "DTSTART", "->", "getDateTime", "(", ")", ";", "$", "endDate", "=", "$", "endDate", "->", "add", "(", "VObject", "\\", "DateTimeParser", "::", "parse", "(", "$", "component", "->", "DURATION", "->", "getValue", "(", ")", ")", ")", ";", "$", "lastOccurence", "=", "$", "endDate", "->", "getTimeStamp", "(", ")", ";", "}", "elseif", "(", "!", "$", "component", "->", "DTSTART", "->", "hasTime", "(", ")", ")", "{", "$", "endDate", "=", "clone", "$", "component", "->", "DTSTART", "->", "getDateTime", "(", ")", ";", "$", "endDate", "=", "$", "endDate", "->", "modify", "(", "'+1 day'", ")", ";", "$", "lastOccurence", "=", "$", "endDate", "->", "getTimeStamp", "(", ")", ";", "}", "else", "{", "$", "lastOccurence", "=", "$", "firstOccurence", ";", "}", "}", "else", "{", "$", "it", "=", "new", "VObject", "\\", "Recur", "\\", "EventIterator", "(", "$", "vObject", ",", "(", "string", ")", "$", "component", "->", "UID", ")", ";", "$", "maxDate", "=", "new", "\\", "DateTime", "(", "self", "::", "MAX_DATE", ")", ";", "if", "(", "$", "it", "->", "isInfinite", "(", ")", ")", "{", "$", "lastOccurence", "=", "$", "maxDate", "->", "getTimeStamp", "(", ")", ";", "}", "else", "{", "$", "end", "=", "$", "it", "->", "getDtEnd", "(", ")", ";", "while", "(", "$", "it", "->", "valid", "(", ")", "&&", "$", "end", "<", "$", "maxDate", ")", "{", "$", "end", "=", "$", "it", "->", "getDtEnd", "(", ")", ";", "$", "it", "->", "next", "(", ")", ";", "}", "$", "lastOccurence", "=", "$", "end", "->", "getTimeStamp", "(", ")", ";", "}", "}", "// Ensure Occurence values are positive", "if", "(", "$", "firstOccurence", "<", "0", ")", "{", "$", "firstOccurence", "=", "0", ";", "}", "if", "(", "$", "lastOccurence", "<", "0", ")", "{", "$", "lastOccurence", "=", "0", ";", "}", "}", "// Destroy circular references to PHP will GC the object.", "$", "vObject", "->", "destroy", "(", ")", ";", "return", "[", "'etag'", "=>", "md5", "(", "$", "calendarData", ")", ",", "'size'", "=>", "strlen", "(", "$", "calendarData", ")", ",", "'componentType'", "=>", "$", "componentType", ",", "'firstOccurence'", "=>", "$", "firstOccurence", ",", "'lastOccurence'", "=>", "$", "lastOccurence", ",", "'uid'", "=>", "$", "uid", ",", "]", ";", "}" ]
Parses some information from calendar objects, used for optimized calendar-queries. Returns an array with the following keys: * etag - An md5 checksum of the object without the quotes. * size - Size of the object in bytes * componentType - VEVENT, VTODO or VJOURNAL * firstOccurence * lastOccurence * uid - value of the UID property @param string $calendarData @return array
[ "Parses", "some", "information", "from", "calendar", "objects", "used", "for", "optimized", "calendar", "-", "queries", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L621-L691
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.deleteCalendarObject
public function deleteCalendarObject($calendarId, $objectUri) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; $stmt = $this->pdo->prepare('DELETE FROM '.$this->calendarObjectTableName.' WHERE calendarid = ? AND uri = ?'); $stmt->execute([$calendarId, $objectUri]); $this->addChange($calendarId, $objectUri, 3); }
php
public function deleteCalendarObject($calendarId, $objectUri) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; $stmt = $this->pdo->prepare('DELETE FROM '.$this->calendarObjectTableName.' WHERE calendarid = ? AND uri = ?'); $stmt->execute([$calendarId, $objectUri]); $this->addChange($calendarId, $objectUri, 3); }
[ "public", "function", "deleteCalendarObject", "(", "$", "calendarId", ",", "$", "objectUri", ")", "{", "if", "(", "!", "is_array", "(", "$", "calendarId", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'", ")", ";", "}", "list", "(", "$", "calendarId", ",", "$", "instanceId", ")", "=", "$", "calendarId", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'DELETE FROM '", ".", "$", "this", "->", "calendarObjectTableName", ".", "' WHERE calendarid = ? AND uri = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "calendarId", ",", "$", "objectUri", "]", ")", ";", "$", "this", "->", "addChange", "(", "$", "calendarId", ",", "$", "objectUri", ",", "3", ")", ";", "}" ]
Deletes an existing calendar object. The object uri is only the basename, or filename and not a full path. @param mixed $calendarId @param string $objectUri
[ "Deletes", "an", "existing", "calendar", "object", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L701-L712
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.calendarQuery
public function calendarQuery($calendarId, array $filters) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; $componentType = null; $requirePostFilter = true; $timeRange = null; // if no filters were specified, we don't need to filter after a query if (!$filters['prop-filters'] && !$filters['comp-filters']) { $requirePostFilter = false; } // Figuring out if there's a component filter if (count($filters['comp-filters']) > 0 && !$filters['comp-filters'][0]['is-not-defined']) { $componentType = $filters['comp-filters'][0]['name']; // Checking if we need post-filters if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['time-range'] && !$filters['comp-filters'][0]['prop-filters']) { $requirePostFilter = false; } // There was a time-range filter if ('VEVENT' == $componentType && isset($filters['comp-filters'][0]['time-range'])) { $timeRange = $filters['comp-filters'][0]['time-range']; // If start time OR the end time is not specified, we can do a // 100% accurate mysql query. if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['prop-filters'] && (!$timeRange['start'] || !$timeRange['end'])) { $requirePostFilter = false; } } } if ($requirePostFilter) { $query = 'SELECT uri, calendardata FROM '.$this->calendarObjectTableName.' WHERE calendarid = :calendarid'; } else { $query = 'SELECT uri FROM '.$this->calendarObjectTableName.' WHERE calendarid = :calendarid'; } $values = [ 'calendarid' => $calendarId, ]; if ($componentType) { $query .= ' AND componenttype = :componenttype'; $values['componenttype'] = $componentType; } if ($timeRange && $timeRange['start']) { $query .= ' AND lastoccurence > :startdate'; $values['startdate'] = $timeRange['start']->getTimeStamp(); } if ($timeRange && $timeRange['end']) { $query .= ' AND firstoccurence < :enddate'; $values['enddate'] = $timeRange['end']->getTimeStamp(); } $stmt = $this->pdo->prepare($query); $stmt->execute($values); $result = []; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { if ($requirePostFilter) { if (!$this->validateFilterForObject($row, $filters)) { continue; } } $result[] = $row['uri']; } return $result; }
php
public function calendarQuery($calendarId, array $filters) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; $componentType = null; $requirePostFilter = true; $timeRange = null; if (!$filters['prop-filters'] && !$filters['comp-filters']) { $requirePostFilter = false; } if (count($filters['comp-filters']) > 0 && !$filters['comp-filters'][0]['is-not-defined']) { $componentType = $filters['comp-filters'][0]['name']; if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['time-range'] && !$filters['comp-filters'][0]['prop-filters']) { $requirePostFilter = false; } if ('VEVENT' == $componentType && isset($filters['comp-filters'][0]['time-range'])) { $timeRange = $filters['comp-filters'][0]['time-range']; if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['prop-filters'] && (!$timeRange['start'] || !$timeRange['end'])) { $requirePostFilter = false; } } } if ($requirePostFilter) { $query = 'SELECT uri, calendardata FROM '.$this->calendarObjectTableName.' WHERE calendarid = :calendarid'; } else { $query = 'SELECT uri FROM '.$this->calendarObjectTableName.' WHERE calendarid = :calendarid'; } $values = [ 'calendarid' => $calendarId, ]; if ($componentType) { $query .= ' AND componenttype = :componenttype'; $values['componenttype'] = $componentType; } if ($timeRange && $timeRange['start']) { $query .= ' AND lastoccurence > :startdate'; $values['startdate'] = $timeRange['start']->getTimeStamp(); } if ($timeRange && $timeRange['end']) { $query .= ' AND firstoccurence < :enddate'; $values['enddate'] = $timeRange['end']->getTimeStamp(); } $stmt = $this->pdo->prepare($query); $stmt->execute($values); $result = []; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { if ($requirePostFilter) { if (!$this->validateFilterForObject($row, $filters)) { continue; } } $result[] = $row['uri']; } return $result; }
[ "public", "function", "calendarQuery", "(", "$", "calendarId", ",", "array", "$", "filters", ")", "{", "if", "(", "!", "is_array", "(", "$", "calendarId", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'", ")", ";", "}", "list", "(", "$", "calendarId", ",", "$", "instanceId", ")", "=", "$", "calendarId", ";", "$", "componentType", "=", "null", ";", "$", "requirePostFilter", "=", "true", ";", "$", "timeRange", "=", "null", ";", "// if no filters were specified, we don't need to filter after a query", "if", "(", "!", "$", "filters", "[", "'prop-filters'", "]", "&&", "!", "$", "filters", "[", "'comp-filters'", "]", ")", "{", "$", "requirePostFilter", "=", "false", ";", "}", "// Figuring out if there's a component filter", "if", "(", "count", "(", "$", "filters", "[", "'comp-filters'", "]", ")", ">", "0", "&&", "!", "$", "filters", "[", "'comp-filters'", "]", "[", "0", "]", "[", "'is-not-defined'", "]", ")", "{", "$", "componentType", "=", "$", "filters", "[", "'comp-filters'", "]", "[", "0", "]", "[", "'name'", "]", ";", "// Checking if we need post-filters", "if", "(", "!", "$", "filters", "[", "'prop-filters'", "]", "&&", "!", "$", "filters", "[", "'comp-filters'", "]", "[", "0", "]", "[", "'comp-filters'", "]", "&&", "!", "$", "filters", "[", "'comp-filters'", "]", "[", "0", "]", "[", "'time-range'", "]", "&&", "!", "$", "filters", "[", "'comp-filters'", "]", "[", "0", "]", "[", "'prop-filters'", "]", ")", "{", "$", "requirePostFilter", "=", "false", ";", "}", "// There was a time-range filter", "if", "(", "'VEVENT'", "==", "$", "componentType", "&&", "isset", "(", "$", "filters", "[", "'comp-filters'", "]", "[", "0", "]", "[", "'time-range'", "]", ")", ")", "{", "$", "timeRange", "=", "$", "filters", "[", "'comp-filters'", "]", "[", "0", "]", "[", "'time-range'", "]", ";", "// If start time OR the end time is not specified, we can do a", "// 100% accurate mysql query.", "if", "(", "!", "$", "filters", "[", "'prop-filters'", "]", "&&", "!", "$", "filters", "[", "'comp-filters'", "]", "[", "0", "]", "[", "'comp-filters'", "]", "&&", "!", "$", "filters", "[", "'comp-filters'", "]", "[", "0", "]", "[", "'prop-filters'", "]", "&&", "(", "!", "$", "timeRange", "[", "'start'", "]", "||", "!", "$", "timeRange", "[", "'end'", "]", ")", ")", "{", "$", "requirePostFilter", "=", "false", ";", "}", "}", "}", "if", "(", "$", "requirePostFilter", ")", "{", "$", "query", "=", "'SELECT uri, calendardata FROM '", ".", "$", "this", "->", "calendarObjectTableName", ".", "' WHERE calendarid = :calendarid'", ";", "}", "else", "{", "$", "query", "=", "'SELECT uri FROM '", ".", "$", "this", "->", "calendarObjectTableName", ".", "' WHERE calendarid = :calendarid'", ";", "}", "$", "values", "=", "[", "'calendarid'", "=>", "$", "calendarId", ",", "]", ";", "if", "(", "$", "componentType", ")", "{", "$", "query", ".=", "' AND componenttype = :componenttype'", ";", "$", "values", "[", "'componenttype'", "]", "=", "$", "componentType", ";", "}", "if", "(", "$", "timeRange", "&&", "$", "timeRange", "[", "'start'", "]", ")", "{", "$", "query", ".=", "' AND lastoccurence > :startdate'", ";", "$", "values", "[", "'startdate'", "]", "=", "$", "timeRange", "[", "'start'", "]", "->", "getTimeStamp", "(", ")", ";", "}", "if", "(", "$", "timeRange", "&&", "$", "timeRange", "[", "'end'", "]", ")", "{", "$", "query", ".=", "' AND firstoccurence < :enddate'", ";", "$", "values", "[", "'enddate'", "]", "=", "$", "timeRange", "[", "'end'", "]", "->", "getTimeStamp", "(", ")", ";", "}", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "$", "query", ")", ";", "$", "stmt", "->", "execute", "(", "$", "values", ")", ";", "$", "result", "=", "[", "]", ";", "while", "(", "$", "row", "=", "$", "stmt", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ")", "{", "if", "(", "$", "requirePostFilter", ")", "{", "if", "(", "!", "$", "this", "->", "validateFilterForObject", "(", "$", "row", ",", "$", "filters", ")", ")", "{", "continue", ";", "}", "}", "$", "result", "[", "]", "=", "$", "row", "[", "'uri'", "]", ";", "}", "return", "$", "result", ";", "}" ]
Performs a calendar-query on the contents of this calendar. The calendar-query is defined in RFC4791 : CalDAV. Using the calendar-query it is possible for a client to request a specific set of object, based on contents of iCalendar properties, date-ranges and iCalendar component types (VTODO, VEVENT). This method should just return a list of (relative) urls that match this query. The list of filters are specified as an array. The exact array is documented by \Sabre\CalDAV\CalendarQueryParser. Note that it is extremely likely that getCalendarObject for every path returned from this method will be called almost immediately after. You may want to anticipate this to speed up these requests. This method provides a default implementation, which parses *all* the iCalendar objects in the specified calendar. This default may well be good enough for personal use, and calendars that aren't very large. But if you anticipate high usage, big calendars or high loads, you are strongly adviced to optimize certain paths. The best way to do so is override this method and to optimize specifically for 'common filters'. Requests that are extremely common are: * requests for just VEVENTS * requests for just VTODO * requests with a time-range-filter on a VEVENT. ..and combinations of these requests. It may not be worth it to try to handle every possible situation and just rely on the (relatively easy to use) CalendarQueryValidator to handle the rest. Note that especially time-range-filters may be difficult to parse. A time-range filter specified on a VEVENT must for instance also handle recurrence rules correctly. A good example of how to interpret all these filters can also simply be found in \Sabre\CalDAV\CalendarQueryFilter. This class is as correct as possible, so it gives you a good idea on what type of stuff you need to think of. This specific implementation (for the PDO) backend optimizes filters on specific components, and VEVENT time-ranges. @param mixed $calendarId @param array $filters @return array
[ "Performs", "a", "calendar", "-", "query", "on", "the", "contents", "of", "this", "calendar", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L767-L841
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.getCalendarObjectByUID
public function getCalendarObjectByUID($principalUri, $uid) { $query = <<<SQL SELECT calendar_instances.uri AS calendaruri, calendarobjects.uri as objecturi FROM $this->calendarObjectTableName AS calendarobjects LEFT JOIN $this->calendarInstancesTableName AS calendar_instances ON calendarobjects.calendarid = calendar_instances.calendarid WHERE calendar_instances.principaluri = ? AND calendarobjects.uid = ? SQL; $stmt = $this->pdo->prepare($query); $stmt->execute([$principalUri, $uid]); if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { return $row['calendaruri'].'/'.$row['objecturi']; } }
php
public function getCalendarObjectByUID($principalUri, $uid) { $query = <<<SQL SELECT calendar_instances.uri AS calendaruri, calendarobjects.uri as objecturi FROM $this->calendarObjectTableName AS calendarobjects LEFT JOIN $this->calendarInstancesTableName AS calendar_instances ON calendarobjects.calendarid = calendar_instances.calendarid WHERE calendar_instances.principaluri = ? AND calendarobjects.uid = ? SQL; $stmt = $this->pdo->prepare($query); $stmt->execute([$principalUri, $uid]); if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { return $row['calendaruri'].'/'.$row['objecturi']; } }
[ "public", "function", "getCalendarObjectByUID", "(", "$", "principalUri", ",", "$", "uid", ")", "{", "$", "query", "=", " <<<SQL\nSELECT\n calendar_instances.uri AS calendaruri, calendarobjects.uri as objecturi\nFROM\n $this->calendarObjectTableName AS calendarobjects\nLEFT JOIN\n $this->calendarInstancesTableName AS calendar_instances\n ON calendarobjects.calendarid = calendar_instances.calendarid\nWHERE\n calendar_instances.principaluri = ?\n AND\n calendarobjects.uid = ?\nSQL", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "$", "query", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "principalUri", ",", "$", "uid", "]", ")", ";", "if", "(", "$", "row", "=", "$", "stmt", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ")", "{", "return", "$", "row", "[", "'calendaruri'", "]", ".", "'/'", ".", "$", "row", "[", "'objecturi'", "]", ";", "}", "}" ]
Searches through all of a users calendars and calendar objects to find an object with a specific UID. This method should return the path to this object, relative to the calendar home, so this path usually only contains two parts: calendarpath/objectpath.ics If the uid is not found, return null. This method should only consider * objects that the principal owns, so any calendars owned by other principals that also appear in this collection should be ignored. @param string $principalUri @param string $uid @return string|null
[ "Searches", "through", "all", "of", "a", "users", "calendars", "and", "calendar", "objects", "to", "find", "an", "object", "with", "a", "specific", "UID", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L863-L885
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.getChangesForCalendar
public function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; // Current synctoken $stmt = $this->pdo->prepare('SELECT synctoken FROM '.$this->calendarTableName.' WHERE id = ?'); $stmt->execute([$calendarId]); $currentToken = $stmt->fetchColumn(0); if (is_null($currentToken)) { return null; } $result = [ 'syncToken' => $currentToken, 'added' => [], 'modified' => [], 'deleted' => [], ]; if ($syncToken) { $query = 'SELECT uri, operation FROM '.$this->calendarChangesTableName.' WHERE synctoken >= ? AND synctoken < ? AND calendarid = ? ORDER BY synctoken'; if ($limit > 0) { $query .= ' LIMIT '.(int) $limit; } // Fetching all changes $stmt = $this->pdo->prepare($query); $stmt->execute([$syncToken, $currentToken, $calendarId]); $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->calendarObjectTableName.' WHERE calendarid = ?'; $stmt = $this->pdo->prepare($query); $stmt->execute([$calendarId]); $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); } return $result; }
php
public function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; $stmt = $this->pdo->prepare('SELECT synctoken FROM '.$this->calendarTableName.' WHERE id = ?'); $stmt->execute([$calendarId]); $currentToken = $stmt->fetchColumn(0); if (is_null($currentToken)) { return null; } $result = [ 'syncToken' => $currentToken, 'added' => [], 'modified' => [], 'deleted' => [], ]; if ($syncToken) { $query = 'SELECT uri, operation FROM '.$this->calendarChangesTableName.' WHERE synctoken >= ? AND synctoken < ? AND calendarid = ? ORDER BY synctoken'; if ($limit > 0) { $query .= ' LIMIT '.(int) $limit; } $stmt = $this->pdo->prepare($query); $stmt->execute([$syncToken, $currentToken, $calendarId]); $changes = []; 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 { $query = 'SELECT uri FROM '.$this->calendarObjectTableName.' WHERE calendarid = ?'; $stmt = $this->pdo->prepare($query); $stmt->execute([$calendarId]); $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); } return $result; }
[ "public", "function", "getChangesForCalendar", "(", "$", "calendarId", ",", "$", "syncToken", ",", "$", "syncLevel", ",", "$", "limit", "=", "null", ")", "{", "if", "(", "!", "is_array", "(", "$", "calendarId", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'", ")", ";", "}", "list", "(", "$", "calendarId", ",", "$", "instanceId", ")", "=", "$", "calendarId", ";", "// Current synctoken", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'SELECT synctoken FROM '", ".", "$", "this", "->", "calendarTableName", ".", "' WHERE id = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "calendarId", "]", ")", ";", "$", "currentToken", "=", "$", "stmt", "->", "fetchColumn", "(", "0", ")", ";", "if", "(", "is_null", "(", "$", "currentToken", ")", ")", "{", "return", "null", ";", "}", "$", "result", "=", "[", "'syncToken'", "=>", "$", "currentToken", ",", "'added'", "=>", "[", "]", ",", "'modified'", "=>", "[", "]", ",", "'deleted'", "=>", "[", "]", ",", "]", ";", "if", "(", "$", "syncToken", ")", "{", "$", "query", "=", "'SELECT uri, operation FROM '", ".", "$", "this", "->", "calendarChangesTableName", ".", "' WHERE synctoken >= ? AND synctoken < ? AND calendarid = ? ORDER BY synctoken'", ";", "if", "(", "$", "limit", ">", "0", ")", "{", "$", "query", ".=", "' LIMIT '", ".", "(", "int", ")", "$", "limit", ";", "}", "// Fetching all changes", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "$", "query", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "syncToken", ",", "$", "currentToken", ",", "$", "calendarId", "]", ")", ";", "$", "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", "->", "calendarObjectTableName", ".", "' WHERE calendarid = ?'", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "$", "query", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "calendarId", "]", ")", ";", "$", "result", "[", "'added'", "]", "=", "$", "stmt", "->", "fetchAll", "(", "\\", "PDO", "::", "FETCH_COLUMN", ")", ";", "}", "return", "$", "result", ";", "}" ]
The getChanges method returns all the changes that have happened, since the specified syncToken in the specified calendar. This function should return an array, such as the following: [ 'syncToken' => 'The current synctoken', 'added' => [ 'new.txt', ], 'modified' => [ 'modified.txt', ], 'deleted' => [ 'foo.php.bak', 'old.txt' ] ]; The returned syncToken property should reflect the *current* syncToken of the calendar, 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 mixed $calendarId @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", "calendar", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L944-L1008
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.addChange
protected function addChange($calendarId, $objectUri, $operation) { $stmt = $this->pdo->prepare('INSERT INTO '.$this->calendarChangesTableName.' (uri, synctoken, calendarid, operation) SELECT ?, synctoken, ?, ? FROM '.$this->calendarTableName.' WHERE id = ?'); $stmt->execute([ $objectUri, $calendarId, $operation, $calendarId, ]); $stmt = $this->pdo->prepare('UPDATE '.$this->calendarTableName.' SET synctoken = synctoken + 1 WHERE id = ?'); $stmt->execute([ $calendarId, ]); }
php
protected function addChange($calendarId, $objectUri, $operation) { $stmt = $this->pdo->prepare('INSERT INTO '.$this->calendarChangesTableName.' (uri, synctoken, calendarid, operation) SELECT ?, synctoken, ?, ? FROM '.$this->calendarTableName.' WHERE id = ?'); $stmt->execute([ $objectUri, $calendarId, $operation, $calendarId, ]); $stmt = $this->pdo->prepare('UPDATE '.$this->calendarTableName.' SET synctoken = synctoken + 1 WHERE id = ?'); $stmt->execute([ $calendarId, ]); }
[ "protected", "function", "addChange", "(", "$", "calendarId", ",", "$", "objectUri", ",", "$", "operation", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'INSERT INTO '", ".", "$", "this", "->", "calendarChangesTableName", ".", "' (uri, synctoken, calendarid, operation) SELECT ?, synctoken, ?, ? FROM '", ".", "$", "this", "->", "calendarTableName", ".", "' WHERE id = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "objectUri", ",", "$", "calendarId", ",", "$", "operation", ",", "$", "calendarId", ",", "]", ")", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'UPDATE '", ".", "$", "this", "->", "calendarTableName", ".", "' SET synctoken = synctoken + 1 WHERE id = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "calendarId", ",", "]", ")", ";", "}" ]
Adds a change record to the calendarchanges table. @param mixed $calendarId @param string $objectUri @param int $operation 1 = add, 2 = modify, 3 = delete
[ "Adds", "a", "change", "record", "to", "the", "calendarchanges", "table", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L1017-L1030
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.getSubscriptionsForUser
public function getSubscriptionsForUser($principalUri) { $fields = array_values($this->subscriptionPropertyMap); $fields[] = 'id'; $fields[] = 'uri'; $fields[] = 'source'; $fields[] = 'principaluri'; $fields[] = 'lastmodified'; // Making fields a comma-delimited list $fields = implode(', ', $fields); $stmt = $this->pdo->prepare('SELECT '.$fields.' FROM '.$this->calendarSubscriptionsTableName.' WHERE principaluri = ? ORDER BY calendarorder ASC'); $stmt->execute([$principalUri]); $subscriptions = []; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $subscription = [ 'id' => $row['id'], 'uri' => $row['uri'], 'principaluri' => $row['principaluri'], 'source' => $row['source'], 'lastmodified' => $row['lastmodified'], '{'.CalDAV\Plugin::NS_CALDAV.'}supported-calendar-component-set' => new CalDAV\Xml\Property\SupportedCalendarComponentSet(['VTODO', 'VEVENT']), ]; foreach ($this->subscriptionPropertyMap as $xmlName => $dbName) { if (!is_null($row[$dbName])) { $subscription[$xmlName] = $row[$dbName]; } } $subscriptions[] = $subscription; } return $subscriptions; }
php
public function getSubscriptionsForUser($principalUri) { $fields = array_values($this->subscriptionPropertyMap); $fields[] = 'id'; $fields[] = 'uri'; $fields[] = 'source'; $fields[] = 'principaluri'; $fields[] = 'lastmodified'; $fields = implode(', ', $fields); $stmt = $this->pdo->prepare('SELECT '.$fields.' FROM '.$this->calendarSubscriptionsTableName.' WHERE principaluri = ? ORDER BY calendarorder ASC'); $stmt->execute([$principalUri]); $subscriptions = []; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $subscription = [ 'id' => $row['id'], 'uri' => $row['uri'], 'principaluri' => $row['principaluri'], 'source' => $row['source'], 'lastmodified' => $row['lastmodified'], '{'.CalDAV\Plugin::NS_CALDAV.'}supported-calendar-component-set' => new CalDAV\Xml\Property\SupportedCalendarComponentSet(['VTODO', 'VEVENT']), ]; foreach ($this->subscriptionPropertyMap as $xmlName => $dbName) { if (!is_null($row[$dbName])) { $subscription[$xmlName] = $row[$dbName]; } } $subscriptions[] = $subscription; } return $subscriptions; }
[ "public", "function", "getSubscriptionsForUser", "(", "$", "principalUri", ")", "{", "$", "fields", "=", "array_values", "(", "$", "this", "->", "subscriptionPropertyMap", ")", ";", "$", "fields", "[", "]", "=", "'id'", ";", "$", "fields", "[", "]", "=", "'uri'", ";", "$", "fields", "[", "]", "=", "'source'", ";", "$", "fields", "[", "]", "=", "'principaluri'", ";", "$", "fields", "[", "]", "=", "'lastmodified'", ";", "// Making fields a comma-delimited list", "$", "fields", "=", "implode", "(", "', '", ",", "$", "fields", ")", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'SELECT '", ".", "$", "fields", ".", "' FROM '", ".", "$", "this", "->", "calendarSubscriptionsTableName", ".", "' WHERE principaluri = ? ORDER BY calendarorder ASC'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "principalUri", "]", ")", ";", "$", "subscriptions", "=", "[", "]", ";", "while", "(", "$", "row", "=", "$", "stmt", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ")", "{", "$", "subscription", "=", "[", "'id'", "=>", "$", "row", "[", "'id'", "]", ",", "'uri'", "=>", "$", "row", "[", "'uri'", "]", ",", "'principaluri'", "=>", "$", "row", "[", "'principaluri'", "]", ",", "'source'", "=>", "$", "row", "[", "'source'", "]", ",", "'lastmodified'", "=>", "$", "row", "[", "'lastmodified'", "]", ",", "'{'", ".", "CalDAV", "\\", "Plugin", "::", "NS_CALDAV", ".", "'}supported-calendar-component-set'", "=>", "new", "CalDAV", "\\", "Xml", "\\", "Property", "\\", "SupportedCalendarComponentSet", "(", "[", "'VTODO'", ",", "'VEVENT'", "]", ")", ",", "]", ";", "foreach", "(", "$", "this", "->", "subscriptionPropertyMap", "as", "$", "xmlName", "=>", "$", "dbName", ")", "{", "if", "(", "!", "is_null", "(", "$", "row", "[", "$", "dbName", "]", ")", ")", "{", "$", "subscription", "[", "$", "xmlName", "]", "=", "$", "row", "[", "$", "dbName", "]", ";", "}", "}", "$", "subscriptions", "[", "]", "=", "$", "subscription", ";", "}", "return", "$", "subscriptions", ";", "}" ]
Returns a list of subscriptions for a principal. Every subscription is an array with the following keys: * id, a unique id that will be used by other functions to modify the subscription. This can be the same as the uri or a database key. * uri. This is just the 'base uri' or 'filename' of the subscription. * principaluri. The owner of the subscription. Almost always the same as principalUri passed to this method. * source. Url to the actual feed Furthermore, all the subscription info must be returned too: 1. {DAV:}displayname 2. {http://apple.com/ns/ical/}refreshrate 3. {http://calendarserver.org/ns/}subscribed-strip-todos (omit if todos should not be stripped). 4. {http://calendarserver.org/ns/}subscribed-strip-alarms (omit if alarms should not be stripped). 5. {http://calendarserver.org/ns/}subscribed-strip-attachments (omit if attachments should not be stripped). 7. {http://apple.com/ns/ical/}calendar-color 8. {http://apple.com/ns/ical/}calendar-order 9. {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set (should just be an instance of Sabre\CalDAV\Property\SupportedCalendarComponentSet, with a bunch of default components). @param string $principalUri @return array
[ "Returns", "a", "list", "of", "subscriptions", "for", "a", "principal", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L1064-L1100
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.createSubscription
public function createSubscription($principalUri, $uri, array $properties) { $fieldNames = [ 'principaluri', 'uri', 'source', 'lastmodified', ]; if (!isset($properties['{http://calendarserver.org/ns/}source'])) { throw new Forbidden('The {http://calendarserver.org/ns/}source property is required when creating subscriptions'); } $values = [ ':principaluri' => $principalUri, ':uri' => $uri, ':source' => $properties['{http://calendarserver.org/ns/}source']->getHref(), ':lastmodified' => time(), ]; foreach ($this->subscriptionPropertyMap as $xmlName => $dbName) { if (isset($properties[$xmlName])) { $values[':'.$dbName] = $properties[$xmlName]; $fieldNames[] = $dbName; } } $stmt = $this->pdo->prepare('INSERT INTO '.$this->calendarSubscriptionsTableName.' ('.implode(', ', $fieldNames).') VALUES ('.implode(', ', array_keys($values)).')'); $stmt->execute($values); return $this->pdo->lastInsertId( $this->calendarSubscriptionsTableName.'_id_seq' ); }
php
public function createSubscription($principalUri, $uri, array $properties) { $fieldNames = [ 'principaluri', 'uri', 'source', 'lastmodified', ]; if (!isset($properties['{http: throw new Forbidden('The {http: } $values = [ ':principaluri' => $principalUri, ':uri' => $uri, ':source' => $properties['{http: ':lastmodified' => time(), ]; foreach ($this->subscriptionPropertyMap as $xmlName => $dbName) { if (isset($properties[$xmlName])) { $values[':'.$dbName] = $properties[$xmlName]; $fieldNames[] = $dbName; } } $stmt = $this->pdo->prepare('INSERT INTO '.$this->calendarSubscriptionsTableName.' ('.implode(', ', $fieldNames).') VALUES ('.implode(', ', array_keys($values)).')'); $stmt->execute($values); return $this->pdo->lastInsertId( $this->calendarSubscriptionsTableName.'_id_seq' ); }
[ "public", "function", "createSubscription", "(", "$", "principalUri", ",", "$", "uri", ",", "array", "$", "properties", ")", "{", "$", "fieldNames", "=", "[", "'principaluri'", ",", "'uri'", ",", "'source'", ",", "'lastmodified'", ",", "]", ";", "if", "(", "!", "isset", "(", "$", "properties", "[", "'{http://calendarserver.org/ns/}source'", "]", ")", ")", "{", "throw", "new", "Forbidden", "(", "'The {http://calendarserver.org/ns/}source property is required when creating subscriptions'", ")", ";", "}", "$", "values", "=", "[", "':principaluri'", "=>", "$", "principalUri", ",", "':uri'", "=>", "$", "uri", ",", "':source'", "=>", "$", "properties", "[", "'{http://calendarserver.org/ns/}source'", "]", "->", "getHref", "(", ")", ",", "':lastmodified'", "=>", "time", "(", ")", ",", "]", ";", "foreach", "(", "$", "this", "->", "subscriptionPropertyMap", "as", "$", "xmlName", "=>", "$", "dbName", ")", "{", "if", "(", "isset", "(", "$", "properties", "[", "$", "xmlName", "]", ")", ")", "{", "$", "values", "[", "':'", ".", "$", "dbName", "]", "=", "$", "properties", "[", "$", "xmlName", "]", ";", "$", "fieldNames", "[", "]", "=", "$", "dbName", ";", "}", "}", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'INSERT INTO '", ".", "$", "this", "->", "calendarSubscriptionsTableName", ".", "' ('", ".", "implode", "(", "', '", ",", "$", "fieldNames", ")", ".", "') VALUES ('", ".", "implode", "(", "', '", ",", "array_keys", "(", "$", "values", ")", ")", ".", "')'", ")", ";", "$", "stmt", "->", "execute", "(", "$", "values", ")", ";", "return", "$", "this", "->", "pdo", "->", "lastInsertId", "(", "$", "this", "->", "calendarSubscriptionsTableName", ".", "'_id_seq'", ")", ";", "}" ]
Creates a new subscription for a principal. If the creation was a success, an id must be returned that can be used to reference this subscription in other methods, such as updateSubscription. @param string $principalUri @param string $uri @param array $properties @return mixed
[ "Creates", "a", "new", "subscription", "for", "a", "principal", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L1114-L1147
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.updateSubscription
public function updateSubscription($subscriptionId, DAV\PropPatch $propPatch) { $supportedProperties = array_keys($this->subscriptionPropertyMap); $supportedProperties[] = '{http://calendarserver.org/ns/}source'; $propPatch->handle($supportedProperties, function ($mutations) use ($subscriptionId) { $newValues = []; foreach ($mutations as $propertyName => $propertyValue) { if ('{http://calendarserver.org/ns/}source' === $propertyName) { $newValues['source'] = $propertyValue->getHref(); } else { $fieldName = $this->subscriptionPropertyMap[$propertyName]; $newValues[$fieldName] = $propertyValue; } } // Now we're generating the sql query. $valuesSql = []; foreach ($newValues as $fieldName => $value) { $valuesSql[] = $fieldName.' = ?'; } $stmt = $this->pdo->prepare('UPDATE '.$this->calendarSubscriptionsTableName.' SET '.implode(', ', $valuesSql).', lastmodified = ? WHERE id = ?'); $newValues['lastmodified'] = time(); $newValues['id'] = $subscriptionId; $stmt->execute(array_values($newValues)); return true; }); }
php
public function updateSubscription($subscriptionId, DAV\PropPatch $propPatch) { $supportedProperties = array_keys($this->subscriptionPropertyMap); $supportedProperties[] = '{http: $propPatch->handle($supportedProperties, function ($mutations) use ($subscriptionId) { $newValues = []; foreach ($mutations as $propertyName => $propertyValue) { if ('{http: $newValues['source'] = $propertyValue->getHref(); } else { $fieldName = $this->subscriptionPropertyMap[$propertyName]; $newValues[$fieldName] = $propertyValue; } } $valuesSql = []; foreach ($newValues as $fieldName => $value) { $valuesSql[] = $fieldName.' = ?'; } $stmt = $this->pdo->prepare('UPDATE '.$this->calendarSubscriptionsTableName.' SET '.implode(', ', $valuesSql).', lastmodified = ? WHERE id = ?'); $newValues['lastmodified'] = time(); $newValues['id'] = $subscriptionId; $stmt->execute(array_values($newValues)); return true; }); }
[ "public", "function", "updateSubscription", "(", "$", "subscriptionId", ",", "DAV", "\\", "PropPatch", "$", "propPatch", ")", "{", "$", "supportedProperties", "=", "array_keys", "(", "$", "this", "->", "subscriptionPropertyMap", ")", ";", "$", "supportedProperties", "[", "]", "=", "'{http://calendarserver.org/ns/}source'", ";", "$", "propPatch", "->", "handle", "(", "$", "supportedProperties", ",", "function", "(", "$", "mutations", ")", "use", "(", "$", "subscriptionId", ")", "{", "$", "newValues", "=", "[", "]", ";", "foreach", "(", "$", "mutations", "as", "$", "propertyName", "=>", "$", "propertyValue", ")", "{", "if", "(", "'{http://calendarserver.org/ns/}source'", "===", "$", "propertyName", ")", "{", "$", "newValues", "[", "'source'", "]", "=", "$", "propertyValue", "->", "getHref", "(", ")", ";", "}", "else", "{", "$", "fieldName", "=", "$", "this", "->", "subscriptionPropertyMap", "[", "$", "propertyName", "]", ";", "$", "newValues", "[", "$", "fieldName", "]", "=", "$", "propertyValue", ";", "}", "}", "// Now we're generating the sql query.", "$", "valuesSql", "=", "[", "]", ";", "foreach", "(", "$", "newValues", "as", "$", "fieldName", "=>", "$", "value", ")", "{", "$", "valuesSql", "[", "]", "=", "$", "fieldName", ".", "' = ?'", ";", "}", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'UPDATE '", ".", "$", "this", "->", "calendarSubscriptionsTableName", ".", "' SET '", ".", "implode", "(", "', '", ",", "$", "valuesSql", ")", ".", "', lastmodified = ? WHERE id = ?'", ")", ";", "$", "newValues", "[", "'lastmodified'", "]", "=", "time", "(", ")", ";", "$", "newValues", "[", "'id'", "]", "=", "$", "subscriptionId", ";", "$", "stmt", "->", "execute", "(", "array_values", "(", "$", "newValues", ")", ")", ";", "return", "true", ";", "}", ")", ";", "}" ]
Updates a subscription. 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 mixed $subscriptionId @param \Sabre\DAV\PropPatch $propPatch
[ "Updates", "a", "subscription", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L1164-L1194
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.deleteSubscription
public function deleteSubscription($subscriptionId) { $stmt = $this->pdo->prepare('DELETE FROM '.$this->calendarSubscriptionsTableName.' WHERE id = ?'); $stmt->execute([$subscriptionId]); }
php
public function deleteSubscription($subscriptionId) { $stmt = $this->pdo->prepare('DELETE FROM '.$this->calendarSubscriptionsTableName.' WHERE id = ?'); $stmt->execute([$subscriptionId]); }
[ "public", "function", "deleteSubscription", "(", "$", "subscriptionId", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'DELETE FROM '", ".", "$", "this", "->", "calendarSubscriptionsTableName", ".", "' WHERE id = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "subscriptionId", "]", ")", ";", "}" ]
Deletes a subscription. @param mixed $subscriptionId
[ "Deletes", "a", "subscription", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L1201-L1205
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.getSchedulingObject
public function getSchedulingObject($principalUri, $objectUri) { $stmt = $this->pdo->prepare('SELECT uri, calendardata, lastmodified, etag, size FROM '.$this->schedulingObjectTableName.' WHERE principaluri = ? AND uri = ?'); $stmt->execute([$principalUri, $objectUri]); $row = $stmt->fetch(\PDO::FETCH_ASSOC); if (!$row) { return null; } return [ 'uri' => $row['uri'], 'calendardata' => $row['calendardata'], 'lastmodified' => $row['lastmodified'], 'etag' => '"'.$row['etag'].'"', 'size' => (int) $row['size'], ]; }
php
public function getSchedulingObject($principalUri, $objectUri) { $stmt = $this->pdo->prepare('SELECT uri, calendardata, lastmodified, etag, size FROM '.$this->schedulingObjectTableName.' WHERE principaluri = ? AND uri = ?'); $stmt->execute([$principalUri, $objectUri]); $row = $stmt->fetch(\PDO::FETCH_ASSOC); if (!$row) { return null; } return [ 'uri' => $row['uri'], 'calendardata' => $row['calendardata'], 'lastmodified' => $row['lastmodified'], 'etag' => '"'.$row['etag'].'"', 'size' => (int) $row['size'], ]; }
[ "public", "function", "getSchedulingObject", "(", "$", "principalUri", ",", "$", "objectUri", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'SELECT uri, calendardata, lastmodified, etag, size FROM '", ".", "$", "this", "->", "schedulingObjectTableName", ".", "' WHERE principaluri = ? AND uri = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "principalUri", ",", "$", "objectUri", "]", ")", ";", "$", "row", "=", "$", "stmt", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ";", "if", "(", "!", "$", "row", ")", "{", "return", "null", ";", "}", "return", "[", "'uri'", "=>", "$", "row", "[", "'uri'", "]", ",", "'calendardata'", "=>", "$", "row", "[", "'calendardata'", "]", ",", "'lastmodified'", "=>", "$", "row", "[", "'lastmodified'", "]", ",", "'etag'", "=>", "'\"'", ".", "$", "row", "[", "'etag'", "]", ".", "'\"'", ",", "'size'", "=>", "(", "int", ")", "$", "row", "[", "'size'", "]", ",", "]", ";", "}" ]
Returns a single scheduling object. The returned array should contain the following elements: * uri - A unique basename for the object. This will be used to construct a full uri. * calendardata - The iCalendar object * lastmodified - The last modification date. Can be an int for a unix timestamp, or a PHP DateTime object. * etag - A unique token that must change if the object changed. * size - The size of the object, in bytes. @param string $principalUri @param string $objectUri @return array
[ "Returns", "a", "single", "scheduling", "object", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L1224-L1241
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.getSchedulingObjects
public function getSchedulingObjects($principalUri) { $stmt = $this->pdo->prepare('SELECT id, calendardata, uri, lastmodified, etag, size FROM '.$this->schedulingObjectTableName.' WHERE principaluri = ?'); $stmt->execute([$principalUri]); $result = []; foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { $result[] = [ 'calendardata' => $row['calendardata'], 'uri' => $row['uri'], 'lastmodified' => $row['lastmodified'], 'etag' => '"'.$row['etag'].'"', 'size' => (int) $row['size'], ]; } return $result; }
php
public function getSchedulingObjects($principalUri) { $stmt = $this->pdo->prepare('SELECT id, calendardata, uri, lastmodified, etag, size FROM '.$this->schedulingObjectTableName.' WHERE principaluri = ?'); $stmt->execute([$principalUri]); $result = []; foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { $result[] = [ 'calendardata' => $row['calendardata'], 'uri' => $row['uri'], 'lastmodified' => $row['lastmodified'], 'etag' => '"'.$row['etag'].'"', 'size' => (int) $row['size'], ]; } return $result; }
[ "public", "function", "getSchedulingObjects", "(", "$", "principalUri", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'SELECT id, calendardata, uri, lastmodified, etag, size FROM '", ".", "$", "this", "->", "schedulingObjectTableName", ".", "' WHERE principaluri = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "principalUri", "]", ")", ";", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "stmt", "->", "fetchAll", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", "as", "$", "row", ")", "{", "$", "result", "[", "]", "=", "[", "'calendardata'", "=>", "$", "row", "[", "'calendardata'", "]", ",", "'uri'", "=>", "$", "row", "[", "'uri'", "]", ",", "'lastmodified'", "=>", "$", "row", "[", "'lastmodified'", "]", ",", "'etag'", "=>", "'\"'", ".", "$", "row", "[", "'etag'", "]", ".", "'\"'", ",", "'size'", "=>", "(", "int", ")", "$", "row", "[", "'size'", "]", ",", "]", ";", "}", "return", "$", "result", ";", "}" ]
Returns all scheduling objects for the inbox collection. These objects should be returned as an array. Every item in the array should follow the same structure as returned from getSchedulingObject. The main difference is that 'calendardata' is optional. @param string $principalUri @return array
[ "Returns", "all", "scheduling", "objects", "for", "the", "inbox", "collection", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L1255-L1272
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.deleteSchedulingObject
public function deleteSchedulingObject($principalUri, $objectUri) { $stmt = $this->pdo->prepare('DELETE FROM '.$this->schedulingObjectTableName.' WHERE principaluri = ? AND uri = ?'); $stmt->execute([$principalUri, $objectUri]); }
php
public function deleteSchedulingObject($principalUri, $objectUri) { $stmt = $this->pdo->prepare('DELETE FROM '.$this->schedulingObjectTableName.' WHERE principaluri = ? AND uri = ?'); $stmt->execute([$principalUri, $objectUri]); }
[ "public", "function", "deleteSchedulingObject", "(", "$", "principalUri", ",", "$", "objectUri", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'DELETE FROM '", ".", "$", "this", "->", "schedulingObjectTableName", ".", "' WHERE principaluri = ? AND uri = ?'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "principalUri", ",", "$", "objectUri", "]", ")", ";", "}" ]
Deletes a scheduling object. @param string $principalUri @param string $objectUri
[ "Deletes", "a", "scheduling", "object", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L1280-L1284
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.createSchedulingObject
public function createSchedulingObject($principalUri, $objectUri, $objectData) { $stmt = $this->pdo->prepare('INSERT INTO '.$this->schedulingObjectTableName.' (principaluri, calendardata, uri, lastmodified, etag, size) VALUES (?, ?, ?, ?, ?, ?)'); $stmt->execute([$principalUri, $objectData, $objectUri, time(), md5($objectData), strlen($objectData)]); }
php
public function createSchedulingObject($principalUri, $objectUri, $objectData) { $stmt = $this->pdo->prepare('INSERT INTO '.$this->schedulingObjectTableName.' (principaluri, calendardata, uri, lastmodified, etag, size) VALUES (?, ?, ?, ?, ?, ?)'); $stmt->execute([$principalUri, $objectData, $objectUri, time(), md5($objectData), strlen($objectData)]); }
[ "public", "function", "createSchedulingObject", "(", "$", "principalUri", ",", "$", "objectUri", ",", "$", "objectData", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'INSERT INTO '", ".", "$", "this", "->", "schedulingObjectTableName", ".", "' (principaluri, calendardata, uri, lastmodified, etag, size) VALUES (?, ?, ?, ?, ?, ?)'", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "principalUri", ",", "$", "objectData", ",", "$", "objectUri", ",", "time", "(", ")", ",", "md5", "(", "$", "objectData", ")", ",", "strlen", "(", "$", "objectData", ")", "]", ")", ";", "}" ]
Creates a new scheduling object. This should land in a users' inbox. @param string $principalUri @param string $objectUri @param string $objectData
[ "Creates", "a", "new", "scheduling", "object", ".", "This", "should", "land", "in", "a", "users", "inbox", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L1293-L1297
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.updateInvites
public function updateInvites($calendarId, array $sharees) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } $currentInvites = $this->getInvites($calendarId); list($calendarId, $instanceId) = $calendarId; $removeStmt = $this->pdo->prepare('DELETE FROM '.$this->calendarInstancesTableName.' WHERE calendarid = ? AND share_href = ? AND access IN (2,3)'); $updateStmt = $this->pdo->prepare('UPDATE '.$this->calendarInstancesTableName.' SET access = ?, share_displayname = ?, share_invitestatus = ? WHERE calendarid = ? AND share_href = ?'); $insertStmt = $this->pdo->prepare(' INSERT INTO '.$this->calendarInstancesTableName.' ( calendarid, principaluri, access, displayname, uri, description, calendarorder, calendarcolor, timezone, transparent, share_href, share_displayname, share_invitestatus ) SELECT ?, ?, ?, displayname, ?, description, calendarorder, calendarcolor, timezone, 1, ?, ?, ? FROM '.$this->calendarInstancesTableName.' WHERE id = ?'); foreach ($sharees as $sharee) { if (\Sabre\DAV\Sharing\Plugin::ACCESS_NOACCESS === $sharee->access) { // if access was set no NOACCESS, it means access for an // existing sharee was removed. $removeStmt->execute([$calendarId, $sharee->href]); continue; } if (is_null($sharee->principal)) { // If the server could not determine the principal automatically, // we will mark the invite status as invalid. $sharee->inviteStatus = \Sabre\DAV\Sharing\Plugin::INVITE_INVALID; } else { // Because sabre/dav does not yet have an invitation system, // every invite is automatically accepted for now. $sharee->inviteStatus = \Sabre\DAV\Sharing\Plugin::INVITE_ACCEPTED; } foreach ($currentInvites as $oldSharee) { if ($oldSharee->href === $sharee->href) { // This is an update $sharee->properties = array_merge( $oldSharee->properties, $sharee->properties ); $updateStmt->execute([ $sharee->access, isset($sharee->properties['{DAV:}displayname']) ? $sharee->properties['{DAV:}displayname'] : null, $sharee->inviteStatus ?: $oldSharee->inviteStatus, $calendarId, $sharee->href, ]); continue 2; } } // If we got here, it means it was a new sharee $insertStmt->execute([ $calendarId, $sharee->principal, $sharee->access, \Sabre\DAV\UUIDUtil::getUUID(), $sharee->href, isset($sharee->properties['{DAV:}displayname']) ? $sharee->properties['{DAV:}displayname'] : null, $sharee->inviteStatus ?: \Sabre\DAV\Sharing\Plugin::INVITE_NORESPONSE, $instanceId, ]); } }
php
public function updateInvites($calendarId, array $sharees) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'); } $currentInvites = $this->getInvites($calendarId); list($calendarId, $instanceId) = $calendarId; $removeStmt = $this->pdo->prepare('DELETE FROM '.$this->calendarInstancesTableName.' WHERE calendarid = ? AND share_href = ? AND access IN (2,3)'); $updateStmt = $this->pdo->prepare('UPDATE '.$this->calendarInstancesTableName.' SET access = ?, share_displayname = ?, share_invitestatus = ? WHERE calendarid = ? AND share_href = ?'); $insertStmt = $this->pdo->prepare(' INSERT INTO '.$this->calendarInstancesTableName.' ( calendarid, principaluri, access, displayname, uri, description, calendarorder, calendarcolor, timezone, transparent, share_href, share_displayname, share_invitestatus ) SELECT ?, ?, ?, displayname, ?, description, calendarorder, calendarcolor, timezone, 1, ?, ?, ? FROM '.$this->calendarInstancesTableName.' WHERE id = ?'); foreach ($sharees as $sharee) { if (\Sabre\DAV\Sharing\Plugin::ACCESS_NOACCESS === $sharee->access) { $removeStmt->execute([$calendarId, $sharee->href]); continue; } if (is_null($sharee->principal)) { $sharee->inviteStatus = \Sabre\DAV\Sharing\Plugin::INVITE_INVALID; } else { $sharee->inviteStatus = \Sabre\DAV\Sharing\Plugin::INVITE_ACCEPTED; } foreach ($currentInvites as $oldSharee) { if ($oldSharee->href === $sharee->href) { $sharee->properties = array_merge( $oldSharee->properties, $sharee->properties ); $updateStmt->execute([ $sharee->access, isset($sharee->properties['{DAV:}displayname']) ? $sharee->properties['{DAV:}displayname'] : null, $sharee->inviteStatus ?: $oldSharee->inviteStatus, $calendarId, $sharee->href, ]); continue 2; } } $insertStmt->execute([ $calendarId, $sharee->principal, $sharee->access, \Sabre\DAV\UUIDUtil::getUUID(), $sharee->href, isset($sharee->properties['{DAV:}displayname']) ? $sharee->properties['{DAV:}displayname'] : null, $sharee->inviteStatus ?: \Sabre\DAV\Sharing\Plugin::INVITE_NORESPONSE, $instanceId, ]); } }
[ "public", "function", "updateInvites", "(", "$", "calendarId", ",", "array", "$", "sharees", ")", "{", "if", "(", "!", "is_array", "(", "$", "calendarId", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The value passed to $calendarId is expected to be an array with a calendarId and an instanceId'", ")", ";", "}", "$", "currentInvites", "=", "$", "this", "->", "getInvites", "(", "$", "calendarId", ")", ";", "list", "(", "$", "calendarId", ",", "$", "instanceId", ")", "=", "$", "calendarId", ";", "$", "removeStmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'DELETE FROM '", ".", "$", "this", "->", "calendarInstancesTableName", ".", "' WHERE calendarid = ? AND share_href = ? AND access IN (2,3)'", ")", ";", "$", "updateStmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'UPDATE '", ".", "$", "this", "->", "calendarInstancesTableName", ".", "' SET access = ?, share_displayname = ?, share_invitestatus = ? WHERE calendarid = ? AND share_href = ?'", ")", ";", "$", "insertStmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'\nINSERT INTO '", ".", "$", "this", "->", "calendarInstancesTableName", ".", "'\n (\n calendarid,\n principaluri,\n access,\n displayname,\n uri,\n description,\n calendarorder,\n calendarcolor,\n timezone,\n transparent,\n share_href,\n share_displayname,\n share_invitestatus\n )\n SELECT\n ?,\n ?,\n ?,\n displayname,\n ?,\n description,\n calendarorder,\n calendarcolor,\n timezone,\n 1,\n ?,\n ?,\n ?\n FROM '", ".", "$", "this", "->", "calendarInstancesTableName", ".", "' WHERE id = ?'", ")", ";", "foreach", "(", "$", "sharees", "as", "$", "sharee", ")", "{", "if", "(", "\\", "Sabre", "\\", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "ACCESS_NOACCESS", "===", "$", "sharee", "->", "access", ")", "{", "// if access was set no NOACCESS, it means access for an", "// existing sharee was removed.", "$", "removeStmt", "->", "execute", "(", "[", "$", "calendarId", ",", "$", "sharee", "->", "href", "]", ")", ";", "continue", ";", "}", "if", "(", "is_null", "(", "$", "sharee", "->", "principal", ")", ")", "{", "// If the server could not determine the principal automatically,", "// we will mark the invite status as invalid.", "$", "sharee", "->", "inviteStatus", "=", "\\", "Sabre", "\\", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "INVITE_INVALID", ";", "}", "else", "{", "// Because sabre/dav does not yet have an invitation system,", "// every invite is automatically accepted for now.", "$", "sharee", "->", "inviteStatus", "=", "\\", "Sabre", "\\", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "INVITE_ACCEPTED", ";", "}", "foreach", "(", "$", "currentInvites", "as", "$", "oldSharee", ")", "{", "if", "(", "$", "oldSharee", "->", "href", "===", "$", "sharee", "->", "href", ")", "{", "// This is an update", "$", "sharee", "->", "properties", "=", "array_merge", "(", "$", "oldSharee", "->", "properties", ",", "$", "sharee", "->", "properties", ")", ";", "$", "updateStmt", "->", "execute", "(", "[", "$", "sharee", "->", "access", ",", "isset", "(", "$", "sharee", "->", "properties", "[", "'{DAV:}displayname'", "]", ")", "?", "$", "sharee", "->", "properties", "[", "'{DAV:}displayname'", "]", ":", "null", ",", "$", "sharee", "->", "inviteStatus", "?", ":", "$", "oldSharee", "->", "inviteStatus", ",", "$", "calendarId", ",", "$", "sharee", "->", "href", ",", "]", ")", ";", "continue", "2", ";", "}", "}", "// If we got here, it means it was a new sharee", "$", "insertStmt", "->", "execute", "(", "[", "$", "calendarId", ",", "$", "sharee", "->", "principal", ",", "$", "sharee", "->", "access", ",", "\\", "Sabre", "\\", "DAV", "\\", "UUIDUtil", "::", "getUUID", "(", ")", ",", "$", "sharee", "->", "href", ",", "isset", "(", "$", "sharee", "->", "properties", "[", "'{DAV:}displayname'", "]", ")", "?", "$", "sharee", "->", "properties", "[", "'{DAV:}displayname'", "]", ":", "null", ",", "$", "sharee", "->", "inviteStatus", "?", ":", "\\", "Sabre", "\\", "DAV", "\\", "Sharing", "\\", "Plugin", "::", "INVITE_NORESPONSE", ",", "$", "instanceId", ",", "]", ")", ";", "}", "}" ]
Updates the list of shares. @param mixed $calendarId @param \Sabre\DAV\Xml\Element\Sharee[] $sharees
[ "Updates", "the", "list", "of", "shares", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L1305-L1396
sabre-io/dav
lib/CalDAV/Backend/PDO.php
PDO.getInvites
public function getInvites($calendarId) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to getInvites() is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; $query = <<<SQL SELECT principaluri, access, share_href, share_displayname, share_invitestatus FROM {$this->calendarInstancesTableName} WHERE calendarid = ? SQL; $stmt = $this->pdo->prepare($query); $stmt->execute([$calendarId]); $result = []; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $result[] = new Sharee([ 'href' => isset($row['share_href']) ? $row['share_href'] : \Sabre\HTTP\encodePath($row['principaluri']), 'access' => (int) $row['access'], /// Everyone is always immediately accepted, for now. 'inviteStatus' => (int) $row['share_invitestatus'], 'properties' => !empty($row['share_displayname']) ? ['{DAV:}displayname' => $row['share_displayname']] : [], 'principal' => $row['principaluri'], ]); } return $result; }
php
public function getInvites($calendarId) { if (!is_array($calendarId)) { throw new \InvalidArgumentException('The value passed to getInvites() is expected to be an array with a calendarId and an instanceId'); } list($calendarId, $instanceId) = $calendarId; $query = <<<SQL SELECT principaluri, access, share_href, share_displayname, share_invitestatus FROM {$this->calendarInstancesTableName} WHERE calendarid = ? SQL; $stmt = $this->pdo->prepare($query); $stmt->execute([$calendarId]); $result = []; while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $result[] = new Sharee([ 'href' => isset($row['share_href']) ? $row['share_href'] : \Sabre\HTTP\encodePath($row['principaluri']), 'access' => (int) $row['access'], 'inviteStatus' => (int) $row['share_invitestatus'], 'properties' => !empty($row['share_displayname']) ? ['{DAV:}displayname' => $row['share_displayname']] : [], 'principal' => $row['principaluri'], ]); } return $result; }
[ "public", "function", "getInvites", "(", "$", "calendarId", ")", "{", "if", "(", "!", "is_array", "(", "$", "calendarId", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The value passed to getInvites() is expected to be an array with a calendarId and an instanceId'", ")", ";", "}", "list", "(", "$", "calendarId", ",", "$", "instanceId", ")", "=", "$", "calendarId", ";", "$", "query", "=", " <<<SQL\nSELECT\n principaluri,\n access,\n share_href,\n share_displayname,\n share_invitestatus\nFROM {$this->calendarInstancesTableName}\nWHERE\n calendarid = ?\nSQL", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "$", "query", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "calendarId", "]", ")", ";", "$", "result", "=", "[", "]", ";", "while", "(", "$", "row", "=", "$", "stmt", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ")", "{", "$", "result", "[", "]", "=", "new", "Sharee", "(", "[", "'href'", "=>", "isset", "(", "$", "row", "[", "'share_href'", "]", ")", "?", "$", "row", "[", "'share_href'", "]", ":", "\\", "Sabre", "\\", "HTTP", "\\", "encodePath", "(", "$", "row", "[", "'principaluri'", "]", ")", ",", "'access'", "=>", "(", "int", ")", "$", "row", "[", "'access'", "]", ",", "/// Everyone is always immediately accepted, for now.", "'inviteStatus'", "=>", "(", "int", ")", "$", "row", "[", "'share_invitestatus'", "]", ",", "'properties'", "=>", "!", "empty", "(", "$", "row", "[", "'share_displayname'", "]", ")", "?", "[", "'{DAV:}displayname'", "=>", "$", "row", "[", "'share_displayname'", "]", "]", ":", "[", "]", ",", "'principal'", "=>", "$", "row", "[", "'principaluri'", "]", ",", "]", ")", ";", "}", "return", "$", "result", ";", "}" ]
Returns the list of people whom a calendar is shared with. Every item in the returned list must be a Sharee object with at least the following properties set: $href $shareAccess $inviteStatus and optionally: $properties @param mixed $calendarId @return \Sabre\DAV\Xml\Element\Sharee[]
[ "Returns", "the", "list", "of", "people", "whom", "a", "calendar", "is", "shared", "with", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Backend/PDO.php#L1414-L1451
sabre-io/dav
lib/DAV/PropertyStorage/Backend/PDO.php
PDO.propFind
public function propFind($path, PropFind $propFind) { if (!$propFind->isAllProps() && 0 === count($propFind->get404Properties())) { return; } $query = 'SELECT name, value, valuetype FROM '.$this->tableName.' WHERE path = ?'; $stmt = $this->pdo->prepare($query); $stmt->execute([$path]); while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { if ('resource' === gettype($row['value'])) { $row['value'] = stream_get_contents($row['value']); } switch ($row['valuetype']) { case null: case self::VT_STRING: $propFind->set($row['name'], $row['value']); break; case self::VT_XML: $propFind->set($row['name'], new Complex($row['value'])); break; case self::VT_OBJECT: $propFind->set($row['name'], unserialize($row['value'])); break; } } }
php
public function propFind($path, PropFind $propFind) { if (!$propFind->isAllProps() && 0 === count($propFind->get404Properties())) { return; } $query = 'SELECT name, value, valuetype FROM '.$this->tableName.' WHERE path = ?'; $stmt = $this->pdo->prepare($query); $stmt->execute([$path]); while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { if ('resource' === gettype($row['value'])) { $row['value'] = stream_get_contents($row['value']); } switch ($row['valuetype']) { case null: case self::VT_STRING: $propFind->set($row['name'], $row['value']); break; case self::VT_XML: $propFind->set($row['name'], new Complex($row['value'])); break; case self::VT_OBJECT: $propFind->set($row['name'], unserialize($row['value'])); break; } } }
[ "public", "function", "propFind", "(", "$", "path", ",", "PropFind", "$", "propFind", ")", "{", "if", "(", "!", "$", "propFind", "->", "isAllProps", "(", ")", "&&", "0", "===", "count", "(", "$", "propFind", "->", "get404Properties", "(", ")", ")", ")", "{", "return", ";", "}", "$", "query", "=", "'SELECT name, value, valuetype FROM '", ".", "$", "this", "->", "tableName", ".", "' WHERE path = ?'", ";", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "$", "query", ")", ";", "$", "stmt", "->", "execute", "(", "[", "$", "path", "]", ")", ";", "while", "(", "$", "row", "=", "$", "stmt", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ")", "{", "if", "(", "'resource'", "===", "gettype", "(", "$", "row", "[", "'value'", "]", ")", ")", "{", "$", "row", "[", "'value'", "]", "=", "stream_get_contents", "(", "$", "row", "[", "'value'", "]", ")", ";", "}", "switch", "(", "$", "row", "[", "'valuetype'", "]", ")", "{", "case", "null", ":", "case", "self", "::", "VT_STRING", ":", "$", "propFind", "->", "set", "(", "$", "row", "[", "'name'", "]", ",", "$", "row", "[", "'value'", "]", ")", ";", "break", ";", "case", "self", "::", "VT_XML", ":", "$", "propFind", "->", "set", "(", "$", "row", "[", "'name'", "]", ",", "new", "Complex", "(", "$", "row", "[", "'value'", "]", ")", ")", ";", "break", ";", "case", "self", "::", "VT_OBJECT", ":", "$", "propFind", "->", "set", "(", "$", "row", "[", "'name'", "]", ",", "unserialize", "(", "$", "row", "[", "'value'", "]", ")", ")", ";", "break", ";", "}", "}", "}" ]
Fetches properties for a path. This method received a PropFind object, which contains all the information about the properties that need to be fetched. Usually you would just want to call 'get404Properties' on this object, as this will give you the _exact_ list of properties that need to be fetched, and haven't yet. However, you can also support the 'allprops' property here. In that case, you should check for $propFind->isAllProps(). @param string $path @param PropFind $propFind
[ "Fetches", "properties", "for", "a", "path", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PropertyStorage/Backend/PDO.php#L80-L107
sabre-io/dav
lib/DAV/PropertyStorage/Backend/PDO.php
PDO.propPatch
public function propPatch($path, PropPatch $propPatch) { $propPatch->handleRemaining(function ($properties) use ($path) { if ('pgsql' === $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME)) { $updateSql = <<<SQL INSERT INTO {$this->tableName} (path, name, valuetype, value) VALUES (:path, :name, :valuetype, :value) ON CONFLICT (path, name) DO UPDATE SET valuetype = :valuetype, value = :value SQL; } else { $updateSql = <<<SQL REPLACE INTO {$this->tableName} (path, name, valuetype, value) VALUES (:path, :name, :valuetype, :value) SQL; } $updateStmt = $this->pdo->prepare($updateSql); $deleteStmt = $this->pdo->prepare('DELETE FROM '.$this->tableName.' WHERE path = ? AND name = ?'); foreach ($properties as $name => $value) { if (!is_null($value)) { if (is_scalar($value)) { $valueType = self::VT_STRING; } elseif ($value instanceof Complex) { $valueType = self::VT_XML; $value = $value->getXml(); } else { $valueType = self::VT_OBJECT; $value = serialize($value); } $updateStmt->bindParam('path', $path, \PDO::PARAM_STR); $updateStmt->bindParam('name', $name, \PDO::PARAM_STR); $updateStmt->bindParam('valuetype', $valueType, \PDO::PARAM_INT); $updateStmt->bindParam('value', $value, \PDO::PARAM_LOB); $updateStmt->execute(); } else { $deleteStmt->execute([$path, $name]); } } return true; }); }
php
public function propPatch($path, PropPatch $propPatch) { $propPatch->handleRemaining(function ($properties) use ($path) { if ('pgsql' === $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME)) { $updateSql = <<<SQL INSERT INTO {$this->tableName} (path, name, valuetype, value) VALUES (:path, :name, :valuetype, :value) ON CONFLICT (path, name) DO UPDATE SET valuetype = :valuetype, value = :value SQL; } else { $updateSql = <<<SQL REPLACE INTO {$this->tableName} (path, name, valuetype, value) VALUES (:path, :name, :valuetype, :value) SQL; } $updateStmt = $this->pdo->prepare($updateSql); $deleteStmt = $this->pdo->prepare('DELETE FROM '.$this->tableName.' WHERE path = ? AND name = ?'); foreach ($properties as $name => $value) { if (!is_null($value)) { if (is_scalar($value)) { $valueType = self::VT_STRING; } elseif ($value instanceof Complex) { $valueType = self::VT_XML; $value = $value->getXml(); } else { $valueType = self::VT_OBJECT; $value = serialize($value); } $updateStmt->bindParam('path', $path, \PDO::PARAM_STR); $updateStmt->bindParam('name', $name, \PDO::PARAM_STR); $updateStmt->bindParam('valuetype', $valueType, \PDO::PARAM_INT); $updateStmt->bindParam('value', $value, \PDO::PARAM_LOB); $updateStmt->execute(); } else { $deleteStmt->execute([$path, $name]); } } return true; }); }
[ "public", "function", "propPatch", "(", "$", "path", ",", "PropPatch", "$", "propPatch", ")", "{", "$", "propPatch", "->", "handleRemaining", "(", "function", "(", "$", "properties", ")", "use", "(", "$", "path", ")", "{", "if", "(", "'pgsql'", "===", "$", "this", "->", "pdo", "->", "getAttribute", "(", "\\", "PDO", "::", "ATTR_DRIVER_NAME", ")", ")", "{", "$", "updateSql", "=", " <<<SQL\nINSERT INTO {$this->tableName} (path, name, valuetype, value)\nVALUES (:path, :name, :valuetype, :value)\nON CONFLICT (path, name)\nDO UPDATE SET valuetype = :valuetype, value = :value\nSQL", ";", "}", "else", "{", "$", "updateSql", "=", " <<<SQL\nREPLACE INTO {$this->tableName} (path, name, valuetype, value)\nVALUES (:path, :name, :valuetype, :value)\nSQL", ";", "}", "$", "updateStmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "$", "updateSql", ")", ";", "$", "deleteStmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'DELETE FROM '", ".", "$", "this", "->", "tableName", ".", "' WHERE path = ? AND name = ?'", ")", ";", "foreach", "(", "$", "properties", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "!", "is_null", "(", "$", "value", ")", ")", "{", "if", "(", "is_scalar", "(", "$", "value", ")", ")", "{", "$", "valueType", "=", "self", "::", "VT_STRING", ";", "}", "elseif", "(", "$", "value", "instanceof", "Complex", ")", "{", "$", "valueType", "=", "self", "::", "VT_XML", ";", "$", "value", "=", "$", "value", "->", "getXml", "(", ")", ";", "}", "else", "{", "$", "valueType", "=", "self", "::", "VT_OBJECT", ";", "$", "value", "=", "serialize", "(", "$", "value", ")", ";", "}", "$", "updateStmt", "->", "bindParam", "(", "'path'", ",", "$", "path", ",", "\\", "PDO", "::", "PARAM_STR", ")", ";", "$", "updateStmt", "->", "bindParam", "(", "'name'", ",", "$", "name", ",", "\\", "PDO", "::", "PARAM_STR", ")", ";", "$", "updateStmt", "->", "bindParam", "(", "'valuetype'", ",", "$", "valueType", ",", "\\", "PDO", "::", "PARAM_INT", ")", ";", "$", "updateStmt", "->", "bindParam", "(", "'value'", ",", "$", "value", ",", "\\", "PDO", "::", "PARAM_LOB", ")", ";", "$", "updateStmt", "->", "execute", "(", ")", ";", "}", "else", "{", "$", "deleteStmt", "->", "execute", "(", "[", "$", "path", ",", "$", "name", "]", ")", ";", "}", "}", "return", "true", ";", "}", ")", ";", "}" ]
Updates properties for a path. This method received a PropPatch object, which contains all the information about the update. Usually you would want to call 'handleRemaining' on this object, to get; a list of all properties that need to be stored. @param string $path @param PropPatch $propPatch
[ "Updates", "properties", "for", "a", "path", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PropertyStorage/Backend/PDO.php#L121-L166
sabre-io/dav
lib/DAV/PropertyStorage/Backend/PDO.php
PDO.delete
public function delete($path) { $stmt = $this->pdo->prepare('DELETE FROM '.$this->tableName." WHERE path = ? OR path LIKE ? ESCAPE '='"); $childPath = strtr( $path, [ '=' => '==', '%' => '=%', '_' => '=_', ] ).'/%'; $stmt->execute([$path, $childPath]); }
php
public function delete($path) { $stmt = $this->pdo->prepare('DELETE FROM '.$this->tableName." WHERE path = ? OR path LIKE ? ESCAPE '='"); $childPath = strtr( $path, [ '=' => '==', '%' => '=%', '_' => '=_', ] ).'/%'; $stmt->execute([$path, $childPath]); }
[ "public", "function", "delete", "(", "$", "path", ")", "{", "$", "stmt", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'DELETE FROM '", ".", "$", "this", "->", "tableName", ".", "\" WHERE path = ? OR path LIKE ? ESCAPE '='\"", ")", ";", "$", "childPath", "=", "strtr", "(", "$", "path", ",", "[", "'='", "=>", "'=='", ",", "'%'", "=>", "'=%'", ",", "'_'", "=>", "'=_'", ",", "]", ")", ".", "'/%'", ";", "$", "stmt", "->", "execute", "(", "[", "$", "path", ",", "$", "childPath", "]", ")", ";", "}" ]
This method is called after a node is deleted. This allows a backend to clean up all associated properties. The delete method will get called once for the deletion of an entire tree. @param string $path
[ "This", "method", "is", "called", "after", "a", "node", "is", "deleted", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PropertyStorage/Backend/PDO.php#L178-L191
sabre-io/dav
lib/DAV/PropertyStorage/Backend/PDO.php
PDO.move
public function move($source, $destination) { // I don't know a way to write this all in a single sql query that's // also compatible across db engines, so we're letting PHP do all the // updates. Much slower, but it should still be pretty fast in most // cases. $select = $this->pdo->prepare('SELECT id, path FROM '.$this->tableName.' WHERE path = ? OR path LIKE ?'); $select->execute([$source, $source.'/%']); $update = $this->pdo->prepare('UPDATE '.$this->tableName.' SET path = ? WHERE id = ?'); while ($row = $select->fetch(\PDO::FETCH_ASSOC)) { // Sanity check. SQL may select too many records, such as records // with different cases. if ($row['path'] !== $source && 0 !== strpos($row['path'], $source.'/')) { continue; } $trailingPart = substr($row['path'], strlen($source) + 1); $newPath = $destination; if ($trailingPart) { $newPath .= '/'.$trailingPart; } $update->execute([$newPath, $row['id']]); } }
php
public function move($source, $destination) { $select = $this->pdo->prepare('SELECT id, path FROM '.$this->tableName.' WHERE path = ? OR path LIKE ?'); $select->execute([$source, $source.'/%']); $update = $this->pdo->prepare('UPDATE '.$this->tableName.' SET path = ? WHERE id = ?'); while ($row = $select->fetch(\PDO::FETCH_ASSOC)) { if ($row['path'] !== $source && 0 !== strpos($row['path'], $source.'/')) { continue; } $trailingPart = substr($row['path'], strlen($source) + 1); $newPath = $destination; if ($trailingPart) { $newPath .= '/'.$trailingPart; } $update->execute([$newPath, $row['id']]); } }
[ "public", "function", "move", "(", "$", "source", ",", "$", "destination", ")", "{", "// I don't know a way to write this all in a single sql query that's", "// also compatible across db engines, so we're letting PHP do all the", "// updates. Much slower, but it should still be pretty fast in most", "// cases.", "$", "select", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'SELECT id, path FROM '", ".", "$", "this", "->", "tableName", ".", "' WHERE path = ? OR path LIKE ?'", ")", ";", "$", "select", "->", "execute", "(", "[", "$", "source", ",", "$", "source", ".", "'/%'", "]", ")", ";", "$", "update", "=", "$", "this", "->", "pdo", "->", "prepare", "(", "'UPDATE '", ".", "$", "this", "->", "tableName", ".", "' SET path = ? WHERE id = ?'", ")", ";", "while", "(", "$", "row", "=", "$", "select", "->", "fetch", "(", "\\", "PDO", "::", "FETCH_ASSOC", ")", ")", "{", "// Sanity check. SQL may select too many records, such as records", "// with different cases.", "if", "(", "$", "row", "[", "'path'", "]", "!==", "$", "source", "&&", "0", "!==", "strpos", "(", "$", "row", "[", "'path'", "]", ",", "$", "source", ".", "'/'", ")", ")", "{", "continue", ";", "}", "$", "trailingPart", "=", "substr", "(", "$", "row", "[", "'path'", "]", ",", "strlen", "(", "$", "source", ")", "+", "1", ")", ";", "$", "newPath", "=", "$", "destination", ";", "if", "(", "$", "trailingPart", ")", "{", "$", "newPath", ".=", "'/'", ".", "$", "trailingPart", ";", "}", "$", "update", "->", "execute", "(", "[", "$", "newPath", ",", "$", "row", "[", "'id'", "]", "]", ")", ";", "}", "}" ]
This method is called after a successful MOVE. This should be used to migrate all properties from one path to another. Note that entire collections may be moved, so ensure that all properties for children are also moved along. @param string $source @param string $destination
[ "This", "method", "is", "called", "after", "a", "successful", "MOVE", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PropertyStorage/Backend/PDO.php#L203-L227
sabre-io/dav
lib/DAV/FSExt/Directory.php
Directory.createFile
public function createFile($name, $data = null) { // We're not allowing dots if ('.' == $name || '..' == $name) { throw new DAV\Exception\Forbidden('Permission denied to . and ..'); } $newPath = $this->path.'/'.$name; file_put_contents($newPath, $data); clearstatcache(true, $newPath); return '"'.sha1( fileinode($newPath). filesize($newPath). filemtime($newPath) ).'"'; }
php
public function createFile($name, $data = null) { if ('.' == $name || '..' == $name) { throw new DAV\Exception\Forbidden('Permission denied to . and ..'); } $newPath = $this->path.'/'.$name; file_put_contents($newPath, $data); clearstatcache(true, $newPath); return '"'.sha1( fileinode($newPath). filesize($newPath). filemtime($newPath) ).'"'; }
[ "public", "function", "createFile", "(", "$", "name", ",", "$", "data", "=", "null", ")", "{", "// We're not allowing dots", "if", "(", "'.'", "==", "$", "name", "||", "'..'", "==", "$", "name", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "Forbidden", "(", "'Permission denied to . and ..'", ")", ";", "}", "$", "newPath", "=", "$", "this", "->", "path", ".", "'/'", ".", "$", "name", ";", "file_put_contents", "(", "$", "newPath", ",", "$", "data", ")", ";", "clearstatcache", "(", "true", ",", "$", "newPath", ")", ";", "return", "'\"'", ".", "sha1", "(", "fileinode", "(", "$", "newPath", ")", ".", "filesize", "(", "$", "newPath", ")", ".", "filemtime", "(", "$", "newPath", ")", ")", ".", "'\"'", ";", "}" ]
Creates a new file in the directory. Data will either be supplied as a stream resource, or in certain cases as a string. Keep in mind that you may have to support either. After successful creation of the file, you may choose to return the ETag of the new file here. The returned ETag must be surrounded by double-quotes (The quotes should be part of the actual string). If you cannot accurately determine the ETag, you should not return it. If you don't store the file exactly as-is (you're transforming it somehow) you should also not return an ETag. This means that if a subsequent GET to this new file does not exactly return the same contents of what was submitted here, you are strongly recommended to omit the ETag. @param string $name Name of the file @param resource|string $data Initial payload @return string|null
[ "Creates", "a", "new", "file", "in", "the", "directory", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/FSExt/Directory.php#L44-L59
sabre-io/dav
lib/DAV/FSExt/Directory.php
Directory.createDirectory
public function createDirectory($name) { // We're not allowing dots if ('.' == $name || '..' == $name) { throw new DAV\Exception\Forbidden('Permission denied to . and ..'); } $newPath = $this->path.'/'.$name; mkdir($newPath); clearstatcache(true, $newPath); }
php
public function createDirectory($name) { if ('.' == $name || '..' == $name) { throw new DAV\Exception\Forbidden('Permission denied to . and ..'); } $newPath = $this->path.'/'.$name; mkdir($newPath); clearstatcache(true, $newPath); }
[ "public", "function", "createDirectory", "(", "$", "name", ")", "{", "// We're not allowing dots", "if", "(", "'.'", "==", "$", "name", "||", "'..'", "==", "$", "name", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "Forbidden", "(", "'Permission denied to . and ..'", ")", ";", "}", "$", "newPath", "=", "$", "this", "->", "path", ".", "'/'", ".", "$", "name", ";", "mkdir", "(", "$", "newPath", ")", ";", "clearstatcache", "(", "true", ",", "$", "newPath", ")", ";", "}" ]
Creates a new subdirectory. @param string $name
[ "Creates", "a", "new", "subdirectory", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/FSExt/Directory.php#L66-L75
sabre-io/dav
lib/DAV/FSExt/Directory.php
Directory.getChild
public function getChild($name) { $path = $this->path.'/'.$name; if (!file_exists($path)) { throw new DAV\Exception\NotFound('File could not be located'); } if ('.' == $name || '..' == $name) { throw new DAV\Exception\Forbidden('Permission denied to . and ..'); } if (is_dir($path)) { return new self($path); } else { return new File($path); } }
php
public function getChild($name) { $path = $this->path.'/'.$name; if (!file_exists($path)) { throw new DAV\Exception\NotFound('File could not be located'); } if ('.' == $name || '..' == $name) { throw new DAV\Exception\Forbidden('Permission denied to . and ..'); } if (is_dir($path)) { return new self($path); } else { return new File($path); } }
[ "public", "function", "getChild", "(", "$", "name", ")", "{", "$", "path", "=", "$", "this", "->", "path", ".", "'/'", ".", "$", "name", ";", "if", "(", "!", "file_exists", "(", "$", "path", ")", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "NotFound", "(", "'File could not be located'", ")", ";", "}", "if", "(", "'.'", "==", "$", "name", "||", "'..'", "==", "$", "name", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "Forbidden", "(", "'Permission denied to . and ..'", ")", ";", "}", "if", "(", "is_dir", "(", "$", "path", ")", ")", "{", "return", "new", "self", "(", "$", "path", ")", ";", "}", "else", "{", "return", "new", "File", "(", "$", "path", ")", ";", "}", "}" ]
Returns a specific child node, referenced by its name. This method must throw Sabre\DAV\Exception\NotFound if the node does not exist. @param string $name @throws DAV\Exception\NotFound @return DAV\INode
[ "Returns", "a", "specific", "child", "node", "referenced", "by", "its", "name", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/FSExt/Directory.php#L89-L104
sabre-io/dav
lib/DAV/FSExt/Directory.php
Directory.childExists
public function childExists($name) { if ('.' == $name || '..' == $name) { throw new DAV\Exception\Forbidden('Permission denied to . and ..'); } $path = $this->path.'/'.$name; return file_exists($path); }
php
public function childExists($name) { if ('.' == $name || '..' == $name) { throw new DAV\Exception\Forbidden('Permission denied to . and ..'); } $path = $this->path.'/'.$name; return file_exists($path); }
[ "public", "function", "childExists", "(", "$", "name", ")", "{", "if", "(", "'.'", "==", "$", "name", "||", "'..'", "==", "$", "name", ")", "{", "throw", "new", "DAV", "\\", "Exception", "\\", "Forbidden", "(", "'Permission denied to . and ..'", ")", ";", "}", "$", "path", "=", "$", "this", "->", "path", ".", "'/'", ".", "$", "name", ";", "return", "file_exists", "(", "$", "path", ")", ";", "}" ]
Checks if a child exists. @param string $name @return bool
[ "Checks", "if", "a", "child", "exists", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/FSExt/Directory.php#L113-L121
sabre-io/dav
lib/DAV/FSExt/Directory.php
Directory.getChildren
public function getChildren() { $nodes = []; $iterator = new \FilesystemIterator( $this->path, \FilesystemIterator::CURRENT_AS_SELF | \FilesystemIterator::SKIP_DOTS ); foreach ($iterator as $entry) { $nodes[] = $this->getChild($entry->getFilename()); } return $nodes; }
php
public function getChildren() { $nodes = []; $iterator = new \FilesystemIterator( $this->path, \FilesystemIterator::CURRENT_AS_SELF | \FilesystemIterator::SKIP_DOTS ); foreach ($iterator as $entry) { $nodes[] = $this->getChild($entry->getFilename()); } return $nodes; }
[ "public", "function", "getChildren", "(", ")", "{", "$", "nodes", "=", "[", "]", ";", "$", "iterator", "=", "new", "\\", "FilesystemIterator", "(", "$", "this", "->", "path", ",", "\\", "FilesystemIterator", "::", "CURRENT_AS_SELF", "|", "\\", "FilesystemIterator", "::", "SKIP_DOTS", ")", ";", "foreach", "(", "$", "iterator", "as", "$", "entry", ")", "{", "$", "nodes", "[", "]", "=", "$", "this", "->", "getChild", "(", "$", "entry", "->", "getFilename", "(", ")", ")", ";", "}", "return", "$", "nodes", ";", "}" ]
Returns an array with all the child nodes. @return DAV\INode[]
[ "Returns", "an", "array", "with", "all", "the", "child", "nodes", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/FSExt/Directory.php#L128-L142
sabre-io/dav
lib/DAV/FSExt/Directory.php
Directory.delete
public function delete() { // Deleting all children foreach ($this->getChildren() as $child) { $child->delete(); } // Removing the directory itself rmdir($this->path); return true; }
php
public function delete() { foreach ($this->getChildren() as $child) { $child->delete(); } rmdir($this->path); return true; }
[ "public", "function", "delete", "(", ")", "{", "// Deleting all children", "foreach", "(", "$", "this", "->", "getChildren", "(", ")", "as", "$", "child", ")", "{", "$", "child", "->", "delete", "(", ")", ";", "}", "// Removing the directory itself", "rmdir", "(", "$", "this", "->", "path", ")", ";", "return", "true", ";", "}" ]
Deletes all files in this directory, and then itself. @return bool
[ "Deletes", "all", "files", "in", "this", "directory", "and", "then", "itself", "." ]
train
https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/FSExt/Directory.php#L149-L160