/** * Return a GraphObject loaded with data from Facebook Graph API * * @param GraphObjectType $type * @param string|int $id * * @return ObjectAbstract * @throws UnsupportedObjectException unable to find a class to support this */ public static function load(GraphObjectType $type, $id) { $class_name = __NAMESPACE__ . '\\' . $type->value(); if (class_exists($class_name)) { /** @var ObjectAbstract $obj */ $obj = new $class_name(); return $obj; } else { throw new UnsupportedObjectException('Unsupported Object, class not found for ' . $object); } }
/** * Iterate round all the GraphObjectType supported Object names * and instantiate a new Object using the Factory::create method */ public function testObjectCreation() { foreach (GraphObjectType::members() as $graph_object) { /** @var GraphObjectType $graph_object */ $this->assertInstanceOf('ChrisNoden\\Facebook\\Graph\\GraphObjectType', $graph_object); $class_name = $graph_object->value(); $obj = ObjectFactory::create($class_name); $this->assertInstanceOf('ChrisNoden\\Facebook\\Graph\\Object\\ObjectAbstract', $obj); $this->assertInstanceOf('ChrisNoden\\Facebook\\Graph\\Object\\' . $class_name, $obj); $this->assertEquals($class_name, $obj->__toString()); // all objects have an ID field - if not then this will throw an InvalidArgumentException $obj->getFieldDetails('id'); // dispose of the object before next iteration $obj = null; unset($obj); } }