public function graph() { return Entity::graph(['GraphObjectBase'])->properties(['aString' => Type::String(), 'anInteger' => Type::Integer()->expected(array('integer_val')), 'aBoolean' => Type::Boolean(), 'flatArray' => Type::FlatArray(), 'aDouble' => Type::Double()->defaultVal(20.0)])->finalize(function (GraphObjectBase $instance, $scenario) { if ($scenario === 'test-finalize-inject') { $instance->aString = 'thisisthefinalizedstring'; $instance->aDouble = $instance->aDouble + 1.5; } }); }
public function graph() { return parent::graph()->extend(['GraphObjectChild'])->properties(['childValueStr' => Type::String()->expected(array('child_val_str', 'cvsrt')), 'childValueBool' => Type::Boolean()->expected(array('child_val_bool'))])->finalize(function ($instance, $scenario) { if ($scenario === 'test-finalize-map') { //when using map we are dealing with the same instance of the object and can use $this directly $this->childValueStr = $this->childValueStr . '__append_finalize_value'; //but is safer to change the $instance values instead $instance->aDouble = $instance->aDouble + 1.5; } }); }
public function graph() { return parent::graph()->extend(['User'])->properties(['age' => Type::Integer(), 'email' => Type::String(), 'loggedIn' => Type::Boolean(), 'location' => Type::Object(Location::create()), 'friends' => Type::Collection(Person::create())])->finalize(function (User $instance, $scenario, $data) { $instance->email .= '__appended_finalized_value'; }); }