public function hydrate($data) { parent::hydrate($data); $object = Objects::create(ActivityFeedStoryEnum::$storyTypes[$this->story->storyType], []); $object->hydrate($this->story); $this->story = $object; }
public function testNewv() { $expect = new Pancake('Blueberry', "Maple Syrup"); $this->assertEquals($expect, Objects::create('Pancake', ['Blueberry', "Maple Syrup"])); $expect = new Pancake(); $this->assertEquals($expect, Objects::create('Pancake', [])); }
/** * Create an instance of this endpoint already bound to the API * * @param ApiInterface $api * * @return static */ public static function bound(ApiInterface $api) { $args = func_get_args(); array_shift($args); $new = Objects::create(get_called_class(), $args); /** * @var $new ApiAwareInterface */ $api->bind($new); return $new; }
public function hydrate($data) { parent::hydrate($data); $items = []; foreach ($this->items as $k => $story) { $object = Objects::create(ActivityFeedStoryEnum::$storyTypes[$story->storyType], []); $object->hydrate($story); $items[$k] = $object; } $this->items = $items; }
public function hydrate($data) { parent::hydrate($data); $items = []; foreach ($this->items as $item) { $raw = DynamicDataNodeResponse::make($item); $node = Objects::create($raw->class, []); if ($node instanceof DataNodeResponse) { $node->hydrate($raw->data); } $items[] = $node; } $this->items = $items; }
/** * @param $fresh bool Create a new instance of the DAO Class * * @return IDao */ public function createNewDao($fresh = true) { if ($fresh || $this->_dao === null) { $class = Objects::create($this->_daoClass, []); if ($class instanceof IDao) { if (!$fresh) { $this->_dao = $class; } return $class; } else { throw new \RuntimeException("'{$this->_daoClass}' is not a valid DAO Class"); } } return $this->_dao; }
/** * @param $class * @param $expect * * @dataProvider tagDataProvider */ public function testTagHtml($class, $expect) { $tag = Objects::create($class, ['Test']); $this->assertInstanceOf('\\Packaged\\Glimpse\\Core\\HtmlTag', $tag); /** * @var $tag HtmlTag */ $this->assertEquals('<' . $expect . '>Test</' . $expect . '>', $tag->asHtml()); $tag = $class::create('Test'); $this->assertInstanceOf('\\Packaged\\Glimpse\\Core\\HtmlTag', $tag); /** * @var $tag HtmlTag */ $this->assertEquals('<' . $expect . '>Test</' . $expect . '>', $tag->asHtml()); }
/** * Invokes the "new" operator with a vector of arguments. There is no way to * call_user_func_array() on a class constructor, so you can instead use this * function: * * $obj = newv($class_name, $argv); * * That is, these two statements are equivalent: * * $pancake = new Pancake('Blueberry', 'Maple Syrup', true); * $pancake = newv('Pancake', array('Blueberry', 'Maple Syrup', true)); * * DO NOT solve this problem in other, more creative ways! Three popular * alternatives are: * * - Build a fake serialized object and unserialize it. * - Invoke the constructor twice. * - just use eval() lol * * These are really bad solutions to the problem because they can have side * effects (e.g., __wakeup()) and give you an object in an otherwise impossible * state. Please endeavor to keep your objects in possible states. * * If you own the classes you're doing this for, you should consider whether * or not restructuring your code (for instance, by creating static * construction methods) might make it cleaner before using newv(). Static * constructors can be invoked with call_user_func_array(), and may give your * class a cleaner and more descriptive API. * * @param $className string The name of a class. * @param $argv array Array of arguments to pass to its constructor. * * @return object A new object of the specified class, constructed by * passing the argument vector to its constructor. * @group util * * @deprecated */ function newv($className, array $argv) { return \Packaged\Helpers\Objects::create($className, $argv); }