From 580c3f4ffe9608d2beb56d418c68b3b112420e76 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 10 Nov 2019 12:49:51 +0000 Subject: another bulk of composer updates (cherry picked from commit 6685381fd8db507493c3d7c1793f8c05c681bbce) --- vendor/sabre/dav/lib/CalDAV/ICSExportPlugin.php | 154 ++++++++++++------------ 1 file changed, 79 insertions(+), 75 deletions(-) (limited to 'vendor/sabre/dav/lib/CalDAV/ICSExportPlugin.php') diff --git a/vendor/sabre/dav/lib/CalDAV/ICSExportPlugin.php b/vendor/sabre/dav/lib/CalDAV/ICSExportPlugin.php index fc8b971f3..717d3a9c9 100644 --- a/vendor/sabre/dav/lib/CalDAV/ICSExportPlugin.php +++ b/vendor/sabre/dav/lib/CalDAV/ICSExportPlugin.php @@ -1,5 +1,7 @@ server = $server; $server->on('method:GET', [$this, 'httpGet'], 90); - $server->on('browserButtonActions', function($path, $node, &$actions) { + $server->on('browserButtonActions', function ($path, $node, &$actions) { if ($node instanceof ICalendar) { - $actions .= ''; + $actions .= ''; } }); - } /** * Intercepts GET requests on calendar urls ending with ?export. * - * @param RequestInterface $request + * @param RequestInterface $request * @param ResponseInterface $response + * + * @throws BadRequest + * @throws DAV\Exception\NotFound + * @throws VObject\InvalidDataException + * * @return bool */ - function httpGet(RequestInterface $request, ResponseInterface $response) { - + public function httpGet(RequestInterface $request, ResponseInterface $response) + { $queryParams = $request->getQueryParameters(); - if (!array_key_exists('export', $queryParams)) return; + if (!array_key_exists('export', $queryParams)) { + return; + } $path = $request->getPath(); @@ -93,7 +100,7 @@ class ICSExportPlugin extends DAV\ServerPlugin { '{http://apple.com/ns/ical/}calendar-color', ]); - if (!isset($node['{DAV:}resourcetype']) || !$node['{DAV:}resourcetype']->is('{' . Plugin::NS_CALDAV . '}calendar')) { + if (!isset($node['{DAV:}resourcetype']) || !$node['{DAV:}resourcetype']->is('{'.Plugin::NS_CALDAV.'}calendar')) { return; } // Marking the transactionType, for logging purposes. @@ -117,7 +124,7 @@ class ICSExportPlugin extends DAV\ServerPlugin { } $end = DateTime::createFromFormat('U', $queryParams['end']); } - if (isset($queryParams['expand']) && !!$queryParams['expand']) { + if (isset($queryParams['expand']) && (bool) $queryParams['expand']) { if (!$start || !$end) { throw new BadRequest('If you\'d like to expand recurrences, you must specify both a start= and end= parameter.'); } @@ -126,12 +133,12 @@ class ICSExportPlugin extends DAV\ServerPlugin { } if (isset($queryParams['componentType'])) { if (!in_array($queryParams['componentType'], ['VEVENT', 'VTODO', 'VJOURNAL'])) { - throw new BadRequest('You are not allowed to search for components of type: ' . $queryParams['componentType'] . ' here'); + throw new BadRequest('You are not allowed to search for components of type: '.$queryParams['componentType'].' here'); } $componentType = $queryParams['componentType']; } - $format = \Sabre\HTTP\Util::Negotiate( + $format = \Sabre\HTTP\negotiateContentType( $request->getHeader('Accept'), [ 'text/calendar', @@ -140,7 +147,7 @@ class ICSExportPlugin extends DAV\ServerPlugin { ); if (isset($queryParams['accept'])) { - if ($queryParams['accept'] === 'application/calendar+json' || $queryParams['accept'] === 'jcal') { + if ('application/calendar+json' === $queryParams['accept'] || 'jcal' === $queryParams['accept']) { $format = 'application/calendar+json'; } } @@ -152,61 +159,61 @@ class ICSExportPlugin extends DAV\ServerPlugin { // Returning false to break the event chain return false; - } /** * This method is responsible for generating the actual, full response. * - * @param string $path - * @param DateTime|null $start - * @param DateTime|null $end - * @param bool $expand - * @param string $componentType - * @param string $format - * @param array $properties + * @param string $path + * @param DateTime|null $start + * @param DateTime|null $end + * @param bool $expand + * @param string $componentType + * @param string $format + * @param array $properties * @param ResponseInterface $response + * + * @throws DAV\Exception\NotFound + * @throws VObject\InvalidDataException */ - protected function generateResponse($path, $start, $end, $expand, $componentType, $format, $properties, ResponseInterface $response) { - - $calDataProp = '{' . Plugin::NS_CALDAV . '}calendar-data'; + protected function generateResponse($path, $start, $end, $expand, $componentType, $format, $properties, ResponseInterface $response) + { + $calDataProp = '{'.Plugin::NS_CALDAV.'}calendar-data'; $calendarNode = $this->server->tree->getNodeForPath($path); $blobs = []; if ($start || $end || $componentType) { - // If there was a start or end filter, we need to enlist // calendarQuery for speed. $queryResult = $calendarNode->calendarQuery([ - 'name' => 'VCALENDAR', + 'name' => 'VCALENDAR', 'comp-filters' => [ [ - 'name' => $componentType, - 'comp-filters' => [], - 'prop-filters' => [], + 'name' => $componentType, + 'comp-filters' => [], + 'prop-filters' => [], 'is-not-defined' => false, - 'time-range' => [ + 'time-range' => [ 'start' => $start, - 'end' => $end, + 'end' => $end, ], ], ], - 'prop-filters' => [], + 'prop-filters' => [], 'is-not-defined' => false, - 'time-range' => null, + 'time-range' => null, ]); // queryResult is just a list of base urls. We need to prefix the // calendar path. $queryResult = array_map( - function($item) use ($path) { - return $path . '/' . $item; + function ($item) use ($path) { + return $path.'/'.$item; }, $queryResult ); $nodes = $this->server->getPropertiesForMultiplePaths($queryResult, [$calDataProp]); unset($queryResult); - } else { $nodes = $this->server->getPropertiesForPath($path, [$calDataProp], 1); } @@ -228,7 +235,7 @@ class ICSExportPlugin extends DAV\ServerPlugin { $calendarTimeZone = null; // We're expanding, and for that we need to figure out the // calendar's timezone. - $tzProp = '{' . Plugin::NS_CALDAV . '}calendar-timezone'; + $tzProp = '{'.Plugin::NS_CALDAV.'}calendar-timezone'; $tzResult = $this->server->getProperties($path, [$tzProp]); if (isset($tzResult[$tzProp])) { // This property contains a VCALENDAR with a single @@ -249,11 +256,11 @@ class ICSExportPlugin extends DAV\ServerPlugin { $filenameExtension = '.ics'; switch ($format) { - case 'text/calendar' : + case 'text/calendar': $mergedCalendar = $mergedCalendar->serialize(); $filenameExtension = '.ics'; break; - case 'application/calendar+json' : + case 'application/calendar+json': $mergedCalendar = json_encode($mergedCalendar->jsonSerialize()); $filenameExtension = '.json'; break; @@ -264,29 +271,29 @@ class ICSExportPlugin extends DAV\ServerPlugin { '', $calendarNode->getName() ); - $filename .= '-' . date('Y-m-d') . $filenameExtension; + $filename .= '-'.date('Y-m-d').$filenameExtension; - $response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"'); + $response->setHeader('Content-Disposition', 'attachment; filename="'.$filename.'"'); $response->setHeader('Content-Type', $format); $response->setStatus(200); $response->setBody($mergedCalendar); - } /** * Merges all calendar objects, and builds one big iCalendar blob. * - * @param array $properties Some CalDAV properties + * @param array $properties Some CalDAV properties * @param array $inputObjects + * * @return VObject\Component\VCalendar */ - function mergeObjects(array $properties, array $inputObjects) { - + public function mergeObjects(array $properties, array $inputObjects) + { $calendar = new VObject\Component\VCalendar(); $calendar->VERSION = '2.0'; if (DAV\Server::$exposeVersion) { - $calendar->PRODID = '-//SabreDAV//SabreDAV ' . DAV\Version::VERSION . '//EN'; + $calendar->PRODID = '-//SabreDAV//SabreDAV '.DAV\Version::VERSION.'//EN'; } else { $calendar->PRODID = '-//SabreDAV//SabreDAV//EN'; } @@ -303,41 +310,41 @@ class ICSExportPlugin extends DAV\ServerPlugin { $objects = []; foreach ($inputObjects as $href => $inputObject) { - $nodeComp = VObject\Reader::read($inputObject); foreach ($nodeComp->children() as $child) { - switch ($child->name) { - case 'VEVENT' : - case 'VTODO' : - case 'VJOURNAL' : + case 'VEVENT': + case 'VTODO': + case 'VJOURNAL': $objects[] = clone $child; break; // VTIMEZONE is special, because we need to filter out the duplicates - case 'VTIMEZONE' : + case 'VTIMEZONE': // Naively just checking tzid. - if (in_array((string)$child->TZID, $collectedTimezones)) continue; + if (in_array((string) $child->TZID, $collectedTimezones)) { + break; + } $timezones[] = clone $child; $collectedTimezones[] = $child->TZID; break; - } - } // Destroy circular references to PHP will GC the object. $nodeComp->destroy(); unset($nodeComp); - } - foreach ($timezones as $tz) $calendar->add($tz); - foreach ($objects as $obj) $calendar->add($obj); + foreach ($timezones as $tz) { + $calendar->add($tz); + } + foreach ($objects as $obj) { + $calendar->add($obj); + } return $calendar; - } /** @@ -348,10 +355,9 @@ class ICSExportPlugin extends DAV\ServerPlugin { * * @return string */ - function getPluginName() { - + public function getPluginName() + { return 'ics-export'; - } /** @@ -365,14 +371,12 @@ class ICSExportPlugin extends DAV\ServerPlugin { * * @return array */ - function getPluginInfo() { - + public function getPluginInfo() + { return [ - 'name' => $this->getPluginName(), + 'name' => $this->getPluginName(), 'description' => 'Adds the ability to export CalDAV calendars as a single iCalendar file.', - 'link' => 'http://sabre.io/dav/ics-export-plugin/', + 'link' => 'http://sabre.io/dav/ics-export-plugin/', ]; - } - } -- cgit v1.2.3