repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 39
1.84M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
sabre-io/dav | lib/CalDAV/Subscriptions/Plugin.php | Plugin.initialize | public function initialize(Server $server)
{
$server->resourceTypeMapping['Sabre\\CalDAV\\Subscriptions\\ISubscription'] =
'{http://calendarserver.org/ns/}subscribed';
$server->xml->elementMap['{http://calendarserver.org/ns/}source'] =
'Sabre\\DAV\\Xml\\Property\\Href';
$server->on('propFind', [$this, 'propFind'], 150);
} | php | public function initialize(Server $server)
{
$server->resourceTypeMapping['Sabre\\CalDAV\\Subscriptions\\ISubscription'] =
'{http:
$server->xml->elementMap['{http:
'Sabre\\DAV\\Xml\\Property\\Href';
$server->on('propFind', [$this, 'propFind'], 150);
} | [
"public",
"function",
"initialize",
"(",
"Server",
"$",
"server",
")",
"{",
"$",
"server",
"->",
"resourceTypeMapping",
"[",
"'Sabre\\\\CalDAV\\\\Subscriptions\\\\ISubscription'",
"]",
"=",
"'{http://calendarserver.org/ns/}subscribed'",
";",
"$",
"server",
"->",
"xml",
"->",
"elementMap",
"[",
"'{http://calendarserver.org/ns/}source'",
"]",
"=",
"'Sabre\\\\DAV\\\\Xml\\\\Property\\\\Href'",
";",
"$",
"server",
"->",
"on",
"(",
"'propFind'",
",",
"[",
"$",
"this",
",",
"'propFind'",
"]",
",",
"150",
")",
";",
"}"
] | This initializes the plugin.
This function is called by Sabre\DAV\Server, after
addPlugin is called.
This method should set up the required event subscriptions.
@param Server $server | [
"This",
"initializes",
"the",
"plugin",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Subscriptions/Plugin.php#L34-L43 |
sabre-io/dav | lib/CalDAV/Subscriptions/Plugin.php | Plugin.propFind | public function propFind(PropFind $propFind, INode $node)
{
// There's a bunch of properties that must appear as a self-closing
// xml-element. This event handler ensures that this will be the case.
$props = [
'{http://calendarserver.org/ns/}subscribed-strip-alarms',
'{http://calendarserver.org/ns/}subscribed-strip-attachments',
'{http://calendarserver.org/ns/}subscribed-strip-todos',
];
foreach ($props as $prop) {
if (200 === $propFind->getStatus($prop)) {
$propFind->set($prop, '', 200);
}
}
} | php | public function propFind(PropFind $propFind, INode $node)
{
$props = [
'{http:
'{http:
'{http:
];
foreach ($props as $prop) {
if (200 === $propFind->getStatus($prop)) {
$propFind->set($prop, '', 200);
}
}
} | [
"public",
"function",
"propFind",
"(",
"PropFind",
"$",
"propFind",
",",
"INode",
"$",
"node",
")",
"{",
"// There's a bunch of properties that must appear as a self-closing",
"// xml-element. This event handler ensures that this will be the case.",
"$",
"props",
"=",
"[",
"'{http://calendarserver.org/ns/}subscribed-strip-alarms'",
",",
"'{http://calendarserver.org/ns/}subscribed-strip-attachments'",
",",
"'{http://calendarserver.org/ns/}subscribed-strip-todos'",
",",
"]",
";",
"foreach",
"(",
"$",
"props",
"as",
"$",
"prop",
")",
"{",
"if",
"(",
"200",
"===",
"$",
"propFind",
"->",
"getStatus",
"(",
"$",
"prop",
")",
")",
"{",
"$",
"propFind",
"->",
"set",
"(",
"$",
"prop",
",",
"''",
",",
"200",
")",
";",
"}",
"}",
"}"
] | Triggered after properties have been fetched.
@param PropFind $propFind
@param INode $node | [
"Triggered",
"after",
"properties",
"have",
"been",
"fetched",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Subscriptions/Plugin.php#L64-L79 |
sabre-io/dav | lib/CalDAV/Xml/Property/EmailAddressSet.php | EmailAddressSet.xmlSerialize | public function xmlSerialize(Writer $writer)
{
foreach ($this->emails as $email) {
$writer->writeElement('{http://calendarserver.org/ns/}email-address', $email);
}
} | php | public function xmlSerialize(Writer $writer)
{
foreach ($this->emails as $email) {
$writer->writeElement('{http:
}
} | [
"public",
"function",
"xmlSerialize",
"(",
"Writer",
"$",
"writer",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"emails",
"as",
"$",
"email",
")",
"{",
"$",
"writer",
"->",
"writeElement",
"(",
"'{http://calendarserver.org/ns/}email-address'",
",",
"$",
"email",
")",
";",
"}",
"}"
] | 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/EmailAddressSet.php#L69-L74 |
sabre-io/dav | lib/CalDAV/Schedule/Plugin.php | Plugin.initialize | public function initialize(Server $server)
{
$this->server = $server;
$server->on('method:POST', [$this, 'httpPost']);
$server->on('propFind', [$this, 'propFind']);
$server->on('propPatch', [$this, 'propPatch']);
$server->on('calendarObjectChange', [$this, 'calendarObjectChange']);
$server->on('beforeUnbind', [$this, 'beforeUnbind']);
$server->on('schedule', [$this, 'scheduleLocalDelivery']);
$server->on('getSupportedPrivilegeSet', [$this, 'getSupportedPrivilegeSet']);
$ns = '{'.self::NS_CALDAV.'}';
/*
* This information ensures that the {DAV:}resourcetype property has
* the correct values.
*/
$server->resourceTypeMapping['\\Sabre\\CalDAV\\Schedule\\IOutbox'] = $ns.'schedule-outbox';
$server->resourceTypeMapping['\\Sabre\\CalDAV\\Schedule\\IInbox'] = $ns.'schedule-inbox';
/*
* Properties we protect are made read-only by the server.
*/
array_push($server->protectedProperties,
$ns.'schedule-inbox-URL',
$ns.'schedule-outbox-URL',
$ns.'calendar-user-address-set',
$ns.'calendar-user-type',
$ns.'schedule-default-calendar-URL'
);
} | php | public function initialize(Server $server)
{
$this->server = $server;
$server->on('method:POST', [$this, 'httpPost']);
$server->on('propFind', [$this, 'propFind']);
$server->on('propPatch', [$this, 'propPatch']);
$server->on('calendarObjectChange', [$this, 'calendarObjectChange']);
$server->on('beforeUnbind', [$this, 'beforeUnbind']);
$server->on('schedule', [$this, 'scheduleLocalDelivery']);
$server->on('getSupportedPrivilegeSet', [$this, 'getSupportedPrivilegeSet']);
$ns = '{'.self::NS_CALDAV.'}';
$server->resourceTypeMapping['\\Sabre\\CalDAV\\Schedule\\IOutbox'] = $ns.'schedule-outbox';
$server->resourceTypeMapping['\\Sabre\\CalDAV\\Schedule\\IInbox'] = $ns.'schedule-inbox';
array_push($server->protectedProperties,
$ns.'schedule-inbox-URL',
$ns.'schedule-outbox-URL',
$ns.'calendar-user-address-set',
$ns.'calendar-user-type',
$ns.'schedule-default-calendar-URL'
);
} | [
"public",
"function",
"initialize",
"(",
"Server",
"$",
"server",
")",
"{",
"$",
"this",
"->",
"server",
"=",
"$",
"server",
";",
"$",
"server",
"->",
"on",
"(",
"'method:POST'",
",",
"[",
"$",
"this",
",",
"'httpPost'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'propFind'",
",",
"[",
"$",
"this",
",",
"'propFind'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'propPatch'",
",",
"[",
"$",
"this",
",",
"'propPatch'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'calendarObjectChange'",
",",
"[",
"$",
"this",
",",
"'calendarObjectChange'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'beforeUnbind'",
",",
"[",
"$",
"this",
",",
"'beforeUnbind'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'schedule'",
",",
"[",
"$",
"this",
",",
"'scheduleLocalDelivery'",
"]",
")",
";",
"$",
"server",
"->",
"on",
"(",
"'getSupportedPrivilegeSet'",
",",
"[",
"$",
"this",
",",
"'getSupportedPrivilegeSet'",
"]",
")",
";",
"$",
"ns",
"=",
"'{'",
".",
"self",
"::",
"NS_CALDAV",
".",
"'}'",
";",
"/*\n * This information ensures that the {DAV:}resourcetype property has\n * the correct values.\n */",
"$",
"server",
"->",
"resourceTypeMapping",
"[",
"'\\\\Sabre\\\\CalDAV\\\\Schedule\\\\IOutbox'",
"]",
"=",
"$",
"ns",
".",
"'schedule-outbox'",
";",
"$",
"server",
"->",
"resourceTypeMapping",
"[",
"'\\\\Sabre\\\\CalDAV\\\\Schedule\\\\IInbox'",
"]",
"=",
"$",
"ns",
".",
"'schedule-inbox'",
";",
"/*\n * Properties we protect are made read-only by the server.\n */",
"array_push",
"(",
"$",
"server",
"->",
"protectedProperties",
",",
"$",
"ns",
".",
"'schedule-inbox-URL'",
",",
"$",
"ns",
".",
"'schedule-outbox-URL'",
",",
"$",
"ns",
".",
"'calendar-user-address-set'",
",",
"$",
"ns",
".",
"'calendar-user-type'",
",",
"$",
"ns",
".",
"'schedule-default-calendar-URL'",
")",
";",
"}"
] | Initializes the plugin.
@param Server $server | [
"Initializes",
"the",
"plugin",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/Plugin.php#L100-L130 |
sabre-io/dav | lib/CalDAV/Schedule/Plugin.php | Plugin.getHTTPMethods | public function getHTTPMethods($uri)
{
try {
$node = $this->server->tree->getNodeForPath($uri);
} catch (NotFound $e) {
return [];
}
if ($node instanceof IOutbox) {
return ['POST'];
}
return [];
} | php | public function getHTTPMethods($uri)
{
try {
$node = $this->server->tree->getNodeForPath($uri);
} catch (NotFound $e) {
return [];
}
if ($node instanceof IOutbox) {
return ['POST'];
}
return [];
} | [
"public",
"function",
"getHTTPMethods",
"(",
"$",
"uri",
")",
"{",
"try",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"uri",
")",
";",
"}",
"catch",
"(",
"NotFound",
"$",
"e",
")",
"{",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"$",
"node",
"instanceof",
"IOutbox",
")",
"{",
"return",
"[",
"'POST'",
"]",
";",
"}",
"return",
"[",
"]",
";",
"}"
] | Use this method to tell the server this plugin defines additional
HTTP methods.
This method is passed a uri. It should only return HTTP methods that are
available for the specified uri.
@param string $uri
@return array | [
"Use",
"this",
"method",
"to",
"tell",
"the",
"server",
"this",
"plugin",
"defines",
"additional",
"HTTP",
"methods",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/Plugin.php#L143-L156 |
sabre-io/dav | lib/CalDAV/Schedule/Plugin.php | Plugin.httpPost | public function httpPost(RequestInterface $request, ResponseInterface $response)
{
// Checking if this is a text/calendar content type
$contentType = $request->getHeader('Content-Type');
if (!$contentType || 0 !== strpos($contentType, 'text/calendar')) {
return;
}
$path = $request->getPath();
// Checking if we're talking to an outbox
try {
$node = $this->server->tree->getNodeForPath($path);
} catch (NotFound $e) {
return;
}
if (!$node instanceof IOutbox) {
return;
}
$this->server->transactionType = 'post-caldav-outbox';
$this->outboxRequest($node, $request, $response);
// Returning false breaks the event chain and tells the server we've
// handled the request.
return false;
} | php | public function httpPost(RequestInterface $request, ResponseInterface $response)
{
$contentType = $request->getHeader('Content-Type');
if (!$contentType || 0 !== strpos($contentType, 'text/calendar')) {
return;
}
$path = $request->getPath();
try {
$node = $this->server->tree->getNodeForPath($path);
} catch (NotFound $e) {
return;
}
if (!$node instanceof IOutbox) {
return;
}
$this->server->transactionType = 'post-caldav-outbox';
$this->outboxRequest($node, $request, $response);
return false;
} | [
"public",
"function",
"httpPost",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"// Checking if this is a text/calendar content type",
"$",
"contentType",
"=",
"$",
"request",
"->",
"getHeader",
"(",
"'Content-Type'",
")",
";",
"if",
"(",
"!",
"$",
"contentType",
"||",
"0",
"!==",
"strpos",
"(",
"$",
"contentType",
",",
"'text/calendar'",
")",
")",
"{",
"return",
";",
"}",
"$",
"path",
"=",
"$",
"request",
"->",
"getPath",
"(",
")",
";",
"// Checking if we're talking to an outbox",
"try",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"path",
")",
";",
"}",
"catch",
"(",
"NotFound",
"$",
"e",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"node",
"instanceof",
"IOutbox",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"server",
"->",
"transactionType",
"=",
"'post-caldav-outbox'",
";",
"$",
"this",
"->",
"outboxRequest",
"(",
"$",
"node",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"// Returning false breaks the event chain and tells the server we've",
"// handled the request.",
"return",
"false",
";",
"}"
] | This method handles POST request for the outbox.
@param RequestInterface $request
@param ResponseInterface $response
@return bool | [
"This",
"method",
"handles",
"POST",
"request",
"for",
"the",
"outbox",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/Plugin.php#L166-L192 |
sabre-io/dav | lib/CalDAV/Schedule/Plugin.php | Plugin.propFind | public function propFind(PropFind $propFind, INode $node)
{
if ($node instanceof DAVACL\IPrincipal) {
$caldavPlugin = $this->server->getPlugin('caldav');
$principalUrl = $node->getPrincipalUrl();
// schedule-outbox-URL property
$propFind->handle('{'.self::NS_CALDAV.'}schedule-outbox-URL', function () use ($principalUrl, $caldavPlugin) {
$calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
if (!$calendarHomePath) {
return null;
}
$outboxPath = $calendarHomePath.'/outbox/';
return new LocalHref($outboxPath);
});
// schedule-inbox-URL property
$propFind->handle('{'.self::NS_CALDAV.'}schedule-inbox-URL', function () use ($principalUrl, $caldavPlugin) {
$calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
if (!$calendarHomePath) {
return null;
}
$inboxPath = $calendarHomePath.'/inbox/';
return new LocalHref($inboxPath);
});
$propFind->handle('{'.self::NS_CALDAV.'}schedule-default-calendar-URL', function () use ($principalUrl, $caldavPlugin) {
// We don't support customizing this property yet, so in the
// meantime we just grab the first calendar in the home-set.
$calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
if (!$calendarHomePath) {
return null;
}
$sccs = '{'.self::NS_CALDAV.'}supported-calendar-component-set';
$result = $this->server->getPropertiesForPath($calendarHomePath, [
'{DAV:}resourcetype',
'{DAV:}share-access',
$sccs,
], 1);
foreach ($result as $child) {
if (!isset($child[200]['{DAV:}resourcetype']) || !$child[200]['{DAV:}resourcetype']->is('{'.self::NS_CALDAV.'}calendar')) {
// Node is either not a calendar
continue;
}
if (isset($child[200]['{DAV:}share-access'])) {
$shareAccess = $child[200]['{DAV:}share-access']->getValue();
if (Sharing\Plugin::ACCESS_NOTSHARED !== $shareAccess && Sharing\Plugin::ACCESS_SHAREDOWNER !== $shareAccess) {
// Node is a shared node, not owned by the relevant
// user.
continue;
}
}
if (!isset($child[200][$sccs]) || in_array('VEVENT', $child[200][$sccs]->getValue())) {
// Either there is no supported-calendar-component-set
// (which is fine) or we found one that supports VEVENT.
return new LocalHref($child['href']);
}
}
});
// The server currently reports every principal to be of type
// 'INDIVIDUAL'
$propFind->handle('{'.self::NS_CALDAV.'}calendar-user-type', function () {
return 'INDIVIDUAL';
});
}
// Mapping the old property to the new property.
$propFind->handle('{http://calendarserver.org/ns/}calendar-availability', function () use ($propFind, $node) {
// In case it wasn't clear, the only difference is that we map the
// old property to a different namespace.
$availProp = '{'.self::NS_CALDAV.'}calendar-availability';
$subPropFind = new PropFind(
$propFind->getPath(),
[$availProp]
);
$this->server->getPropertiesByNode(
$subPropFind,
$node
);
$propFind->set(
'{http://calendarserver.org/ns/}calendar-availability',
$subPropFind->get($availProp),
$subPropFind->getStatus($availProp)
);
});
} | php | public function propFind(PropFind $propFind, INode $node)
{
if ($node instanceof DAVACL\IPrincipal) {
$caldavPlugin = $this->server->getPlugin('caldav');
$principalUrl = $node->getPrincipalUrl();
$propFind->handle('{'.self::NS_CALDAV.'}schedule-outbox-URL', function () use ($principalUrl, $caldavPlugin) {
$calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
if (!$calendarHomePath) {
return null;
}
$outboxPath = $calendarHomePath.'/outbox/';
return new LocalHref($outboxPath);
});
$propFind->handle('{'.self::NS_CALDAV.'}schedule-inbox-URL', function () use ($principalUrl, $caldavPlugin) {
$calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
if (!$calendarHomePath) {
return null;
}
$inboxPath = $calendarHomePath.'/inbox/';
return new LocalHref($inboxPath);
});
$propFind->handle('{'.self::NS_CALDAV.'}schedule-default-calendar-URL', function () use ($principalUrl, $caldavPlugin) {
$calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
if (!$calendarHomePath) {
return null;
}
$sccs = '{'.self::NS_CALDAV.'}supported-calendar-component-set';
$result = $this->server->getPropertiesForPath($calendarHomePath, [
'{DAV:}resourcetype',
'{DAV:}share-access',
$sccs,
], 1);
foreach ($result as $child) {
if (!isset($child[200]['{DAV:}resourcetype']) || !$child[200]['{DAV:}resourcetype']->is('{'.self::NS_CALDAV.'}calendar')) {
continue;
}
if (isset($child[200]['{DAV:}share-access'])) {
$shareAccess = $child[200]['{DAV:}share-access']->getValue();
if (Sharing\Plugin::ACCESS_NOTSHARED !== $shareAccess && Sharing\Plugin::ACCESS_SHAREDOWNER !== $shareAccess) {
continue;
}
}
if (!isset($child[200][$sccs]) || in_array('VEVENT', $child[200][$sccs]->getValue())) {
return new LocalHref($child['href']);
}
}
});
$propFind->handle('{'.self::NS_CALDAV.'}calendar-user-type', function () {
return 'INDIVIDUAL';
});
}
$propFind->handle('{http:
$availProp = '{'.self::NS_CALDAV.'}calendar-availability';
$subPropFind = new PropFind(
$propFind->getPath(),
[$availProp]
);
$this->server->getPropertiesByNode(
$subPropFind,
$node
);
$propFind->set(
'{http:
$subPropFind->get($availProp),
$subPropFind->getStatus($availProp)
);
});
} | [
"public",
"function",
"propFind",
"(",
"PropFind",
"$",
"propFind",
",",
"INode",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"DAVACL",
"\\",
"IPrincipal",
")",
"{",
"$",
"caldavPlugin",
"=",
"$",
"this",
"->",
"server",
"->",
"getPlugin",
"(",
"'caldav'",
")",
";",
"$",
"principalUrl",
"=",
"$",
"node",
"->",
"getPrincipalUrl",
"(",
")",
";",
"// schedule-outbox-URL property",
"$",
"propFind",
"->",
"handle",
"(",
"'{'",
".",
"self",
"::",
"NS_CALDAV",
".",
"'}schedule-outbox-URL'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"principalUrl",
",",
"$",
"caldavPlugin",
")",
"{",
"$",
"calendarHomePath",
"=",
"$",
"caldavPlugin",
"->",
"getCalendarHomeForPrincipal",
"(",
"$",
"principalUrl",
")",
";",
"if",
"(",
"!",
"$",
"calendarHomePath",
")",
"{",
"return",
"null",
";",
"}",
"$",
"outboxPath",
"=",
"$",
"calendarHomePath",
".",
"'/outbox/'",
";",
"return",
"new",
"LocalHref",
"(",
"$",
"outboxPath",
")",
";",
"}",
")",
";",
"// schedule-inbox-URL property",
"$",
"propFind",
"->",
"handle",
"(",
"'{'",
".",
"self",
"::",
"NS_CALDAV",
".",
"'}schedule-inbox-URL'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"principalUrl",
",",
"$",
"caldavPlugin",
")",
"{",
"$",
"calendarHomePath",
"=",
"$",
"caldavPlugin",
"->",
"getCalendarHomeForPrincipal",
"(",
"$",
"principalUrl",
")",
";",
"if",
"(",
"!",
"$",
"calendarHomePath",
")",
"{",
"return",
"null",
";",
"}",
"$",
"inboxPath",
"=",
"$",
"calendarHomePath",
".",
"'/inbox/'",
";",
"return",
"new",
"LocalHref",
"(",
"$",
"inboxPath",
")",
";",
"}",
")",
";",
"$",
"propFind",
"->",
"handle",
"(",
"'{'",
".",
"self",
"::",
"NS_CALDAV",
".",
"'}schedule-default-calendar-URL'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"principalUrl",
",",
"$",
"caldavPlugin",
")",
"{",
"// We don't support customizing this property yet, so in the",
"// meantime we just grab the first calendar in the home-set.",
"$",
"calendarHomePath",
"=",
"$",
"caldavPlugin",
"->",
"getCalendarHomeForPrincipal",
"(",
"$",
"principalUrl",
")",
";",
"if",
"(",
"!",
"$",
"calendarHomePath",
")",
"{",
"return",
"null",
";",
"}",
"$",
"sccs",
"=",
"'{'",
".",
"self",
"::",
"NS_CALDAV",
".",
"'}supported-calendar-component-set'",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"server",
"->",
"getPropertiesForPath",
"(",
"$",
"calendarHomePath",
",",
"[",
"'{DAV:}resourcetype'",
",",
"'{DAV:}share-access'",
",",
"$",
"sccs",
",",
"]",
",",
"1",
")",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"child",
"[",
"200",
"]",
"[",
"'{DAV:}resourcetype'",
"]",
")",
"||",
"!",
"$",
"child",
"[",
"200",
"]",
"[",
"'{DAV:}resourcetype'",
"]",
"->",
"is",
"(",
"'{'",
".",
"self",
"::",
"NS_CALDAV",
".",
"'}calendar'",
")",
")",
"{",
"// Node is either not a calendar",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"child",
"[",
"200",
"]",
"[",
"'{DAV:}share-access'",
"]",
")",
")",
"{",
"$",
"shareAccess",
"=",
"$",
"child",
"[",
"200",
"]",
"[",
"'{DAV:}share-access'",
"]",
"->",
"getValue",
"(",
")",
";",
"if",
"(",
"Sharing",
"\\",
"Plugin",
"::",
"ACCESS_NOTSHARED",
"!==",
"$",
"shareAccess",
"&&",
"Sharing",
"\\",
"Plugin",
"::",
"ACCESS_SHAREDOWNER",
"!==",
"$",
"shareAccess",
")",
"{",
"// Node is a shared node, not owned by the relevant",
"// user.",
"continue",
";",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"child",
"[",
"200",
"]",
"[",
"$",
"sccs",
"]",
")",
"||",
"in_array",
"(",
"'VEVENT'",
",",
"$",
"child",
"[",
"200",
"]",
"[",
"$",
"sccs",
"]",
"->",
"getValue",
"(",
")",
")",
")",
"{",
"// Either there is no supported-calendar-component-set",
"// (which is fine) or we found one that supports VEVENT.",
"return",
"new",
"LocalHref",
"(",
"$",
"child",
"[",
"'href'",
"]",
")",
";",
"}",
"}",
"}",
")",
";",
"// The server currently reports every principal to be of type",
"// 'INDIVIDUAL'",
"$",
"propFind",
"->",
"handle",
"(",
"'{'",
".",
"self",
"::",
"NS_CALDAV",
".",
"'}calendar-user-type'",
",",
"function",
"(",
")",
"{",
"return",
"'INDIVIDUAL'",
";",
"}",
")",
";",
"}",
"// Mapping the old property to the new property.",
"$",
"propFind",
"->",
"handle",
"(",
"'{http://calendarserver.org/ns/}calendar-availability'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"propFind",
",",
"$",
"node",
")",
"{",
"// In case it wasn't clear, the only difference is that we map the",
"// old property to a different namespace.",
"$",
"availProp",
"=",
"'{'",
".",
"self",
"::",
"NS_CALDAV",
".",
"'}calendar-availability'",
";",
"$",
"subPropFind",
"=",
"new",
"PropFind",
"(",
"$",
"propFind",
"->",
"getPath",
"(",
")",
",",
"[",
"$",
"availProp",
"]",
")",
";",
"$",
"this",
"->",
"server",
"->",
"getPropertiesByNode",
"(",
"$",
"subPropFind",
",",
"$",
"node",
")",
";",
"$",
"propFind",
"->",
"set",
"(",
"'{http://calendarserver.org/ns/}calendar-availability'",
",",
"$",
"subPropFind",
"->",
"get",
"(",
"$",
"availProp",
")",
",",
"$",
"subPropFind",
"->",
"getStatus",
"(",
"$",
"availProp",
")",
")",
";",
"}",
")",
";",
"}"
] | This method handler is invoked during fetching of properties.
We use this event to add calendar-auto-schedule-specific properties.
@param PropFind $propFind
@param INode $node | [
"This",
"method",
"handler",
"is",
"invoked",
"during",
"fetching",
"of",
"properties",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/Plugin.php#L202-L295 |
sabre-io/dav | lib/CalDAV/Schedule/Plugin.php | Plugin.propPatch | public function propPatch($path, PropPatch $propPatch)
{
// Mapping the old property to the new property.
$propPatch->handle('{http://calendarserver.org/ns/}calendar-availability', function ($value) use ($path) {
$availProp = '{'.self::NS_CALDAV.'}calendar-availability';
$subPropPatch = new PropPatch([$availProp => $value]);
$this->server->emit('propPatch', [$path, $subPropPatch]);
$subPropPatch->commit();
return $subPropPatch->getResult()[$availProp];
});
} | php | public function propPatch($path, PropPatch $propPatch)
{
$propPatch->handle('{http:
$availProp = '{'.self::NS_CALDAV.'}calendar-availability';
$subPropPatch = new PropPatch([$availProp => $value]);
$this->server->emit('propPatch', [$path, $subPropPatch]);
$subPropPatch->commit();
return $subPropPatch->getResult()[$availProp];
});
} | [
"public",
"function",
"propPatch",
"(",
"$",
"path",
",",
"PropPatch",
"$",
"propPatch",
")",
"{",
"// Mapping the old property to the new property.",
"$",
"propPatch",
"->",
"handle",
"(",
"'{http://calendarserver.org/ns/}calendar-availability'",
",",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"path",
")",
"{",
"$",
"availProp",
"=",
"'{'",
".",
"self",
"::",
"NS_CALDAV",
".",
"'}calendar-availability'",
";",
"$",
"subPropPatch",
"=",
"new",
"PropPatch",
"(",
"[",
"$",
"availProp",
"=>",
"$",
"value",
"]",
")",
";",
"$",
"this",
"->",
"server",
"->",
"emit",
"(",
"'propPatch'",
",",
"[",
"$",
"path",
",",
"$",
"subPropPatch",
"]",
")",
";",
"$",
"subPropPatch",
"->",
"commit",
"(",
")",
";",
"return",
"$",
"subPropPatch",
"->",
"getResult",
"(",
")",
"[",
"$",
"availProp",
"]",
";",
"}",
")",
";",
"}"
] | This method is called during property updates.
@param string $path
@param PropPatch $propPatch | [
"This",
"method",
"is",
"called",
"during",
"property",
"updates",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/Plugin.php#L303-L314 |
sabre-io/dav | lib/CalDAV/Schedule/Plugin.php | Plugin.calendarObjectChange | public function calendarObjectChange(RequestInterface $request, ResponseInterface $response, VCalendar $vCal, $calendarPath, &$modified, $isNew)
{
if (!$this->scheduleReply($this->server->httpRequest)) {
return;
}
$calendarNode = $this->server->tree->getNodeForPath($calendarPath);
$addresses = $this->getAddressesForPrincipal(
$calendarNode->getOwner()
);
if (!$isNew) {
$node = $this->server->tree->getNodeForPath($request->getPath());
$oldObj = Reader::read($node->get());
} else {
$oldObj = null;
}
$this->processICalendarChange($oldObj, $vCal, $addresses, [], $modified);
if ($oldObj) {
// Destroy circular references so PHP will GC the object.
$oldObj->destroy();
}
} | php | public function calendarObjectChange(RequestInterface $request, ResponseInterface $response, VCalendar $vCal, $calendarPath, &$modified, $isNew)
{
if (!$this->scheduleReply($this->server->httpRequest)) {
return;
}
$calendarNode = $this->server->tree->getNodeForPath($calendarPath);
$addresses = $this->getAddressesForPrincipal(
$calendarNode->getOwner()
);
if (!$isNew) {
$node = $this->server->tree->getNodeForPath($request->getPath());
$oldObj = Reader::read($node->get());
} else {
$oldObj = null;
}
$this->processICalendarChange($oldObj, $vCal, $addresses, [], $modified);
if ($oldObj) {
$oldObj->destroy();
}
} | [
"public",
"function",
"calendarObjectChange",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
",",
"VCalendar",
"$",
"vCal",
",",
"$",
"calendarPath",
",",
"&",
"$",
"modified",
",",
"$",
"isNew",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"scheduleReply",
"(",
"$",
"this",
"->",
"server",
"->",
"httpRequest",
")",
")",
"{",
"return",
";",
"}",
"$",
"calendarNode",
"=",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"calendarPath",
")",
";",
"$",
"addresses",
"=",
"$",
"this",
"->",
"getAddressesForPrincipal",
"(",
"$",
"calendarNode",
"->",
"getOwner",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"isNew",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"request",
"->",
"getPath",
"(",
")",
")",
";",
"$",
"oldObj",
"=",
"Reader",
"::",
"read",
"(",
"$",
"node",
"->",
"get",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"oldObj",
"=",
"null",
";",
"}",
"$",
"this",
"->",
"processICalendarChange",
"(",
"$",
"oldObj",
",",
"$",
"vCal",
",",
"$",
"addresses",
",",
"[",
"]",
",",
"$",
"modified",
")",
";",
"if",
"(",
"$",
"oldObj",
")",
"{",
"// Destroy circular references so PHP will GC the object.",
"$",
"oldObj",
"->",
"destroy",
"(",
")",
";",
"}",
"}"
] | This method is triggered whenever there was a calendar object gets
created or updated.
@param RequestInterface $request HTTP request
@param ResponseInterface $response HTTP Response
@param VCalendar $vCal Parsed iCalendar object
@param mixed $calendarPath Path to calendar collection
@param mixed $modified the iCalendar object has been touched
@param mixed $isNew Whether this was a new item or we're updating one | [
"This",
"method",
"is",
"triggered",
"whenever",
"there",
"was",
"a",
"calendar",
"object",
"gets",
"created",
"or",
"updated",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/Plugin.php#L327-L352 |
sabre-io/dav | lib/CalDAV/Schedule/Plugin.php | Plugin.deliver | public function deliver(ITip\Message $iTipMessage)
{
$this->server->emit('schedule', [$iTipMessage]);
if (!$iTipMessage->scheduleStatus) {
$iTipMessage->scheduleStatus = '5.2;There was no system capable of delivering the scheduling message';
}
// In case the change was considered 'insignificant', we are going to
// remove any error statuses, if any. See ticket #525.
list($baseCode) = explode('.', $iTipMessage->scheduleStatus);
if (!$iTipMessage->significantChange && in_array($baseCode, ['3', '5'])) {
$iTipMessage->scheduleStatus = null;
}
} | php | public function deliver(ITip\Message $iTipMessage)
{
$this->server->emit('schedule', [$iTipMessage]);
if (!$iTipMessage->scheduleStatus) {
$iTipMessage->scheduleStatus = '5.2;There was no system capable of delivering the scheduling message';
}
list($baseCode) = explode('.', $iTipMessage->scheduleStatus);
if (!$iTipMessage->significantChange && in_array($baseCode, ['3', '5'])) {
$iTipMessage->scheduleStatus = null;
}
} | [
"public",
"function",
"deliver",
"(",
"ITip",
"\\",
"Message",
"$",
"iTipMessage",
")",
"{",
"$",
"this",
"->",
"server",
"->",
"emit",
"(",
"'schedule'",
",",
"[",
"$",
"iTipMessage",
"]",
")",
";",
"if",
"(",
"!",
"$",
"iTipMessage",
"->",
"scheduleStatus",
")",
"{",
"$",
"iTipMessage",
"->",
"scheduleStatus",
"=",
"'5.2;There was no system capable of delivering the scheduling message'",
";",
"}",
"// In case the change was considered 'insignificant', we are going to",
"// remove any error statuses, if any. See ticket #525.",
"list",
"(",
"$",
"baseCode",
")",
"=",
"explode",
"(",
"'.'",
",",
"$",
"iTipMessage",
"->",
"scheduleStatus",
")",
";",
"if",
"(",
"!",
"$",
"iTipMessage",
"->",
"significantChange",
"&&",
"in_array",
"(",
"$",
"baseCode",
",",
"[",
"'3'",
",",
"'5'",
"]",
")",
")",
"{",
"$",
"iTipMessage",
"->",
"scheduleStatus",
"=",
"null",
";",
"}",
"}"
] | This method is responsible for delivering the ITip message.
@param ITip\Message $iTipMessage | [
"This",
"method",
"is",
"responsible",
"for",
"delivering",
"the",
"ITip",
"message",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/Plugin.php#L359-L371 |
sabre-io/dav | lib/CalDAV/Schedule/Plugin.php | Plugin.beforeUnbind | public function beforeUnbind($path)
{
// FIXME: We shouldn't trigger this functionality when we're issuing a
// MOVE. This is a hack.
if ('MOVE' === $this->server->httpRequest->getMethod()) {
return;
}
$node = $this->server->tree->getNodeForPath($path);
if (!$node instanceof ICalendarObject || $node instanceof ISchedulingObject) {
return;
}
if (!$this->scheduleReply($this->server->httpRequest)) {
return;
}
$addresses = $this->getAddressesForPrincipal(
$node->getOwner()
);
$broker = new ITip\Broker();
$messages = $broker->parseEvent(null, $addresses, $node->get());
foreach ($messages as $message) {
$this->deliver($message);
}
} | php | public function beforeUnbind($path)
{
if ('MOVE' === $this->server->httpRequest->getMethod()) {
return;
}
$node = $this->server->tree->getNodeForPath($path);
if (!$node instanceof ICalendarObject || $node instanceof ISchedulingObject) {
return;
}
if (!$this->scheduleReply($this->server->httpRequest)) {
return;
}
$addresses = $this->getAddressesForPrincipal(
$node->getOwner()
);
$broker = new ITip\Broker();
$messages = $broker->parseEvent(null, $addresses, $node->get());
foreach ($messages as $message) {
$this->deliver($message);
}
} | [
"public",
"function",
"beforeUnbind",
"(",
"$",
"path",
")",
"{",
"// FIXME: We shouldn't trigger this functionality when we're issuing a",
"// MOVE. This is a hack.",
"if",
"(",
"'MOVE'",
"===",
"$",
"this",
"->",
"server",
"->",
"httpRequest",
"->",
"getMethod",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"node",
"=",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"$",
"node",
"instanceof",
"ICalendarObject",
"||",
"$",
"node",
"instanceof",
"ISchedulingObject",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"scheduleReply",
"(",
"$",
"this",
"->",
"server",
"->",
"httpRequest",
")",
")",
"{",
"return",
";",
"}",
"$",
"addresses",
"=",
"$",
"this",
"->",
"getAddressesForPrincipal",
"(",
"$",
"node",
"->",
"getOwner",
"(",
")",
")",
";",
"$",
"broker",
"=",
"new",
"ITip",
"\\",
"Broker",
"(",
")",
";",
"$",
"messages",
"=",
"$",
"broker",
"->",
"parseEvent",
"(",
"null",
",",
"$",
"addresses",
",",
"$",
"node",
"->",
"get",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"deliver",
"(",
"$",
"message",
")",
";",
"}",
"}"
] | This method is triggered before a file gets deleted.
We use this event to make sure that when this happens, attendees get
cancellations, and organizers get 'DECLINED' statuses.
@param string $path | [
"This",
"method",
"is",
"triggered",
"before",
"a",
"file",
"gets",
"deleted",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/Plugin.php#L381-L409 |
sabre-io/dav | lib/CalDAV/Schedule/Plugin.php | Plugin.scheduleLocalDelivery | public function scheduleLocalDelivery(ITip\Message $iTipMessage)
{
$aclPlugin = $this->server->getPlugin('acl');
// Local delivery is not available if the ACL plugin is not loaded.
if (!$aclPlugin) {
return;
}
$caldavNS = '{'.self::NS_CALDAV.'}';
$principalUri = $aclPlugin->getPrincipalByUri($iTipMessage->recipient);
if (!$principalUri) {
$iTipMessage->scheduleStatus = '3.7;Could not find principal.';
return;
}
// We found a principal URL, now we need to find its inbox.
// Unfortunately we may not have sufficient privileges to find this, so
// we are temporarily turning off ACL to let this come through.
//
// Once we support PHP 5.5, this should be wrapped in a try..finally
// block so we can ensure that this privilege gets added again after.
$this->server->removeListener('propFind', [$aclPlugin, 'propFind']);
$result = $this->server->getProperties(
$principalUri,
[
'{DAV:}principal-URL',
$caldavNS.'calendar-home-set',
$caldavNS.'schedule-inbox-URL',
$caldavNS.'schedule-default-calendar-URL',
'{http://sabredav.org/ns}email-address',
]
);
// Re-registering the ACL event
$this->server->on('propFind', [$aclPlugin, 'propFind'], 20);
if (!isset($result[$caldavNS.'schedule-inbox-URL'])) {
$iTipMessage->scheduleStatus = '5.2;Could not find local inbox';
return;
}
if (!isset($result[$caldavNS.'calendar-home-set'])) {
$iTipMessage->scheduleStatus = '5.2;Could not locate a calendar-home-set';
return;
}
if (!isset($result[$caldavNS.'schedule-default-calendar-URL'])) {
$iTipMessage->scheduleStatus = '5.2;Could not find a schedule-default-calendar-URL property';
return;
}
$calendarPath = $result[$caldavNS.'schedule-default-calendar-URL']->getHref();
$homePath = $result[$caldavNS.'calendar-home-set']->getHref();
$inboxPath = $result[$caldavNS.'schedule-inbox-URL']->getHref();
if ('REPLY' === $iTipMessage->method) {
$privilege = 'schedule-deliver-reply';
} else {
$privilege = 'schedule-deliver-invite';
}
if (!$aclPlugin->checkPrivileges($inboxPath, $caldavNS.$privilege, DAVACL\Plugin::R_PARENT, false)) {
$iTipMessage->scheduleStatus = '3.8;insufficient privileges: '.$privilege.' is required on the recipient schedule inbox.';
return;
}
// Next, we're going to find out if the item already exits in one of
// the users' calendars.
$uid = $iTipMessage->uid;
$newFileName = 'sabredav-'.\Sabre\DAV\UUIDUtil::getUUID().'.ics';
$home = $this->server->tree->getNodeForPath($homePath);
$inbox = $this->server->tree->getNodeForPath($inboxPath);
$currentObject = null;
$objectNode = null;
$isNewNode = false;
$result = $home->getCalendarObjectByUID($uid);
if ($result) {
// There was an existing object, we need to update probably.
$objectPath = $homePath.'/'.$result;
$objectNode = $this->server->tree->getNodeForPath($objectPath);
$oldICalendarData = $objectNode->get();
$currentObject = Reader::read($oldICalendarData);
} else {
$isNewNode = true;
}
$broker = new ITip\Broker();
$newObject = $broker->processMessage($iTipMessage, $currentObject);
$inbox->createFile($newFileName, $iTipMessage->message->serialize());
if (!$newObject) {
// We received an iTip message referring to a UID that we don't
// have in any calendars yet, and processMessage did not give us a
// calendarobject back.
//
// The implication is that processMessage did not understand the
// iTip message.
$iTipMessage->scheduleStatus = '5.0;iTip message was not processed by the server, likely because we didn\'t understand it.';
return;
}
// Note that we are bypassing ACL on purpose by calling this directly.
// We may need to look a bit deeper into this later. Supporting ACL
// here would be nice.
if ($isNewNode) {
$calendar = $this->server->tree->getNodeForPath($calendarPath);
$calendar->createFile($newFileName, $newObject->serialize());
} else {
// If the message was a reply, we may have to inform other
// attendees of this attendees status. Therefore we're shooting off
// another itipMessage.
if ('REPLY' === $iTipMessage->method) {
$this->processICalendarChange(
$oldICalendarData,
$newObject,
[$iTipMessage->recipient],
[$iTipMessage->sender]
);
}
$objectNode->put($newObject->serialize());
}
$iTipMessage->scheduleStatus = '1.2;Message delivered locally';
} | php | public function scheduleLocalDelivery(ITip\Message $iTipMessage)
{
$aclPlugin = $this->server->getPlugin('acl');
if (!$aclPlugin) {
return;
}
$caldavNS = '{'.self::NS_CALDAV.'}';
$principalUri = $aclPlugin->getPrincipalByUri($iTipMessage->recipient);
if (!$principalUri) {
$iTipMessage->scheduleStatus = '3.7;Could not find principal.';
return;
}
$this->server->removeListener('propFind', [$aclPlugin, 'propFind']);
$result = $this->server->getProperties(
$principalUri,
[
'{DAV:}principal-URL',
$caldavNS.'calendar-home-set',
$caldavNS.'schedule-inbox-URL',
$caldavNS.'schedule-default-calendar-URL',
'{http:
]
);
$this->server->on('propFind', [$aclPlugin, 'propFind'], 20);
if (!isset($result[$caldavNS.'schedule-inbox-URL'])) {
$iTipMessage->scheduleStatus = '5.2;Could not find local inbox';
return;
}
if (!isset($result[$caldavNS.'calendar-home-set'])) {
$iTipMessage->scheduleStatus = '5.2;Could not locate a calendar-home-set';
return;
}
if (!isset($result[$caldavNS.'schedule-default-calendar-URL'])) {
$iTipMessage->scheduleStatus = '5.2;Could not find a schedule-default-calendar-URL property';
return;
}
$calendarPath = $result[$caldavNS.'schedule-default-calendar-URL']->getHref();
$homePath = $result[$caldavNS.'calendar-home-set']->getHref();
$inboxPath = $result[$caldavNS.'schedule-inbox-URL']->getHref();
if ('REPLY' === $iTipMessage->method) {
$privilege = 'schedule-deliver-reply';
} else {
$privilege = 'schedule-deliver-invite';
}
if (!$aclPlugin->checkPrivileges($inboxPath, $caldavNS.$privilege, DAVACL\Plugin::R_PARENT, false)) {
$iTipMessage->scheduleStatus = '3.8;insufficient privileges: '.$privilege.' is required on the recipient schedule inbox.';
return;
}
$uid = $iTipMessage->uid;
$newFileName = 'sabredav-'.\Sabre\DAV\UUIDUtil::getUUID().'.ics';
$home = $this->server->tree->getNodeForPath($homePath);
$inbox = $this->server->tree->getNodeForPath($inboxPath);
$currentObject = null;
$objectNode = null;
$isNewNode = false;
$result = $home->getCalendarObjectByUID($uid);
if ($result) {
$objectPath = $homePath.'/'.$result;
$objectNode = $this->server->tree->getNodeForPath($objectPath);
$oldICalendarData = $objectNode->get();
$currentObject = Reader::read($oldICalendarData);
} else {
$isNewNode = true;
}
$broker = new ITip\Broker();
$newObject = $broker->processMessage($iTipMessage, $currentObject);
$inbox->createFile($newFileName, $iTipMessage->message->serialize());
if (!$newObject) {
$iTipMessage->scheduleStatus = '5.0;iTip message was not processed by the server, likely because we didn\'t understand it.';
return;
}
if ($isNewNode) {
$calendar = $this->server->tree->getNodeForPath($calendarPath);
$calendar->createFile($newFileName, $newObject->serialize());
} else {
if ('REPLY' === $iTipMessage->method) {
$this->processICalendarChange(
$oldICalendarData,
$newObject,
[$iTipMessage->recipient],
[$iTipMessage->sender]
);
}
$objectNode->put($newObject->serialize());
}
$iTipMessage->scheduleStatus = '1.2;Message delivered locally';
} | [
"public",
"function",
"scheduleLocalDelivery",
"(",
"ITip",
"\\",
"Message",
"$",
"iTipMessage",
")",
"{",
"$",
"aclPlugin",
"=",
"$",
"this",
"->",
"server",
"->",
"getPlugin",
"(",
"'acl'",
")",
";",
"// Local delivery is not available if the ACL plugin is not loaded.",
"if",
"(",
"!",
"$",
"aclPlugin",
")",
"{",
"return",
";",
"}",
"$",
"caldavNS",
"=",
"'{'",
".",
"self",
"::",
"NS_CALDAV",
".",
"'}'",
";",
"$",
"principalUri",
"=",
"$",
"aclPlugin",
"->",
"getPrincipalByUri",
"(",
"$",
"iTipMessage",
"->",
"recipient",
")",
";",
"if",
"(",
"!",
"$",
"principalUri",
")",
"{",
"$",
"iTipMessage",
"->",
"scheduleStatus",
"=",
"'3.7;Could not find principal.'",
";",
"return",
";",
"}",
"// We found a principal URL, now we need to find its inbox.",
"// Unfortunately we may not have sufficient privileges to find this, so",
"// we are temporarily turning off ACL to let this come through.",
"//",
"// Once we support PHP 5.5, this should be wrapped in a try..finally",
"// block so we can ensure that this privilege gets added again after.",
"$",
"this",
"->",
"server",
"->",
"removeListener",
"(",
"'propFind'",
",",
"[",
"$",
"aclPlugin",
",",
"'propFind'",
"]",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"server",
"->",
"getProperties",
"(",
"$",
"principalUri",
",",
"[",
"'{DAV:}principal-URL'",
",",
"$",
"caldavNS",
".",
"'calendar-home-set'",
",",
"$",
"caldavNS",
".",
"'schedule-inbox-URL'",
",",
"$",
"caldavNS",
".",
"'schedule-default-calendar-URL'",
",",
"'{http://sabredav.org/ns}email-address'",
",",
"]",
")",
";",
"// Re-registering the ACL event",
"$",
"this",
"->",
"server",
"->",
"on",
"(",
"'propFind'",
",",
"[",
"$",
"aclPlugin",
",",
"'propFind'",
"]",
",",
"20",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
"[",
"$",
"caldavNS",
".",
"'schedule-inbox-URL'",
"]",
")",
")",
"{",
"$",
"iTipMessage",
"->",
"scheduleStatus",
"=",
"'5.2;Could not find local inbox'",
";",
"return",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
"[",
"$",
"caldavNS",
".",
"'calendar-home-set'",
"]",
")",
")",
"{",
"$",
"iTipMessage",
"->",
"scheduleStatus",
"=",
"'5.2;Could not locate a calendar-home-set'",
";",
"return",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
"[",
"$",
"caldavNS",
".",
"'schedule-default-calendar-URL'",
"]",
")",
")",
"{",
"$",
"iTipMessage",
"->",
"scheduleStatus",
"=",
"'5.2;Could not find a schedule-default-calendar-URL property'",
";",
"return",
";",
"}",
"$",
"calendarPath",
"=",
"$",
"result",
"[",
"$",
"caldavNS",
".",
"'schedule-default-calendar-URL'",
"]",
"->",
"getHref",
"(",
")",
";",
"$",
"homePath",
"=",
"$",
"result",
"[",
"$",
"caldavNS",
".",
"'calendar-home-set'",
"]",
"->",
"getHref",
"(",
")",
";",
"$",
"inboxPath",
"=",
"$",
"result",
"[",
"$",
"caldavNS",
".",
"'schedule-inbox-URL'",
"]",
"->",
"getHref",
"(",
")",
";",
"if",
"(",
"'REPLY'",
"===",
"$",
"iTipMessage",
"->",
"method",
")",
"{",
"$",
"privilege",
"=",
"'schedule-deliver-reply'",
";",
"}",
"else",
"{",
"$",
"privilege",
"=",
"'schedule-deliver-invite'",
";",
"}",
"if",
"(",
"!",
"$",
"aclPlugin",
"->",
"checkPrivileges",
"(",
"$",
"inboxPath",
",",
"$",
"caldavNS",
".",
"$",
"privilege",
",",
"DAVACL",
"\\",
"Plugin",
"::",
"R_PARENT",
",",
"false",
")",
")",
"{",
"$",
"iTipMessage",
"->",
"scheduleStatus",
"=",
"'3.8;insufficient privileges: '",
".",
"$",
"privilege",
".",
"' is required on the recipient schedule inbox.'",
";",
"return",
";",
"}",
"// Next, we're going to find out if the item already exits in one of",
"// the users' calendars.",
"$",
"uid",
"=",
"$",
"iTipMessage",
"->",
"uid",
";",
"$",
"newFileName",
"=",
"'sabredav-'",
".",
"\\",
"Sabre",
"\\",
"DAV",
"\\",
"UUIDUtil",
"::",
"getUUID",
"(",
")",
".",
"'.ics'",
";",
"$",
"home",
"=",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"homePath",
")",
";",
"$",
"inbox",
"=",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"inboxPath",
")",
";",
"$",
"currentObject",
"=",
"null",
";",
"$",
"objectNode",
"=",
"null",
";",
"$",
"isNewNode",
"=",
"false",
";",
"$",
"result",
"=",
"$",
"home",
"->",
"getCalendarObjectByUID",
"(",
"$",
"uid",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"// There was an existing object, we need to update probably.",
"$",
"objectPath",
"=",
"$",
"homePath",
".",
"'/'",
".",
"$",
"result",
";",
"$",
"objectNode",
"=",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"objectPath",
")",
";",
"$",
"oldICalendarData",
"=",
"$",
"objectNode",
"->",
"get",
"(",
")",
";",
"$",
"currentObject",
"=",
"Reader",
"::",
"read",
"(",
"$",
"oldICalendarData",
")",
";",
"}",
"else",
"{",
"$",
"isNewNode",
"=",
"true",
";",
"}",
"$",
"broker",
"=",
"new",
"ITip",
"\\",
"Broker",
"(",
")",
";",
"$",
"newObject",
"=",
"$",
"broker",
"->",
"processMessage",
"(",
"$",
"iTipMessage",
",",
"$",
"currentObject",
")",
";",
"$",
"inbox",
"->",
"createFile",
"(",
"$",
"newFileName",
",",
"$",
"iTipMessage",
"->",
"message",
"->",
"serialize",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"newObject",
")",
"{",
"// We received an iTip message referring to a UID that we don't",
"// have in any calendars yet, and processMessage did not give us a",
"// calendarobject back.",
"//",
"// The implication is that processMessage did not understand the",
"// iTip message.",
"$",
"iTipMessage",
"->",
"scheduleStatus",
"=",
"'5.0;iTip message was not processed by the server, likely because we didn\\'t understand it.'",
";",
"return",
";",
"}",
"// Note that we are bypassing ACL on purpose by calling this directly.",
"// We may need to look a bit deeper into this later. Supporting ACL",
"// here would be nice.",
"if",
"(",
"$",
"isNewNode",
")",
"{",
"$",
"calendar",
"=",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"calendarPath",
")",
";",
"$",
"calendar",
"->",
"createFile",
"(",
"$",
"newFileName",
",",
"$",
"newObject",
"->",
"serialize",
"(",
")",
")",
";",
"}",
"else",
"{",
"// If the message was a reply, we may have to inform other",
"// attendees of this attendees status. Therefore we're shooting off",
"// another itipMessage.",
"if",
"(",
"'REPLY'",
"===",
"$",
"iTipMessage",
"->",
"method",
")",
"{",
"$",
"this",
"->",
"processICalendarChange",
"(",
"$",
"oldICalendarData",
",",
"$",
"newObject",
",",
"[",
"$",
"iTipMessage",
"->",
"recipient",
"]",
",",
"[",
"$",
"iTipMessage",
"->",
"sender",
"]",
")",
";",
"}",
"$",
"objectNode",
"->",
"put",
"(",
"$",
"newObject",
"->",
"serialize",
"(",
")",
")",
";",
"}",
"$",
"iTipMessage",
"->",
"scheduleStatus",
"=",
"'1.2;Message delivered locally'",
";",
"}"
] | Event handler for the 'schedule' event.
This handler attempts to look at local accounts to deliver the
scheduling object.
@param ITip\Message $iTipMessage | [
"Event",
"handler",
"for",
"the",
"schedule",
"event",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/Plugin.php#L419-L553 |
sabre-io/dav | lib/CalDAV/Schedule/Plugin.php | Plugin.getSupportedPrivilegeSet | public function getSupportedPrivilegeSet(INode $node, array &$supportedPrivilegeSet)
{
$ns = '{'.self::NS_CALDAV.'}';
if ($node instanceof IOutbox) {
$supportedPrivilegeSet[$ns.'schedule-send'] = [
'abstract' => false,
'aggregates' => [
$ns.'schedule-send-invite' => [
'abstract' => false,
'aggregates' => [],
],
$ns.'schedule-send-reply' => [
'abstract' => false,
'aggregates' => [],
],
$ns.'schedule-send-freebusy' => [
'abstract' => false,
'aggregates' => [],
],
// Privilege from an earlier scheduling draft, but still
// used by some clients.
$ns.'schedule-post-vevent' => [
'abstract' => false,
'aggregates' => [],
],
],
];
}
if ($node instanceof IInbox) {
$supportedPrivilegeSet[$ns.'schedule-deliver'] = [
'abstract' => false,
'aggregates' => [
$ns.'schedule-deliver-invite' => [
'abstract' => false,
'aggregates' => [],
],
$ns.'schedule-deliver-reply' => [
'abstract' => false,
'aggregates' => [],
],
$ns.'schedule-query-freebusy' => [
'abstract' => false,
'aggregates' => [],
],
],
];
}
} | php | public function getSupportedPrivilegeSet(INode $node, array &$supportedPrivilegeSet)
{
$ns = '{'.self::NS_CALDAV.'}';
if ($node instanceof IOutbox) {
$supportedPrivilegeSet[$ns.'schedule-send'] = [
'abstract' => false,
'aggregates' => [
$ns.'schedule-send-invite' => [
'abstract' => false,
'aggregates' => [],
],
$ns.'schedule-send-reply' => [
'abstract' => false,
'aggregates' => [],
],
$ns.'schedule-send-freebusy' => [
'abstract' => false,
'aggregates' => [],
],
$ns.'schedule-post-vevent' => [
'abstract' => false,
'aggregates' => [],
],
],
];
}
if ($node instanceof IInbox) {
$supportedPrivilegeSet[$ns.'schedule-deliver'] = [
'abstract' => false,
'aggregates' => [
$ns.'schedule-deliver-invite' => [
'abstract' => false,
'aggregates' => [],
],
$ns.'schedule-deliver-reply' => [
'abstract' => false,
'aggregates' => [],
],
$ns.'schedule-query-freebusy' => [
'abstract' => false,
'aggregates' => [],
],
],
];
}
} | [
"public",
"function",
"getSupportedPrivilegeSet",
"(",
"INode",
"$",
"node",
",",
"array",
"&",
"$",
"supportedPrivilegeSet",
")",
"{",
"$",
"ns",
"=",
"'{'",
".",
"self",
"::",
"NS_CALDAV",
".",
"'}'",
";",
"if",
"(",
"$",
"node",
"instanceof",
"IOutbox",
")",
"{",
"$",
"supportedPrivilegeSet",
"[",
"$",
"ns",
".",
"'schedule-send'",
"]",
"=",
"[",
"'abstract'",
"=>",
"false",
",",
"'aggregates'",
"=>",
"[",
"$",
"ns",
".",
"'schedule-send-invite'",
"=>",
"[",
"'abstract'",
"=>",
"false",
",",
"'aggregates'",
"=>",
"[",
"]",
",",
"]",
",",
"$",
"ns",
".",
"'schedule-send-reply'",
"=>",
"[",
"'abstract'",
"=>",
"false",
",",
"'aggregates'",
"=>",
"[",
"]",
",",
"]",
",",
"$",
"ns",
".",
"'schedule-send-freebusy'",
"=>",
"[",
"'abstract'",
"=>",
"false",
",",
"'aggregates'",
"=>",
"[",
"]",
",",
"]",
",",
"// Privilege from an earlier scheduling draft, but still",
"// used by some clients.",
"$",
"ns",
".",
"'schedule-post-vevent'",
"=>",
"[",
"'abstract'",
"=>",
"false",
",",
"'aggregates'",
"=>",
"[",
"]",
",",
"]",
",",
"]",
",",
"]",
";",
"}",
"if",
"(",
"$",
"node",
"instanceof",
"IInbox",
")",
"{",
"$",
"supportedPrivilegeSet",
"[",
"$",
"ns",
".",
"'schedule-deliver'",
"]",
"=",
"[",
"'abstract'",
"=>",
"false",
",",
"'aggregates'",
"=>",
"[",
"$",
"ns",
".",
"'schedule-deliver-invite'",
"=>",
"[",
"'abstract'",
"=>",
"false",
",",
"'aggregates'",
"=>",
"[",
"]",
",",
"]",
",",
"$",
"ns",
".",
"'schedule-deliver-reply'",
"=>",
"[",
"'abstract'",
"=>",
"false",
",",
"'aggregates'",
"=>",
"[",
"]",
",",
"]",
",",
"$",
"ns",
".",
"'schedule-query-freebusy'",
"=>",
"[",
"'abstract'",
"=>",
"false",
",",
"'aggregates'",
"=>",
"[",
"]",
",",
"]",
",",
"]",
",",
"]",
";",
"}",
"}"
] | This method is triggered whenever a subsystem requests the privileges
that are supported on a particular node.
We need to add a number of privileges for scheduling purposes.
@param INode $node
@param array $supportedPrivilegeSet | [
"This",
"method",
"is",
"triggered",
"whenever",
"a",
"subsystem",
"requests",
"the",
"privileges",
"that",
"are",
"supported",
"on",
"a",
"particular",
"node",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/Plugin.php#L564-L611 |
sabre-io/dav | lib/CalDAV/Schedule/Plugin.php | Plugin.processICalendarChange | protected function processICalendarChange($oldObject = null, VCalendar $newObject, array $addresses, array $ignore = [], &$modified = false)
{
$broker = new ITip\Broker();
$messages = $broker->parseEvent($newObject, $addresses, $oldObject);
if ($messages) {
$modified = true;
}
foreach ($messages as $message) {
if (in_array($message->recipient, $ignore)) {
continue;
}
$this->deliver($message);
if (isset($newObject->VEVENT->ORGANIZER) && ($newObject->VEVENT->ORGANIZER->getNormalizedValue() === $message->recipient)) {
if ($message->scheduleStatus) {
$newObject->VEVENT->ORGANIZER['SCHEDULE-STATUS'] = $message->getScheduleStatus();
}
unset($newObject->VEVENT->ORGANIZER['SCHEDULE-FORCE-SEND']);
} else {
if (isset($newObject->VEVENT->ATTENDEE)) {
foreach ($newObject->VEVENT->ATTENDEE as $attendee) {
if ($attendee->getNormalizedValue() === $message->recipient) {
if ($message->scheduleStatus) {
$attendee['SCHEDULE-STATUS'] = $message->getScheduleStatus();
}
unset($attendee['SCHEDULE-FORCE-SEND']);
break;
}
}
}
}
}
} | php | protected function processICalendarChange($oldObject = null, VCalendar $newObject, array $addresses, array $ignore = [], &$modified = false)
{
$broker = new ITip\Broker();
$messages = $broker->parseEvent($newObject, $addresses, $oldObject);
if ($messages) {
$modified = true;
}
foreach ($messages as $message) {
if (in_array($message->recipient, $ignore)) {
continue;
}
$this->deliver($message);
if (isset($newObject->VEVENT->ORGANIZER) && ($newObject->VEVENT->ORGANIZER->getNormalizedValue() === $message->recipient)) {
if ($message->scheduleStatus) {
$newObject->VEVENT->ORGANIZER['SCHEDULE-STATUS'] = $message->getScheduleStatus();
}
unset($newObject->VEVENT->ORGANIZER['SCHEDULE-FORCE-SEND']);
} else {
if (isset($newObject->VEVENT->ATTENDEE)) {
foreach ($newObject->VEVENT->ATTENDEE as $attendee) {
if ($attendee->getNormalizedValue() === $message->recipient) {
if ($message->scheduleStatus) {
$attendee['SCHEDULE-STATUS'] = $message->getScheduleStatus();
}
unset($attendee['SCHEDULE-FORCE-SEND']);
break;
}
}
}
}
}
} | [
"protected",
"function",
"processICalendarChange",
"(",
"$",
"oldObject",
"=",
"null",
",",
"VCalendar",
"$",
"newObject",
",",
"array",
"$",
"addresses",
",",
"array",
"$",
"ignore",
"=",
"[",
"]",
",",
"&",
"$",
"modified",
"=",
"false",
")",
"{",
"$",
"broker",
"=",
"new",
"ITip",
"\\",
"Broker",
"(",
")",
";",
"$",
"messages",
"=",
"$",
"broker",
"->",
"parseEvent",
"(",
"$",
"newObject",
",",
"$",
"addresses",
",",
"$",
"oldObject",
")",
";",
"if",
"(",
"$",
"messages",
")",
"{",
"$",
"modified",
"=",
"true",
";",
"}",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"message",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"message",
"->",
"recipient",
",",
"$",
"ignore",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"deliver",
"(",
"$",
"message",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"newObject",
"->",
"VEVENT",
"->",
"ORGANIZER",
")",
"&&",
"(",
"$",
"newObject",
"->",
"VEVENT",
"->",
"ORGANIZER",
"->",
"getNormalizedValue",
"(",
")",
"===",
"$",
"message",
"->",
"recipient",
")",
")",
"{",
"if",
"(",
"$",
"message",
"->",
"scheduleStatus",
")",
"{",
"$",
"newObject",
"->",
"VEVENT",
"->",
"ORGANIZER",
"[",
"'SCHEDULE-STATUS'",
"]",
"=",
"$",
"message",
"->",
"getScheduleStatus",
"(",
")",
";",
"}",
"unset",
"(",
"$",
"newObject",
"->",
"VEVENT",
"->",
"ORGANIZER",
"[",
"'SCHEDULE-FORCE-SEND'",
"]",
")",
";",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"newObject",
"->",
"VEVENT",
"->",
"ATTENDEE",
")",
")",
"{",
"foreach",
"(",
"$",
"newObject",
"->",
"VEVENT",
"->",
"ATTENDEE",
"as",
"$",
"attendee",
")",
"{",
"if",
"(",
"$",
"attendee",
"->",
"getNormalizedValue",
"(",
")",
"===",
"$",
"message",
"->",
"recipient",
")",
"{",
"if",
"(",
"$",
"message",
"->",
"scheduleStatus",
")",
"{",
"$",
"attendee",
"[",
"'SCHEDULE-STATUS'",
"]",
"=",
"$",
"message",
"->",
"getScheduleStatus",
"(",
")",
";",
"}",
"unset",
"(",
"$",
"attendee",
"[",
"'SCHEDULE-FORCE-SEND'",
"]",
")",
";",
"break",
";",
"}",
"}",
"}",
"}",
"}",
"}"
] | This method looks at an old iCalendar object, a new iCalendar object and
starts sending scheduling messages based on the changes.
A list of addresses needs to be specified, so the system knows who made
the update, because the behavior may be different based on if it's an
attendee or an organizer.
This method may update $newObject to add any status changes.
@param VCalendar|string $oldObject
@param VCalendar $newObject
@param array $addresses
@param array $ignore any addresses to not send messages to
@param bool $modified a marker to indicate that the original object
modified by this process | [
"This",
"method",
"looks",
"at",
"an",
"old",
"iCalendar",
"object",
"a",
"new",
"iCalendar",
"object",
"and",
"starts",
"sending",
"scheduling",
"messages",
"based",
"on",
"the",
"changes",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/Plugin.php#L630-L665 |
sabre-io/dav | lib/CalDAV/Schedule/Plugin.php | Plugin.getAddressesForPrincipal | protected function getAddressesForPrincipal($principal)
{
$CUAS = '{'.self::NS_CALDAV.'}calendar-user-address-set';
$properties = $this->server->getProperties(
$principal,
[$CUAS]
);
// If we can't find this information, we'll stop processing
if (!isset($properties[$CUAS])) {
return [];
}
$addresses = $properties[$CUAS]->getHrefs();
return $addresses;
} | php | protected function getAddressesForPrincipal($principal)
{
$CUAS = '{'.self::NS_CALDAV.'}calendar-user-address-set';
$properties = $this->server->getProperties(
$principal,
[$CUAS]
);
if (!isset($properties[$CUAS])) {
return [];
}
$addresses = $properties[$CUAS]->getHrefs();
return $addresses;
} | [
"protected",
"function",
"getAddressesForPrincipal",
"(",
"$",
"principal",
")",
"{",
"$",
"CUAS",
"=",
"'{'",
".",
"self",
"::",
"NS_CALDAV",
".",
"'}calendar-user-address-set'",
";",
"$",
"properties",
"=",
"$",
"this",
"->",
"server",
"->",
"getProperties",
"(",
"$",
"principal",
",",
"[",
"$",
"CUAS",
"]",
")",
";",
"// If we can't find this information, we'll stop processing",
"if",
"(",
"!",
"isset",
"(",
"$",
"properties",
"[",
"$",
"CUAS",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"addresses",
"=",
"$",
"properties",
"[",
"$",
"CUAS",
"]",
"->",
"getHrefs",
"(",
")",
";",
"return",
"$",
"addresses",
";",
"}"
] | Returns a list of addresses that are associated with a principal.
@param string $principal
@return array | [
"Returns",
"a",
"list",
"of",
"addresses",
"that",
"are",
"associated",
"with",
"a",
"principal",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/Plugin.php#L674-L691 |
sabre-io/dav | lib/CalDAV/Schedule/Plugin.php | Plugin.outboxRequest | public function outboxRequest(IOutbox $outboxNode, RequestInterface $request, ResponseInterface $response)
{
$outboxPath = $request->getPath();
// Parsing the request body
try {
$vObject = VObject\Reader::read($request->getBody());
} catch (VObject\ParseException $e) {
throw new BadRequest('The request body must be a valid iCalendar object. Parse error: '.$e->getMessage());
}
// The incoming iCalendar object must have a METHOD property, and a
// component. The combination of both determines what type of request
// this is.
$componentType = null;
foreach ($vObject->getComponents() as $component) {
if ('VTIMEZONE' !== $component->name) {
$componentType = $component->name;
break;
}
}
if (is_null($componentType)) {
throw new BadRequest('We expected at least one VTODO, VJOURNAL, VFREEBUSY or VEVENT component');
}
// Validating the METHOD
$method = strtoupper((string) $vObject->METHOD);
if (!$method) {
throw new BadRequest('A METHOD property must be specified in iTIP messages');
}
// So we support one type of request:
//
// REQUEST with a VFREEBUSY component
$acl = $this->server->getPlugin('acl');
if ('VFREEBUSY' === $componentType && 'REQUEST' === $method) {
$acl && $acl->checkPrivileges($outboxPath, '{'.self::NS_CALDAV.'}schedule-send-freebusy');
$this->handleFreeBusyRequest($outboxNode, $vObject, $request, $response);
// Destroy circular references so PHP can GC the object.
$vObject->destroy();
unset($vObject);
} else {
throw new NotImplemented('We only support VFREEBUSY (REQUEST) on this endpoint');
}
} | php | public function outboxRequest(IOutbox $outboxNode, RequestInterface $request, ResponseInterface $response)
{
$outboxPath = $request->getPath();
try {
$vObject = VObject\Reader::read($request->getBody());
} catch (VObject\ParseException $e) {
throw new BadRequest('The request body must be a valid iCalendar object. Parse error: '.$e->getMessage());
}
$componentType = null;
foreach ($vObject->getComponents() as $component) {
if ('VTIMEZONE' !== $component->name) {
$componentType = $component->name;
break;
}
}
if (is_null($componentType)) {
throw new BadRequest('We expected at least one VTODO, VJOURNAL, VFREEBUSY or VEVENT component');
}
$method = strtoupper((string) $vObject->METHOD);
if (!$method) {
throw new BadRequest('A METHOD property must be specified in iTIP messages');
}
$acl = $this->server->getPlugin('acl');
if ('VFREEBUSY' === $componentType && 'REQUEST' === $method) {
$acl && $acl->checkPrivileges($outboxPath, '{'.self::NS_CALDAV.'}schedule-send-freebusy');
$this->handleFreeBusyRequest($outboxNode, $vObject, $request, $response);
$vObject->destroy();
unset($vObject);
} else {
throw new NotImplemented('We only support VFREEBUSY (REQUEST) on this endpoint');
}
} | [
"public",
"function",
"outboxRequest",
"(",
"IOutbox",
"$",
"outboxNode",
",",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"outboxPath",
"=",
"$",
"request",
"->",
"getPath",
"(",
")",
";",
"// Parsing the request body",
"try",
"{",
"$",
"vObject",
"=",
"VObject",
"\\",
"Reader",
"::",
"read",
"(",
"$",
"request",
"->",
"getBody",
"(",
")",
")",
";",
"}",
"catch",
"(",
"VObject",
"\\",
"ParseException",
"$",
"e",
")",
"{",
"throw",
"new",
"BadRequest",
"(",
"'The request body must be a valid iCalendar object. Parse error: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"// The incoming iCalendar object must have a METHOD property, and a",
"// component. The combination of both determines what type of request",
"// this is.",
"$",
"componentType",
"=",
"null",
";",
"foreach",
"(",
"$",
"vObject",
"->",
"getComponents",
"(",
")",
"as",
"$",
"component",
")",
"{",
"if",
"(",
"'VTIMEZONE'",
"!==",
"$",
"component",
"->",
"name",
")",
"{",
"$",
"componentType",
"=",
"$",
"component",
"->",
"name",
";",
"break",
";",
"}",
"}",
"if",
"(",
"is_null",
"(",
"$",
"componentType",
")",
")",
"{",
"throw",
"new",
"BadRequest",
"(",
"'We expected at least one VTODO, VJOURNAL, VFREEBUSY or VEVENT component'",
")",
";",
"}",
"// Validating the METHOD",
"$",
"method",
"=",
"strtoupper",
"(",
"(",
"string",
")",
"$",
"vObject",
"->",
"METHOD",
")",
";",
"if",
"(",
"!",
"$",
"method",
")",
"{",
"throw",
"new",
"BadRequest",
"(",
"'A METHOD property must be specified in iTIP messages'",
")",
";",
"}",
"// So we support one type of request:",
"//",
"// REQUEST with a VFREEBUSY component",
"$",
"acl",
"=",
"$",
"this",
"->",
"server",
"->",
"getPlugin",
"(",
"'acl'",
")",
";",
"if",
"(",
"'VFREEBUSY'",
"===",
"$",
"componentType",
"&&",
"'REQUEST'",
"===",
"$",
"method",
")",
"{",
"$",
"acl",
"&&",
"$",
"acl",
"->",
"checkPrivileges",
"(",
"$",
"outboxPath",
",",
"'{'",
".",
"self",
"::",
"NS_CALDAV",
".",
"'}schedule-send-freebusy'",
")",
";",
"$",
"this",
"->",
"handleFreeBusyRequest",
"(",
"$",
"outboxNode",
",",
"$",
"vObject",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"// Destroy circular references so PHP can GC the object.",
"$",
"vObject",
"->",
"destroy",
"(",
")",
";",
"unset",
"(",
"$",
"vObject",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"NotImplemented",
"(",
"'We only support VFREEBUSY (REQUEST) on this endpoint'",
")",
";",
"}",
"}"
] | This method handles POST requests to the schedule-outbox.
Currently, two types of requests are supported:
* FREEBUSY requests from RFC 6638
* Simple iTIP messages from draft-desruisseaux-caldav-sched-04
The latter is from an expired early draft of the CalDAV scheduling
extensions, but iCal depends on a feature from that spec, so we
implement it.
@param IOutbox $outboxNode
@param RequestInterface $request
@param ResponseInterface $response | [
"This",
"method",
"handles",
"POST",
"requests",
"to",
"the",
"schedule",
"-",
"outbox",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/Plugin.php#L708-L755 |
sabre-io/dav | lib/CalDAV/Schedule/Plugin.php | Plugin.handleFreeBusyRequest | protected function handleFreeBusyRequest(IOutbox $outbox, VObject\Component $vObject, RequestInterface $request, ResponseInterface $response)
{
$vFreeBusy = $vObject->VFREEBUSY;
$organizer = $vFreeBusy->ORGANIZER;
$organizer = (string) $organizer;
// Validating if the organizer matches the owner of the inbox.
$owner = $outbox->getOwner();
$caldavNS = '{'.self::NS_CALDAV.'}';
$uas = $caldavNS.'calendar-user-address-set';
$props = $this->server->getProperties($owner, [$uas]);
if (empty($props[$uas]) || !in_array($organizer, $props[$uas]->getHrefs())) {
throw new Forbidden('The organizer in the request did not match any of the addresses for the owner of this inbox');
}
if (!isset($vFreeBusy->ATTENDEE)) {
throw new BadRequest('You must at least specify 1 attendee');
}
$attendees = [];
foreach ($vFreeBusy->ATTENDEE as $attendee) {
$attendees[] = (string) $attendee;
}
if (!isset($vFreeBusy->DTSTART) || !isset($vFreeBusy->DTEND)) {
throw new BadRequest('DTSTART and DTEND must both be specified');
}
$startRange = $vFreeBusy->DTSTART->getDateTime();
$endRange = $vFreeBusy->DTEND->getDateTime();
$results = [];
foreach ($attendees as $attendee) {
$results[] = $this->getFreeBusyForEmail($attendee, $startRange, $endRange, $vObject);
}
$dom = new \DOMDocument('1.0', 'utf-8');
$dom->formatOutput = true;
$scheduleResponse = $dom->createElement('cal:schedule-response');
foreach ($this->server->xml->namespaceMap as $namespace => $prefix) {
$scheduleResponse->setAttribute('xmlns:'.$prefix, $namespace);
}
$dom->appendChild($scheduleResponse);
foreach ($results as $result) {
$xresponse = $dom->createElement('cal:response');
$recipient = $dom->createElement('cal:recipient');
$recipientHref = $dom->createElement('d:href');
$recipientHref->appendChild($dom->createTextNode($result['href']));
$recipient->appendChild($recipientHref);
$xresponse->appendChild($recipient);
$reqStatus = $dom->createElement('cal:request-status');
$reqStatus->appendChild($dom->createTextNode($result['request-status']));
$xresponse->appendChild($reqStatus);
if (isset($result['calendar-data'])) {
$calendardata = $dom->createElement('cal:calendar-data');
$calendardata->appendChild($dom->createTextNode(str_replace("\r\n", "\n", $result['calendar-data']->serialize())));
$xresponse->appendChild($calendardata);
}
$scheduleResponse->appendChild($xresponse);
}
$response->setStatus(200);
$response->setHeader('Content-Type', 'application/xml');
$response->setBody($dom->saveXML());
} | php | protected function handleFreeBusyRequest(IOutbox $outbox, VObject\Component $vObject, RequestInterface $request, ResponseInterface $response)
{
$vFreeBusy = $vObject->VFREEBUSY;
$organizer = $vFreeBusy->ORGANIZER;
$organizer = (string) $organizer;
$owner = $outbox->getOwner();
$caldavNS = '{'.self::NS_CALDAV.'}';
$uas = $caldavNS.'calendar-user-address-set';
$props = $this->server->getProperties($owner, [$uas]);
if (empty($props[$uas]) || !in_array($organizer, $props[$uas]->getHrefs())) {
throw new Forbidden('The organizer in the request did not match any of the addresses for the owner of this inbox');
}
if (!isset($vFreeBusy->ATTENDEE)) {
throw new BadRequest('You must at least specify 1 attendee');
}
$attendees = [];
foreach ($vFreeBusy->ATTENDEE as $attendee) {
$attendees[] = (string) $attendee;
}
if (!isset($vFreeBusy->DTSTART) || !isset($vFreeBusy->DTEND)) {
throw new BadRequest('DTSTART and DTEND must both be specified');
}
$startRange = $vFreeBusy->DTSTART->getDateTime();
$endRange = $vFreeBusy->DTEND->getDateTime();
$results = [];
foreach ($attendees as $attendee) {
$results[] = $this->getFreeBusyForEmail($attendee, $startRange, $endRange, $vObject);
}
$dom = new \DOMDocument('1.0', 'utf-8');
$dom->formatOutput = true;
$scheduleResponse = $dom->createElement('cal:schedule-response');
foreach ($this->server->xml->namespaceMap as $namespace => $prefix) {
$scheduleResponse->setAttribute('xmlns:'.$prefix, $namespace);
}
$dom->appendChild($scheduleResponse);
foreach ($results as $result) {
$xresponse = $dom->createElement('cal:response');
$recipient = $dom->createElement('cal:recipient');
$recipientHref = $dom->createElement('d:href');
$recipientHref->appendChild($dom->createTextNode($result['href']));
$recipient->appendChild($recipientHref);
$xresponse->appendChild($recipient);
$reqStatus = $dom->createElement('cal:request-status');
$reqStatus->appendChild($dom->createTextNode($result['request-status']));
$xresponse->appendChild($reqStatus);
if (isset($result['calendar-data'])) {
$calendardata = $dom->createElement('cal:calendar-data');
$calendardata->appendChild($dom->createTextNode(str_replace("\r\n", "\n", $result['calendar-data']->serialize())));
$xresponse->appendChild($calendardata);
}
$scheduleResponse->appendChild($xresponse);
}
$response->setStatus(200);
$response->setHeader('Content-Type', 'application/xml');
$response->setBody($dom->saveXML());
} | [
"protected",
"function",
"handleFreeBusyRequest",
"(",
"IOutbox",
"$",
"outbox",
",",
"VObject",
"\\",
"Component",
"$",
"vObject",
",",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"vFreeBusy",
"=",
"$",
"vObject",
"->",
"VFREEBUSY",
";",
"$",
"organizer",
"=",
"$",
"vFreeBusy",
"->",
"ORGANIZER",
";",
"$",
"organizer",
"=",
"(",
"string",
")",
"$",
"organizer",
";",
"// Validating if the organizer matches the owner of the inbox.",
"$",
"owner",
"=",
"$",
"outbox",
"->",
"getOwner",
"(",
")",
";",
"$",
"caldavNS",
"=",
"'{'",
".",
"self",
"::",
"NS_CALDAV",
".",
"'}'",
";",
"$",
"uas",
"=",
"$",
"caldavNS",
".",
"'calendar-user-address-set'",
";",
"$",
"props",
"=",
"$",
"this",
"->",
"server",
"->",
"getProperties",
"(",
"$",
"owner",
",",
"[",
"$",
"uas",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"props",
"[",
"$",
"uas",
"]",
")",
"||",
"!",
"in_array",
"(",
"$",
"organizer",
",",
"$",
"props",
"[",
"$",
"uas",
"]",
"->",
"getHrefs",
"(",
")",
")",
")",
"{",
"throw",
"new",
"Forbidden",
"(",
"'The organizer in the request did not match any of the addresses for the owner of this inbox'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"vFreeBusy",
"->",
"ATTENDEE",
")",
")",
"{",
"throw",
"new",
"BadRequest",
"(",
"'You must at least specify 1 attendee'",
")",
";",
"}",
"$",
"attendees",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"vFreeBusy",
"->",
"ATTENDEE",
"as",
"$",
"attendee",
")",
"{",
"$",
"attendees",
"[",
"]",
"=",
"(",
"string",
")",
"$",
"attendee",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"vFreeBusy",
"->",
"DTSTART",
")",
"||",
"!",
"isset",
"(",
"$",
"vFreeBusy",
"->",
"DTEND",
")",
")",
"{",
"throw",
"new",
"BadRequest",
"(",
"'DTSTART and DTEND must both be specified'",
")",
";",
"}",
"$",
"startRange",
"=",
"$",
"vFreeBusy",
"->",
"DTSTART",
"->",
"getDateTime",
"(",
")",
";",
"$",
"endRange",
"=",
"$",
"vFreeBusy",
"->",
"DTEND",
"->",
"getDateTime",
"(",
")",
";",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"attendees",
"as",
"$",
"attendee",
")",
"{",
"$",
"results",
"[",
"]",
"=",
"$",
"this",
"->",
"getFreeBusyForEmail",
"(",
"$",
"attendee",
",",
"$",
"startRange",
",",
"$",
"endRange",
",",
"$",
"vObject",
")",
";",
"}",
"$",
"dom",
"=",
"new",
"\\",
"DOMDocument",
"(",
"'1.0'",
",",
"'utf-8'",
")",
";",
"$",
"dom",
"->",
"formatOutput",
"=",
"true",
";",
"$",
"scheduleResponse",
"=",
"$",
"dom",
"->",
"createElement",
"(",
"'cal:schedule-response'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"server",
"->",
"xml",
"->",
"namespaceMap",
"as",
"$",
"namespace",
"=>",
"$",
"prefix",
")",
"{",
"$",
"scheduleResponse",
"->",
"setAttribute",
"(",
"'xmlns:'",
".",
"$",
"prefix",
",",
"$",
"namespace",
")",
";",
"}",
"$",
"dom",
"->",
"appendChild",
"(",
"$",
"scheduleResponse",
")",
";",
"foreach",
"(",
"$",
"results",
"as",
"$",
"result",
")",
"{",
"$",
"xresponse",
"=",
"$",
"dom",
"->",
"createElement",
"(",
"'cal:response'",
")",
";",
"$",
"recipient",
"=",
"$",
"dom",
"->",
"createElement",
"(",
"'cal:recipient'",
")",
";",
"$",
"recipientHref",
"=",
"$",
"dom",
"->",
"createElement",
"(",
"'d:href'",
")",
";",
"$",
"recipientHref",
"->",
"appendChild",
"(",
"$",
"dom",
"->",
"createTextNode",
"(",
"$",
"result",
"[",
"'href'",
"]",
")",
")",
";",
"$",
"recipient",
"->",
"appendChild",
"(",
"$",
"recipientHref",
")",
";",
"$",
"xresponse",
"->",
"appendChild",
"(",
"$",
"recipient",
")",
";",
"$",
"reqStatus",
"=",
"$",
"dom",
"->",
"createElement",
"(",
"'cal:request-status'",
")",
";",
"$",
"reqStatus",
"->",
"appendChild",
"(",
"$",
"dom",
"->",
"createTextNode",
"(",
"$",
"result",
"[",
"'request-status'",
"]",
")",
")",
";",
"$",
"xresponse",
"->",
"appendChild",
"(",
"$",
"reqStatus",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"'calendar-data'",
"]",
")",
")",
"{",
"$",
"calendardata",
"=",
"$",
"dom",
"->",
"createElement",
"(",
"'cal:calendar-data'",
")",
";",
"$",
"calendardata",
"->",
"appendChild",
"(",
"$",
"dom",
"->",
"createTextNode",
"(",
"str_replace",
"(",
"\"\\r\\n\"",
",",
"\"\\n\"",
",",
"$",
"result",
"[",
"'calendar-data'",
"]",
"->",
"serialize",
"(",
")",
")",
")",
")",
";",
"$",
"xresponse",
"->",
"appendChild",
"(",
"$",
"calendardata",
")",
";",
"}",
"$",
"scheduleResponse",
"->",
"appendChild",
"(",
"$",
"xresponse",
")",
";",
"}",
"$",
"response",
"->",
"setStatus",
"(",
"200",
")",
";",
"$",
"response",
"->",
"setHeader",
"(",
"'Content-Type'",
",",
"'application/xml'",
")",
";",
"$",
"response",
"->",
"setBody",
"(",
"$",
"dom",
"->",
"saveXML",
"(",
")",
")",
";",
"}"
] | This method is responsible for parsing a free-busy query request and
returning it's result.
@param IOutbox $outbox
@param VObject\Component $vObject
@param RequestInterface $request
@param ResponseInterface $response
@return string | [
"This",
"method",
"is",
"responsible",
"for",
"parsing",
"a",
"free",
"-",
"busy",
"query",
"request",
"and",
"returning",
"it",
"s",
"result",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/Plugin.php#L768-L841 |
sabre-io/dav | lib/CalDAV/Schedule/Plugin.php | Plugin.getFreeBusyForEmail | protected function getFreeBusyForEmail($email, \DateTimeInterface $start, \DateTimeInterface $end, VObject\Component $request)
{
$caldavNS = '{'.self::NS_CALDAV.'}';
$aclPlugin = $this->server->getPlugin('acl');
if ('mailto:' === substr($email, 0, 7)) {
$email = substr($email, 7);
}
$result = $aclPlugin->principalSearch(
['{http://sabredav.org/ns}email-address' => $email],
[
'{DAV:}principal-URL',
$caldavNS.'calendar-home-set',
$caldavNS.'schedule-inbox-URL',
'{http://sabredav.org/ns}email-address',
]
);
if (!count($result)) {
return [
'request-status' => '3.7;Could not find principal',
'href' => 'mailto:'.$email,
];
}
if (!isset($result[0][200][$caldavNS.'calendar-home-set'])) {
return [
'request-status' => '3.7;No calendar-home-set property found',
'href' => 'mailto:'.$email,
];
}
if (!isset($result[0][200][$caldavNS.'schedule-inbox-URL'])) {
return [
'request-status' => '3.7;No schedule-inbox-URL property found',
'href' => 'mailto:'.$email,
];
}
$homeSet = $result[0][200][$caldavNS.'calendar-home-set']->getHref();
$inboxUrl = $result[0][200][$caldavNS.'schedule-inbox-URL']->getHref();
// Do we have permission?
$aclPlugin->checkPrivileges($inboxUrl, $caldavNS.'schedule-query-freebusy');
// Grabbing the calendar list
$objects = [];
$calendarTimeZone = new DateTimeZone('UTC');
foreach ($this->server->tree->getNodeForPath($homeSet)->getChildren() as $node) {
if (!$node instanceof ICalendar) {
continue;
}
$sct = $caldavNS.'schedule-calendar-transp';
$ctz = $caldavNS.'calendar-timezone';
$props = $node->getProperties([$sct, $ctz]);
if (isset($props[$sct]) && ScheduleCalendarTransp::TRANSPARENT == $props[$sct]->getValue()) {
// If a calendar is marked as 'transparent', it means we must
// ignore it for free-busy purposes.
continue;
}
if (isset($props[$ctz])) {
$vtimezoneObj = VObject\Reader::read($props[$ctz]);
$calendarTimeZone = $vtimezoneObj->VTIMEZONE->getTimeZone();
// Destroy circular references so PHP can garbage collect the object.
$vtimezoneObj->destroy();
}
// Getting the list of object uris within the time-range
$urls = $node->calendarQuery([
'name' => 'VCALENDAR',
'comp-filters' => [
[
'name' => 'VEVENT',
'comp-filters' => [],
'prop-filters' => [],
'is-not-defined' => false,
'time-range' => [
'start' => $start,
'end' => $end,
],
],
],
'prop-filters' => [],
'is-not-defined' => false,
'time-range' => null,
]);
$calObjects = array_map(function ($url) use ($node) {
$obj = $node->getChild($url)->get();
return $obj;
}, $urls);
$objects = array_merge($objects, $calObjects);
}
$inboxProps = $this->server->getProperties(
$inboxUrl,
$caldavNS.'calendar-availability'
);
$vcalendar = new VObject\Component\VCalendar();
$vcalendar->METHOD = 'REPLY';
$generator = new VObject\FreeBusyGenerator();
$generator->setObjects($objects);
$generator->setTimeRange($start, $end);
$generator->setBaseObject($vcalendar);
$generator->setTimeZone($calendarTimeZone);
if ($inboxProps) {
$generator->setVAvailability(
VObject\Reader::read(
$inboxProps[$caldavNS.'calendar-availability']
)
);
}
$result = $generator->getResult();
$vcalendar->VFREEBUSY->ATTENDEE = 'mailto:'.$email;
$vcalendar->VFREEBUSY->UID = (string) $request->VFREEBUSY->UID;
$vcalendar->VFREEBUSY->ORGANIZER = clone $request->VFREEBUSY->ORGANIZER;
return [
'calendar-data' => $result,
'request-status' => '2.0;Success',
'href' => 'mailto:'.$email,
];
} | php | protected function getFreeBusyForEmail($email, \DateTimeInterface $start, \DateTimeInterface $end, VObject\Component $request)
{
$caldavNS = '{'.self::NS_CALDAV.'}';
$aclPlugin = $this->server->getPlugin('acl');
if ('mailto:' === substr($email, 0, 7)) {
$email = substr($email, 7);
}
$result = $aclPlugin->principalSearch(
['{http:
[
'{DAV:}principal-URL',
$caldavNS.'calendar-home-set',
$caldavNS.'schedule-inbox-URL',
'{http:
]
);
if (!count($result)) {
return [
'request-status' => '3.7;Could not find principal',
'href' => 'mailto:'.$email,
];
}
if (!isset($result[0][200][$caldavNS.'calendar-home-set'])) {
return [
'request-status' => '3.7;No calendar-home-set property found',
'href' => 'mailto:'.$email,
];
}
if (!isset($result[0][200][$caldavNS.'schedule-inbox-URL'])) {
return [
'request-status' => '3.7;No schedule-inbox-URL property found',
'href' => 'mailto:'.$email,
];
}
$homeSet = $result[0][200][$caldavNS.'calendar-home-set']->getHref();
$inboxUrl = $result[0][200][$caldavNS.'schedule-inbox-URL']->getHref();
$aclPlugin->checkPrivileges($inboxUrl, $caldavNS.'schedule-query-freebusy');
$objects = [];
$calendarTimeZone = new DateTimeZone('UTC');
foreach ($this->server->tree->getNodeForPath($homeSet)->getChildren() as $node) {
if (!$node instanceof ICalendar) {
continue;
}
$sct = $caldavNS.'schedule-calendar-transp';
$ctz = $caldavNS.'calendar-timezone';
$props = $node->getProperties([$sct, $ctz]);
if (isset($props[$sct]) && ScheduleCalendarTransp::TRANSPARENT == $props[$sct]->getValue()) {
continue;
}
if (isset($props[$ctz])) {
$vtimezoneObj = VObject\Reader::read($props[$ctz]);
$calendarTimeZone = $vtimezoneObj->VTIMEZONE->getTimeZone();
$vtimezoneObj->destroy();
}
$urls = $node->calendarQuery([
'name' => 'VCALENDAR',
'comp-filters' => [
[
'name' => 'VEVENT',
'comp-filters' => [],
'prop-filters' => [],
'is-not-defined' => false,
'time-range' => [
'start' => $start,
'end' => $end,
],
],
],
'prop-filters' => [],
'is-not-defined' => false,
'time-range' => null,
]);
$calObjects = array_map(function ($url) use ($node) {
$obj = $node->getChild($url)->get();
return $obj;
}, $urls);
$objects = array_merge($objects, $calObjects);
}
$inboxProps = $this->server->getProperties(
$inboxUrl,
$caldavNS.'calendar-availability'
);
$vcalendar = new VObject\Component\VCalendar();
$vcalendar->METHOD = 'REPLY';
$generator = new VObject\FreeBusyGenerator();
$generator->setObjects($objects);
$generator->setTimeRange($start, $end);
$generator->setBaseObject($vcalendar);
$generator->setTimeZone($calendarTimeZone);
if ($inboxProps) {
$generator->setVAvailability(
VObject\Reader::read(
$inboxProps[$caldavNS.'calendar-availability']
)
);
}
$result = $generator->getResult();
$vcalendar->VFREEBUSY->ATTENDEE = 'mailto:'.$email;
$vcalendar->VFREEBUSY->UID = (string) $request->VFREEBUSY->UID;
$vcalendar->VFREEBUSY->ORGANIZER = clone $request->VFREEBUSY->ORGANIZER;
return [
'calendar-data' => $result,
'request-status' => '2.0;Success',
'href' => 'mailto:'.$email,
];
} | [
"protected",
"function",
"getFreeBusyForEmail",
"(",
"$",
"email",
",",
"\\",
"DateTimeInterface",
"$",
"start",
",",
"\\",
"DateTimeInterface",
"$",
"end",
",",
"VObject",
"\\",
"Component",
"$",
"request",
")",
"{",
"$",
"caldavNS",
"=",
"'{'",
".",
"self",
"::",
"NS_CALDAV",
".",
"'}'",
";",
"$",
"aclPlugin",
"=",
"$",
"this",
"->",
"server",
"->",
"getPlugin",
"(",
"'acl'",
")",
";",
"if",
"(",
"'mailto:'",
"===",
"substr",
"(",
"$",
"email",
",",
"0",
",",
"7",
")",
")",
"{",
"$",
"email",
"=",
"substr",
"(",
"$",
"email",
",",
"7",
")",
";",
"}",
"$",
"result",
"=",
"$",
"aclPlugin",
"->",
"principalSearch",
"(",
"[",
"'{http://sabredav.org/ns}email-address'",
"=>",
"$",
"email",
"]",
",",
"[",
"'{DAV:}principal-URL'",
",",
"$",
"caldavNS",
".",
"'calendar-home-set'",
",",
"$",
"caldavNS",
".",
"'schedule-inbox-URL'",
",",
"'{http://sabredav.org/ns}email-address'",
",",
"]",
")",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"result",
")",
")",
"{",
"return",
"[",
"'request-status'",
"=>",
"'3.7;Could not find principal'",
",",
"'href'",
"=>",
"'mailto:'",
".",
"$",
"email",
",",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
"[",
"0",
"]",
"[",
"200",
"]",
"[",
"$",
"caldavNS",
".",
"'calendar-home-set'",
"]",
")",
")",
"{",
"return",
"[",
"'request-status'",
"=>",
"'3.7;No calendar-home-set property found'",
",",
"'href'",
"=>",
"'mailto:'",
".",
"$",
"email",
",",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
"[",
"0",
"]",
"[",
"200",
"]",
"[",
"$",
"caldavNS",
".",
"'schedule-inbox-URL'",
"]",
")",
")",
"{",
"return",
"[",
"'request-status'",
"=>",
"'3.7;No schedule-inbox-URL property found'",
",",
"'href'",
"=>",
"'mailto:'",
".",
"$",
"email",
",",
"]",
";",
"}",
"$",
"homeSet",
"=",
"$",
"result",
"[",
"0",
"]",
"[",
"200",
"]",
"[",
"$",
"caldavNS",
".",
"'calendar-home-set'",
"]",
"->",
"getHref",
"(",
")",
";",
"$",
"inboxUrl",
"=",
"$",
"result",
"[",
"0",
"]",
"[",
"200",
"]",
"[",
"$",
"caldavNS",
".",
"'schedule-inbox-URL'",
"]",
"->",
"getHref",
"(",
")",
";",
"// Do we have permission?",
"$",
"aclPlugin",
"->",
"checkPrivileges",
"(",
"$",
"inboxUrl",
",",
"$",
"caldavNS",
".",
"'schedule-query-freebusy'",
")",
";",
"// Grabbing the calendar list",
"$",
"objects",
"=",
"[",
"]",
";",
"$",
"calendarTimeZone",
"=",
"new",
"DateTimeZone",
"(",
"'UTC'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"homeSet",
")",
"->",
"getChildren",
"(",
")",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"!",
"$",
"node",
"instanceof",
"ICalendar",
")",
"{",
"continue",
";",
"}",
"$",
"sct",
"=",
"$",
"caldavNS",
".",
"'schedule-calendar-transp'",
";",
"$",
"ctz",
"=",
"$",
"caldavNS",
".",
"'calendar-timezone'",
";",
"$",
"props",
"=",
"$",
"node",
"->",
"getProperties",
"(",
"[",
"$",
"sct",
",",
"$",
"ctz",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"props",
"[",
"$",
"sct",
"]",
")",
"&&",
"ScheduleCalendarTransp",
"::",
"TRANSPARENT",
"==",
"$",
"props",
"[",
"$",
"sct",
"]",
"->",
"getValue",
"(",
")",
")",
"{",
"// If a calendar is marked as 'transparent', it means we must",
"// ignore it for free-busy purposes.",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"props",
"[",
"$",
"ctz",
"]",
")",
")",
"{",
"$",
"vtimezoneObj",
"=",
"VObject",
"\\",
"Reader",
"::",
"read",
"(",
"$",
"props",
"[",
"$",
"ctz",
"]",
")",
";",
"$",
"calendarTimeZone",
"=",
"$",
"vtimezoneObj",
"->",
"VTIMEZONE",
"->",
"getTimeZone",
"(",
")",
";",
"// Destroy circular references so PHP can garbage collect the object.",
"$",
"vtimezoneObj",
"->",
"destroy",
"(",
")",
";",
"}",
"// Getting the list of object uris within the time-range",
"$",
"urls",
"=",
"$",
"node",
"->",
"calendarQuery",
"(",
"[",
"'name'",
"=>",
"'VCALENDAR'",
",",
"'comp-filters'",
"=>",
"[",
"[",
"'name'",
"=>",
"'VEVENT'",
",",
"'comp-filters'",
"=>",
"[",
"]",
",",
"'prop-filters'",
"=>",
"[",
"]",
",",
"'is-not-defined'",
"=>",
"false",
",",
"'time-range'",
"=>",
"[",
"'start'",
"=>",
"$",
"start",
",",
"'end'",
"=>",
"$",
"end",
",",
"]",
",",
"]",
",",
"]",
",",
"'prop-filters'",
"=>",
"[",
"]",
",",
"'is-not-defined'",
"=>",
"false",
",",
"'time-range'",
"=>",
"null",
",",
"]",
")",
";",
"$",
"calObjects",
"=",
"array_map",
"(",
"function",
"(",
"$",
"url",
")",
"use",
"(",
"$",
"node",
")",
"{",
"$",
"obj",
"=",
"$",
"node",
"->",
"getChild",
"(",
"$",
"url",
")",
"->",
"get",
"(",
")",
";",
"return",
"$",
"obj",
";",
"}",
",",
"$",
"urls",
")",
";",
"$",
"objects",
"=",
"array_merge",
"(",
"$",
"objects",
",",
"$",
"calObjects",
")",
";",
"}",
"$",
"inboxProps",
"=",
"$",
"this",
"->",
"server",
"->",
"getProperties",
"(",
"$",
"inboxUrl",
",",
"$",
"caldavNS",
".",
"'calendar-availability'",
")",
";",
"$",
"vcalendar",
"=",
"new",
"VObject",
"\\",
"Component",
"\\",
"VCalendar",
"(",
")",
";",
"$",
"vcalendar",
"->",
"METHOD",
"=",
"'REPLY'",
";",
"$",
"generator",
"=",
"new",
"VObject",
"\\",
"FreeBusyGenerator",
"(",
")",
";",
"$",
"generator",
"->",
"setObjects",
"(",
"$",
"objects",
")",
";",
"$",
"generator",
"->",
"setTimeRange",
"(",
"$",
"start",
",",
"$",
"end",
")",
";",
"$",
"generator",
"->",
"setBaseObject",
"(",
"$",
"vcalendar",
")",
";",
"$",
"generator",
"->",
"setTimeZone",
"(",
"$",
"calendarTimeZone",
")",
";",
"if",
"(",
"$",
"inboxProps",
")",
"{",
"$",
"generator",
"->",
"setVAvailability",
"(",
"VObject",
"\\",
"Reader",
"::",
"read",
"(",
"$",
"inboxProps",
"[",
"$",
"caldavNS",
".",
"'calendar-availability'",
"]",
")",
")",
";",
"}",
"$",
"result",
"=",
"$",
"generator",
"->",
"getResult",
"(",
")",
";",
"$",
"vcalendar",
"->",
"VFREEBUSY",
"->",
"ATTENDEE",
"=",
"'mailto:'",
".",
"$",
"email",
";",
"$",
"vcalendar",
"->",
"VFREEBUSY",
"->",
"UID",
"=",
"(",
"string",
")",
"$",
"request",
"->",
"VFREEBUSY",
"->",
"UID",
";",
"$",
"vcalendar",
"->",
"VFREEBUSY",
"->",
"ORGANIZER",
"=",
"clone",
"$",
"request",
"->",
"VFREEBUSY",
"->",
"ORGANIZER",
";",
"return",
"[",
"'calendar-data'",
"=>",
"$",
"result",
",",
"'request-status'",
"=>",
"'2.0;Success'",
",",
"'href'",
"=>",
"'mailto:'",
".",
"$",
"email",
",",
"]",
";",
"}"
] | Returns free-busy information for a specific address. The returned
data is an array containing the following properties:.
calendar-data : A VFREEBUSY VObject
request-status : an iTip status code.
href: The principal's email address, as requested
The following request status codes may be returned:
* 2.0;description
* 3.7;description
@param string $email address
@param \DateTimeInterface $start
@param \DateTimeInterface $end
@param VObject\Component $request
@return array | [
"Returns",
"free",
"-",
"busy",
"information",
"for",
"a",
"specific",
"address",
".",
"The",
"returned",
"data",
"is",
"an",
"array",
"containing",
"the",
"following",
"properties",
":",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/CalDAV/Schedule/Plugin.php#L862-L995 |
sabre-io/dav | lib/DAV/PropFind.php | PropFind.handle | public function handle($propertyName, $valueOrCallBack)
{
if ($this->itemsLeft && isset($this->result[$propertyName]) && 404 === $this->result[$propertyName][0]) {
if (is_callable($valueOrCallBack)) {
$value = $valueOrCallBack();
} else {
$value = $valueOrCallBack;
}
if (!is_null($value)) {
--$this->itemsLeft;
$this->result[$propertyName] = [200, $value];
}
}
} | php | public function handle($propertyName, $valueOrCallBack)
{
if ($this->itemsLeft && isset($this->result[$propertyName]) && 404 === $this->result[$propertyName][0]) {
if (is_callable($valueOrCallBack)) {
$value = $valueOrCallBack();
} else {
$value = $valueOrCallBack;
}
if (!is_null($value)) {
--$this->itemsLeft;
$this->result[$propertyName] = [200, $value];
}
}
} | [
"public",
"function",
"handle",
"(",
"$",
"propertyName",
",",
"$",
"valueOrCallBack",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"itemsLeft",
"&&",
"isset",
"(",
"$",
"this",
"->",
"result",
"[",
"$",
"propertyName",
"]",
")",
"&&",
"404",
"===",
"$",
"this",
"->",
"result",
"[",
"$",
"propertyName",
"]",
"[",
"0",
"]",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"valueOrCallBack",
")",
")",
"{",
"$",
"value",
"=",
"$",
"valueOrCallBack",
"(",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"valueOrCallBack",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"--",
"$",
"this",
"->",
"itemsLeft",
";",
"$",
"this",
"->",
"result",
"[",
"$",
"propertyName",
"]",
"=",
"[",
"200",
",",
"$",
"value",
"]",
";",
"}",
"}",
"}"
] | Handles a specific property.
This method checks whether the specified property was requested in this
PROPFIND request, and if so, it will call the callback and use the
return value for it's value.
Example:
$propFind->handle('{DAV:}displayname', function() {
return 'hello';
});
Note that handle will only work the first time. If null is returned, the
value is ignored.
It's also possible to not pass a callback, but immediately pass a value
@param string $propertyName
@param mixed $valueOrCallBack | [
"Handles",
"a",
"specific",
"property",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PropFind.php#L92-L105 |
sabre-io/dav | lib/DAV/PropFind.php | PropFind.set | public function set($propertyName, $value, $status = null)
{
if (is_null($status)) {
$status = is_null($value) ? 404 : 200;
}
// If this is an ALLPROPS request and the property is
// unknown, add it to the result; else ignore it:
if (!isset($this->result[$propertyName])) {
if (self::ALLPROPS === $this->requestType) {
$this->result[$propertyName] = [$status, $value];
}
return;
}
if (404 !== $status && 404 === $this->result[$propertyName][0]) {
--$this->itemsLeft;
} elseif (404 === $status && 404 !== $this->result[$propertyName][0]) {
++$this->itemsLeft;
}
$this->result[$propertyName] = [$status, $value];
} | php | public function set($propertyName, $value, $status = null)
{
if (is_null($status)) {
$status = is_null($value) ? 404 : 200;
}
if (!isset($this->result[$propertyName])) {
if (self::ALLPROPS === $this->requestType) {
$this->result[$propertyName] = [$status, $value];
}
return;
}
if (404 !== $status && 404 === $this->result[$propertyName][0]) {
--$this->itemsLeft;
} elseif (404 === $status && 404 !== $this->result[$propertyName][0]) {
++$this->itemsLeft;
}
$this->result[$propertyName] = [$status, $value];
} | [
"public",
"function",
"set",
"(",
"$",
"propertyName",
",",
"$",
"value",
",",
"$",
"status",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"status",
")",
")",
"{",
"$",
"status",
"=",
"is_null",
"(",
"$",
"value",
")",
"?",
"404",
":",
"200",
";",
"}",
"// If this is an ALLPROPS request and the property is",
"// unknown, add it to the result; else ignore it:",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"result",
"[",
"$",
"propertyName",
"]",
")",
")",
"{",
"if",
"(",
"self",
"::",
"ALLPROPS",
"===",
"$",
"this",
"->",
"requestType",
")",
"{",
"$",
"this",
"->",
"result",
"[",
"$",
"propertyName",
"]",
"=",
"[",
"$",
"status",
",",
"$",
"value",
"]",
";",
"}",
"return",
";",
"}",
"if",
"(",
"404",
"!==",
"$",
"status",
"&&",
"404",
"===",
"$",
"this",
"->",
"result",
"[",
"$",
"propertyName",
"]",
"[",
"0",
"]",
")",
"{",
"--",
"$",
"this",
"->",
"itemsLeft",
";",
"}",
"elseif",
"(",
"404",
"===",
"$",
"status",
"&&",
"404",
"!==",
"$",
"this",
"->",
"result",
"[",
"$",
"propertyName",
"]",
"[",
"0",
"]",
")",
"{",
"++",
"$",
"this",
"->",
"itemsLeft",
";",
"}",
"$",
"this",
"->",
"result",
"[",
"$",
"propertyName",
"]",
"=",
"[",
"$",
"status",
",",
"$",
"value",
"]",
";",
"}"
] | Sets the value of the property.
If status is not supplied, the status will default to 200 for non-null
properties, and 404 for null properties.
@param string $propertyName
@param mixed $value
@param int $status | [
"Sets",
"the",
"value",
"of",
"the",
"property",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PropFind.php#L117-L137 |
sabre-io/dav | lib/DAV/PropFind.php | PropFind.getStatus | public function getStatus($propertyName)
{
return isset($this->result[$propertyName]) ? $this->result[$propertyName][0] : null;
} | php | public function getStatus($propertyName)
{
return isset($this->result[$propertyName]) ? $this->result[$propertyName][0] : null;
} | [
"public",
"function",
"getStatus",
"(",
"$",
"propertyName",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"result",
"[",
"$",
"propertyName",
"]",
")",
"?",
"$",
"this",
"->",
"result",
"[",
"$",
"propertyName",
"]",
"[",
"0",
"]",
":",
"null",
";",
"}"
] | Returns the current status code for a property name.
If the property does not appear in the list of requested properties,
null will be returned.
@param string $propertyName
@return int|null | [
"Returns",
"the",
"current",
"status",
"code",
"for",
"a",
"property",
"name",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PropFind.php#L161-L164 |
sabre-io/dav | lib/DAV/PropFind.php | PropFind.getResultForMultiStatus | public function getResultForMultiStatus()
{
$r = [
200 => [],
404 => [],
];
foreach ($this->result as $propertyName => $info) {
if (!isset($r[$info[0]])) {
$r[$info[0]] = [$propertyName => $info[1]];
} else {
$r[$info[0]][$propertyName] = $info[1];
}
}
// Removing the 404's for multi-status requests.
if (self::ALLPROPS === $this->requestType) {
unset($r[404]);
}
return $r;
} | php | public function getResultForMultiStatus()
{
$r = [
200 => [],
404 => [],
];
foreach ($this->result as $propertyName => $info) {
if (!isset($r[$info[0]])) {
$r[$info[0]] = [$propertyName => $info[1]];
} else {
$r[$info[0]][$propertyName] = $info[1];
}
}
if (self::ALLPROPS === $this->requestType) {
unset($r[404]);
}
return $r;
} | [
"public",
"function",
"getResultForMultiStatus",
"(",
")",
"{",
"$",
"r",
"=",
"[",
"200",
"=>",
"[",
"]",
",",
"404",
"=>",
"[",
"]",
",",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"result",
"as",
"$",
"propertyName",
"=>",
"$",
"info",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"r",
"[",
"$",
"info",
"[",
"0",
"]",
"]",
")",
")",
"{",
"$",
"r",
"[",
"$",
"info",
"[",
"0",
"]",
"]",
"=",
"[",
"$",
"propertyName",
"=>",
"$",
"info",
"[",
"1",
"]",
"]",
";",
"}",
"else",
"{",
"$",
"r",
"[",
"$",
"info",
"[",
"0",
"]",
"]",
"[",
"$",
"propertyName",
"]",
"=",
"$",
"info",
"[",
"1",
"]",
";",
"}",
"}",
"// Removing the 404's for multi-status requests.",
"if",
"(",
"self",
"::",
"ALLPROPS",
"===",
"$",
"this",
"->",
"requestType",
")",
"{",
"unset",
"(",
"$",
"r",
"[",
"404",
"]",
")",
";",
"}",
"return",
"$",
"r",
";",
"}"
] | Returns a result array that's often used in multistatus responses.
The array uses status codes as keys, and property names and value pairs
as the value of the top array.. such as :
[
200 => [ '{DAV:}displayname' => 'foo' ],
]
@return array | [
"Returns",
"a",
"result",
"array",
"that",
"s",
"often",
"used",
"in",
"multistatus",
"responses",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PropFind.php#L261-L280 |
sabre-io/dav | lib/CalDAV/Schedule/Outbox.php | Outbox.getACL | public function getACL()
{
return [
[
'privilege' => '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-send',
'principal' => $this->getOwner(),
'protected' => true,
],
[
'privilege' => '{DAV:}read',
'principal' => $this->getOwner(),
'protected' => true,
],
[
'privilege' => '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-send',
'principal' => $this->getOwner().'/calendar-proxy-write',
'protected' => true,
],
[
'privilege' => '{DAV:}read',
'principal' => $this->getOwner().'/calendar-proxy-read',
'protected' => true,
],
[
'privilege' => '{DAV:}read',
'principal' => $this->getOwner().'/calendar-proxy-write',
'protected' => true,
],
];
} | php | public function getACL()
{
return [
[
'privilege' => '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-send',
'principal' => $this->getOwner(),
'protected' => true,
],
[
'privilege' => '{DAV:}read',
'principal' => $this->getOwner(),
'protected' => true,
],
[
'privilege' => '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-send',
'principal' => $this->getOwner().'/calendar-proxy-write',
'protected' => true,
],
[
'privilege' => '{DAV:}read',
'principal' => $this->getOwner().'/calendar-proxy-read',
'protected' => true,
],
[
'privilege' => '{DAV:}read',
'principal' => $this->getOwner().'/calendar-proxy-write',
'protected' => true,
],
];
} | [
"public",
"function",
"getACL",
"(",
")",
"{",
"return",
"[",
"[",
"'privilege'",
"=>",
"'{'",
".",
"CalDAV",
"\\",
"Plugin",
"::",
"NS_CALDAV",
".",
"'}schedule-send'",
",",
"'principal'",
"=>",
"$",
"this",
"->",
"getOwner",
"(",
")",
",",
"'protected'",
"=>",
"true",
",",
"]",
",",
"[",
"'privilege'",
"=>",
"'{DAV:}read'",
",",
"'principal'",
"=>",
"$",
"this",
"->",
"getOwner",
"(",
")",
",",
"'protected'",
"=>",
"true",
",",
"]",
",",
"[",
"'privilege'",
"=>",
"'{'",
".",
"CalDAV",
"\\",
"Plugin",
"::",
"NS_CALDAV",
".",
"'}schedule-send'",
",",
"'principal'",
"=>",
"$",
"this",
"->",
"getOwner",
"(",
")",
".",
"'/calendar-proxy-write'",
",",
"'protected'",
"=>",
"true",
",",
"]",
",",
"[",
"'privilege'",
"=>",
"'{DAV:}read'",
",",
"'principal'",
"=>",
"$",
"this",
"->",
"getOwner",
"(",
")",
".",
"'/calendar-proxy-read'",
",",
"'protected'",
"=>",
"true",
",",
"]",
",",
"[",
"'privilege'",
"=>",
"'{DAV:}read'",
",",
"'principal'",
"=>",
"$",
"this",
"->",
"getOwner",
"(",
")",
".",
"'/calendar-proxy-write'",
",",
"'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/Outbox.php#L89-L118 |
sabre-io/dav | lib/DAV/PartialUpdate/Plugin.php | Plugin.getHTTPMethods | public function getHTTPMethods($uri)
{
$tree = $this->server->tree;
if ($tree->nodeExists($uri)) {
$node = $tree->getNodeForPath($uri);
if ($node instanceof IPatchSupport) {
return ['PATCH'];
}
}
return [];
} | php | public function getHTTPMethods($uri)
{
$tree = $this->server->tree;
if ($tree->nodeExists($uri)) {
$node = $tree->getNodeForPath($uri);
if ($node instanceof IPatchSupport) {
return ['PATCH'];
}
}
return [];
} | [
"public",
"function",
"getHTTPMethods",
"(",
"$",
"uri",
")",
"{",
"$",
"tree",
"=",
"$",
"this",
"->",
"server",
"->",
"tree",
";",
"if",
"(",
"$",
"tree",
"->",
"nodeExists",
"(",
"$",
"uri",
")",
")",
"{",
"$",
"node",
"=",
"$",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"uri",
")",
";",
"if",
"(",
"$",
"node",
"instanceof",
"IPatchSupport",
")",
"{",
"return",
"[",
"'PATCH'",
"]",
";",
"}",
"}",
"return",
"[",
"]",
";",
"}"
] | Use this method to tell the server this plugin defines additional
HTTP methods.
This method is passed a uri. It should only return HTTP methods that are
available for the specified uri.
We claim to support PATCH method (partirl update) if and only if
- the node exist
- the node implements our partial update interface
@param string $uri
@return array | [
"Use",
"this",
"method",
"to",
"tell",
"the",
"server",
"this",
"plugin",
"defines",
"additional",
"HTTP",
"methods",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PartialUpdate/Plugin.php#L79-L91 |
sabre-io/dav | lib/DAV/PartialUpdate/Plugin.php | Plugin.httpPatch | public function httpPatch(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
// Get the node. Will throw a 404 if not found
$node = $this->server->tree->getNodeForPath($path);
if (!$node instanceof IPatchSupport) {
throw new DAV\Exception\MethodNotAllowed('The target resource does not support the PATCH method.');
}
$range = $this->getHTTPUpdateRange($request);
if (!$range) {
throw new DAV\Exception\BadRequest('No valid "X-Update-Range" found in the headers');
}
$contentType = strtolower(
(string) $request->getHeader('Content-Type')
);
if ('application/x-sabredav-partialupdate' != $contentType) {
throw new DAV\Exception\UnsupportedMediaType('Unknown Content-Type header "'.$contentType.'"');
}
$len = $this->server->httpRequest->getHeader('Content-Length');
if (!$len) {
throw new DAV\Exception\LengthRequired('A Content-Length header is required');
}
switch ($range[0]) {
case self::RANGE_START:
// Calculate the end-range if it doesn't exist.
if (!$range[2]) {
$range[2] = $range[1] + $len - 1;
} else {
if ($range[2] < $range[1]) {
throw new DAV\Exception\RequestedRangeNotSatisfiable('The end offset ('.$range[2].') is lower than the start offset ('.$range[1].')');
}
if ($range[2] - $range[1] + 1 != $len) {
throw new DAV\Exception\RequestedRangeNotSatisfiable('Actual data length ('.$len.') is not consistent with begin ('.$range[1].') and end ('.$range[2].') offsets');
}
}
break;
}
if (!$this->server->emit('beforeWriteContent', [$path, $node, null])) {
return;
}
$body = $this->server->httpRequest->getBody();
$etag = $node->patch($body, $range[0], isset($range[1]) ? $range[1] : null);
$this->server->emit('afterWriteContent', [$path, $node]);
$response->setHeader('Content-Length', '0');
if ($etag) {
$response->setHeader('ETag', $etag);
}
$response->setStatus(204);
// Breaks the event chain
return false;
} | php | public function httpPatch(RequestInterface $request, ResponseInterface $response)
{
$path = $request->getPath();
$node = $this->server->tree->getNodeForPath($path);
if (!$node instanceof IPatchSupport) {
throw new DAV\Exception\MethodNotAllowed('The target resource does not support the PATCH method.');
}
$range = $this->getHTTPUpdateRange($request);
if (!$range) {
throw new DAV\Exception\BadRequest('No valid "X-Update-Range" found in the headers');
}
$contentType = strtolower(
(string) $request->getHeader('Content-Type')
);
if ('application/x-sabredav-partialupdate' != $contentType) {
throw new DAV\Exception\UnsupportedMediaType('Unknown Content-Type header "'.$contentType.'"');
}
$len = $this->server->httpRequest->getHeader('Content-Length');
if (!$len) {
throw new DAV\Exception\LengthRequired('A Content-Length header is required');
}
switch ($range[0]) {
case self::RANGE_START:
if (!$range[2]) {
$range[2] = $range[1] + $len - 1;
} else {
if ($range[2] < $range[1]) {
throw new DAV\Exception\RequestedRangeNotSatisfiable('The end offset ('.$range[2].') is lower than the start offset ('.$range[1].')');
}
if ($range[2] - $range[1] + 1 != $len) {
throw new DAV\Exception\RequestedRangeNotSatisfiable('Actual data length ('.$len.') is not consistent with begin ('.$range[1].') and end ('.$range[2].') offsets');
}
}
break;
}
if (!$this->server->emit('beforeWriteContent', [$path, $node, null])) {
return;
}
$body = $this->server->httpRequest->getBody();
$etag = $node->patch($body, $range[0], isset($range[1]) ? $range[1] : null);
$this->server->emit('afterWriteContent', [$path, $node]);
$response->setHeader('Content-Length', '0');
if ($etag) {
$response->setHeader('ETag', $etag);
}
$response->setStatus(204);
return false;
} | [
"public",
"function",
"httpPatch",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"path",
"=",
"$",
"request",
"->",
"getPath",
"(",
")",
";",
"// Get the node. Will throw a 404 if not found",
"$",
"node",
"=",
"$",
"this",
"->",
"server",
"->",
"tree",
"->",
"getNodeForPath",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"$",
"node",
"instanceof",
"IPatchSupport",
")",
"{",
"throw",
"new",
"DAV",
"\\",
"Exception",
"\\",
"MethodNotAllowed",
"(",
"'The target resource does not support the PATCH method.'",
")",
";",
"}",
"$",
"range",
"=",
"$",
"this",
"->",
"getHTTPUpdateRange",
"(",
"$",
"request",
")",
";",
"if",
"(",
"!",
"$",
"range",
")",
"{",
"throw",
"new",
"DAV",
"\\",
"Exception",
"\\",
"BadRequest",
"(",
"'No valid \"X-Update-Range\" found in the headers'",
")",
";",
"}",
"$",
"contentType",
"=",
"strtolower",
"(",
"(",
"string",
")",
"$",
"request",
"->",
"getHeader",
"(",
"'Content-Type'",
")",
")",
";",
"if",
"(",
"'application/x-sabredav-partialupdate'",
"!=",
"$",
"contentType",
")",
"{",
"throw",
"new",
"DAV",
"\\",
"Exception",
"\\",
"UnsupportedMediaType",
"(",
"'Unknown Content-Type header \"'",
".",
"$",
"contentType",
".",
"'\"'",
")",
";",
"}",
"$",
"len",
"=",
"$",
"this",
"->",
"server",
"->",
"httpRequest",
"->",
"getHeader",
"(",
"'Content-Length'",
")",
";",
"if",
"(",
"!",
"$",
"len",
")",
"{",
"throw",
"new",
"DAV",
"\\",
"Exception",
"\\",
"LengthRequired",
"(",
"'A Content-Length header is required'",
")",
";",
"}",
"switch",
"(",
"$",
"range",
"[",
"0",
"]",
")",
"{",
"case",
"self",
"::",
"RANGE_START",
":",
"// Calculate the end-range if it doesn't exist.",
"if",
"(",
"!",
"$",
"range",
"[",
"2",
"]",
")",
"{",
"$",
"range",
"[",
"2",
"]",
"=",
"$",
"range",
"[",
"1",
"]",
"+",
"$",
"len",
"-",
"1",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"range",
"[",
"2",
"]",
"<",
"$",
"range",
"[",
"1",
"]",
")",
"{",
"throw",
"new",
"DAV",
"\\",
"Exception",
"\\",
"RequestedRangeNotSatisfiable",
"(",
"'The end offset ('",
".",
"$",
"range",
"[",
"2",
"]",
".",
"') is lower than the start offset ('",
".",
"$",
"range",
"[",
"1",
"]",
".",
"')'",
")",
";",
"}",
"if",
"(",
"$",
"range",
"[",
"2",
"]",
"-",
"$",
"range",
"[",
"1",
"]",
"+",
"1",
"!=",
"$",
"len",
")",
"{",
"throw",
"new",
"DAV",
"\\",
"Exception",
"\\",
"RequestedRangeNotSatisfiable",
"(",
"'Actual data length ('",
".",
"$",
"len",
".",
"') is not consistent with begin ('",
".",
"$",
"range",
"[",
"1",
"]",
".",
"') and end ('",
".",
"$",
"range",
"[",
"2",
"]",
".",
"') offsets'",
")",
";",
"}",
"}",
"break",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"server",
"->",
"emit",
"(",
"'beforeWriteContent'",
",",
"[",
"$",
"path",
",",
"$",
"node",
",",
"null",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"body",
"=",
"$",
"this",
"->",
"server",
"->",
"httpRequest",
"->",
"getBody",
"(",
")",
";",
"$",
"etag",
"=",
"$",
"node",
"->",
"patch",
"(",
"$",
"body",
",",
"$",
"range",
"[",
"0",
"]",
",",
"isset",
"(",
"$",
"range",
"[",
"1",
"]",
")",
"?",
"$",
"range",
"[",
"1",
"]",
":",
"null",
")",
";",
"$",
"this",
"->",
"server",
"->",
"emit",
"(",
"'afterWriteContent'",
",",
"[",
"$",
"path",
",",
"$",
"node",
"]",
")",
";",
"$",
"response",
"->",
"setHeader",
"(",
"'Content-Length'",
",",
"'0'",
")",
";",
"if",
"(",
"$",
"etag",
")",
"{",
"$",
"response",
"->",
"setHeader",
"(",
"'ETag'",
",",
"$",
"etag",
")",
";",
"}",
"$",
"response",
"->",
"setStatus",
"(",
"204",
")",
";",
"// Breaks the event chain",
"return",
"false",
";",
"}"
] | Patch an uri.
The WebDAV patch request can be used to modify only a part of an
existing resource. If the resource does not exist yet and the first
offset is not 0, the request fails
@param RequestInterface $request
@param ResponseInterface $response | [
"Patch",
"an",
"uri",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PartialUpdate/Plugin.php#L113-L175 |
sabre-io/dav | lib/DAV/PartialUpdate/Plugin.php | Plugin.getHTTPUpdateRange | public function getHTTPUpdateRange(RequestInterface $request)
{
$range = $request->getHeader('X-Update-Range');
if (is_null($range)) {
return null;
}
// Matching "Range: bytes=1234-5678: both numbers are optional
if (!preg_match('/^(append)|(?:bytes=([0-9]+)-([0-9]*))|(?:bytes=(-[0-9]+))$/i', $range, $matches)) {
return null;
}
if ('append' === $matches[1]) {
return [self::RANGE_APPEND];
} elseif (strlen($matches[2]) > 0) {
return [self::RANGE_START, (int) $matches[2], (int) $matches[3] ?: null];
} else {
return [self::RANGE_END, (int) $matches[4]];
}
} | php | public function getHTTPUpdateRange(RequestInterface $request)
{
$range = $request->getHeader('X-Update-Range');
if (is_null($range)) {
return null;
}
if (!preg_match('/^(append)|(?:bytes=([0-9]+)-([0-9]*))|(?:bytes=(-[0-9]+))$/i', $range, $matches)) {
return null;
}
if ('append' === $matches[1]) {
return [self::RANGE_APPEND];
} elseif (strlen($matches[2]) > 0) {
return [self::RANGE_START, (int) $matches[2], (int) $matches[3] ?: null];
} else {
return [self::RANGE_END, (int) $matches[4]];
}
} | [
"public",
"function",
"getHTTPUpdateRange",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"$",
"range",
"=",
"$",
"request",
"->",
"getHeader",
"(",
"'X-Update-Range'",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"range",
")",
")",
"{",
"return",
"null",
";",
"}",
"// Matching \"Range: bytes=1234-5678: both numbers are optional",
"if",
"(",
"!",
"preg_match",
"(",
"'/^(append)|(?:bytes=([0-9]+)-([0-9]*))|(?:bytes=(-[0-9]+))$/i'",
",",
"$",
"range",
",",
"$",
"matches",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"'append'",
"===",
"$",
"matches",
"[",
"1",
"]",
")",
"{",
"return",
"[",
"self",
"::",
"RANGE_APPEND",
"]",
";",
"}",
"elseif",
"(",
"strlen",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
">",
"0",
")",
"{",
"return",
"[",
"self",
"::",
"RANGE_START",
",",
"(",
"int",
")",
"$",
"matches",
"[",
"2",
"]",
",",
"(",
"int",
")",
"$",
"matches",
"[",
"3",
"]",
"?",
":",
"null",
"]",
";",
"}",
"else",
"{",
"return",
"[",
"self",
"::",
"RANGE_END",
",",
"(",
"int",
")",
"$",
"matches",
"[",
"4",
"]",
"]",
";",
"}",
"}"
] | Returns the HTTP custom range update header.
This method returns null if there is no well-formed HTTP range request
header. It returns array(1) if it was an append request, array(2,
$start, $end) if it's a start and end range, lastly it's array(3,
$endoffset) if the offset was negative, and should be calculated from
the end of the file.
Examples:
null - invalid
[1] - append
[2,10,15] - update bytes 10, 11, 12, 13, 14, 15
[2,10,null] - update bytes 10 until the end of the patch body
[3,-5] - update from 5 bytes from the end of the file.
@param RequestInterface $request
@return array|null | [
"Returns",
"the",
"HTTP",
"custom",
"range",
"update",
"header",
"."
] | train | https://github.com/sabre-io/dav/blob/44b0f2d07fd9e6e44b65f7edf2238d3bf0b428e0/lib/DAV/PartialUpdate/Plugin.php#L198-L218 |
phpDocumentor/ReflectionDocBlock | src/DocBlock/Tags/Method.php | Method.create | public static function create(
string $body,
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): ?self {
Assert::stringNotEmpty($body);
Assert::allNotNull([$typeResolver, $descriptionFactory]);
// 1. none or more whitespace
// 2. optionally the keyword "static" followed by whitespace
// 3. optionally a word with underscores followed by whitespace : as
// type for the return value
// 4. then optionally a word with underscores followed by () and
// whitespace : as method name as used by phpDocumentor
// 5. then a word with underscores, followed by ( and any character
// until a ) and whitespace : as method name with signature
// 6. any remaining text : as description
if (!preg_match(
'/^
# Static keyword
# Declares a static method ONLY if type is also present
(?:
(static)
\s+
)?
# Return type
(?:
(
(?:[\w\|_\\\\]*\$this[\w\|_\\\\]*)
|
(?:
(?:[\w\|_\\\\]+)
# array notation
(?:\[\])*
)*
)
\s+
)?
# Legacy method name (not captured)
(?:
[\w_]+\(\)\s+
)?
# Method name
([\w\|_\\\\]+)
# Arguments
(?:
\(([^\)]*)\)
)?
\s*
# Description
(.*)
$/sux',
$body,
$matches
)) {
return null;
}
[, $static, $returnType, $methodName, $arguments, $description] = $matches;
$static = $static === 'static';
if ($returnType === '') {
$returnType = 'void';
}
$returnType = $typeResolver->resolve($returnType, $context);
$description = $descriptionFactory->create($description, $context);
if (is_string($arguments) && strlen($arguments) > 0) {
$arguments = explode(',', $arguments);
foreach ($arguments as &$argument) {
$argument = explode(' ', self::stripRestArg(trim($argument)), 2);
if ($argument[0][0] === '$') {
$argumentName = substr($argument[0], 1);
$argumentType = new Void_();
} else {
$argumentType = $typeResolver->resolve($argument[0], $context);
$argumentName = '';
if (isset($argument[1])) {
$argument[1] = self::stripRestArg($argument[1]);
$argumentName = substr($argument[1], 1);
}
}
$argument = ['name' => $argumentName, 'type' => $argumentType];
}
} else {
$arguments = [];
}
return new static($methodName, $arguments, $returnType, $static, $description);
} | php | public static function create(
string $body,
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): ?self {
Assert::stringNotEmpty($body);
Assert::allNotNull([$typeResolver, $descriptionFactory]);
if (!preg_match(
'/^
(?:
(static)
\s+
)?
(?:
(
(?:[\w\|_\\\\]*\$this[\w\|_\\\\]*)
|
(?:
(?:[\w\|_\\\\]+)
(?:\[\])*
)*
)
\s+
)?
(?:
[\w_]+\(\)\s+
)?
([\w\|_\\\\]+)
(?:
\(([^\)]*)\)
)?
\s*
(.*)
$/sux',
$body,
$matches
)) {
return null;
}
[, $static, $returnType, $methodName, $arguments, $description] = $matches;
$static = $static === 'static';
if ($returnType === '') {
$returnType = 'void';
}
$returnType = $typeResolver->resolve($returnType, $context);
$description = $descriptionFactory->create($description, $context);
if (is_string($arguments) && strlen($arguments) > 0) {
$arguments = explode(',', $arguments);
foreach ($arguments as &$argument) {
$argument = explode(' ', self::stripRestArg(trim($argument)), 2);
if ($argument[0][0] === '$') {
$argumentName = substr($argument[0], 1);
$argumentType = new Void_();
} else {
$argumentType = $typeResolver->resolve($argument[0], $context);
$argumentName = '';
if (isset($argument[1])) {
$argument[1] = self::stripRestArg($argument[1]);
$argumentName = substr($argument[1], 1);
}
}
$argument = ['name' => $argumentName, 'type' => $argumentType];
}
} else {
$arguments = [];
}
return new static($methodName, $arguments, $returnType, $static, $description);
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"body",
",",
"?",
"TypeResolver",
"$",
"typeResolver",
"=",
"null",
",",
"?",
"DescriptionFactory",
"$",
"descriptionFactory",
"=",
"null",
",",
"?",
"TypeContext",
"$",
"context",
"=",
"null",
")",
":",
"?",
"self",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"body",
")",
";",
"Assert",
"::",
"allNotNull",
"(",
"[",
"$",
"typeResolver",
",",
"$",
"descriptionFactory",
"]",
")",
";",
"// 1. none or more whitespace",
"// 2. optionally the keyword \"static\" followed by whitespace",
"// 3. optionally a word with underscores followed by whitespace : as",
"// type for the return value",
"// 4. then optionally a word with underscores followed by () and",
"// whitespace : as method name as used by phpDocumentor",
"// 5. then a word with underscores, followed by ( and any character",
"// until a ) and whitespace : as method name with signature",
"// 6. any remaining text : as description",
"if",
"(",
"!",
"preg_match",
"(",
"'/^\n # Static keyword\n # Declares a static method ONLY if type is also present\n (?:\n (static)\n \\s+\n )?\n # Return type\n (?:\n (\n (?:[\\w\\|_\\\\\\\\]*\\$this[\\w\\|_\\\\\\\\]*)\n |\n (?:\n (?:[\\w\\|_\\\\\\\\]+)\n # array notation\n (?:\\[\\])*\n )*\n )\n \\s+\n )?\n # Legacy method name (not captured)\n (?:\n [\\w_]+\\(\\)\\s+\n )?\n # Method name\n ([\\w\\|_\\\\\\\\]+)\n # Arguments\n (?:\n \\(([^\\)]*)\\)\n )?\n \\s*\n # Description\n (.*)\n $/sux'",
",",
"$",
"body",
",",
"$",
"matches",
")",
")",
"{",
"return",
"null",
";",
"}",
"[",
",",
"$",
"static",
",",
"$",
"returnType",
",",
"$",
"methodName",
",",
"$",
"arguments",
",",
"$",
"description",
"]",
"=",
"$",
"matches",
";",
"$",
"static",
"=",
"$",
"static",
"===",
"'static'",
";",
"if",
"(",
"$",
"returnType",
"===",
"''",
")",
"{",
"$",
"returnType",
"=",
"'void'",
";",
"}",
"$",
"returnType",
"=",
"$",
"typeResolver",
"->",
"resolve",
"(",
"$",
"returnType",
",",
"$",
"context",
")",
";",
"$",
"description",
"=",
"$",
"descriptionFactory",
"->",
"create",
"(",
"$",
"description",
",",
"$",
"context",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"arguments",
")",
"&&",
"strlen",
"(",
"$",
"arguments",
")",
">",
"0",
")",
"{",
"$",
"arguments",
"=",
"explode",
"(",
"','",
",",
"$",
"arguments",
")",
";",
"foreach",
"(",
"$",
"arguments",
"as",
"&",
"$",
"argument",
")",
"{",
"$",
"argument",
"=",
"explode",
"(",
"' '",
",",
"self",
"::",
"stripRestArg",
"(",
"trim",
"(",
"$",
"argument",
")",
")",
",",
"2",
")",
";",
"if",
"(",
"$",
"argument",
"[",
"0",
"]",
"[",
"0",
"]",
"===",
"'$'",
")",
"{",
"$",
"argumentName",
"=",
"substr",
"(",
"$",
"argument",
"[",
"0",
"]",
",",
"1",
")",
";",
"$",
"argumentType",
"=",
"new",
"Void_",
"(",
")",
";",
"}",
"else",
"{",
"$",
"argumentType",
"=",
"$",
"typeResolver",
"->",
"resolve",
"(",
"$",
"argument",
"[",
"0",
"]",
",",
"$",
"context",
")",
";",
"$",
"argumentName",
"=",
"''",
";",
"if",
"(",
"isset",
"(",
"$",
"argument",
"[",
"1",
"]",
")",
")",
"{",
"$",
"argument",
"[",
"1",
"]",
"=",
"self",
"::",
"stripRestArg",
"(",
"$",
"argument",
"[",
"1",
"]",
")",
";",
"$",
"argumentName",
"=",
"substr",
"(",
"$",
"argument",
"[",
"1",
"]",
",",
"1",
")",
";",
"}",
"}",
"$",
"argument",
"=",
"[",
"'name'",
"=>",
"$",
"argumentName",
",",
"'type'",
"=>",
"$",
"argumentType",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"arguments",
"=",
"[",
"]",
";",
"}",
"return",
"new",
"static",
"(",
"$",
"methodName",
",",
"$",
"arguments",
",",
"$",
"returnType",
",",
"$",
"static",
",",
"$",
"description",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock/Tags/Method.php#L67-L160 |
phpDocumentor/ReflectionDocBlock | src/DocBlock/Description.php | Description.render | public function render(?Formatter $formatter = null): string
{
if ($formatter === null) {
$formatter = new PassthroughFormatter();
}
$tags = [];
foreach ($this->tags as $tag) {
$tags[] = '{' . $formatter->format($tag) . '}';
}
return vsprintf($this->bodyTemplate, $tags);
} | php | public function render(?Formatter $formatter = null): string
{
if ($formatter === null) {
$formatter = new PassthroughFormatter();
}
$tags = [];
foreach ($this->tags as $tag) {
$tags[] = '{' . $formatter->format($tag) . '}';
}
return vsprintf($this->bodyTemplate, $tags);
} | [
"public",
"function",
"render",
"(",
"?",
"Formatter",
"$",
"formatter",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"$",
"formatter",
"===",
"null",
")",
"{",
"$",
"formatter",
"=",
"new",
"PassthroughFormatter",
"(",
")",
";",
"}",
"$",
"tags",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"tags",
"as",
"$",
"tag",
")",
"{",
"$",
"tags",
"[",
"]",
"=",
"'{'",
".",
"$",
"formatter",
"->",
"format",
"(",
"$",
"tag",
")",
".",
"'}'",
";",
"}",
"return",
"vsprintf",
"(",
"$",
"this",
"->",
"bodyTemplate",
",",
"$",
"tags",
")",
";",
"}"
] | Renders this description as a string where the provided formatter will format the tags in the expected string
format. | [
"Renders",
"this",
"description",
"as",
"a",
"string",
"where",
"the",
"provided",
"formatter",
"will",
"format",
"the",
"tags",
"in",
"the",
"expected",
"string",
"format",
"."
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock/Description.php#L84-L96 |
phpDocumentor/ReflectionDocBlock | examples/04-adding-your-own-tag.php | MyTag.create | public static function create(string $body, DescriptionFactory $descriptionFactory = null, Context $context = null): MyTag
{
Assert::notNull($descriptionFactory);
return new static($descriptionFactory->create($body, $context));
} | php | public static function create(string $body, DescriptionFactory $descriptionFactory = null, Context $context = null): MyTag
{
Assert::notNull($descriptionFactory);
return new static($descriptionFactory->create($body, $context));
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"body",
",",
"DescriptionFactory",
"$",
"descriptionFactory",
"=",
"null",
",",
"Context",
"$",
"context",
"=",
"null",
")",
":",
"MyTag",
"{",
"Assert",
"::",
"notNull",
"(",
"$",
"descriptionFactory",
")",
";",
"return",
"new",
"static",
"(",
"$",
"descriptionFactory",
"->",
"create",
"(",
"$",
"body",
",",
"$",
"context",
")",
")",
";",
"}"
] | A static Factory that creates a new instance of the current Tag.
In this example the MyTag tag can be created by passing a description text as $body. Because we have added
a $descriptionFactory that is type-hinted as DescriptionFactory we can now construct a new Description object
and pass that to the constructor.
> You could directly instantiate a Description object here but that won't be parsed for inline tags and Types
> won't be resolved. The DescriptionFactory will take care of those actions.
The `create` method's interface states that this method only features a single parameter (`$body`) but the
{@see TagFactory} will read the signature of this method and if it has more parameters then it will try
to find declarations for it in the ServiceLocator of the TagFactory (see {@see TagFactory::$serviceLocator}).
> Important: all properties following the `$body` should default to `null`, otherwise PHP will error because
> it no longer matches the interface. This is why you often see the default tags check that an optional argument
> is not null nonetheless.
@param string $body
@param DescriptionFactory $descriptionFactory
@param Context|null $context The Context is used to resolve Types and FQSENs, although optional
it is highly recommended to pass it. If you omit it then it is assumed that
the DocBlock is in the global namespace and has no `use` statements.
@see Tag for the interface declaration of the `create` method.
@see Tag::create() for more information on this method's workings. | [
"A",
"static",
"Factory",
"that",
"creates",
"a",
"new",
"instance",
"of",
"the",
"current",
"Tag",
"."
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/examples/04-adding-your-own-tag.php#L87-L92 |
phpDocumentor/ReflectionDocBlock | src/DocBlock.php | DocBlock.getTagsByName | public function getTagsByName(string $name): array
{
$result = [];
/** @var Tag $tag */
foreach ($this->getTags() as $tag) {
if ($tag->getName() !== $name) {
continue;
}
$result[] = $tag;
}
return $result;
} | php | public function getTagsByName(string $name): array
{
$result = [];
foreach ($this->getTags() as $tag) {
if ($tag->getName() !== $name) {
continue;
}
$result[] = $tag;
}
return $result;
} | [
"public",
"function",
"getTagsByName",
"(",
"string",
"$",
"name",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"/** @var Tag $tag */",
"foreach",
"(",
"$",
"this",
"->",
"getTags",
"(",
")",
"as",
"$",
"tag",
")",
"{",
"if",
"(",
"$",
"tag",
"->",
"getName",
"(",
")",
"!==",
"$",
"name",
")",
"{",
"continue",
";",
"}",
"$",
"result",
"[",
"]",
"=",
"$",
"tag",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns an array of tags matching the given name. If no tags are found
an empty array is returned.
@param string $name String to search by.
@return Tag[] | [
"Returns",
"an",
"array",
"of",
"tags",
"matching",
"the",
"given",
"name",
".",
"If",
"no",
"tags",
"are",
"found",
"an",
"empty",
"array",
"is",
"returned",
"."
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock.php#L149-L163 |
phpDocumentor/ReflectionDocBlock | src/DocBlock.php | DocBlock.hasTag | public function hasTag(string $name): bool
{
/** @var Tag $tag */
foreach ($this->getTags() as $tag) {
if ($tag->getName() === $name) {
return true;
}
}
return false;
} | php | public function hasTag(string $name): bool
{
foreach ($this->getTags() as $tag) {
if ($tag->getName() === $name) {
return true;
}
}
return false;
} | [
"public",
"function",
"hasTag",
"(",
"string",
"$",
"name",
")",
":",
"bool",
"{",
"/** @var Tag $tag */",
"foreach",
"(",
"$",
"this",
"->",
"getTags",
"(",
")",
"as",
"$",
"tag",
")",
"{",
"if",
"(",
"$",
"tag",
"->",
"getName",
"(",
")",
"===",
"$",
"name",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks if a tag of a certain type is present in this DocBlock.
@param string $name Tag name to check for. | [
"Checks",
"if",
"a",
"tag",
"of",
"a",
"certain",
"type",
"is",
"present",
"in",
"this",
"DocBlock",
"."
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock.php#L170-L180 |
phpDocumentor/ReflectionDocBlock | src/DocBlock.php | DocBlock.removeTag | public function removeTag(Tag $tagToRemove): void
{
foreach ($this->tags as $key => $tag) {
if ($tag === $tagToRemove) {
unset($this->tags[$key]);
break;
}
}
} | php | public function removeTag(Tag $tagToRemove): void
{
foreach ($this->tags as $key => $tag) {
if ($tag === $tagToRemove) {
unset($this->tags[$key]);
break;
}
}
} | [
"public",
"function",
"removeTag",
"(",
"Tag",
"$",
"tagToRemove",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"this",
"->",
"tags",
"as",
"$",
"key",
"=>",
"$",
"tag",
")",
"{",
"if",
"(",
"$",
"tag",
"===",
"$",
"tagToRemove",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"tags",
"[",
"$",
"key",
"]",
")",
";",
"break",
";",
"}",
"}",
"}"
] | Remove a tag from this DocBlock.
@param Tag $tagToRemove The tag to remove. | [
"Remove",
"a",
"tag",
"from",
"this",
"DocBlock",
"."
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock.php#L187-L195 |
phpDocumentor/ReflectionDocBlock | src/DocBlock/Tags/Generic.php | Generic.create | public static function create(
string $body,
string $name = '',
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): self {
Assert::stringNotEmpty($name);
Assert::notNull($descriptionFactory);
$description = $descriptionFactory && $body !== "" ? $descriptionFactory->create($body, $context) : null;
return new static($name, $description);
} | php | public static function create(
string $body,
string $name = '',
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): self {
Assert::stringNotEmpty($name);
Assert::notNull($descriptionFactory);
$description = $descriptionFactory && $body !== "" ? $descriptionFactory->create($body, $context) : null;
return new static($name, $description);
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"body",
",",
"string",
"$",
"name",
"=",
"''",
",",
"?",
"DescriptionFactory",
"$",
"descriptionFactory",
"=",
"null",
",",
"?",
"TypeContext",
"$",
"context",
"=",
"null",
")",
":",
"self",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"name",
")",
";",
"Assert",
"::",
"notNull",
"(",
"$",
"descriptionFactory",
")",
";",
"$",
"description",
"=",
"$",
"descriptionFactory",
"&&",
"$",
"body",
"!==",
"\"\"",
"?",
"$",
"descriptionFactory",
"->",
"create",
"(",
"$",
"body",
",",
"$",
"context",
")",
":",
"null",
";",
"return",
"new",
"static",
"(",
"$",
"name",
",",
"$",
"description",
")",
";",
"}"
] | Creates a new tag that represents any unknown tag type.
@return static | [
"Creates",
"a",
"new",
"tag",
"that",
"represents",
"any",
"unknown",
"tag",
"type",
"."
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock/Tags/Generic.php#L47-L59 |
phpDocumentor/ReflectionDocBlock | src/DocBlock/Tags/Generic.php | Generic.validateTagName | private function validateTagName(string $name): void
{
if (! preg_match('/^' . StandardTagFactory::REGEX_TAGNAME . '$/u', $name)) {
throw new \InvalidArgumentException(
'The tag name "' . $name . '" is not wellformed. Tags may only consist of letters, underscores, '
. 'hyphens and backslashes.'
);
}
} | php | private function validateTagName(string $name): void
{
if (! preg_match('/^' . StandardTagFactory::REGEX_TAGNAME . '$/u', $name)) {
throw new \InvalidArgumentException(
'The tag name "' . $name . '" is not wellformed. Tags may only consist of letters, underscores, '
. 'hyphens and backslashes.'
);
}
} | [
"private",
"function",
"validateTagName",
"(",
"string",
"$",
"name",
")",
":",
"void",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'/^'",
".",
"StandardTagFactory",
"::",
"REGEX_TAGNAME",
".",
"'$/u'",
",",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The tag name \"'",
".",
"$",
"name",
".",
"'\" is not wellformed. Tags may only consist of letters, underscores, '",
".",
"'hyphens and backslashes.'",
")",
";",
"}",
"}"
] | Validates if the tag name matches the expected format, otherwise throws an exception. | [
"Validates",
"if",
"the",
"tag",
"name",
"matches",
"the",
"expected",
"format",
"otherwise",
"throws",
"an",
"exception",
"."
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock/Tags/Generic.php#L72-L80 |
phpDocumentor/ReflectionDocBlock | src/DocBlock/Tags/Var_.php | Var_.create | public static function create(
string $body,
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): self {
Assert::stringNotEmpty($body);
Assert::allNotNull([$typeResolver, $descriptionFactory]);
$parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE);
$type = null;
$variableName = '';
// if the first item that is encountered is not a variable; it is a type
if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] !== '$')) {
$type = $typeResolver->resolve(array_shift($parts), $context);
array_shift($parts);
}
// if the next item starts with a $ or ...$ it must be the variable name
if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] === '$')) {
$variableName = array_shift($parts);
array_shift($parts);
if (substr($variableName, 0, 1) === '$') {
$variableName = substr($variableName, 1);
}
}
$description = $descriptionFactory->create(implode('', $parts), $context);
return new static($variableName, $type, $description);
} | php | public static function create(
string $body,
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): self {
Assert::stringNotEmpty($body);
Assert::allNotNull([$typeResolver, $descriptionFactory]);
$parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE);
$type = null;
$variableName = '';
if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] !== '$')) {
$type = $typeResolver->resolve(array_shift($parts), $context);
array_shift($parts);
}
if (isset($parts[0]) && (strlen($parts[0]) > 0) && ($parts[0][0] === '$')) {
$variableName = array_shift($parts);
array_shift($parts);
if (substr($variableName, 0, 1) === '$') {
$variableName = substr($variableName, 1);
}
}
$description = $descriptionFactory->create(implode('', $parts), $context);
return new static($variableName, $type, $description);
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"body",
",",
"?",
"TypeResolver",
"$",
"typeResolver",
"=",
"null",
",",
"?",
"DescriptionFactory",
"$",
"descriptionFactory",
"=",
"null",
",",
"?",
"TypeContext",
"$",
"context",
"=",
"null",
")",
":",
"self",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"body",
")",
";",
"Assert",
"::",
"allNotNull",
"(",
"[",
"$",
"typeResolver",
",",
"$",
"descriptionFactory",
"]",
")",
";",
"$",
"parts",
"=",
"preg_split",
"(",
"'/(\\s+)/Su'",
",",
"$",
"body",
",",
"3",
",",
"PREG_SPLIT_DELIM_CAPTURE",
")",
";",
"$",
"type",
"=",
"null",
";",
"$",
"variableName",
"=",
"''",
";",
"// if the first item that is encountered is not a variable; it is a type",
"if",
"(",
"isset",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
"&&",
"(",
"strlen",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
">",
"0",
")",
"&&",
"(",
"$",
"parts",
"[",
"0",
"]",
"[",
"0",
"]",
"!==",
"'$'",
")",
")",
"{",
"$",
"type",
"=",
"$",
"typeResolver",
"->",
"resolve",
"(",
"array_shift",
"(",
"$",
"parts",
")",
",",
"$",
"context",
")",
";",
"array_shift",
"(",
"$",
"parts",
")",
";",
"}",
"// if the next item starts with a $ or ...$ it must be the variable name",
"if",
"(",
"isset",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
"&&",
"(",
"strlen",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
">",
"0",
")",
"&&",
"(",
"$",
"parts",
"[",
"0",
"]",
"[",
"0",
"]",
"===",
"'$'",
")",
")",
"{",
"$",
"variableName",
"=",
"array_shift",
"(",
"$",
"parts",
")",
";",
"array_shift",
"(",
"$",
"parts",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"variableName",
",",
"0",
",",
"1",
")",
"===",
"'$'",
")",
"{",
"$",
"variableName",
"=",
"substr",
"(",
"$",
"variableName",
",",
"1",
")",
";",
"}",
"}",
"$",
"description",
"=",
"$",
"descriptionFactory",
"->",
"create",
"(",
"implode",
"(",
"''",
",",
"$",
"parts",
")",
",",
"$",
"context",
")",
";",
"return",
"new",
"static",
"(",
"$",
"variableName",
",",
"$",
"type",
",",
"$",
"description",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock/Tags/Var_.php#L47-L79 |
phpDocumentor/ReflectionDocBlock | src/DocBlock/DescriptionFactory.php | DescriptionFactory.create | public function create(string $contents, ?TypeContext $context = null): Description
{
[$text, $tags] = $this->parse($this->lex($contents), $context);
return new Description($text, $tags);
} | php | public function create(string $contents, ?TypeContext $context = null): Description
{
[$text, $tags] = $this->parse($this->lex($contents), $context);
return new Description($text, $tags);
} | [
"public",
"function",
"create",
"(",
"string",
"$",
"contents",
",",
"?",
"TypeContext",
"$",
"context",
"=",
"null",
")",
":",
"Description",
"{",
"[",
"$",
"text",
",",
"$",
"tags",
"]",
"=",
"$",
"this",
"->",
"parse",
"(",
"$",
"this",
"->",
"lex",
"(",
"$",
"contents",
")",
",",
"$",
"context",
")",
";",
"return",
"new",
"Description",
"(",
"$",
"text",
",",
"$",
"tags",
")",
";",
"}"
] | Returns the parsed text of this description. | [
"Returns",
"the",
"parsed",
"text",
"of",
"this",
"description",
"."
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock/DescriptionFactory.php#L51-L56 |
phpDocumentor/ReflectionDocBlock | src/DocBlock/DescriptionFactory.php | DescriptionFactory.lex | private function lex(string $contents): array
{
$contents = $this->removeSuperfluousStartingWhitespace($contents);
// performance optimalization; if there is no inline tag, don't bother splitting it up.
if (strpos($contents, '{@') === false) {
return [$contents];
}
return preg_split(
'/\{
# "{@}" is not a valid inline tag. This ensures that we do not treat it as one, but treat it literally.
(?!@\})
# We want to capture the whole tag line, but without the inline tag delimiters.
(\@
# Match everything up to the next delimiter.
[^{}]*
# Nested inline tag content should not be captured, or it will appear in the result separately.
(?:
# Match nested inline tags.
(?:
# Because we did not catch the tag delimiters earlier, we must be explicit with them here.
# Notice that this also matches "{}", as a way to later introduce it as an escape sequence.
\{(?1)?\}
|
# Make sure we match hanging "{".
\{
)
# Match content after the nested inline tag.
[^{}]*
)* # If there are more inline tags, match them as well. We use "*" since there may not be any
# nested inline tags.
)
\}/Sux',
$contents,
0,
PREG_SPLIT_DELIM_CAPTURE
);
} | php | private function lex(string $contents): array
{
$contents = $this->removeSuperfluousStartingWhitespace($contents);
if (strpos($contents, '{@') === false) {
return [$contents];
}
return preg_split(
'/\{
(?!@\})
(\@
[^{}]*
(?:
(?:
\{(?1)?\}
|
\{
)
[^{}]*
)*
)
\}/Sux',
$contents,
0,
PREG_SPLIT_DELIM_CAPTURE
);
} | [
"private",
"function",
"lex",
"(",
"string",
"$",
"contents",
")",
":",
"array",
"{",
"$",
"contents",
"=",
"$",
"this",
"->",
"removeSuperfluousStartingWhitespace",
"(",
"$",
"contents",
")",
";",
"// performance optimalization; if there is no inline tag, don't bother splitting it up.",
"if",
"(",
"strpos",
"(",
"$",
"contents",
",",
"'{@'",
")",
"===",
"false",
")",
"{",
"return",
"[",
"$",
"contents",
"]",
";",
"}",
"return",
"preg_split",
"(",
"'/\\{\n # \"{@}\" is not a valid inline tag. This ensures that we do not treat it as one, but treat it literally.\n (?!@\\})\n # We want to capture the whole tag line, but without the inline tag delimiters.\n (\\@\n # Match everything up to the next delimiter.\n [^{}]*\n # Nested inline tag content should not be captured, or it will appear in the result separately.\n (?:\n # Match nested inline tags.\n (?:\n # Because we did not catch the tag delimiters earlier, we must be explicit with them here.\n # Notice that this also matches \"{}\", as a way to later introduce it as an escape sequence.\n \\{(?1)?\\}\n |\n # Make sure we match hanging \"{\".\n \\{\n )\n # Match content after the nested inline tag.\n [^{}]*\n )* # If there are more inline tags, match them as well. We use \"*\" since there may not be any\n # nested inline tags.\n )\n \\}/Sux'",
",",
"$",
"contents",
",",
"0",
",",
"PREG_SPLIT_DELIM_CAPTURE",
")",
";",
"}"
] | Strips the contents from superfluous whitespace and splits the description into a series of tokens.
@return string[] A series of tokens of which the description text is composed. | [
"Strips",
"the",
"contents",
"from",
"superfluous",
"whitespace",
"and",
"splits",
"the",
"description",
"into",
"a",
"series",
"of",
"tokens",
"."
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock/DescriptionFactory.php#L64-L102 |
phpDocumentor/ReflectionDocBlock | src/DocBlock/DescriptionFactory.php | DescriptionFactory.parse | private function parse($tokens, ?TypeContext $context = null): array
{
$count = count($tokens);
$tagCount = 0;
$tags = [];
for ($i = 1; $i < $count; $i += 2) {
$tags[] = $this->tagFactory->create($tokens[$i], $context);
$tokens[$i] = '%' . ++$tagCount . '$s';
}
//In order to allow "literal" inline tags, the otherwise invalid
//sequence "{@}" is changed to "@", and "{}" is changed to "}".
//"%" is escaped to "%%" because of vsprintf.
//See unit tests for examples.
for ($i = 0; $i < $count; $i += 2) {
$tokens[$i] = str_replace(['{@}', '{}', '%'], ['@', '}', '%%'], $tokens[$i]);
}
return [implode('', $tokens), $tags];
} | php | private function parse($tokens, ?TypeContext $context = null): array
{
$count = count($tokens);
$tagCount = 0;
$tags = [];
for ($i = 1; $i < $count; $i += 2) {
$tags[] = $this->tagFactory->create($tokens[$i], $context);
$tokens[$i] = '%' . ++$tagCount . '$s';
}
for ($i = 0; $i < $count; $i += 2) {
$tokens[$i] = str_replace(['{@}', '{}', '%'], ['@', '}', '%%'], $tokens[$i]);
}
return [implode('', $tokens), $tags];
} | [
"private",
"function",
"parse",
"(",
"$",
"tokens",
",",
"?",
"TypeContext",
"$",
"context",
"=",
"null",
")",
":",
"array",
"{",
"$",
"count",
"=",
"count",
"(",
"$",
"tokens",
")",
";",
"$",
"tagCount",
"=",
"0",
";",
"$",
"tags",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"+=",
"2",
")",
"{",
"$",
"tags",
"[",
"]",
"=",
"$",
"this",
"->",
"tagFactory",
"->",
"create",
"(",
"$",
"tokens",
"[",
"$",
"i",
"]",
",",
"$",
"context",
")",
";",
"$",
"tokens",
"[",
"$",
"i",
"]",
"=",
"'%'",
".",
"++",
"$",
"tagCount",
".",
"'$s'",
";",
"}",
"//In order to allow \"literal\" inline tags, the otherwise invalid",
"//sequence \"{@}\" is changed to \"@\", and \"{}\" is changed to \"}\".",
"//\"%\" is escaped to \"%%\" because of vsprintf.",
"//See unit tests for examples.",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"+=",
"2",
")",
"{",
"$",
"tokens",
"[",
"$",
"i",
"]",
"=",
"str_replace",
"(",
"[",
"'{@}'",
",",
"'{}'",
",",
"'%'",
"]",
",",
"[",
"'@'",
",",
"'}'",
",",
"'%%'",
"]",
",",
"$",
"tokens",
"[",
"$",
"i",
"]",
")",
";",
"}",
"return",
"[",
"implode",
"(",
"''",
",",
"$",
"tokens",
")",
",",
"$",
"tags",
"]",
";",
"}"
] | Parses the stream of tokens in to a new set of tokens containing Tags.
@param string[] $tokens
@return string[]|Tag[] | [
"Parses",
"the",
"stream",
"of",
"tokens",
"in",
"to",
"a",
"new",
"set",
"of",
"tokens",
"containing",
"Tags",
"."
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock/DescriptionFactory.php#L111-L131 |
phpDocumentor/ReflectionDocBlock | src/DocBlock/DescriptionFactory.php | DescriptionFactory.removeSuperfluousStartingWhitespace | private function removeSuperfluousStartingWhitespace(string $contents): string
{
$lines = explode("\n", $contents);
// if there is only one line then we don't have lines with superfluous whitespace and
// can use the contents as-is
if (count($lines) <= 1) {
return $contents;
}
// determine how many whitespace characters need to be stripped
$startingSpaceCount = 9999999;
for ($i = 1; $i < count($lines); ++$i) {
// lines with a no length do not count as they are not indented at all
if (strlen(trim($lines[$i])) === 0) {
continue;
}
// determine the number of prefixing spaces by checking the difference in line length before and after
// an ltrim
$startingSpaceCount = min($startingSpaceCount, strlen($lines[$i]) - strlen(ltrim($lines[$i])));
}
// strip the number of spaces from each line
if ($startingSpaceCount > 0) {
for ($i = 1; $i < count($lines); ++$i) {
$lines[$i] = substr($lines[$i], $startingSpaceCount);
}
}
return implode("\n", $lines);
} | php | private function removeSuperfluousStartingWhitespace(string $contents): string
{
$lines = explode("\n", $contents);
if (count($lines) <= 1) {
return $contents;
}
$startingSpaceCount = 9999999;
for ($i = 1; $i < count($lines); ++$i) {
if (strlen(trim($lines[$i])) === 0) {
continue;
}
$startingSpaceCount = min($startingSpaceCount, strlen($lines[$i]) - strlen(ltrim($lines[$i])));
}
if ($startingSpaceCount > 0) {
for ($i = 1; $i < count($lines); ++$i) {
$lines[$i] = substr($lines[$i], $startingSpaceCount);
}
}
return implode("\n", $lines);
} | [
"private",
"function",
"removeSuperfluousStartingWhitespace",
"(",
"string",
"$",
"contents",
")",
":",
"string",
"{",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"contents",
")",
";",
"// if there is only one line then we don't have lines with superfluous whitespace and",
"// can use the contents as-is",
"if",
"(",
"count",
"(",
"$",
"lines",
")",
"<=",
"1",
")",
"{",
"return",
"$",
"contents",
";",
"}",
"// determine how many whitespace characters need to be stripped",
"$",
"startingSpaceCount",
"=",
"9999999",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"lines",
")",
";",
"++",
"$",
"i",
")",
"{",
"// lines with a no length do not count as they are not indented at all",
"if",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"lines",
"[",
"$",
"i",
"]",
")",
")",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"// determine the number of prefixing spaces by checking the difference in line length before and after",
"// an ltrim",
"$",
"startingSpaceCount",
"=",
"min",
"(",
"$",
"startingSpaceCount",
",",
"strlen",
"(",
"$",
"lines",
"[",
"$",
"i",
"]",
")",
"-",
"strlen",
"(",
"ltrim",
"(",
"$",
"lines",
"[",
"$",
"i",
"]",
")",
")",
")",
";",
"}",
"// strip the number of spaces from each line",
"if",
"(",
"$",
"startingSpaceCount",
">",
"0",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"lines",
")",
";",
"++",
"$",
"i",
")",
"{",
"$",
"lines",
"[",
"$",
"i",
"]",
"=",
"substr",
"(",
"$",
"lines",
"[",
"$",
"i",
"]",
",",
"$",
"startingSpaceCount",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"lines",
")",
";",
"}"
] | Removes the superfluous from a multi-line description.
When a description has more than one line then it can happen that the second and subsequent lines have an
additional indentation. This is commonly in use with tags like this:
{@}since 1.1.0 This is an example
description where we have an
indentation in the second and
subsequent lines.
If we do not normalize the indentation then we have superfluous whitespace on the second and subsequent
lines and this may cause rendering issues when, for example, using a Markdown converter. | [
"Removes",
"the",
"superfluous",
"from",
"a",
"multi",
"-",
"line",
"description",
"."
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock/DescriptionFactory.php#L147-L178 |
phpDocumentor/ReflectionDocBlock | src/DocBlock/Serializer.php | Serializer.getDocComment | public function getDocComment(DocBlock $docblock): string
{
$indent = str_repeat($this->indentString, $this->indent);
$firstIndent = $this->isFirstLineIndented ? $indent : '';
// 3 === strlen(' * ')
$wrapLength = $this->lineLength ? $this->lineLength - strlen($indent) - 3 : null;
$text = $this->removeTrailingSpaces(
$indent,
$this->addAsterisksForEachLine(
$indent,
$this->getSummaryAndDescriptionTextBlock($docblock, $wrapLength)
)
);
$comment = "{$firstIndent}/**\n";
if ($text) {
$comment .= "{$indent} * {$text}\n";
$comment .= "{$indent} *\n";
}
$comment = $this->addTagBlock($docblock, $wrapLength, $indent, $comment);
$comment .= $indent . ' */';
return $comment;
} | php | public function getDocComment(DocBlock $docblock): string
{
$indent = str_repeat($this->indentString, $this->indent);
$firstIndent = $this->isFirstLineIndented ? $indent : '';
$wrapLength = $this->lineLength ? $this->lineLength - strlen($indent) - 3 : null;
$text = $this->removeTrailingSpaces(
$indent,
$this->addAsterisksForEachLine(
$indent,
$this->getSummaryAndDescriptionTextBlock($docblock, $wrapLength)
)
);
$comment = "{$firstIndent}';
return $comment;
} | [
"public",
"function",
"getDocComment",
"(",
"DocBlock",
"$",
"docblock",
")",
":",
"string",
"{",
"$",
"indent",
"=",
"str_repeat",
"(",
"$",
"this",
"->",
"indentString",
",",
"$",
"this",
"->",
"indent",
")",
";",
"$",
"firstIndent",
"=",
"$",
"this",
"->",
"isFirstLineIndented",
"?",
"$",
"indent",
":",
"''",
";",
"// 3 === strlen(' * ')",
"$",
"wrapLength",
"=",
"$",
"this",
"->",
"lineLength",
"?",
"$",
"this",
"->",
"lineLength",
"-",
"strlen",
"(",
"$",
"indent",
")",
"-",
"3",
":",
"null",
";",
"$",
"text",
"=",
"$",
"this",
"->",
"removeTrailingSpaces",
"(",
"$",
"indent",
",",
"$",
"this",
"->",
"addAsterisksForEachLine",
"(",
"$",
"indent",
",",
"$",
"this",
"->",
"getSummaryAndDescriptionTextBlock",
"(",
"$",
"docblock",
",",
"$",
"wrapLength",
")",
")",
")",
";",
"$",
"comment",
"=",
"\"{$firstIndent}/**\\n\"",
";",
"if",
"(",
"$",
"text",
")",
"{",
"$",
"comment",
".=",
"\"{$indent} * {$text}\\n\"",
";",
"$",
"comment",
".=",
"\"{$indent} *\\n\"",
";",
"}",
"$",
"comment",
"=",
"$",
"this",
"->",
"addTagBlock",
"(",
"$",
"docblock",
",",
"$",
"wrapLength",
",",
"$",
"indent",
",",
"$",
"comment",
")",
";",
"$",
"comment",
".=",
"$",
"indent",
".",
"' */'",
";",
"return",
"$",
"comment",
";",
"}"
] | Generate a DocBlock comment.
@param DocBlock $docblock The DocBlock to serialize.
@return string The serialized doc block. | [
"Generate",
"a",
"DocBlock",
"comment",
"."
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock/Serializer.php#L63-L88 |
phpDocumentor/ReflectionDocBlock | src/DocBlock/Tags/Source.php | Source.create | public static function create(
string $body,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): self {
Assert::stringNotEmpty($body);
Assert::notNull($descriptionFactory);
$startingLine = 1;
$lineCount = null;
$description = null;
// Starting line / Number of lines / Description
if (preg_match('/^([1-9]\d*)\s*(?:((?1))\s+)?(.*)$/sux', $body, $matches)) {
$startingLine = (int) $matches[1];
if (isset($matches[2]) && $matches[2] !== '') {
$lineCount = (int) $matches[2];
}
$description = $matches[3];
}
return new static($startingLine, $lineCount, $descriptionFactory->create($description, $context));
} | php | public static function create(
string $body,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): self {
Assert::stringNotEmpty($body);
Assert::notNull($descriptionFactory);
$startingLine = 1;
$lineCount = null;
$description = null;
if (preg_match('/^([1-9]\d*)\s*(?:((?1))\s+)?(.*)$/sux', $body, $matches)) {
$startingLine = (int) $matches[1];
if (isset($matches[2]) && $matches[2] !== '') {
$lineCount = (int) $matches[2];
}
$description = $matches[3];
}
return new static($startingLine, $lineCount, $descriptionFactory->create($description, $context));
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"body",
",",
"?",
"DescriptionFactory",
"$",
"descriptionFactory",
"=",
"null",
",",
"?",
"TypeContext",
"$",
"context",
"=",
"null",
")",
":",
"self",
"{",
"Assert",
"::",
"stringNotEmpty",
"(",
"$",
"body",
")",
";",
"Assert",
"::",
"notNull",
"(",
"$",
"descriptionFactory",
")",
";",
"$",
"startingLine",
"=",
"1",
";",
"$",
"lineCount",
"=",
"null",
";",
"$",
"description",
"=",
"null",
";",
"// Starting line / Number of lines / Description",
"if",
"(",
"preg_match",
"(",
"'/^([1-9]\\d*)\\s*(?:((?1))\\s+)?(.*)$/sux'",
",",
"$",
"body",
",",
"$",
"matches",
")",
")",
"{",
"$",
"startingLine",
"=",
"(",
"int",
")",
"$",
"matches",
"[",
"1",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
"&&",
"$",
"matches",
"[",
"2",
"]",
"!==",
"''",
")",
"{",
"$",
"lineCount",
"=",
"(",
"int",
")",
"$",
"matches",
"[",
"2",
"]",
";",
"}",
"$",
"description",
"=",
"$",
"matches",
"[",
"3",
"]",
";",
"}",
"return",
"new",
"static",
"(",
"$",
"startingLine",
",",
"$",
"lineCount",
",",
"$",
"descriptionFactory",
"->",
"create",
"(",
"$",
"description",
",",
"$",
"context",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock/Tags/Source.php#L48-L71 |
phpDocumentor/ReflectionDocBlock | src/DocBlock/Tags/See.php | See.create | public static function create(
string $body,
?FqsenResolver $resolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): self {
Assert::allNotNull([$resolver, $descriptionFactory]);
$parts = preg_split('/\s+/Su', $body, 2);
$description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null;
// https://tools.ietf.org/html/rfc2396#section-3
if (preg_match('/\w:\/\/\w/i', $parts[0])) {
return new static(new Url($parts[0]), $description);
}
return new static(new FqsenRef($resolver->resolve($parts[0], $context)), $description);
} | php | public static function create(
string $body,
?FqsenResolver $resolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): self {
Assert::allNotNull([$resolver, $descriptionFactory]);
$parts = preg_split('/\s+/Su', $body, 2);
$description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null;
if (preg_match('/\w:\/\/\w/i', $parts[0])) {
return new static(new Url($parts[0]), $description);
}
return new static(new FqsenRef($resolver->resolve($parts[0], $context)), $description);
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"body",
",",
"?",
"FqsenResolver",
"$",
"resolver",
"=",
"null",
",",
"?",
"DescriptionFactory",
"$",
"descriptionFactory",
"=",
"null",
",",
"?",
"TypeContext",
"$",
"context",
"=",
"null",
")",
":",
"self",
"{",
"Assert",
"::",
"allNotNull",
"(",
"[",
"$",
"resolver",
",",
"$",
"descriptionFactory",
"]",
")",
";",
"$",
"parts",
"=",
"preg_split",
"(",
"'/\\s+/Su'",
",",
"$",
"body",
",",
"2",
")",
";",
"$",
"description",
"=",
"isset",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
"?",
"$",
"descriptionFactory",
"->",
"create",
"(",
"$",
"parts",
"[",
"1",
"]",
",",
"$",
"context",
")",
":",
"null",
";",
"// https://tools.ietf.org/html/rfc2396#section-3",
"if",
"(",
"preg_match",
"(",
"'/\\w:\\/\\/\\w/i'",
",",
"$",
"parts",
"[",
"0",
"]",
")",
")",
"{",
"return",
"new",
"static",
"(",
"new",
"Url",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
",",
"$",
"description",
")",
";",
"}",
"return",
"new",
"static",
"(",
"new",
"FqsenRef",
"(",
"$",
"resolver",
"->",
"resolve",
"(",
"$",
"parts",
"[",
"0",
"]",
",",
"$",
"context",
")",
")",
",",
"$",
"description",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock/Tags/See.php#L47-L64 |
phpDocumentor/ReflectionDocBlock | src/DocBlock/Tags/Link.php | Link.create | public static function create(string $body, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null): self
{
Assert::notNull($descriptionFactory);
$parts = preg_split('/\s+/Su', $body, 2);
$description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null;
return new static($parts[0], $description);
} | php | public static function create(string $body, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null): self
{
Assert::notNull($descriptionFactory);
$parts = preg_split('/\s+/Su', $body, 2);
$description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null;
return new static($parts[0], $description);
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"body",
",",
"?",
"DescriptionFactory",
"$",
"descriptionFactory",
"=",
"null",
",",
"?",
"TypeContext",
"$",
"context",
"=",
"null",
")",
":",
"self",
"{",
"Assert",
"::",
"notNull",
"(",
"$",
"descriptionFactory",
")",
";",
"$",
"parts",
"=",
"preg_split",
"(",
"'/\\s+/Su'",
",",
"$",
"body",
",",
"2",
")",
";",
"$",
"description",
"=",
"isset",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
"?",
"$",
"descriptionFactory",
"->",
"create",
"(",
"$",
"parts",
"[",
"1",
"]",
",",
"$",
"context",
")",
":",
"null",
";",
"return",
"new",
"static",
"(",
"$",
"parts",
"[",
"0",
"]",
",",
"$",
"description",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock/Tags/Link.php#L43-L51 |
phpDocumentor/ReflectionDocBlock | src/DocBlock/Tags/Throws.php | Throws.create | public static function create(
string $body,
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): self {
Assert::allNotNull([$typeResolver, $descriptionFactory]);
$parts = preg_split('/\s+/Su', $body, 2);
$type = $typeResolver->resolve($parts[0] ?? '', $context);
$description = $descriptionFactory->create($parts[1] ?? '', $context);
return new static($type, $description);
} | php | public static function create(
string $body,
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): self {
Assert::allNotNull([$typeResolver, $descriptionFactory]);
$parts = preg_split('/\s+/Su', $body, 2);
$type = $typeResolver->resolve($parts[0] ?? '', $context);
$description = $descriptionFactory->create($parts[1] ?? '', $context);
return new static($type, $description);
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"body",
",",
"?",
"TypeResolver",
"$",
"typeResolver",
"=",
"null",
",",
"?",
"DescriptionFactory",
"$",
"descriptionFactory",
"=",
"null",
",",
"?",
"TypeContext",
"$",
"context",
"=",
"null",
")",
":",
"self",
"{",
"Assert",
"::",
"allNotNull",
"(",
"[",
"$",
"typeResolver",
",",
"$",
"descriptionFactory",
"]",
")",
";",
"$",
"parts",
"=",
"preg_split",
"(",
"'/\\s+/Su'",
",",
"$",
"body",
",",
"2",
")",
";",
"$",
"type",
"=",
"$",
"typeResolver",
"->",
"resolve",
"(",
"$",
"parts",
"[",
"0",
"]",
"??",
"''",
",",
"$",
"context",
")",
";",
"$",
"description",
"=",
"$",
"descriptionFactory",
"->",
"create",
"(",
"$",
"parts",
"[",
"1",
"]",
"??",
"''",
",",
"$",
"context",
")",
";",
"return",
"new",
"static",
"(",
"$",
"type",
",",
"$",
"description",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock/Tags/Throws.php#L42-L56 |
phpDocumentor/ReflectionDocBlock | src/DocBlock/Tags/Covers.php | Covers.create | public static function create(
string $body,
?DescriptionFactory $descriptionFactory = null,
?FqsenResolver $resolver = null,
?TypeContext $context = null
): self {
Assert::notEmpty($body);
$parts = preg_split('/\s+/Su', $body, 2);
return new static(
$resolver->resolve($parts[0], $context),
$descriptionFactory->create($parts[1] ?? '', $context)
);
} | php | public static function create(
string $body,
?DescriptionFactory $descriptionFactory = null,
?FqsenResolver $resolver = null,
?TypeContext $context = null
): self {
Assert::notEmpty($body);
$parts = preg_split('/\s+/Su', $body, 2);
return new static(
$resolver->resolve($parts[0], $context),
$descriptionFactory->create($parts[1] ?? '', $context)
);
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"body",
",",
"?",
"DescriptionFactory",
"$",
"descriptionFactory",
"=",
"null",
",",
"?",
"FqsenResolver",
"$",
"resolver",
"=",
"null",
",",
"?",
"TypeContext",
"$",
"context",
"=",
"null",
")",
":",
"self",
"{",
"Assert",
"::",
"notEmpty",
"(",
"$",
"body",
")",
";",
"$",
"parts",
"=",
"preg_split",
"(",
"'/\\s+/Su'",
",",
"$",
"body",
",",
"2",
")",
";",
"return",
"new",
"static",
"(",
"$",
"resolver",
"->",
"resolve",
"(",
"$",
"parts",
"[",
"0",
"]",
",",
"$",
"context",
")",
",",
"$",
"descriptionFactory",
"->",
"create",
"(",
"$",
"parts",
"[",
"1",
"]",
"??",
"''",
",",
"$",
"context",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock/Tags/Covers.php#L45-L59 |
phpDocumentor/ReflectionDocBlock | src/DocBlock/ExampleFinder.php | ExampleFinder.find | public function find(Example $example): string
{
$filename = $example->getFilePath();
$file = $this->getExampleFileContents($filename);
if (!$file) {
return "** File not found : {$filename} **";
}
return implode('', array_slice($file, $example->getStartingLine() - 1, $example->getLineCount()));
} | php | public function find(Example $example): string
{
$filename = $example->getFilePath();
$file = $this->getExampleFileContents($filename);
if (!$file) {
return "** File not found : {$filename} **";
}
return implode('', array_slice($file, $example->getStartingLine() - 1, $example->getLineCount()));
} | [
"public",
"function",
"find",
"(",
"Example",
"$",
"example",
")",
":",
"string",
"{",
"$",
"filename",
"=",
"$",
"example",
"->",
"getFilePath",
"(",
")",
";",
"$",
"file",
"=",
"$",
"this",
"->",
"getExampleFileContents",
"(",
"$",
"filename",
")",
";",
"if",
"(",
"!",
"$",
"file",
")",
"{",
"return",
"\"** File not found : {$filename} **\"",
";",
"}",
"return",
"implode",
"(",
"''",
",",
"array_slice",
"(",
"$",
"file",
",",
"$",
"example",
"->",
"getStartingLine",
"(",
")",
"-",
"1",
",",
"$",
"example",
"->",
"getLineCount",
"(",
")",
")",
")",
";",
"}"
] | Attempts to find the example contents for the given descriptor. | [
"Attempts",
"to",
"find",
"the",
"example",
"contents",
"for",
"the",
"given",
"descriptor",
"."
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock/ExampleFinder.php#L32-L42 |
phpDocumentor/ReflectionDocBlock | src/DocBlockFactory.php | DocBlockFactory.createInstance | public static function createInstance(array $additionalTags = []): self
{
$fqsenResolver = new FqsenResolver();
$tagFactory = new StandardTagFactory($fqsenResolver);
$descriptionFactory = new DescriptionFactory($tagFactory);
$tagFactory->addService($descriptionFactory);
$tagFactory->addService(new TypeResolver($fqsenResolver));
$docBlockFactory = new self($descriptionFactory, $tagFactory);
foreach ($additionalTags as $tagName => $tagHandler) {
$docBlockFactory->registerTagHandler($tagName, $tagHandler);
}
return $docBlockFactory;
} | php | public static function createInstance(array $additionalTags = []): self
{
$fqsenResolver = new FqsenResolver();
$tagFactory = new StandardTagFactory($fqsenResolver);
$descriptionFactory = new DescriptionFactory($tagFactory);
$tagFactory->addService($descriptionFactory);
$tagFactory->addService(new TypeResolver($fqsenResolver));
$docBlockFactory = new self($descriptionFactory, $tagFactory);
foreach ($additionalTags as $tagName => $tagHandler) {
$docBlockFactory->registerTagHandler($tagName, $tagHandler);
}
return $docBlockFactory;
} | [
"public",
"static",
"function",
"createInstance",
"(",
"array",
"$",
"additionalTags",
"=",
"[",
"]",
")",
":",
"self",
"{",
"$",
"fqsenResolver",
"=",
"new",
"FqsenResolver",
"(",
")",
";",
"$",
"tagFactory",
"=",
"new",
"StandardTagFactory",
"(",
"$",
"fqsenResolver",
")",
";",
"$",
"descriptionFactory",
"=",
"new",
"DescriptionFactory",
"(",
"$",
"tagFactory",
")",
";",
"$",
"tagFactory",
"->",
"addService",
"(",
"$",
"descriptionFactory",
")",
";",
"$",
"tagFactory",
"->",
"addService",
"(",
"new",
"TypeResolver",
"(",
"$",
"fqsenResolver",
")",
")",
";",
"$",
"docBlockFactory",
"=",
"new",
"self",
"(",
"$",
"descriptionFactory",
",",
"$",
"tagFactory",
")",
";",
"foreach",
"(",
"$",
"additionalTags",
"as",
"$",
"tagName",
"=>",
"$",
"tagHandler",
")",
"{",
"$",
"docBlockFactory",
"->",
"registerTagHandler",
"(",
"$",
"tagName",
",",
"$",
"tagHandler",
")",
";",
"}",
"return",
"$",
"docBlockFactory",
";",
"}"
] | Factory method for easy instantiation.
@param string[] $additionalTags | [
"Factory",
"method",
"for",
"easy",
"instantiation",
"."
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlockFactory.php#L44-L59 |
phpDocumentor/ReflectionDocBlock | src/DocBlockFactory.php | DocBlockFactory.stripDocComment | private function stripDocComment(string $comment): string
{
$comment = trim(preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ \t]{0,1}(.*)?#u', '$1', $comment));
// reg ex above is not able to remove */ from a single line docblock
if (substr($comment, -2) === '*/') {
$comment = trim(substr($comment, 0, -2));
}
return str_replace(["\r\n", "\r"], "\n", $comment);
} | php | private function stripDocComment(string $comment): string
{
$comment = trim(preg_replace('
if (substr($comment, -2) === '*/') {
$comment = trim(substr($comment, 0, -2));
}
return str_replace(["\r\n", "\r"], "\n", $comment);
} | [
"private",
"function",
"stripDocComment",
"(",
"string",
"$",
"comment",
")",
":",
"string",
"{",
"$",
"comment",
"=",
"trim",
"(",
"preg_replace",
"(",
"'#[ \\t]*(?:\\/\\*\\*|\\*\\/|\\*)?[ \\t]{0,1}(.*)?#u'",
",",
"'$1'",
",",
"$",
"comment",
")",
")",
";",
"// reg ex above is not able to remove */ from a single line docblock",
"if",
"(",
"substr",
"(",
"$",
"comment",
",",
"-",
"2",
")",
"===",
"'*/'",
")",
"{",
"$",
"comment",
"=",
"trim",
"(",
"substr",
"(",
"$",
"comment",
",",
"0",
",",
"-",
"2",
")",
")",
";",
"}",
"return",
"str_replace",
"(",
"[",
"\"\\r\\n\"",
",",
"\"\\r\"",
"]",
",",
"\"\\n\"",
",",
"$",
"comment",
")",
";",
"}"
] | Strips the asterisks from the DocBlock comment.
@param string $comment String containing the comment text. | [
"Strips",
"the",
"asterisks",
"from",
"the",
"DocBlock",
"comment",
"."
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlockFactory.php#L108-L118 |
phpDocumentor/ReflectionDocBlock | src/DocBlockFactory.php | DocBlockFactory.splitDocBlock | private function splitDocBlock(string $comment): array
{
// Performance improvement cheat: if the first character is an @ then only tags are in this DocBlock. This
// method does not split tags so we return this verbatim as the fourth result (tags). This saves us the
// performance impact of running a regular expression
if (strpos($comment, '@') === 0) {
return ['', '', '', $comment];
}
// clears all extra horizontal whitespace from the line endings to prevent parsing issues
$comment = preg_replace('/\h*$/Sum', '', $comment);
/*
* Splits the docblock into a template marker, summary, description and tags section.
*
* - The template marker is empty, #@+ or #@- if the DocBlock starts with either of those (a newline may
* occur after it and will be stripped).
* - The short description is started from the first character until a dot is encountered followed by a
* newline OR two consecutive newlines (horizontal whitespace is taken into account to consider spacing
* errors). This is optional.
* - The long description, any character until a new line is encountered followed by an @ and word
* characters (a tag). This is optional.
* - Tags; the remaining characters
*
* Big thanks to RichardJ for contributing this Regular Expression
*/
preg_match(
'/
\A
# 1. Extract the template marker
(?:(\#\@\+|\#\@\-)\n?)?
# 2. Extract the summary
(?:
(?! @\pL ) # The summary may not start with an @
(
[^\n.]+
(?:
(?! \. \n | \n{2} ) # End summary upon a dot followed by newline or two newlines
[\n.]* (?! [ \t]* @\pL ) # End summary when an @ is found as first character on a new line
[^\n.]+ # Include anything else
)*
\.?
)?
)
# 3. Extract the description
(?:
\s* # Some form of whitespace _must_ precede a description because a summary must be there
(?! @\pL ) # The description may not start with an @
(
[^\n]+
(?: \n+
(?! [ \t]* @\pL ) # End description when an @ is found as first character on a new line
[^\n]+ # Include anything else
)*
)
)?
# 4. Extract the tags (anything that follows)
(\s+ [\s\S]*)? # everything that follows
/ux',
$comment,
$matches
);
array_shift($matches);
while (count($matches) < 4) {
$matches[] = '';
}
return $matches;
} | php | private function splitDocBlock(string $comment): array
{
if (strpos($comment, '@') === 0) {
return ['', '', '', $comment];
}
$comment = preg_replace('/\h*$/Sum', '', $comment);
preg_match(
'/
\A
(?:(\
(?:
(?! @\pL )
(
[^\n.]+
(?:
(?! \. \n | \n{2} )
[\n.]* (?! [ \t]* @\pL )
[^\n.]+
)*
\.?
)?
)
(?:
\s*
(?! @\pL )
(
[^\n]+
(?: \n+
(?! [ \t]* @\pL )
[^\n]+
)*
)
)?
(\s+ [\s\S]*)?
/ux',
$comment,
$matches
);
array_shift($matches);
while (count($matches) < 4) {
$matches[] = '';
}
return $matches;
} | [
"private",
"function",
"splitDocBlock",
"(",
"string",
"$",
"comment",
")",
":",
"array",
"{",
"// Performance improvement cheat: if the first character is an @ then only tags are in this DocBlock. This",
"// method does not split tags so we return this verbatim as the fourth result (tags). This saves us the",
"// performance impact of running a regular expression",
"if",
"(",
"strpos",
"(",
"$",
"comment",
",",
"'@'",
")",
"===",
"0",
")",
"{",
"return",
"[",
"''",
",",
"''",
",",
"''",
",",
"$",
"comment",
"]",
";",
"}",
"// clears all extra horizontal whitespace from the line endings to prevent parsing issues",
"$",
"comment",
"=",
"preg_replace",
"(",
"'/\\h*$/Sum'",
",",
"''",
",",
"$",
"comment",
")",
";",
"/*\n * Splits the docblock into a template marker, summary, description and tags section.\n *\n * - The template marker is empty, #@+ or #@- if the DocBlock starts with either of those (a newline may\n * occur after it and will be stripped).\n * - The short description is started from the first character until a dot is encountered followed by a\n * newline OR two consecutive newlines (horizontal whitespace is taken into account to consider spacing\n * errors). This is optional.\n * - The long description, any character until a new line is encountered followed by an @ and word\n * characters (a tag). This is optional.\n * - Tags; the remaining characters\n *\n * Big thanks to RichardJ for contributing this Regular Expression\n */",
"preg_match",
"(",
"'/\n \\A\n # 1. Extract the template marker\n (?:(\\#\\@\\+|\\#\\@\\-)\\n?)?\n\n # 2. Extract the summary\n (?:\n (?! @\\pL ) # The summary may not start with an @\n (\n [^\\n.]+\n (?:\n (?! \\. \\n | \\n{2} ) # End summary upon a dot followed by newline or two newlines\n [\\n.]* (?! [ \\t]* @\\pL ) # End summary when an @ is found as first character on a new line\n [^\\n.]+ # Include anything else\n )*\n \\.?\n )?\n )\n\n # 3. Extract the description\n (?:\n \\s* # Some form of whitespace _must_ precede a description because a summary must be there\n (?! @\\pL ) # The description may not start with an @\n (\n [^\\n]+\n (?: \\n+\n (?! [ \\t]* @\\pL ) # End description when an @ is found as first character on a new line\n [^\\n]+ # Include anything else\n )*\n )\n )?\n\n # 4. Extract the tags (anything that follows)\n (\\s+ [\\s\\S]*)? # everything that follows\n /ux'",
",",
"$",
"comment",
",",
"$",
"matches",
")",
";",
"array_shift",
"(",
"$",
"matches",
")",
";",
"while",
"(",
"count",
"(",
"$",
"matches",
")",
"<",
"4",
")",
"{",
"$",
"matches",
"[",
"]",
"=",
"''",
";",
"}",
"return",
"$",
"matches",
";",
"}"
] | Splits the DocBlock into a template marker, summary, description and block of tags.
@param string $comment Comment to split into the sub-parts.
@author Richard van Velzen (@_richardJ) Special thanks to Richard for the regex responsible for the split.
@author Mike van Riel <[email protected]> for extending the regex with template marker support.
@return string[] containing the template marker (if any), summary, description and a string containing the tags. | [
"Splits",
"the",
"DocBlock",
"into",
"a",
"template",
"marker",
"summary",
"description",
"and",
"block",
"of",
"tags",
"."
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlockFactory.php#L130-L202 |
phpDocumentor/ReflectionDocBlock | src/DocBlockFactory.php | DocBlockFactory.parseTagBlock | private function parseTagBlock(string $tags, Types\Context $context): array
{
$tags = $this->filterTagBlock($tags);
if (!$tags) {
return [];
}
$result = $this->splitTagBlockIntoTagLines($tags);
foreach ($result as $key => $tagLine) {
$result[$key] = $this->tagFactory->create(trim($tagLine), $context);
}
return $result;
} | php | private function parseTagBlock(string $tags, Types\Context $context): array
{
$tags = $this->filterTagBlock($tags);
if (!$tags) {
return [];
}
$result = $this->splitTagBlockIntoTagLines($tags);
foreach ($result as $key => $tagLine) {
$result[$key] = $this->tagFactory->create(trim($tagLine), $context);
}
return $result;
} | [
"private",
"function",
"parseTagBlock",
"(",
"string",
"$",
"tags",
",",
"Types",
"\\",
"Context",
"$",
"context",
")",
":",
"array",
"{",
"$",
"tags",
"=",
"$",
"this",
"->",
"filterTagBlock",
"(",
"$",
"tags",
")",
";",
"if",
"(",
"!",
"$",
"tags",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"splitTagBlockIntoTagLines",
"(",
"$",
"tags",
")",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"key",
"=>",
"$",
"tagLine",
")",
"{",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"tagFactory",
"->",
"create",
"(",
"trim",
"(",
"$",
"tagLine",
")",
",",
"$",
"context",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Creates the tag objects.
@param string $tags Tag block to parse.
@param Types\Context $context Context of the parsed Tag
@return DocBlock\Tag[]|string[]|null[] | [
"Creates",
"the",
"tag",
"objects",
"."
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlockFactory.php#L212-L225 |
phpDocumentor/ReflectionDocBlock | src/DocBlock/Tags/Example.php | Example.getContent | public function getContent()
{
if (null === $this->description) {
$filePath = '"' . $this->filePath . '"';
if ($this->isURI) {
$filePath = $this->isUriRelative($this->filePath)
? str_replace('%2F', '/', rawurlencode($this->filePath))
: $this->filePath;
}
return trim($filePath . ' ' . parent::getDescription());
}
return $this->description;
} | php | public function getContent()
{
if (null === $this->description) {
$filePath = '"' . $this->filePath . '"';
if ($this->isURI) {
$filePath = $this->isUriRelative($this->filePath)
? str_replace('%2F', '/', rawurlencode($this->filePath))
: $this->filePath;
}
return trim($filePath . ' ' . parent::getDescription());
}
return $this->description;
} | [
"public",
"function",
"getContent",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"description",
")",
"{",
"$",
"filePath",
"=",
"'\"'",
".",
"$",
"this",
"->",
"filePath",
".",
"'\"'",
";",
"if",
"(",
"$",
"this",
"->",
"isURI",
")",
"{",
"$",
"filePath",
"=",
"$",
"this",
"->",
"isUriRelative",
"(",
"$",
"this",
"->",
"filePath",
")",
"?",
"str_replace",
"(",
"'%2F'",
",",
"'/'",
",",
"rawurlencode",
"(",
"$",
"this",
"->",
"filePath",
")",
")",
":",
"$",
"this",
"->",
"filePath",
";",
"}",
"return",
"trim",
"(",
"$",
"filePath",
".",
"' '",
".",
"parent",
"::",
"getDescription",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"description",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock/Tags/Example.php#L65-L79 |
phpDocumentor/ReflectionDocBlock | src/DocBlock/Tags/Example.php | Example.create | public static function create(string $body): ?Tag
{
// File component: File path in quotes or File URI / Source information
if (! preg_match('/^(?:\"([^\"]+)\"|(\S+))(?:\s+(.*))?$/sux', $body, $matches)) {
return null;
}
$filePath = null;
$fileUri = null;
if ('' !== $matches[1]) {
$filePath = $matches[1];
} else {
$fileUri = $matches[2];
}
$startingLine = 1;
$lineCount = 0;
$description = null;
if (array_key_exists(3, $matches)) {
$description = $matches[3];
// Starting line / Number of lines / Description
if (preg_match('/^([1-9]\d*)(?:\s+((?1))\s*)?(.*)$/sux', $matches[3], $contentMatches)) {
$startingLine = (int) $contentMatches[1];
if (isset($contentMatches[2]) && $contentMatches[2] !== '') {
$lineCount = (int) $contentMatches[2];
}
if (array_key_exists(3, $contentMatches)) {
$description = $contentMatches[3];
}
}
}
return new static(
$filePath !== null ? $filePath : $fileUri,
$fileUri !== null,
$startingLine,
$lineCount,
$description
);
} | php | public static function create(string $body): ?Tag
{
if (! preg_match('/^(?:\"([^\"]+)\"|(\S+))(?:\s+(.*))?$/sux', $body, $matches)) {
return null;
}
$filePath = null;
$fileUri = null;
if ('' !== $matches[1]) {
$filePath = $matches[1];
} else {
$fileUri = $matches[2];
}
$startingLine = 1;
$lineCount = 0;
$description = null;
if (array_key_exists(3, $matches)) {
$description = $matches[3];
if (preg_match('/^([1-9]\d*)(?:\s+((?1))\s*)?(.*)$/sux', $matches[3], $contentMatches)) {
$startingLine = (int) $contentMatches[1];
if (isset($contentMatches[2]) && $contentMatches[2] !== '') {
$lineCount = (int) $contentMatches[2];
}
if (array_key_exists(3, $contentMatches)) {
$description = $contentMatches[3];
}
}
}
return new static(
$filePath !== null ? $filePath : $fileUri,
$fileUri !== null,
$startingLine,
$lineCount,
$description
);
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"body",
")",
":",
"?",
"Tag",
"{",
"// File component: File path in quotes or File URI / Source information",
"if",
"(",
"!",
"preg_match",
"(",
"'/^(?:\\\"([^\\\"]+)\\\"|(\\S+))(?:\\s+(.*))?$/sux'",
",",
"$",
"body",
",",
"$",
"matches",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"filePath",
"=",
"null",
";",
"$",
"fileUri",
"=",
"null",
";",
"if",
"(",
"''",
"!==",
"$",
"matches",
"[",
"1",
"]",
")",
"{",
"$",
"filePath",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"fileUri",
"=",
"$",
"matches",
"[",
"2",
"]",
";",
"}",
"$",
"startingLine",
"=",
"1",
";",
"$",
"lineCount",
"=",
"0",
";",
"$",
"description",
"=",
"null",
";",
"if",
"(",
"array_key_exists",
"(",
"3",
",",
"$",
"matches",
")",
")",
"{",
"$",
"description",
"=",
"$",
"matches",
"[",
"3",
"]",
";",
"// Starting line / Number of lines / Description",
"if",
"(",
"preg_match",
"(",
"'/^([1-9]\\d*)(?:\\s+((?1))\\s*)?(.*)$/sux'",
",",
"$",
"matches",
"[",
"3",
"]",
",",
"$",
"contentMatches",
")",
")",
"{",
"$",
"startingLine",
"=",
"(",
"int",
")",
"$",
"contentMatches",
"[",
"1",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"contentMatches",
"[",
"2",
"]",
")",
"&&",
"$",
"contentMatches",
"[",
"2",
"]",
"!==",
"''",
")",
"{",
"$",
"lineCount",
"=",
"(",
"int",
")",
"$",
"contentMatches",
"[",
"2",
"]",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"3",
",",
"$",
"contentMatches",
")",
")",
"{",
"$",
"description",
"=",
"$",
"contentMatches",
"[",
"3",
"]",
";",
"}",
"}",
"}",
"return",
"new",
"static",
"(",
"$",
"filePath",
"!==",
"null",
"?",
"$",
"filePath",
":",
"$",
"fileUri",
",",
"$",
"fileUri",
"!==",
"null",
",",
"$",
"startingLine",
",",
"$",
"lineCount",
",",
"$",
"description",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock/Tags/Example.php#L84-L126 |
phpDocumentor/ReflectionDocBlock | src/DocBlock/Tags/Formatter/AlignFormatter.php | AlignFormatter.format | public function format(Tag $tag): string
{
return '@' . $tag->getName() . str_repeat(' ', $this->maxLen - strlen($tag->getName()) + 1) . (string) $tag;
} | php | public function format(Tag $tag): string
{
return '@' . $tag->getName() . str_repeat(' ', $this->maxLen - strlen($tag->getName()) + 1) . (string) $tag;
} | [
"public",
"function",
"format",
"(",
"Tag",
"$",
"tag",
")",
":",
"string",
"{",
"return",
"'@'",
".",
"$",
"tag",
"->",
"getName",
"(",
")",
".",
"str_repeat",
"(",
"' '",
",",
"$",
"this",
"->",
"maxLen",
"-",
"strlen",
"(",
"$",
"tag",
"->",
"getName",
"(",
")",
")",
"+",
"1",
")",
".",
"(",
"string",
")",
"$",
"tag",
";",
"}"
] | Formats the given tag to return a simple plain text version. | [
"Formats",
"the",
"given",
"tag",
"to",
"return",
"a",
"simple",
"plain",
"text",
"version",
"."
] | train | https://github.com/phpDocumentor/ReflectionDocBlock/blob/48351665a881883231add24fbb7ef869adca2316/src/DocBlock/Tags/Formatter/AlignFormatter.php#L40-L43 |