Файл: vendor/intervention/image/src/Geometry/Factories/PolygonFactory.php
Строк: 111
<?php
declare(strict_types=1);
namespace InterventionImageGeometryFactories;
use InterventionImageExceptionsInvalidArgumentException;
use InterventionImageGeometryPoint;
use InterventionImageGeometryPolygon;
use InterventionImageInterfacesColorInterface;
use InterventionImageInterfacesDrawableFactoryInterface;
use InterventionImageInterfacesDrawableInterface;
class PolygonFactory implements DrawableFactoryInterface
{
protected Polygon $polygon;
/**
* Create new factory instance.
*/
public function __construct(null|callable|Polygon $polygon = null)
{
$this->polygon = $polygon instanceof Polygon ? clone $polygon : new Polygon([]);
if (is_callable($polygon)) {
$polygon($this);
}
}
/**
* {@inheritdoc}
*
* @see DrawableFactoryInterface::build()
*/
public static function build(null|callable|DrawableInterface $drawable = null): Polygon
{
return (new self($drawable))->drawable();
}
/**
* {@inheritdoc}
*
* @see DrawableFactoryInterface::drawable()
*/
public function drawable(): Polygon
{
return $this->polygon;
}
/**
* Add a point to the polygon to be produced.
*/
public function point(int $x, int $y): self
{
$this->polygon->addPoint(new Point($x, $y));
return $this;
}
/**
* Set the background color of the polygon to be produced.
*/
public function background(string|ColorInterface $color): self
{
$this->polygon->setBackgroundColor($color);
return $this;
}
/**
* Set the border color & border size of the polygon to be produced.
*
* @throws InvalidArgumentException
*/
public function border(string|ColorInterface $color, int $size = 1): self
{
$this->polygon->setBorder($color, $size);
return $this;
}
}