00001 <?php
00008 class ODDDocument implements Iterator {
00014 private $ODDSupportedVersion = "1.0";
00015
00019 private $elements;
00020
00024 private $wrapperfactory;
00025
00033 public function __construct(array $elements = NULL) {
00034 if ($elements) {
00035 if (is_array($elements)) {
00036 $this->elements = $elements;
00037 } else {
00038 $this->addElement($elements);
00039 }
00040 } else {
00041 $this->elements = array();
00042 }
00043 }
00044
00050 public function getVersion() {
00051 return $this->ODDSupportedVersion;
00052 }
00053
00059 public function getNumElements() {
00060 return count($this->elements);
00061 }
00062
00070 public function addElement(ODD $element) {
00071 if (!is_array($this->elements)) {
00072 $this->elements = array();
00073 }
00074 $this->elements[] = $element;
00075 }
00076
00084 public function addElements(array $elements) {
00085 foreach ($elements as $element) {
00086 $this->addElement($element);
00087 }
00088 }
00089
00095 public function getElements() {
00096 return $this->elements;
00097 }
00098
00106 public function setWrapperFactory(ODDWrapperFactory $factory) {
00107 $this->wrapperfactory = $factory;
00108 }
00109
00115 public function __toString() {
00116 $xml = "";
00117
00118 if ($this->wrapperfactory) {
00119
00120 $wrapper = $this->wrapperfactory->getElementWrapper($this);
00121
00122 $xml = $wrapper->wrap($this);
00123 } else {
00124
00125 $generated = date("r");
00126 $xml .= "<odd version=\"{$this->ODDSupportedVersion}\" generated=\"$generated\">\n";
00127
00128
00129 foreach ($this->elements as $element) {
00130 $xml .= "$element";
00131 }
00132
00133
00134 $xml .= "</odd>\n";
00135 }
00136
00137 return $xml;
00138 }
00139
00140
00141
00142
00143
00144
00145
00146 private $valid = FALSE;
00147
00155 function rewind() {
00156 $this->valid = (FALSE !== reset($this->elements));
00157 }
00158
00166 function current() {
00167 return current($this->elements);
00168 }
00169
00177 function key() {
00178 return key($this->elements);
00179 }
00180
00188 function next() {
00189 $this->valid = (FALSE !== next($this->elements));
00190 }
00191
00199 function valid() {
00200 return $this->valid;
00201 }
00202 }