*/
protected $_properties = array();
- protected $_params;
-
- public function __construct($params)
+ public function __construct($properties = array())
{
- $this->_params = $params;
+ foreach ($properties as $property => $value) {
+ $this->addProperty($property, $value);
+ }
}
/**
*/
public function setProperty($property, $value, $params = array())
{
- $this->$name = $value;
- $this->_properties[$property]['params'] = array($params);
+ $this->$property = $value;
+ $this->_properties[$property]['params'] = $params;
}
/**
{
$this->_validate($property, $value);
if (!$this->_properties[$property]['multiple'] &&
- !isset($this->_properties[$property]['value'])) {
+ isset($this->_properties[$property]['value'])) {
throw new Horde_Icalendar_Exception($property . ' properties must not occur more than once.');
}
if (isset($this->_properties[$property]['value'])) {
break;
default:
// @todo Use LSB (static::__CLASS__) once we require PHP 5.3
- $component = Horde_String::upper(str_replace('Horde_Icalendar_Component_', '', get_class($this)));
- throw new Horde_Icalendar_Exception($component . ' components must have a ' . $name . ' property set');
+ $component = Horde_String::upper(str_replace('Horde_Icalendar_', '', get_class($this)));
+ throw new Horde_Icalendar_Exception('This ' . $component . ' component must have a ' . $name . ' property set');
}
}
}
$this->validate();
$writer = Horde_Icalendar_Writer::factory(
str_replace('Horde_Icalendar_', '', get_class($this)),
- str_replace('.', '', $this->_params['version']));
+ str_replace('.', '', $this->version));
return $writer->export($this);
}
/**
* Constructor.
*/
- public function __construct()
+ public function __construct($properties = array())
{
$this->_properties += array(
'summary' => array('required' => false,
'description' => array('required' => false,
'multiple' => false,
'type' => 'string'));
+ parent::__construct($properties);
}
}
class Horde_Icalendar_Vcalendar extends Horde_Icalendar_Base
{
- public function __construct($params = array())
+ public function __construct($properties = array())
{
- $params = array_merge(array('version' => '2.0'), $params);
- parent::__construct($params);
+ $this->_properties += array(
+ 'version' => array('required' => true,
+ 'multiple' => false,
+ 'type' => 'string'),
+ 'product' => array('required' => true,
+ 'multiple' => false,
+ 'type' => 'string')
+ );
+
+ $properties = array_merge(array('version' => '2.0',
+ 'product' => '-//The Horde Project//Horde_Icalendar Library//EN'),
+ $properties);
+ parent::__construct($properties);
}
}
/**
* Constructor.
*/
- public function __construct()
+ public function __construct($properties = array())
{
$this->_properties += array(
'uid' => array('required' => true,
'description' => array('required' => false,
'multiple' => false,
'type' => 'string'));
+ parent::__construct($properties);
}
public function validate()
/**
* Constructor.
*/
- public function __construct()
+ public function __construct($properties = array())
{
$this->_properties += array(
'uid' => array('required' => true,
'multiple' => false,
'class' => 'Horde_Date'),
);
+ parent::__construct($properties);
}
/**
/**
* Constructor.
*/
- public function __construct()
+ public function __construct($properties = array())
{
$this->_properties += array(
'uid' => array('required' => true,
'description' => array('required' => false,
'multiple' => false,
'type' => 'string'));
+ parent::__construct($properties);
}
}
/**
* Constructor.
*/
- public function __construct()
+ public function __construct($properties = array())
{
$this->_properties += array(
/*
'multiple' => false,
'class' => 'Horde_Date'),
);
+ parent::__construct($properties);
}
}
/**
* Constructor.
*/
- public function __construct()
+ public function __construct($properties = array())
{
$this->_properties += array(
'uid' => array('required' => true,
'description' => array('required' => false,
'multiple' => false,
'type' => 'string'));
+ parent::__construct($properties);
}
}
<?php
-class Horde_Icalendar_Writer_Base
+abstract class Horde_Icalendar_Writer_Base
{
- public function export($component)
+
+ protected $_output = '';
+
+ public function export($object)
+ {
+ $this->_output = '';
+ $this->_exportComponent($object);
+ return $this->_output;
+ }
+
+ protected function _exportComponent($object)
+ {
+ $basename = Horde_String::upper(str_replace('Horde_Icalendar_', '', get_class($object)));
+ $this->_output .= 'BEGIN:' . $basename . "\n";
+ foreach ($object as $name => $property) {
+ $this->_exportProperty($name, $property);
+ }
+ foreach ($object->components as $component) {
+ $this->_exportComponent($component);
+ }
+ $this->_output .= 'END:' . $basename . "\n";
+ return $this->_output;
+ }
+
+ protected function _exportProperty($name, $property)
{
+ if (isset($property['value'])) {
+ $this->_output .= Horde_String::upper($name) . ':' . $property['value'] . "\n";
+ }
}
}