/** * @return string */ public function getLastName() { return Str::studly($this->lastName); }
/** * Get an array representation of this entity. * * @return array */ public function toArray() { $result = []; ArrayList::of($this->getFillable())->append(ArrayList::of($this->getVisible()))->unique(SORT_STRING)->exceptValues($this->getHidden())->each(function ($key) use(&$result) { $getter = vsprintf('get%s', [Str::studly($key)]); if (method_exists($this, $getter)) { $result[$key] = $this->{$getter}(); return; } $camel = Str::camel($key); $result[$key] = $this->{$camel}; }); return $result; }
public function testStudly() { $this->assertEquals('SnakeCaseStuff', Str::studly('snake_case_stuff')); $this->assertEquals('CamelCaseStuff', Str::studly('camelCaseStuff')); }
/** * Set properties of an object by only calling setters of array keys that * are set in the input array. Useful for parsing API responses into * entities. * * @param object $object * @param array $input * @param string[]|null $allowed */ public static function callSetters($object, array $input, array $allowed = null) { $filtered = ArrayMap::of($input); if ($allowed !== null) { $filtered = $filtered->only($allowed); } $filtered->each(function ($value, $key) use(&$object) { $setterName = 'set' . Str::studly($key); $object->{$setterName}($value); }); }
/** * Get a list of example responses for a specific method. * * @param string $methodName * * @return Response[] */ public function getMethodExampleResponses($methodName) { $getterName = vsprintf('get%sExampleResponses', [Str::studly($methodName)]); if (method_exists($this, $getterName)) { return $this->{$getterName}(); } return []; }