]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - extlib/Services/oEmbed/Object/Common.php
Merge branch '0.7.x' into 0.8.x
[quix0rs-gnu-social.git] / extlib / Services / oEmbed / Object / Common.php
1 <?php
2
3 /**
4  * Base class for oEmbed objects
5  *
6  * PHP version 5.1.0+
7  *
8  * Copyright (c) 2008, Digg.com, Inc.
9  * 
10  * All rights reserved.
11  * 
12  * Redistribution and use in source and binary forms, with or without 
13  * modification, are permitted provided that the following conditions are met:
14  *
15  *  - Redistributions of source code must retain the above copyright notice,
16  *    this list of conditions and the following disclaimer.
17  *  - Redistributions in binary form must reproduce the above copyright notice,
18  *    this list of conditions and the following disclaimer in the documentation
19  *    and/or other materials provided with the distribution.
20  *  - Neither the name of Digg.com, Inc. nor the names of its contributors 
21  *    may be used to endorse or promote products derived from this software 
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
25  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
27  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
28  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * @category  Services
37  * @package   Services_oEmbed
38  * @author    Joe Stump <joe@joestump.net> 
39  * @copyright 2008 Digg.com, Inc.
40  * @license   http://tinyurl.com/42zef New BSD License
41  * @version   SVN: @version@
42  * @link      http://code.google.com/p/digg
43  * @link      http://oembed.com
44  */
45
46 /**
47  * Base class for oEmbed objects
48  *
49  * @category  Services
50  * @package   Services_oEmbed
51  * @author    Joe Stump <joe@joestump.net> 
52  * @copyright 2008 Digg.com, Inc.
53  * @license   http://tinyurl.com/42zef New BSD License
54  * @version   Release: @version@
55  * @link      http://code.google.com/p/digg
56  * @link      http://oembed.com
57  */
58 abstract class Services_oEmbed_Object_Common
59 {
60     /**
61      * Raw object returned from API
62      *
63      * @var object $object The raw object from the API
64      */
65     protected $object = null;
66
67     /**
68      * Required fields per the specification
69      *
70      * @var array $required Array of required fields
71      * @link http://oembed.com
72      */
73     protected $required = array();
74
75     /**
76      * Constructor
77      *
78      * @param object $object Raw object returned from the API
79      *
80      * @throws {@link Services_oEmbed_Object_Exception} on missing fields
81      * @return void
82      */
83     public function __construct($object)
84     {
85         $this->object = $object;
86
87         $this->required[] = 'version';
88         foreach ($this->required as $field) {
89             if (!isset($this->$field)) {
90                 throw new Services_oEmbed_Object_Exception(
91                     'Object is missing required ' . $field . ' attribute'
92                 );
93             }
94         }
95     }
96
97     /**
98      * Get object variable
99      *
100      * @param string $var Variable to get
101      *
102      * @see Services_oEmbed_Object_Common::$object
103      * @return mixed Attribute's value or null if it's not set/exists
104      */
105     public function __get($var)
106     {
107         if (property_exists($this->object, $var)) {
108             return $this->object->$var;
109         }
110
111         return null;
112     }
113
114     /**
115      * Is variable set?
116      *
117      * @param string $var Variable name to check
118      * 
119      * @return boolean True if set, false if not
120      * @see Services_oEmbed_Object_Common::$object
121      */
122     public function __isset($var)
123     {
124         if (property_exists($this->object, $var)) {
125             return (isset($this->object->$var));
126         }
127
128         return false;
129     }
130
131     /**
132      * Require a sane __toString for all objects
133      *
134      * @return string
135      */
136     abstract public function __toString();
137 }
138
139 ?>