/** * Set the value of an annotation. * * @param string $fieldName * @param string $name * @param mixed $value * * @return static */ public function withFieldAnnotation($fieldName, $name, $value) { $copy = clone $this; $copy->annotations = $this->annotations->update($fieldName, function (ArrayMap $fieldAnnotations) use($name, $value) { return $fieldAnnotations->insert($name, $value); }, ArrayMap::zero()); return $copy; }
/** * Fill properties in this object using an input array. * * - Only fields that are mentioned in the fillable array can be set. * - Other keys will just be ignored completely. * - If a setter is present, it will be automatically called. * * @param array $input * * @return $this * @throws LackOfCoffeeException */ public function fill(array $input) { $this->assertIsFillable(); ArrayMap::of($input)->only($this->getFillable())->each(function ($value, $key) { $setter = vsprintf('set%s', [Str::studly($key)]); if (method_exists($this, $setter)) { $this->{$setter}($value); return; } $camel = Str::camel($key); $this->{$camel} = $value; }); return $this; }
/** * @return ListInterface */ public static function toValuesList() { return ArrayMap::of(static::getValues())->values(); }
/** * Build an instance of the defined Spec. * * @return Spec */ public function make() { return new Spec($this->constraints->toArray(), $this->defaults->toArray(), $this->required->toArray()); }
/** * Execute the transform. * * @param array $input * * @return array */ public function run(array $input) { return ArrayMap::of($input)->only($this->allowed)->toArray(); }
/** * 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); }); }
/** * Render the attributes part of the opening tag. * * @return string */ protected function renderAttributes() { return ArrayMap::of($this->attributes)->map(function ($value, $name) { return $this->renderAttribute($name, $value); })->join(' '); }