From 76dac45ebaf104b312a8527a05424601ca9d520a Mon Sep 17 00:00:00 2001 From: ewinslow Date: Mon, 6 Sep 2010 02:42:09 +0000 Subject: Refs #2220: Pulled most classes / interfaces out of lib files (except query.php and exception.php) into "classes" folder. Replaced inline classes with "require_once" statements for now. Ran unit tests to verify functionality before committing. git-svn-id: http://code.elgg.org/elgg/trunk@6908 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/classes/ODDDocument.php | 129 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 engine/classes/ODDDocument.php (limited to 'engine/classes/ODDDocument.php') diff --git a/engine/classes/ODDDocument.php b/engine/classes/ODDDocument.php new file mode 100644 index 000000000..0c8731a75 --- /dev/null +++ b/engine/classes/ODDDocument.php @@ -0,0 +1,129 @@ +elements = $elements; + } else { + $this->addElement($elements); + } + } else { + $this->elements = array(); + } + } + + /** + * Return the version of ODD being used. + * + * @return string + */ + 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; + } + + /** + * Set an optional wrapper factory to optionally embed the ODD document in another format. + */ + public function setWrapperFactory(ODDWrapperFactory $factory) { + $this->wrapperfactory = $factory; + } + + /** + * Magic function to generate valid ODD XML for this item. + */ + public function __toString() { + $xml = ""; + + if ($this->wrapperfactory) { + // A wrapper has been provided + $wrapper = $this->wrapperfactory->getElementWrapper($this); // Get the wrapper for this element + + $xml = $wrapper->wrap($this); // Wrap this element (and subelements) + } else { + // Output begin tag + $generated = date("r"); + $xml .= "ODDSupportedVersion}\" generated=\"$generated\">\n"; + + // Get XML for elements + foreach ($this->elements as $element) { + $xml .= "$element"; + } + + // Output end tag + $xml .= "\n"; + } + + return $xml; + } + + // ITERATOR INTERFACE ////////////////////////////////////////////////////////////// + /* + * This lets an entity's attributes be displayed using foreach as a normal array. + * Example: http://www.sitepoint.com/print/php5-standard-library + */ + + 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; + } +} -- cgit v1.2.3