123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- <?php
- class ODDDocument implements \Iterator {
-
- private $ODDSupportedVersion = "1.0";
-
- private $elements;
-
- private $wrapperfactory;
-
- public function __construct(array $elements = null) {
- if ($elements) {
- if (is_array($elements)) {
- $this->elements = $elements;
- } else {
- $this->addElement($elements);
- }
- } else {
- $this->elements = array();
- }
- }
-
- public function getVersion() {
- return $this->ODDSupportedVersion;
- }
-
- public function getNumElements() {
- return count($this->elements);
- }
-
- public function addElement(ODD $element) {
- if (!is_array($this->elements)) {
- $this->elements = array();
- }
- $this->elements[] = $element;
- }
-
- public function addElements(array $elements) {
- foreach ($elements as $element) {
- $this->addElement($element);
- }
- }
-
- public function getElements() {
- return $this->elements;
- }
-
- public function setWrapperFactory(\ODDWrapperFactory $factory) {
- $this->wrapperfactory = $factory;
- }
-
- public function __toString() {
- $xml = "";
- if ($this->wrapperfactory) {
-
- $wrapper = $this->wrapperfactory->getElementWrapper($this);
- $xml = $wrapper->wrap($this);
- } else {
-
- $generated = date("r");
- $xml .= "<odd version=\"{$this->ODDSupportedVersion}\" generated=\"$generated\">\n";
-
- foreach ($this->elements as $element) {
- $xml .= "$element";
- }
-
- $xml .= "</odd>\n";
- }
- return $xml;
- }
-
-
- private $valid = false;
-
- function rewind() {
- $this->valid = (false !== reset($this->elements));
- }
-
- function current() {
- return current($this->elements);
- }
-
- function key() {
- return key($this->elements);
- }
-
- function next() {
- $this->valid = (false !== next($this->elements));
- }
-
- function valid() {
- return $this->valid;
- }
- }
|