From c62c0602feb720fb8c198ea0362c3292bab38415 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Tue, 3 Feb 2009 21:29:06 +0000 Subject: Added PEAR Services/oEmbed and its dependencies for multimedia integration. --- extlib/Services/oEmbed/Object/Common.php | 139 +++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 extlib/Services/oEmbed/Object/Common.php (limited to 'extlib/Services/oEmbed/Object/Common.php') diff --git a/extlib/Services/oEmbed/Object/Common.php b/extlib/Services/oEmbed/Object/Common.php new file mode 100644 index 000000000..f568ec89f --- /dev/null +++ b/extlib/Services/oEmbed/Object/Common.php @@ -0,0 +1,139 @@ + + * @copyright 2008 Digg.com, Inc. + * @license http://tinyurl.com/42zef New BSD License + * @version SVN: @version@ + * @link http://code.google.com/p/digg + * @link http://oembed.com + */ + +/** + * Base class for oEmbed objects + * + * @category Services + * @package Services_oEmbed + * @author Joe Stump + * @copyright 2008 Digg.com, Inc. + * @license http://tinyurl.com/42zef New BSD License + * @version Release: @version@ + * @link http://code.google.com/p/digg + * @link http://oembed.com + */ +abstract class Services_oEmbed_Object_Common +{ + /** + * Raw object returned from API + * + * @var object $object The raw object from the API + */ + protected $object = null; + + /** + * Required fields per the specification + * + * @var array $required Array of required fields + * @link http://oembed.com + */ + protected $required = array(); + + /** + * Constructor + * + * @param object $object Raw object returned from the API + * + * @throws {@link Services_oEmbed_Object_Exception} on missing fields + * @return void + */ + public function __construct($object) + { + $this->object = $object; + + $this->required[] = 'version'; + foreach ($this->required as $field) { + if (!isset($this->$field)) { + throw new Services_oEmbed_Object_Exception( + 'Object is missing required ' . $field . ' attribute' + ); + } + } + } + + /** + * Get object variable + * + * @param string $var Variable to get + * + * @see Services_oEmbed_Object_Common::$object + * @return mixed Attribute's value or null if it's not set/exists + */ + public function __get($var) + { + if (property_exists($this->object, $var)) { + return $this->object->$var; + } + + return null; + } + + /** + * Is variable set? + * + * @param string $var Variable name to check + * + * @return boolean True if set, false if not + * @see Services_oEmbed_Object_Common::$object + */ + public function __isset($var) + { + if (property_exists($this->object, $var)) { + return (isset($this->object->$var)); + } + + return false; + } + + /** + * Require a sane __toString for all objects + * + * @return string + */ + abstract public function __toString(); +} + +?> -- cgit v1.2.3-54-g00ecf