Update vendor folder

This commit is contained in:
Frédéric Guillot
2020-08-17 21:21:20 -07:00
parent d958ddef2c
commit 81019680fa
81 changed files with 1655 additions and 1683 deletions

View File

@@ -23,7 +23,7 @@ abstract class Component
*
* @var Component[]
*/
protected $components = array();
protected $components = [];
/**
* The order in which the components will be rendered during build.
@@ -32,7 +32,7 @@ abstract class Component
*
* @var array
*/
private $componentsBuildOrder = array('VTIMEZONE', 'DAYLIGHT', 'STANDARD');
private $componentsBuildOrder = ['VTIMEZONE', 'DAYLIGHT', 'STANDARD'];
/**
* The type of the concrete Component.
@@ -60,7 +60,7 @@ abstract class Component
* @param Component $component The Component that will be added
* @param null $key The key of the Component
*/
public function addComponent(Component $component, $key = null)
public function addComponent(self $component, $key = null)
{
if (null == $key) {
$this->components[] = $component;
@@ -69,6 +69,19 @@ abstract class Component
}
}
/**
* Set all Components.
*
* @param Component[] $components The array of Component that will be set
* @param null $key The key of the Component
*/
public function setComponents(array $components)
{
$this->components = $components;
return $this;
}
/**
* Renders an array containing the lines of the iCal file.
*
@@ -76,7 +89,7 @@ abstract class Component
*/
public function build()
{
$lines = array();
$lines = [];
$lines[] = sprintf('BEGIN:%s', $this->getType());
@@ -91,7 +104,7 @@ abstract class Component
$lines[] = sprintf('END:%s', $this->getType());
$ret = array();
$ret = [];
foreach ($lines as $line) {
foreach (ComponentUtil::fold($line) as $l) {
@@ -129,13 +142,13 @@ abstract class Component
*/
private function buildComponents(array &$lines)
{
$componentsByType = array();
$componentsByType = [];
/** @var $component Component */
foreach ($this->components as $component) {
$type = $component->getType();
if (!isset($componentsByType[$type])) {
$componentsByType[$type] = array();
$componentsByType[$type] = [];
}
$componentsByType[$type][] = $component;
}
@@ -160,10 +173,9 @@ abstract class Component
}
/**
* @param array $lines
* @param Component $component
*/
private function addComponentLines(array &$lines, Component $component)
private function addComponentLines(array &$lines, self $component)
{
foreach ($component->build() as $l) {
$lines[] = $l;

View File

@@ -13,7 +13,6 @@ namespace Eluceo\iCal\Component;
use Eluceo\iCal\Component;
use Eluceo\iCal\PropertyBag;
use Eluceo\iCal\Property;
/**
* Implementation of the VALARM component.
@@ -25,11 +24,11 @@ class Alarm extends Component
*
* According to RFC 5545: 3.8.6.1. Action
*
* @link http://tools.ietf.org/html/rfc5545#section-3.8.6.1
* @see http://tools.ietf.org/html/rfc5545#section-3.8.6.1
*/
const ACTION_AUDIO = 'AUDIO';
const ACTION_AUDIO = 'AUDIO';
const ACTION_DISPLAY = 'DISPLAY';
const ACTION_EMAIL = 'EMAIL';
const ACTION_EMAIL = 'EMAIL';
protected $action;
protected $repeat;

View File

@@ -19,20 +19,20 @@ class Calendar extends Component
/**
* Methods for calendar components.
*
* According to RFP 5545: 3.7.2. Method
* According to RFC 5545: 3.7.2. Method
*
* @link http://tools.ietf.org/html/rfc5545#section-3.7.2
* @see http://tools.ietf.org/html/rfc5545#section-3.7.2
*
* And then according to RFC 2446: 3 APPLICATION PROTOCOL ELEMENTS
* @link https://www.ietf.org/rfc/rfc2446.txt
* @see https://tools.ietf.org/html/rfc2446#section-3.2
*/
const METHOD_PUBLISH = 'PUBLISH';
const METHOD_REQUEST = 'REQUEST';
const METHOD_REPLY = 'REPLY';
const METHOD_ADD = 'ADD';
const METHOD_CANCEL = 'CANCEL';
const METHOD_REFRESH = 'REFRESH';
const METHOD_COUNTER = 'COUNTER';
const METHOD_PUBLISH = 'PUBLISH';
const METHOD_REQUEST = 'REQUEST';
const METHOD_REPLY = 'REPLY';
const METHOD_ADD = 'ADD';
const METHOD_CANCEL = 'CANCEL';
const METHOD_REFRESH = 'REFRESH';
const METHOD_COUNTER = 'COUNTER';
const METHOD_DECLINECOUNTER = 'DECLINECOUNTER';
/**
@@ -40,26 +40,26 @@ class Calendar extends Component
*
* According to RFC 5545: 3.7.1. Calendar Scale
*
* @link http://tools.ietf.org/html/rfc5545#section-3.7
* @see http://tools.ietf.org/html/rfc5545#section-3.7
*/
const CALSCALE_GREGORIAN = 'GREGORIAN';
/**
* The Product Identifier.
*
* According to RFC 2445: 4.7.3 Product Identifier
* According to RFC 5545: 3.7.3 Product Identifier
*
* This property specifies the identifier for the product that created the Calendar object.
*
* @link http://www.ietf.org/rfc/rfc2445.txt
* @see https://tools.ietf.org/html/rfc5545#section-3.7.3
*
* @var string
*/
protected $prodId = null;
protected $method = null;
protected $name = null;
protected $prodId = null;
protected $method = null;
protected $name = null;
protected $description = null;
protected $timezone = null;
protected $timezone = null;
/**
* This property defines the calendar scale used for the
@@ -96,11 +96,14 @@ class Calendar extends Component
* Specifies a suggested iCalendar file download frequency for clients and
* servers with sync capabilities.
*
* For example you can set the value to 'P1W' if the calendar should be
* synced once a week. Use 'P3H' to sync the file every 3 hours.
*
* @var string
*
* @see http://msdn.microsoft.com/en-us/library/ee178699(v=exchg.80).aspx
*/
protected $publishedTTL = 'P1W';
protected $publishedTTL = null;
/**
* Specifies a color for the calendar in calendar for Apple/Outlook.
@@ -300,8 +303,6 @@ class Calendar extends Component
*
* @see Eluceo\iCal::addComponent
* @deprecated Please, use public method addComponent() from abstract Component class
*
* @param Event $event
*/
public function addEvent(Event $event)
{
@@ -309,7 +310,7 @@ class Calendar extends Component
}
/**
* @return null|string
* @return string|null
*/
public function getProdId()
{

View File

@@ -14,26 +14,33 @@ namespace Eluceo\iCal\Component;
use Eluceo\iCal\Component;
use Eluceo\iCal\Property;
use Eluceo\iCal\Property\DateTimeProperty;
use Eluceo\iCal\Property\Event\Attendees;
use Eluceo\iCal\Property\Event\Organizer;
use Eluceo\iCal\Property\Event\RecurrenceRule;
use Eluceo\iCal\Property\Event\Description;
use Eluceo\iCal\PropertyBag;
use Eluceo\iCal\Property\Event\RecurrenceId;
use Eluceo\iCal\Property\DateTimesProperty;
use Eluceo\iCal\Property\Event\Attachment;
use Eluceo\iCal\Property\Event\Attendees;
use Eluceo\iCal\Property\Event\Geo;
use Eluceo\iCal\Property\Event\Organizer;
use Eluceo\iCal\Property\Event\RecurrenceId;
use Eluceo\iCal\Property\Event\RecurrenceRule;
use Eluceo\iCal\Property\RawStringValue;
use Eluceo\iCal\PropertyBag;
/**
* Implementation of the EVENT component.
*/
class Event extends Component
{
const TIME_TRANSPARENCY_OPAQUE = 'OPAQUE';
const TIME_TRANSPARENCY_OPAQUE = 'OPAQUE';
const TIME_TRANSPARENCY_TRANSPARENT = 'TRANSPARENT';
const STATUS_TENTATIVE = 'TENTATIVE';
const STATUS_CONFIRMED = 'CONFIRMED';
const STATUS_CANCELLED = 'CANCELLED';
const MS_BUSYSTATUS_FREE = 'FREE';
const MS_BUSYSTATUS_TENTATIVE = 'TENTATIVE';
const MS_BUSYSTATUS_BUSY = 'BUSY';
const MS_BUSYSTATUS_OOF = 'OOF';
/**
* @var string
*/
@@ -71,6 +78,11 @@ class Event extends Component
*/
protected $noTime = false;
/**
* @var string
*/
protected $msBusyStatus = null;
/**
* @var string
*/
@@ -87,7 +99,7 @@ class Event extends Component
protected $locationTitle;
/**
* @var string
* @var Geo
*/
protected $locationGeo;
@@ -102,7 +114,7 @@ class Event extends Component
protected $organizer;
/**
* @see http://www.ietf.org/rfc/rfc2445.txt 4.8.2.7 Time Transparency
* @see https://tools.ietf.org/html/rfc5545#section-3.8.2.7
*
* @var string
*/
@@ -115,6 +127,13 @@ class Event extends Component
*/
protected $useTimezone = false;
/**
* If set will be used as the timezone identifier.
*
* @var string
*/
protected $timezoneString = '';
/**
* @var int
*/
@@ -145,6 +164,11 @@ class Event extends Component
*/
protected $recurrenceRule;
/**
* @var array
*/
protected $recurrenceRules = [];
/**
* This property specifies the date and time that the calendar
* information was created.
@@ -198,22 +222,28 @@ class Event extends Component
/**
* Dates to be excluded from a series of events.
*
* @var \DateTime[]
* @var \DateTimeInterface[]
*/
protected $exDates = array();
protected $exDates = [];
/**
* @var RecurrenceId
*/
protected $recurrenceId;
public function __construct($uniqueId = null)
/**
* @var Attachment[]
*/
protected $attachments = [];
public function __construct(string $uniqueId = null)
{
if (null == $uniqueId) {
$uniqueId = uniqid();
}
$this->uniqueId = $uniqueId;
$this->attendees = new Attendees();
}
/**
@@ -234,7 +264,7 @@ class Event extends Component
// mandatory information
$propertyBag->set('UID', $this->uniqueId);
$propertyBag->add(new DateTimeProperty('DTSTART', $this->dtStart, $this->noTime, $this->useTimezone, $this->useUtc));
$propertyBag->add(new DateTimeProperty('DTSTART', $this->dtStart, $this->noTime, $this->useTimezone, $this->useUtc, $this->timezoneString));
$propertyBag->set('SEQUENCE', $this->sequence);
$propertyBag->set('TRANSP', $this->transparency);
@@ -243,9 +273,13 @@ class Event extends Component
}
// An event can have a 'dtend' or 'duration', but not both.
if (null != $this->dtEnd) {
$propertyBag->add(new DateTimeProperty('DTEND', $this->dtEnd, $this->noTime, $this->useTimezone, $this->useUtc));
} elseif (null != $this->duration) {
if ($this->dtEnd !== null) {
$dtEnd = clone $this->dtEnd;
if ($this->noTime === true) {
$dtEnd = $dtEnd->add(new \DateInterval('P1D'));
}
$propertyBag->add(new DateTimeProperty('DTEND', $dtEnd, $this->noTime, $this->useTimezone, $this->useUtc, $this->timezoneString));
} elseif ($this->duration !== null) {
$propertyBag->set('DURATION', $this->duration->format('P%dDT%hH%iM%sS'));
}
@@ -261,19 +295,22 @@ class Event extends Component
$propertyBag->add(
new Property(
'X-APPLE-STRUCTURED-LOCATION',
'geo:' . $this->locationGeo,
array(
'VALUE' => 'URI',
'X-ADDRESS' => $this->location,
new RawStringValue('geo:' . $this->locationGeo->getGeoLocationAsString(',')),
[
'VALUE' => 'URI',
'X-ADDRESS' => $this->location,
'X-APPLE-RADIUS' => 49,
'X-TITLE' => $this->locationTitle,
)
'X-TITLE' => $this->locationTitle,
]
)
);
$propertyBag->set('GEO', str_replace(',', ';', $this->locationGeo));
}
}
if (null != $this->locationGeo) {
$propertyBag->add($this->locationGeo);
}
if (null != $this->summary) {
$propertyBag->set('SUMMARY', $this->summary);
}
@@ -285,7 +322,7 @@ class Event extends Component
$propertyBag->set('CLASS', $this->isPrivate ? 'PRIVATE' : 'PUBLIC');
if (null != $this->description) {
$propertyBag->set('DESCRIPTION', new Description($this->description));
$propertyBag->set('DESCRIPTION', $this->description);
}
if (null != $this->descriptionHTML) {
@@ -293,9 +330,9 @@ class Event extends Component
new Property(
'X-ALT-DESC',
$this->descriptionHTML,
array(
[
'FMTTYPE' => 'text/html',
)
]
)
);
}
@@ -304,13 +341,17 @@ class Event extends Component
$propertyBag->set('RRULE', $this->recurrenceRule);
}
foreach ($this->recurrenceRules as $recurrenceRule) {
$propertyBag->set('RRULE', $recurrenceRule);
}
if (null != $this->recurrenceId) {
$this->recurrenceId->applyTimeSettings($this->noTime, $this->useTimezone, $this->useUtc);
$this->recurrenceId->applyTimeSettings($this->noTime, $this->useTimezone, $this->useUtc, $this->timezoneString);
$propertyBag->add($this->recurrenceId);
}
if (!empty($this->exDates)) {
$propertyBag->add(new DateTimesProperty('EXDATE', $this->exDates, $this->noTime, $this->useTimezone, $this->useUtc));
$propertyBag->add(new DateTimesProperty('EXDATE', $this->exDates, $this->noTime, $this->useTimezone, $this->useUtc, $this->timezoneString));
}
if ($this->cancelled) {
@@ -325,12 +366,17 @@ class Event extends Component
$propertyBag->set('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE');
}
if (null != $this->msBusyStatus) {
$propertyBag->set('X-MICROSOFT-CDO-BUSYSTATUS', $this->msBusyStatus);
$propertyBag->set('X-MICROSOFT-CDO-INTENDEDSTATUS', $this->msBusyStatus);
}
if (null != $this->categories) {
$propertyBag->set('CATEGORIES', $this->categories);
}
$propertyBag->add(
new DateTimeProperty('DTSTAMP', $this->dtStamp ?: new \DateTime(), false, false, true)
new DateTimeProperty('DTSTAMP', $this->dtStamp ?: new \DateTimeImmutable(), false, false, true)
);
if ($this->created) {
@@ -341,6 +387,10 @@ class Event extends Component
$propertyBag->add(new DateTimeProperty('LAST-MODIFIED', $this->modified, false, false, true));
}
foreach ($this->attachments as $attachment) {
$propertyBag->add($attachment);
}
return $propertyBag;
}
@@ -368,6 +418,11 @@ class Event extends Component
return $this;
}
public function getDtStart()
{
return $this->dtStart;
}
/**
* @param $dtStamp
*
@@ -393,17 +448,34 @@ class Event extends Component
}
/**
* @param $location
* @param string $title
* @param null $geo
* @param string $location
* @param string $title
* @param Geo|string $geo
*
* @return $this
*/
public function setLocation($location, $title = '', $geo = null)
{
$this->location = $location;
if (is_scalar($geo)) {
$geo = Geo::fromString($geo);
} elseif (!is_null($geo) && !$geo instanceof Geo) {
$className = get_class($geo);
throw new \InvalidArgumentException("The parameter 'geo' must be a string or an instance of " . Geo::class . " but an instance of {$className} was given.");
}
$this->location = $location;
$this->locationTitle = $title;
$this->locationGeo = $geo;
$this->locationGeo = $geo;
return $this;
}
/**
* @return $this
*/
public function setGeoLocation(Geo $geoProperty)
{
$this->locationGeo = $geoProperty;
return $this;
}
@@ -420,6 +492,37 @@ class Event extends Component
return $this;
}
/**
* @param $msBusyStatus
*
* @return $this
*
* @throws \InvalidArgumentException
*/
public function setMsBusyStatus($msBusyStatus)
{
$msBusyStatus = strtoupper($msBusyStatus);
if ($msBusyStatus == self::MS_BUSYSTATUS_FREE
|| $msBusyStatus == self::MS_BUSYSTATUS_TENTATIVE
|| $msBusyStatus == self::MS_BUSYSTATUS_BUSY
|| $msBusyStatus == self::MS_BUSYSTATUS_OOF
) {
$this->msBusyStatus = $msBusyStatus;
} else {
throw new \InvalidArgumentException('Invalid value for status');
}
return $this;
}
/**
* @return string|null
*/
public function getMsBusyStatus()
{
return $this->msBusyStatus;
}
/**
* @param int $sequence
*
@@ -441,8 +544,6 @@ class Event extends Component
}
/**
* @param Organizer $organizer
*
* @return $this
*/
public function setOrganizer(Organizer $organizer)
@@ -517,10 +618,28 @@ class Event extends Component
}
/**
* @param Attendees $attendees
* @param $timezoneString
*
* @return $this
*/
public function setTimezoneString($timezoneString)
{
$this->timezoneString = $timezoneString;
return $this;
}
/**
* @return bool
*/
public function getTimezoneString()
{
return $this->timezoneString;
}
/**
* @return $this
*/
public function setAttendees(Attendees $attendees)
{
$this->attendees = $attendees;
@@ -534,20 +653,14 @@ class Event extends Component
*
* @return $this
*/
public function addAttendee($attendee, $params = array())
public function addAttendee($attendee, $params = [])
{
if (!isset($this->attendees)) {
$this->attendees = new Attendees();
}
$this->attendees->add($attendee, $params);
return $this;
}
/**
* @return Attendees
*/
public function getAttendees()
public function getAttendees(): Attendees
{
return $this->attendees;
}
@@ -660,25 +773,49 @@ class Event extends Component
}
/**
* @param RecurrenceRule $recurrenceRule
* @deprecated Deprecated since version 0.11.0, to be removed in 1.0. Use addRecurrenceRule instead.
*
* @return $this
*/
public function setRecurrenceRule(RecurrenceRule $recurrenceRule)
{
@trigger_error('setRecurrenceRule() is deprecated since version 0.11.0 and will be removed in 1.0. Use addRecurrenceRule instead.', E_USER_DEPRECATED);
$this->recurrenceRule = $recurrenceRule;
return $this;
}
/**
* @deprecated Deprecated since version 0.11.0, to be removed in 1.0. Use getRecurrenceRules instead.
*
* @return RecurrenceRule
*/
public function getRecurrenceRule()
{
@trigger_error('getRecurrenceRule() is deprecated since version 0.11.0 and will be removed in 1.0. Use getRecurrenceRules instead.', E_USER_DEPRECATED);
return $this->recurrenceRule;
}
/**
* @return $this
*/
public function addRecurrenceRule(RecurrenceRule $recurrenceRule)
{
$this->recurrenceRules[] = $recurrenceRule;
return $this;
}
/**
* @return array
*/
public function getRecurrenceRules()
{
return $this->recurrenceRules;
}
/**
* @param $dtStamp
*
@@ -730,11 +867,9 @@ class Event extends Component
}
/**
* @param \DateTime $dateTime
*
* @return \Eluceo\iCal\Component\Event
*/
public function addExDate(\DateTime $dateTime)
public function addExDate(\DateTimeInterface $dateTime)
{
$this->exDates[] = $dateTime;
@@ -742,7 +877,7 @@ class Event extends Component
}
/**
* @return \DateTime[]
* @return \DateTimeInterface[]
*/
public function getExDates()
{
@@ -750,7 +885,7 @@ class Event extends Component
}
/**
* @param \DateTime[]
* @param \DateTimeInterface[]
*
* @return \Eluceo\iCal\Component\Event
*/
@@ -770,8 +905,6 @@ class Event extends Component
}
/**
* @param RecurrenceId $recurrenceId
*
* @return \Eluceo\iCal\Component\Event
*/
public function setRecurrenceId(RecurrenceId $recurrenceId)
@@ -780,4 +913,29 @@ class Event extends Component
return $this;
}
/**
* @param array $attachment
*
* @return $this
*/
public function addAttachment(Attachment $attachment)
{
$this->attachments[] = $attachment;
return $this;
}
/**
* @return array
*/
public function getAttachments()
{
return $this->attachments;
}
public function addUrlAttachment(string $url)
{
$this->addAttachment(new Attachment($url));
}
}

View File

@@ -12,8 +12,8 @@
namespace Eluceo\iCal\Component;
use Eluceo\iCal\Component;
use Eluceo\iCal\PropertyBag;
use Eluceo\iCal\Property\Event\RecurrenceRule;
use Eluceo\iCal\PropertyBag;
/**
* Implementation of Standard Time and Daylight Saving Time observances (or rules)
@@ -45,7 +45,7 @@ class TimezoneRule extends Component
protected $tzName;
/**
* @var \DateTime
* @var \DateTimeInterface
*/
protected $dtStart;
@@ -138,11 +138,9 @@ class TimezoneRule extends Component
}
/**
* @param \DateTime $dtStart
*
* @return $this
*/
public function setDtStart(\DateTime $dtStart)
public function setDtStart(\DateTimeInterface $dtStart)
{
$this->dtStart = $dtStart;
@@ -150,8 +148,6 @@ class TimezoneRule extends Component
}
/**
* @param RecurrenceRule $recurrenceRule
*
* @return $this
*/
public function setRecurrenceRule(RecurrenceRule $recurrenceRule)

View File

@@ -1,66 +0,0 @@
<?php
/*
* This file is part of the eluceo/iCal package.
*
* (c) Markus Poerschke <markus@eluceo.de>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Eluceo\iCal\Property\Event;
use Eluceo\iCal\Property\ValueInterface;
use Eluceo\iCal\Util\PropertyValueUtil;
/**
* Class Description
* Alows new line charectars to be in the description.
*/
class Description implements ValueInterface
{
/**
* The value.
*
* @var string
*/
protected $value;
public function __construct($value)
{
$this->value = $value;
}
/**
* Return the value of the Property as an escaped string.
*
* Escape values as per RFC 2445. See http://www.kanzaki.com/docs/ical/text.html
*
* @return string
*/
public function getEscapedValue()
{
return PropertyValueUtil::escapeValue((string) $this->value);
}
/**
* @param string $value
*
* @return $this
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
/**
* @return string
*/
public function getValue()
{
return $this->value;
}
}

View File

@@ -1,61 +0,0 @@
<?php
/*
* This file is part of the eluceo/iCal package.
*
* (c) Markus Poerschke <markus@eluceo.de>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Eluceo\iCal\Property;
use Eluceo\iCal\Util\PropertyValueUtil;
class StringValue implements ValueInterface
{
/**
* The value.
*
* @var string
*/
protected $value;
public function __construct($value)
{
$this->value = $value;
}
/**
* Return the value of the Property as an escaped string.
*
* Escape values as per RFC 2445. See http://www.kanzaki.com/docs/ical/text.html
*
* @return string
*/
public function getEscapedValue()
{
return PropertyValueUtil::escapeValue((string) $this->value);
}
/**
* @param string $value
*
* @return $this
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
/**
* @return string
*/
public function getValue()
{
return $this->value;
}
}

View File

@@ -1,48 +0,0 @@
<?php
/*
* This file is part of the eluceo/iCal package.
*
* (c) Markus Poerschke <markus@eluceo.de>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Eluceo\iCal\Util;
class ComponentUtil
{
/**
* Folds a single line.
*
* According to RFC 2445, all lines longer than 75 characters will be folded
*
* @link http://www.ietf.org/rfc/rfc2445.txt
*
* @param $string
*
* @return array
*/
public static function fold($string)
{
$lines = array();
$array = preg_split('/(?<!^)(?!$)/u', $string);
$line = '';
$lineNo = 0;
foreach ($array as $char) {
$charLen = strlen($char);
$lineLen = strlen($line);
if ($lineLen + $charLen > 75) {
$line = ' ' . $char;
++$lineNo;
} else {
$line .= $char;
}
$lines[$lineNo] = $line;
}
return $lines;
}
}

View File

@@ -20,7 +20,7 @@ class ParameterBag
*/
protected $params;
public function __construct($params = array())
public function __construct($params = [])
{
$this->params = $params;
}
@@ -36,33 +36,32 @@ class ParameterBag
/**
* @param $name
*
* @return array|mixed
*/
public function getParam($name)
{
if (array_key_exists($name, $this->params)) {
if (isset($this->params[$name])) {
return $this->params[$name];
}
return null;
}
/**
* Checks if there are any params.
*
* @return bool
*/
public function hasParams()
public function hasParams(): bool
{
return count($this->params) > 0;
}
/**
* @return string
*/
public function toString()
public function toString(): string
{
$line = '';
foreach ($this->params as $param => $paramValues) {
if (!is_array($paramValues)) {
$paramValues = array($paramValues);
$paramValues = [$paramValues];
}
foreach ($paramValues as $k => $v) {
$paramValues[$k] = $this->escapeParamValue($v);
@@ -85,7 +84,7 @@ class ParameterBag
*
* @return string
*/
public function escapeParamValue($value)
private function escapeParamValue($value)
{
$count = 0;
$value = str_replace('\\', '\\\\', $value);

View File

@@ -16,9 +16,11 @@ use Eluceo\iCal\Property\StringValue;
use Eluceo\iCal\Property\ValueInterface;
/**
* The Property Class represents a property as defined in RFC 2445.
* The Property Class represents a property as defined in RFC 5545.
*
* The content of a line (unfolded) will be rendered in this class
* The content of a line (unfolded) will be rendered in this class.
*
* @see https://tools.ietf.org/html/rfc5545#section-3.5
*/
class Property
{
@@ -46,7 +48,7 @@ class Property
* @param $value
* @param array $params
*/
public function __construct($name, $value, $params = array())
public function __construct($name, $value, $params = [])
{
$this->name = $name;
$this->setValue($value);
@@ -82,7 +84,7 @@ class Property
*/
public function toLines()
{
return array($this->toLine());
return [$this->toLine()];
}
/**
@@ -138,10 +140,7 @@ class Property
return $this->value;
}
/**
* @return string
*/
public function getName()
public function getName(): string
{
return $this->name;
}

View File

@@ -11,8 +11,6 @@
namespace Eluceo\iCal\Property;
use Eluceo\iCal\Util\PropertyValueUtil;
class ArrayValue implements ValueInterface
{
/**
@@ -34,10 +32,10 @@ class ArrayValue implements ValueInterface
return $this;
}
public function getEscapedValue()
public function getEscapedValue(): string
{
return implode(',', array_map(function ($value) {
return PropertyValueUtil::escapeValue((string) $value);
return implode(',', array_map(function (string $value): string {
return (new StringValue($value))->getEscapedValue();
}, $this->values));
}
}

View File

@@ -17,21 +17,23 @@ use Eluceo\iCal\Util\DateUtil;
class DateTimeProperty extends Property
{
/**
* @param string $name
* @param \DateTime $dateTime
* @param bool $noTime
* @param bool $useTimezone
* @param bool $useUtc
* @param string $name
* @param \DateTimeInterface $dateTime
* @param bool $noTime
* @param bool $useTimezone
* @param bool $useUtc
* @param string $timezoneString
*/
public function __construct(
$name,
\DateTime $dateTime = null,
\DateTimeInterface $dateTime = null,
$noTime = false,
$useTimezone = false,
$useUtc = false
$useUtc = false,
$timezoneString = ''
) {
$dateString = DateUtil::getDateString($dateTime, $noTime, $useTimezone, $useUtc);
$params = DateUtil::getDefaultParams($dateTime, $noTime, $useTimezone);
$params = DateUtil::getDefaultParams($dateTime, $noTime, $useTimezone, $timezoneString);
parent::__construct($name, $dateString, $params);
}

View File

@@ -17,24 +17,29 @@ use Eluceo\iCal\Util\DateUtil;
class DateTimesProperty extends Property
{
/**
* @param string $name
* @param \DateTime[] $dateTimes
* @param bool $noTime
* @param bool $useTimezone
* @param bool $useUtc
* @param string $name
* @param \DateTimeInterface[] $dateTimes
* @param bool $noTime
* @param bool $useTimezone
* @param bool $useUtc
* @param string $timezoneString
*/
public function __construct(
$name,
$dateTimes = array(),
$dateTimes = [],
$noTime = false,
$useTimezone = false,
$useUtc = false
$useUtc = false,
$timezoneString = ''
) {
$dates = array();
$dates = [];
$dateTime = new \DateTimeImmutable();
foreach ($dateTimes as $dateTime) {
$dates[] = DateUtil::getDateString($dateTime, $noTime, $useTimezone, $useUtc);
}
$params = DateUtil::getDefaultParams($dateTime, $noTime, $useTimezone);
//@todo stop this triggering an E_NOTICE when $dateTimes is empty
$params = DateUtil::getDefaultParams($dateTime, $noTime, $useTimezone, $timezoneString);
parent::__construct($name, $dates, $params);
}

View File

@@ -0,0 +1,39 @@
<?php
/*
* This file is part of the eluceo/iCal package.
*
* (c) Markus Poerschke <markus@eluceo.de>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Eluceo\iCal\Property\Event;
use Eluceo\iCal\Property;
/**
* Class Attachment.
*/
class Attachment extends Property
{
/**
* @param string $value
* @param array $params
*/
public function __construct($value, $params = [])
{
parent::__construct('ATTACH', $value, $params);
}
/**
* @param $url
*
* @throws \Exception
*/
public function setUrl($url)
{
$this->setValue($url);
}
}

View File

@@ -15,14 +15,15 @@ use Eluceo\iCal\Property;
class Attendees extends Property
{
/** @var Property[] */
protected $attendees = array();
const PROPERTY_NAME = 'ATTENDEES';
/**
* @var Property[]
*/
protected $attendees = [];
public function __construct()
{
// Overwrites constructor functionality of Property
$this->name = 'ATTENDEES';
// prevent super constructor to be called
}
/**
@@ -31,7 +32,7 @@ class Attendees extends Property
*
* @return $this
*/
public function add($value, $params = array())
public function add($value, $params = [])
{
$this->attendees[] = new Property('ATTENDEE', $value, $params);
@@ -63,7 +64,7 @@ class Attendees extends Property
*/
public function toLines()
{
$lines = array();
$lines = [];
foreach ($this->attendees as $attendee) {
$lines[] = $attendee->toLine();
}
@@ -91,12 +92,4 @@ class Attendees extends Property
{
throw new \BadMethodCallException('Cannot call getParam on Attendees Property');
}
/**
* {@inheritdoc}
*/
public function getName()
{
return self::PROPERTY_NAME;
}
}

View File

@@ -0,0 +1,82 @@
<?php
/*
* This file is part of the eluceo/iCal package.
*
* (c) Markus Poerschke <markus@eluceo.de>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Eluceo\iCal\Property\Event;
use Eluceo\iCal\Property;
/**
* GEO property.
*
* @see https://tools.ietf.org/html/rfc5545#section-3.8.1.6
*/
class Geo extends Property
{
/**
* @var float
*/
private $latitude;
/**
* @var float
*/
private $longitude;
public function __construct(float $latitude, float $longitude)
{
$this->latitude = $latitude;
$this->longitude = $longitude;
if ($this->latitude < -90 || $this->latitude > 90) {
throw new \InvalidArgumentException("The geographical latitude must be a value between -90 and 90 degrees. '{$this->latitude}' was given.");
}
if ($this->longitude < -180 || $this->longitude > 180) {
throw new \InvalidArgumentException("The geographical longitude must be a value between -180 and 180 degrees. '{$this->longitude}' was given.");
}
parent::__construct('GEO', new Property\RawStringValue($this->getGeoLocationAsString()));
}
/**
* @deprecated This method is used to allow backwards compatibility for Event::setLocation
*
* @return Geo
*/
public static function fromString(string $geoLocationString): self
{
$geoLocationString = str_replace(',', ';', $geoLocationString);
$geoLocationString = str_replace('GEO:', '', $geoLocationString);
$parts = explode(';', $geoLocationString);
return new static((float) $parts[0], (float) $parts[1]);
}
/**
* Returns the coordinates as a string.
*
* @example 37.386013;-122.082932
*/
public function getGeoLocationAsString(string $separator = ';'): string
{
return number_format($this->latitude, 6) . $separator . number_format($this->longitude, 6);
}
public function getLatitude(): float
{
return $this->latitude;
}
public function getLongitude(): float
{
return $this->longitude;
}
}

View File

@@ -18,22 +18,12 @@ use Eluceo\iCal\Property;
*/
class Organizer extends Property
{
const PROPERTY_NAME = 'ORGANIZER';
/**
* @param string $value
* @param array $params
*/
public function __construct($value, $params = array())
public function __construct($value, $params = [])
{
parent::__construct(self::PROPERTY_NAME, $value, $params);
}
/**
* {@inheritdoc}
*/
public function getName()
{
return self::PROPERTY_NAME;
parent::__construct('ORGANIZER', $value, $params);
}
}

View File

@@ -13,29 +13,27 @@ namespace Eluceo\iCal\Property\Event;
use Eluceo\iCal\ParameterBag;
use Eluceo\iCal\Property;
use Eluceo\iCal\Util\DateUtil;
use Eluceo\iCal\Property\ValueInterface;
use Eluceo\iCal\Util\DateUtil;
/**
* Implementation of Recurrence Id.
*
* @see http://www.ietf.org/rfc/rfc2445.txt 4.8.4.4 Recurrence ID
* @see https://tools.ietf.org/html/rfc5545#section-3.8.4.4
*/
class RecurrenceId extends Property
{
const PROPERTY_NAME = 'RECURRENCE-ID';
/**
* The effective range of recurrence instances from the instance
* specified by the recurrence identifier specified by the property.
*/
const RANGE_THISANDPRIOR = 'THISANDPRIOR';
const RANGE_THISANDPRIOR = 'THISANDPRIOR';
const RANGE_THISANDFUTURE = 'THISANDFUTURE';
/**
* The dateTime to identify a particular instance of a recurring event which is getting modified.
*
* @var \DateTime
* @var \DateTimeInterface
*/
protected $dateTime;
@@ -46,17 +44,18 @@ class RecurrenceId extends Property
*/
protected $range;
public function __construct(\DateTime $dateTime = null)
public function __construct(\DateTimeInterface $dateTime = null)
{
$this->name = 'RECURRENCE-ID';
$this->parameterBag = new ParameterBag();
if (isset($dateTime)) {
$this->dateTime = $dateTime;
}
}
public function applyTimeSettings($noTime = false, $useTimezone = false, $useUtc = false)
public function applyTimeSettings($noTime = false, $useTimezone = false, $useUtc = false, $timezoneString = '')
{
$params = DateUtil::getDefaultParams($this->dateTime, $noTime, $useTimezone, $useUtc);
$params = DateUtil::getDefaultParams($this->dateTime, $noTime, $useTimezone, $timezoneString);
foreach ($params as $name => $value) {
$this->parameterBag->setParam($name, $value);
}
@@ -69,7 +68,7 @@ class RecurrenceId extends Property
}
/**
* @return DateTime
* @return \DateTimeInterface
*/
public function getDatetime()
{
@@ -77,11 +76,9 @@ class RecurrenceId extends Property
}
/**
* @param \DateTime $dateTime
*
* @return \Eluceo\iCal\Property\Event\RecurrenceId
*/
public function setDatetime(\DateTime $dateTime)
public function setDatetime(\DateTimeInterface $dateTime)
{
$this->dateTime = $dateTime;
@@ -104,6 +101,8 @@ class RecurrenceId extends Property
public function setRange($range)
{
$this->range = $range;
return $this;
}
/**
@@ -119,12 +118,4 @@ class RecurrenceId extends Property
return parent::toLines();
}
}
/**
* {@inheritdoc}
*/
public function getName()
{
return self::PROPERTY_NAME;
}
}

View File

@@ -11,29 +11,32 @@
namespace Eluceo\iCal\Property\Event;
use Eluceo\iCal\Property\ValueInterface;
use Eluceo\iCal\ParameterBag;
use Eluceo\iCal\Property\ValueInterface;
use InvalidArgumentException;
/**
* Implementation of Recurrence Rule.
*
* @see http://www.ietf.org/rfc/rfc2445.txt 3.3.10. Recurrence Rule
* @see https://tools.ietf.org/html/rfc5545#section-3.8.5.3
*/
class RecurrenceRule implements ValueInterface
{
const FREQ_YEARLY = 'YEARLY';
const FREQ_YEARLY = 'YEARLY';
const FREQ_MONTHLY = 'MONTHLY';
const FREQ_WEEKLY = 'WEEKLY';
const FREQ_DAILY = 'DAILY';
const FREQ_WEEKLY = 'WEEKLY';
const FREQ_DAILY = 'DAILY';
const FREQ_HOURLY = 'HOURLY';
const FREQ_MINUTELY = 'MINUTELY';
const FREQ_SECONDLY = 'SECONDLY';
const WEEKDAY_SUNDAY = 'SU';
const WEEKDAY_MONDAY = 'MO';
const WEEKDAY_TUESDAY = 'TU';
const WEEKDAY_SUNDAY = 'SU';
const WEEKDAY_MONDAY = 'MO';
const WEEKDAY_TUESDAY = 'TU';
const WEEKDAY_WEDNESDAY = 'WE';
const WEEKDAY_THURSDAY = 'TH';
const WEEKDAY_FRIDAY = 'FR';
const WEEKDAY_SATURDAY = 'SA';
const WEEKDAY_THURSDAY = 'TH';
const WEEKDAY_FRIDAY = 'FR';
const WEEKDAY_SATURDAY = 'SA';
/**
* The frequency of an Event.
@@ -43,73 +46,78 @@ class RecurrenceRule implements ValueInterface
protected $freq = self::FREQ_YEARLY;
/**
* @var null|int
* BYSETPOS must require use of other BY*.
*
* @var bool
*/
protected $canUseBySetPos = false;
/**
* @var int|null
*/
protected $interval = 1;
/**
* @var null|int
* @var int|null
*/
protected $count = null;
/**
* @var null|\DateTime
* @var \DateTimeInterface|null
*/
protected $until = null;
/**
* @var null|string
* @var string|null
*/
protected $wkst;
/**
* @var null|string
* @var array|null
*/
protected $bySetPos = null;
/**
* @var string|null
*/
protected $byMonth;
/**
* @var null|string
* @var string|null
*/
protected $byWeekNo;
/**
* @var null|string
* @var string|null
*/
protected $byYearDay;
/**
* @var null|string
* @var string|null
*/
protected $byMonthDay;
/**
* @var null|string
* @var string|null
*/
protected $byDay;
/**
* @var null|string
* @var string|null
*/
protected $byHour;
/**
* @var null|string
* @var string|null
*/
protected $byMinute;
/**
* @var null|string
* @var string|null
*/
protected $bySecond;
/**
* Return the value of the Property as an escaped string.
*
* Escape values as per RFC 2445. See http://www.kanzaki.com/docs/ical/text.html
*
* @return string
*/
public function getEscapedValue()
public function getEscapedValue(): string
{
return $this->buildParameterBag()->toString();
}
@@ -139,36 +147,40 @@ class RecurrenceRule implements ValueInterface
$parameterBag->setParam('WKST', $this->wkst);
}
if (null !== $this->bySetPos && $this->canUseBySetPos) {
$parameterBag->setParam('BYSETPOS', $this->bySetPos);
}
if (null !== $this->byMonth) {
$parameterBag->setParam('BYMONTH', $this->byMonth);
$parameterBag->setParam('BYMONTH', explode(',', $this->byMonth));
}
if (null !== $this->byWeekNo) {
$parameterBag->setParam('BYWEEKNO', $this->byWeekNo);
$parameterBag->setParam('BYWEEKNO', explode(',', $this->byWeekNo));
}
if (null !== $this->byYearDay) {
$parameterBag->setParam('BYYEARDAY', $this->byYearDay);
$parameterBag->setParam('BYYEARDAY', explode(',', $this->byYearDay));
}
if (null !== $this->byMonthDay) {
$parameterBag->setParam('BYMONTHDAY', $this->byMonthDay);
$parameterBag->setParam('BYMONTHDAY', explode(',', $this->byMonthDay));
}
if (null !== $this->byDay) {
$parameterBag->setParam('BYDAY', $this->byDay);
$parameterBag->setParam('BYDAY', explode(',', $this->byDay));
}
if (null !== $this->byHour) {
$parameterBag->setParam('BYHOUR', $this->byHour);
$parameterBag->setParam('BYHOUR', explode(',', $this->byHour));
}
if (null !== $this->byMinute) {
$parameterBag->setParam('BYMINUTE', $this->byMinute);
$parameterBag->setParam('BYMINUTE', explode(',', $this->byMinute));
}
if (null !== $this->bySecond) {
$parameterBag->setParam('BYSECOND', $this->bySecond);
$parameterBag->setParam('BYSECOND', explode(',', $this->bySecond));
}
return $parameterBag;
@@ -195,11 +207,9 @@ class RecurrenceRule implements ValueInterface
}
/**
* @param \DateTime|null $until
*
* @return $this
*/
public function setUntil(\DateTime $until = null)
public function setUntil(\DateTimeInterface $until = null)
{
$this->until = $until;
@@ -207,7 +217,7 @@ class RecurrenceRule implements ValueInterface
}
/**
* @return \DateTime|null
* @return \DateTimeInterface|null
*/
public function getUntil()
{
@@ -235,10 +245,7 @@ class RecurrenceRule implements ValueInterface
*/
public function setFreq($freq)
{
if (self::FREQ_YEARLY === $freq || self::FREQ_MONTHLY === $freq
|| self::FREQ_WEEKLY === $freq
|| self::FREQ_DAILY === $freq
) {
if (@constant('static::FREQ_' . $freq) !== null) {
$this->freq = $freq;
} else {
throw new \InvalidArgumentException("The Frequency {$freq} is not supported.");
@@ -294,23 +301,88 @@ class RecurrenceRule implements ValueInterface
}
/**
* The BYMONTH rule part specifies a COMMA-separated list of months of the year.
* Valid values are 1 to 12.
* The BYSETPOS filters one interval of events by the specified position.
* A positive position will start from the beginning and go forward while
* a negative position will start at the end and move backward.
*
* @param int $month
* Valid values are a comma separated string or an array of integers
* from 1 to 366 or negative integers from -1 to -366.
*
* @param int|string|array|null $value
*
* @throws InvalidArgumentException
*
* @return $this
*/
public function setBySetPos($value)
{
if (null === $value) {
$this->bySetPos = $value;
return $this;
}
if (!(is_string($value) || is_array($value) || is_int($value))) {
throw new InvalidArgumentException('Invalid value for BYSETPOS');
}
$list = $value;
if (is_int($value)) {
if ($value === 0 || $value < -366 || $value > 366) {
throw new InvalidArgumentException('Invalid value for BYSETPOS');
}
$this->bySetPos = [$value];
return $this;
}
if (is_string($value)) {
$list = explode(',', $value);
}
$output = [];
foreach ($list as $item) {
if (is_string($item)) {
if (!preg_match('/^ *-?[0-9]* *$/', $item)) {
throw new InvalidArgumentException('Invalid value for BYSETPOS');
}
$item = intval($item);
}
if (!is_int($item) || $item === 0 || $item < -366 || $item > 366) {
throw new InvalidArgumentException('Invalid value for BYSETPOS');
}
$output[] = $item;
}
$this->bySetPos = $output;
return $this;
}
/**
* The BYMONTH rule part specifies a COMMA-separated list of months of the year.
* Valid values are 1 to 12.
*
* @param int $month
*
* @throws \InvalidArgumentException
*
* @return $this
*/
public function setByMonth($month)
{
if (!is_integer($month) || $month < 0 || $month > 12) {
if (!is_integer($month) || $month <= 0 || $month > 12) {
throw new InvalidArgumentException('Invalid value for BYMONTH');
}
$this->byMonth = $month;
$this->canUseBySetPos = true;
return $this;
}
@@ -320,12 +392,20 @@ class RecurrenceRule implements ValueInterface
*
* @param int $value
*
* @throws \InvalidArgumentException
*
* @return $this
*/
public function setByWeekNo($value)
{
if (!is_integer($value) || $value > 53 || $value < -53 || $value === 0) {
throw new InvalidArgumentException('Invalid value for BYWEEKNO');
}
$this->byWeekNo = $value;
$this->canUseBySetPos = true;
return $this;
}
@@ -335,12 +415,20 @@ class RecurrenceRule implements ValueInterface
*
* @param int $day
*
* @throws \InvalidArgumentException
*
* @return $this
*/
public function setByYearDay($day)
{
if (!is_integer($day) || $day > 366 || $day < -366 || $day === 0) {
throw new InvalidArgumentException('Invalid value for BYYEARDAY');
}
$this->byYearDay = $day;
$this->canUseBySetPos = true;
return $this;
}
@@ -351,11 +439,19 @@ class RecurrenceRule implements ValueInterface
* @param int $day
*
* @return $this
*
* @throws \InvalidArgumentException
*/
public function setByMonthDay($day)
{
if (!is_integer($day) || $day > 31 || $day < -31 || $day === 0) {
throw new InvalidArgumentException('Invalid value for BYMONTHDAY');
}
$this->byMonthDay = $day;
$this->canUseBySetPos = true;
return $this;
}
@@ -368,14 +464,14 @@ class RecurrenceRule implements ValueInterface
* Each BYDAY value can also be preceded by a positive (+n) or negative (-n) integer.
* If present, this indicates the nth occurrence of a specific day within the MONTHLY or YEARLY "RRULE".
*
* @param string $day
*
* @return $this
*/
public function setByDay($day)
public function setByDay(string $day)
{
$this->byDay = $day;
$this->canUseBySetPos = true;
return $this;
}
@@ -397,6 +493,8 @@ class RecurrenceRule implements ValueInterface
$this->byHour = $value;
$this->canUseBySetPos = true;
return $this;
}
@@ -418,6 +516,8 @@ class RecurrenceRule implements ValueInterface
$this->byMinute = $value;
$this->canUseBySetPos = true;
return $this;
}
@@ -439,6 +539,8 @@ class RecurrenceRule implements ValueInterface
$this->bySecond = $value;
$this->canUseBySetPos = true;
return $this;
}
}

View File

@@ -0,0 +1,20 @@
<?php
/*
* This file is part of the eluceo/iCal package.
*
* (c) Markus Poerschke <markus@eluceo.de>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Eluceo\iCal\Property;
class RawStringValue extends StringValue
{
public function getEscapedValue(): string
{
return $this->getValue();
}
}

View File

@@ -9,32 +9,59 @@
* with this source code in the file LICENSE.
*/
namespace Eluceo\iCal\Util;
namespace Eluceo\iCal\Property;
class PropertyValueUtil
class StringValue implements ValueInterface
{
public static function escapeValue($value)
{
$value = self::escapeValueAllowNewLine($value);
$value = str_replace("\n", '\\n', $value);
/**
* The value.
*
* @var string
*/
protected $value;
return $value;
public function __construct($value)
{
$this->value = $value;
}
public static function escapeValueAllowNewLine($value)
public function getEscapedValue(): string
{
$value = $this->value;
$value = str_replace('\\', '\\\\', $value);
$value = str_replace('"', '\\"', $value);
$value = str_replace(',', '\\,', $value);
$value = str_replace(';', '\\;', $value);
$value = str_replace(array(
$value = str_replace("\n", '\\n', $value);
$value = str_replace([
"\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07",
"\x08", "\x09", /* \n*/ "\x0B", "\x0C", "\x0D", "\x0E", "\x0F",
"\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17",
"\x18", "\x19", "\x1A", "\x1B", "\x1C", "\x1D", "\x1E", "\x1F",
"\x7F",
), '', $value);
], '', $value);
return $value;
}
/**
* @param string $value
*
* @return $this
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
/**
* @return string
*/
public function getValue()
{
return $this->value;
}
}

View File

@@ -16,9 +16,9 @@ interface ValueInterface
/**
* Return the value of the Property as an escaped string.
*
* Escape values as per RFC 2445. See http://www.kanzaki.com/docs/ical/text.html
* Escape values as per RFC 5545.
*
* @return string
* @see https://tools.ietf.org/html/rfc5545#section-3.3.11
*/
public function getEscapedValue();
public function getEscapedValue(): string;
}

View File

@@ -16,7 +16,7 @@ class PropertyBag implements \IteratorAggregate
/**
* @var array
*/
protected $elements = array();
protected $elements = [];
/**
* Creates a new Property with $name, $value and $params.
@@ -27,47 +27,41 @@ class PropertyBag implements \IteratorAggregate
*
* @return $this
*/
public function set($name, $value, $params = array())
public function set($name, $value, $params = [])
{
$property = new Property($name, $value, $params);
$this->elements[] = $property;
$this->add(new Property($name, $value, $params));
return $this;
}
/**
* @param string $name
*
* @return null|Property
* @return Property|null
*/
public function get($name)
public function get(string $name)
{
// Searching Property in elements-array
/** @var $property Property */
foreach ($this->elements as $property) {
if ($property->getName() == $name) {
return $property;
}
if (isset($this->elements[$name])) {
return $this->elements[$name];
}
return null;
}
/**
* Adds a Property. If Property already exists an Exception will be thrown.
*
* @param Property $property
*
* @return $this
*
* @throws \Exception
*/
public function add(Property $property)
{
// Property already exists?
if (null !== $this->get($property->getName())) {
throw new \Exception("Property with name '{$property->getName()}' already exists");
$name = $property->getName();
if (isset($this->elements[$name])) {
throw new \Exception("Property with name '{$name}' already exists");
}
$this->elements[] = $property;
$this->elements[$name] = $property;
return $this;
}

View File

@@ -0,0 +1,62 @@
<?php
/*
* This file is part of the eluceo/iCal package.
*
* (c) Markus Poerschke <markus@eluceo.de>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Eluceo\iCal\Util;
class ComponentUtil
{
/**
* Folds a single line.
*
* According to RFC 5545, all lines longer than 75 characters should be folded
*
* @see https://tools.ietf.org/html/rfc5545#section-5
* @see https://tools.ietf.org/html/rfc5545#section-3.1
*
* @param string $string
*
* @return array
*/
public static function fold($string)
{
$lines = [];
if (function_exists('mb_strcut')) {
while (strlen($string) > 0) {
if (strlen($string) > 75) {
$lines[] = mb_strcut($string, 0, 75, 'utf-8');
$string = ' ' . mb_strcut($string, 75, strlen($string), 'utf-8');
} else {
$lines[] = $string;
$string = '';
break;
}
}
} else {
$array = preg_split('/(?<!^)(?!$)/u', $string);
$line = '';
$lineNo = 0;
foreach ($array as $char) {
$charLen = strlen($char);
$lineLen = strlen($line);
if ($lineLen + $charLen > 75) {
$line = ' ' . $char;
++$lineNo;
} else {
$line .= $char;
}
$lines[$lineNo] = $line;
}
}
return $lines;
}
}

View File

@@ -13,12 +13,12 @@ namespace Eluceo\iCal\Util;
class DateUtil
{
public static function getDefaultParams(\DateTime $dateTime = null, $noTime = false, $useTimezone = false)
public static function getDefaultParams(\DateTimeInterface $dateTime = null, $noTime = false, $useTimezone = false, $timezoneString = '')
{
$params = array();
$params = [];
if ($useTimezone) {
$timeZone = $dateTime->getTimezone()->getName();
if ($useTimezone && $noTime === false) {
$timeZone = $timezoneString === '' ? $dateTime->getTimezone()->getName() : $timezoneString;
$params['TZID'] = $timeZone;
}
@@ -32,17 +32,25 @@ class DateUtil
/**
* Returns a formatted date string.
*
* @param \DateTime|null $dateTime The DateTime object
* @param bool $noTime Indicates if the time will be added
* @param bool $useTimezone
* @param bool $useUtc
* @param \DateTimeInterface|null $dateTime The DateTime object
* @param bool $noTime Indicates if the time will be added
* @param bool $useTimezone
* @param bool $useUtc
*
* @return mixed
*/
public static function getDateString(\DateTime $dateTime = null, $noTime = false, $useTimezone = false, $useUtc = false)
public static function getDateString(\DateTimeInterface $dateTime = null, $noTime = false, $useTimezone = false, $useUtc = false)
{
if (empty($dateTime)) {
$dateTime = new \DateTime();
$dateTime = new \DateTimeImmutable();
}
// Only convert the DateTime to UTC if there is a time present. For date-only the
// timezone is meaningless and converting it might shift it to the wrong date.
// Do not convert DateTime to UTC if a timezone it specified, as it should be local time.
if (!$noTime && $useUtc && !$useTimezone) {
$dateTime = clone $dateTime;
$dateTime = $dateTime->setTimezone(new \DateTimeZone('UTC'));
}
return $dateTime->format(self::getDateFormat($noTime, $useTimezone, $useUtc));