* @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(); } ?>