Вход Регистрация
Файл: vendor/intervention/image/src/Geometry/Factories/RectangleFactory.php
Строк: 132
<?php

declare(strict_types=1);

namespace 
InterventionImageGeometryFactories;

use 
InterventionImageExceptionsInvalidArgumentException;
use 
InterventionImageGeometryRectangle;
use 
InterventionImageInterfacesColorInterface;
use 
InterventionImageInterfacesDrawableFactoryInterface;
use 
InterventionImageInterfacesDrawableInterface;

class 
RectangleFactory implements DrawableFactoryInterface
{
    protected 
Rectangle $rectangle;

    
/**
     * Create new instance.
     *
     * @throws InvalidArgumentException
     */
    
public function __construct(null|callable|Rectangle $rectangle null)
    {
        
$this->rectangle $rectangle instanceof Rectangle ? clone $rectangle : new Rectangle(00);

        if (
is_callable($rectangle)) {
            
$rectangle($this);
        }
    }

    
/**
     * {@inheritdoc}
     *
     * @see DrawableFactoryInterface::build()
     *
     * @throws InvalidArgumentException
     */
    
public static function build(null|callable|DrawableInterface $drawable null): Rectangle
    
{
        return (new 
self($drawable))->drawable();
    }

    
/**
     * {@inheritdoc}
     *
     * @see DrawableFactoryInterface::drawable()
     */
    
public function drawable(): Rectangle
    
{
        return 
$this->rectangle;
    }

    
/**
     * Set the size of the rectangle to be produced.
     */
    
public function size(int $widthint $height): self
    
{
        
$this->rectangle->setWidth($width);
        
$this->rectangle->setHeight($height);

        return 
$this;
    }

    
/**
     * Set the width of the rectangle to be produced.
     */
    
public function width(int $width): self
    
{
        
$this->rectangle->setWidth($width);

        return 
$this;
    }

    
/**
     * Set the height of the rectangle to be produced.
     */
    
public function height(int $height): self
    
{
        
$this->rectangle->setHeight($height);

        return 
$this;
    }

    
/**
     * Set the background color of the rectangle to be produced.
     */
    
public function background(string|ColorInterface $color): self
    
{
        
$this->rectangle->setBackgroundColor($color);

        return 
$this;
    }

    
/**
     * Set the border color & border size of the rectangle to be produced.
     *
     * @throws InvalidArgumentException
     */
    
public function border(string|ColorInterface $colorint $size 1): self
    
{
        
$this->rectangle->setBorder($color$size);

        return 
$this;
    }

    
/**
     * Set the position where the rectangle should be drawn.
     */
    
public function at(int $xint $y): self
    
{
        
$this->rectangle->position()->setPosition($x$y);

        return 
$this;
    }
}
Онлайн: 2
Реклама