GradientBuilder

Fluent builder for creating gradients with great developer experience.

Provides a chainable API for constructing gradients with an intuitive syntax.

Methods

at

public function at(string $position): GradientBuilder

Set the position for radial or conic gradients.

Parameters
NameTypeDefault
$position string -
public function build(): GradientInterface

Build the gradient.

public function circle(): GradientBuilder

Set as a circular radial gradient.

conic

static
public static function conic(float $angle): GradientBuilder

Start building a new conic gradient.

Parameters
NameTypeDefault
$angle float 0
public function from(ColorInterface|string $color): GradientBuilder

Add a color stop at the start (position 0.0).

Parameters
NameTypeDefault
$color ColorInterface|string -

in

public function in(InterpolationSpace|string $colorSpace): GradientBuilder

Set the interpolation color space.

Parameters
NameTypeDefault
$colorSpace InterpolationSpace|string -

linear

static
public static function linear(float $angle): GradientBuilder

Start building a new linear gradient.

Parameters
NameTypeDefault
$angle float 180

radial

static
public static function radial(): GradientBuilder

Start building a new radial gradient.

public function shape(RadialShape|string $shape): GradientBuilder

Set the shape for radial gradients.

Parameters
NameTypeDefault
$shape RadialShape|string -
public function size(RadialSize|string $size): GradientBuilder

Set the size for radial gradients.

Parameters
NameTypeDefault
$size RadialSize|string -
public function stop(ColorInterface|string $color, float $position): GradientBuilder

Add a color stop at a specific position.

Parameters
NameTypeDefault
$color ColorInterface|string -
$position float -
public function stops(ColorInterface|GradientStop|string $stops): GradientBuilder

Add multiple color stops with automatic position distribution.

Accepts colors, color strings, or GradientStop objects. GradientStop objects keep their
position, while colors/strings are spread evenly between the surrounding positions.

Parameters
NameTypeDefault
$stops ColorInterface|GradientStop|string -

to

public function to(ColorInterface|string $color): GradientBuilder

Add a color stop at the end (position 1.0).

Parameters
NameTypeDefault
$color ColorInterface|string -

via

public function via(ColorInterface|string $color): GradientBuilder

Add a color stop at the middle (position 0.5).

Parameters
NameTypeDefault
$color ColorInterface|string -