Location: PHPKode > projects > PhpiCalLib > propertyfactory.php
<?php
/**
 * propertyfactory.php produces the right kind of contentline derived class for a content line
 * 
 * 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 'textproperties.php';
require_once 'dateordatetimeproperties.php';
require_once 'datetimeproperties.php';

/**
 * The factory class for creating the right kind of {@link PhpiCalLib_ContentLine} objects. 
 * 
 * Derived from contentline, this factory class is able to create the right specialization of 
 * {@link PhpiCalLib_ContentLine} when you call {@link PhpiCalLib_ContentLine::Create()} or 
 * {@link PhpiCalLib_ContentLine::ToContentLines()}
 */
class PhpiCalLib_PropertyFactory extends PhpiCalLib_ContentLine {
	/**
	 * Overridden, to create the right kind of PhpiCalLib_ContentLine
	 */
	protected function CreateContentLine($Name) {
		// Get the type of the property
		$Type = self::ToPropertyType($Name);

		// Build the right type of object
		switch ($Type) {
			case PHPICALLIB_PROPERTY_BEGIN:
			case PHPICALLIB_PROPERTY_END:
				break;
			//http://tools.ietf.org/html/draft-ietf-calsify-rfc2445bis-08#section-3.7
			//3.7. Calendar Properties
			case PHPICALLIB_PROPERTY_CALSCALE:
				return new PhpiCalLib_Properties_CalscaleProperty();
			case PHPICALLIB_PROPERTY_METHOD:
				return new PhpiCalLib_Properties_MethodProperty();
			case PHPICALLIB_PROPERTY_PRODID:
				return new PhpiCalLib_Properties_ProdIdProperty();
			case PHPICALLIB_PROPERTY_VERSION:
				return new PhpiCalLib_Properties_VersionProperty();
			//http://tools.ietf.org/html/draft-ietf-calsify-rfc2445bis-08#section-3.8.1
			//3.8.1. Descriptive Component Properties
			case PHPICALLIB_PROPERTY_ATTACH:
				break;
			case PHPICALLIB_PROPERTY_CATEGORIES:
				return new PhpiCalLib_Properties_CategoriesProperty();
			case PHPICALLIB_PROPERTY_CLASS:
			case PHPICALLIB_PROPERTY_COMMENT:
				break;
			case PHPICALLIB_PROPERTY_DESCRIPTION:
				return new PhpiCalLib_Properties_DescriptionProperty();
			case PHPICALLIB_PROPERTY_GEO:
			case PHPICALLIB_PROPERTY_LOCATION:
			case PHPICALLIB_PROPERTY_PERCENT_COMPLETE:
			case PHPICALLIB_PROPERTY_PRIORITY:
			case PHPICALLIB_PROPERTY_RESOURCES:
			case PHPICALLIB_PROPERTY_STATUS:
				break;
			case PHPICALLIB_PROPERTY_SUMMARY:
				return new PhpiCalLib_Properties_SummaryProperty();
			//http://tools.ietf.org/html/draft-ietf-calsify-rfc2445bis-08#section-3.8.2
			//3.8.2. Date and Time Component Properties
			case PHPICALLIB_PROPERTY_COMPLETED:
				return new PhpiCalLib_Properties_CompletedProperty();
			case PHPICALLIB_PROPERTY_DTEND:
				return new PhpiCalLib_Properties_DtEndProperty();
			case PHPICALLIB_PROPERTY_DUE:
				return new PhpiCalLib_Properties_DueProperty();
			case PHPICALLIB_PROPERTY_DTSTART:
				return new PhpiCalLib_Properties_DtStartProperty();
			case PHPICALLIB_PROPERTY_DURATION:
				return new PhpiCalLib_Properties_DurationProperty();
			case PHPICALLIB_PROPERTY_FREEBUSY:
			case PHPICALLIB_PROPERTY_TRANSP:
			//http://tools.ietf.org/html/draft-ietf-calsify-rfc2445bis-08#section-3.8.3
			//3.8.3. Time Zone Component Properties
			case PHPICALLIB_PROPERTY_TZID:
			case PHPICALLIB_PROPERTY_TZNAME:
			case PHPICALLIB_PROPERTY_TZOFFSETFROM:
			case PHPICALLIB_PROPERTY_TZOFFSETTO:
			case PHPICALLIB_PROPERTY_TZURL:
			//http://tools.ietf.org/html/draft-ietf-calsify-rfc2445bis-08#section-3.8.4
			//3.8.4. Relationship Component Properties
			case PHPICALLIB_PROPERTY_ATTENDEE:
			case PHPICALLIB_PROPERTY_CONTACT:
			case PHPICALLIB_PROPERTY_ORGANIZER:
				break;
			case PHPICALLIB_PROPERTY_RECURRENCE_ID:
				return new PhpiCalLib_Properties_RecurrenceIdProperty();
			case PHPICALLIB_PROPERTY_RELATED_TO:
			case PHPICALLIB_PROPERTY_URL:
			case PHPICALLIB_PROPERTY_UID:
				break;
			//http://tools.ietf.org/html/draft-ietf-calsify-rfc2445bis-08#section-3.8.5
			//3.8.5. Recurrence Component Properties
			case PHPICALLIB_PROPERTY_EXDATE:
				return new PhpiCalLib_Properties_ExDateProperty();
			case PHPICALLIB_PROPERTY_RDATE:
				return new PhpiCalLib_Properties_RDateProperty();
			case PHPICALLIB_PROPERTY_RRULE:
			//http://tools.ietf.org/html/draft-ietf-calsify-rfc2445bis-08#section-3.8.6
			//3.8.6. Alarm Component Properties
			case PHPICALLIB_PROPERTY_ACTION:
			case PHPICALLIB_PROPERTY_REPEAT:
			case PHPICALLIB_PROPERTY_TRIGGER:
				break;
			//http://tools.ietf.org/html/draft-ietf-calsify-rfc2445bis-08#section-3.8.7
			//3.8.7. Change Management Component Properties
			case PHPICALLIB_PROPERTY_CREATED:
				return new PhpiCalLib_Properties_CreatedProperty();
			case PHPICALLIB_PROPERTY_DTSTAMP:
				return new PhpiCalLib_Properties_DtStampProperty();
			case PHPICALLIB_PROPERTY_LASTMODIFIED:
				return new PhpiCalLib_Properties_LastModifiedProperty();
			case PHPICALLIB_PROPERTY_SEQUENCE:
			//http://tools.ietf.org/html/draft-ietf-calsify-rfc2445bis-08#section-3.8.8
			//3.8.8. Miscellaneous Component Properties
			case PHPICALLIB_PROPERTY_IANAPROP:
			case PHPICALLIB_PROPERTY_XPROP:
				// Very deliberatly the default
				$Result = new PhpiCalLib_ContentLine();
				$Result->SetName($Name);
				return $Result;
			case PHPICALLIB_PROPERTY_REQUEST_STATUS:
				break;
		}
		
		// By default, return a generic ContentLine
		$Result = new PhpiCalLib_ContentLine();
		// We can call SetType(), as we have filtered off IanaProp and XProp
		$Result->SetType($Type);
		return $Result;
	}	
}

?>
Return current item: PhpiCalLib