]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - extlib/Services/oEmbed/Object.php
Merge branch '0.7.x' into 0.8.x
[quix0rs-gnu-social.git] / extlib / Services / oEmbed / Object.php
1 <?php
2
3 /**
4  * An interface for oEmbed consumption
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 require_once 'Services/oEmbed/Object/Exception.php';
47
48 /**
49  * Base class for consuming oEmbed objects
50  *
51  * @category  Services
52  * @package   Services_oEmbed
53  * @author    Joe Stump <joe@joestump.net> 
54  * @copyright 2008 Digg.com, Inc.
55  * @license   http://tinyurl.com/42zef New BSD License
56  * @version   Release: @version@
57  * @link      http://code.google.com/p/digg
58  * @link      http://oembed.com
59  */
60 abstract class Services_oEmbed_Object 
61 {
62     
63     /**
64      * Valid oEmbed object types
65      *
66      * @var array $types Array of valid object types
67      * @see Services_oEmbed_Object::factory()
68      */
69     static protected $types = array(
70         'photo' => 'Photo',
71         'video' => 'Video',
72         'link'  => 'Link',
73         'rich'  => 'Rich'
74     );
75
76     /**
77      * Create an oEmbed object from result
78      *
79      * @param object $object Raw object returned from API
80      *
81      * @throws {@link Services_oEmbed_Object_Exception} on object error
82      * @return object Instance of object driver
83      * @see Services_oEmbed_Object_Link, Services_oEmbed_Object_Photo
84      * @see Services_oEmbed_Object_Rich, Services_oEmbed_Object_Video
85      */
86     static public function factory($object)
87     {
88         if (!isset($object->type)) {
89             throw new Services_oEmbed_Object_Exception(
90                 'Object has no type'
91             );
92         }
93
94         $type = (string)$object->type;
95         if (!isset(self::$types[$type])) {
96             throw new Services_oEmbed_Object_Exception(
97                 'Object type is unknown or invalid: ' . $type
98             );
99         }
100
101         $file = 'Services/oEmbed/Object/' . self::$types[$type] . '.php';
102         include_once $file;
103
104         $class = 'Services_oEmbed_Object_' . self::$types[$type];
105         if (!class_exists($class)) {
106             throw new Services_oEmbed_Object_Exception(
107                 'Object class is invalid or not present'
108             );
109         }
110
111         $instance = new $class($object);
112         return $instance;
113     }
114
115     /**
116      * Instantiation is not allowed
117      *
118      * @return void
119      */
120     private function __construct()
121     {
122     
123     }
124 }
125
126 ?>