<?php
/**
* properties.php: iCalendar property classes
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @copyright Copyright (C) 2008 Nigel Swinson, hide@address.com
* @author Nigel Swinson
* @package PhpiCalLib
* @version 1.0
*/
require_once 'exceptions.php';
require_once 'parameters.php';
require_once 'contentline.php';
require_once 'datatypes.php';
/**
* For properties that require no encoding of the value.
*
* Provides GetValue/SetValue methods rather than having to call Get/SetEncodedValue
*/
class PhpiCalLib_Properties_UnencodedProperty extends PhpiCalLib_ContentLine {
/**
* Simple accessor to set this property which has no encoding, only validation
*
* @param string $Value
*/
public function SetValue($Value) {
$this->SetEncodedValue($Value);
}
/**
* Simple accessor to get this property which has no encoding
*
* @return string
*/
public function GetValue() {
return $this->GetEncodedValue();
}
}
/**
* The VERSION property.
* <pre>
* vervalue = "2.0" ;This memo
* / maxver
* / (minver ";" maxver)
*
* minver = <A IANA registered iCalendar version identifier>
* ;Minimum iCalendar version needed to parse the iCalendar object
*
* maxver = <A IANA registered iCalendar version identifier>
* ;Maximum iCalendar version needed to parse the iCalendar object
* </pre>
* @link http://tools.ietf.org/html/draft-ietf-calsify-rfc2445bis-08#section-3.7.4
*/
class PhpiCalLib_Properties_VersionProperty extends PhpiCalLib_Properties_UnencodedProperty {
public function __construct() {
parent::__construct();
$this->SetType(PHPICALLIB_PROPERTY_VERSION);
}
/**
* Overridden to provide extra validation
*
* @param string $Other
*/
public function SetEncodedValue($Other) {
// ### Can't be bothered validating the version, kinda hard to anyway when it say we have to
// validate <A IANA registered iCalendar version identifier> yet no grammer is supplied :o(
parent::SetEncodedValue($Other);
}
}
/**
* The CALSCALE property.
* <pre>
* calvalue = "GREGORIAN"
* </pre>
* @link http://tools.ietf.org/html/draft-ietf-calsify-rfc2445bis-08#section-3.7.1
*/
class PhpiCalLib_Properties_CalscaleProperty extends PhpiCalLib_Properties_UnencodedProperty {
public function __construct() {
parent::__construct();
$this->SetType(PHPICALLIB_PROPERTY_CALSCALE);
}
/**
* Overridden to provide extra validation
*
* @param string $Value
*/
public function SetEncodedValue($Value) {
if ($Value != "GREGORIAN") {
throw new PhpiCalLib_ParameterException(sprintf('Invalid calscale "%s" token. Only GREGORIAN is supported.', $Value));
}
parent::SetEncodedValue($Value);
}
}
/**
* The METHOD property.
* <pre>
* metvalue = iana-token
* </pre>
* @link http://tools.ietf.org/html/draft-ietf-calsify-rfc2445bis-08#section-3.7.2
*/
class PhpiCalLib_Properties_MethodProperty extends PhpiCalLib_Properties_UnencodedProperty {
public function __construct() {
parent::__construct();
$this->SetType(PHPICALLIB_PROPERTY_METHOD);
}
/**
* Overridden to make sure the token matches iana-token
*
* @param string $Value
*/
public function SetEncodedValue($Value) {
$Pattern = sprintf("/^%s$/D", self::$IanaTokenRegex);
if (!preg_match($Pattern, $Value)) {
throw new PhpiCalLib_ParameterException(sprintf('Invalid metvalue (%s) token: %s', $Pattern, $Value));
}
parent::SetEncodedValue($Value);
}
}
/**
* The DURATION property.
* <pre>
* duration = "DURATION" durparam ":" dur-value CRLF
* ;consisting of a positive duration of time.
*
* durparam = *(";" other-param)
* </pre>
* @link http://tools.ietf.org/html/draft-ietf-calsify-rfc2445bis-08#section-3.8.2.5
*/
class PhpiCalLib_Properties_DurationProperty extends PhpiCalLib_Properties_UnencodedProperty {
private $Duration = null;
public function __construct() {
parent::__construct();
$this->Duration = new PhpiCalLib_DataTypes_Duration();
$this->SetType(PHPICALLIB_PROPERTY_DURATION);
}
public function SetDuration($Duration) {
$this->Duration = $Duration;
$this->EncodedValue = $Duration->ToString();
}
}