123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- <?php
- namespace Sabre\VObject;
- abstract class Document extends Component {
-
- const UNKNOWN = 1;
-
- const VCALENDAR10 = 2;
-
- const ICALENDAR20 = 3;
-
- const VCARD21 = 4;
-
- const VCARD30 = 5;
-
- const VCARD40 = 6;
-
- static public $defaultName;
-
- static public $propertyMap = array();
-
- static public $componentMap = array();
-
- static public $valueMap = array();
-
- public function __construct() {
- $args = func_get_args();
- if (count($args)===0 || is_array($args[0])) {
- array_unshift($args, $this, static::$defaultName);
- call_user_func_array(array('parent', '__construct'), $args);
- } else {
- array_unshift($args, $this);
- call_user_func_array(array('parent', '__construct'), $args);
- }
- }
-
- public function getDocumentType() {
- return self::UNKNOWN;
- }
-
- public function create($name) {
- if (isset(static::$componentMap[strtoupper($name)])) {
- return call_user_func_array(array($this,'createComponent'), func_get_args());
- } else {
- return call_user_func_array(array($this,'createProperty'), func_get_args());
- }
- }
-
- public function createComponent($name, array $children = null, $defaults = true) {
- $name = strtoupper($name);
- $class = 'Sabre\\VObject\\Component';
- if (isset(static::$componentMap[$name])) {
- $class=static::$componentMap[$name];
- }
- if (is_null($children)) $children = array();
- return new $class($this, $name, $children, $defaults);
- }
-
- public function createProperty($name, $value = null, array $parameters = null, $valueType = null) {
-
- if (($i=strpos($name,'.'))!==false) {
- $group = substr($name, 0, $i);
- $name = strtoupper(substr($name, $i+1));
- } else {
- $name = strtoupper($name);
- $group = null;
- }
- $class = null;
- if ($valueType) {
-
-
- $class = $this->getClassNameForPropertyValue($valueType);
- }
- if (is_null($class) && isset($parameters['VALUE'])) {
-
- $class = $this->getClassNameForPropertyValue($parameters['VALUE']);
- }
- if (is_null($class)) {
- $class = $this->getClassNameForPropertyName($name);
- }
- if (is_null($parameters)) $parameters = array();
- return new $class($this, $name, $value, $parameters, $group);
- }
-
- public function getClassNameForPropertyValue($valueParam) {
- $valueParam = strtoupper($valueParam);
- if (isset(static::$valueMap[$valueParam])) {
- return static::$valueMap[$valueParam];
- }
- }
-
- public function getClassNameForPropertyName($propertyName) {
- if (isset(static::$propertyMap[$propertyName])) {
- return static::$propertyMap[$propertyName];
- } else {
- return 'Sabre\\VObject\\Property\\Unknown';
- }
- }
- }
|