File: D:/HostingSpaces/stafa/werkenbijstafa.nl/app/Komma/Kms/Core/Attributes/Models/ImageProperty.php
<?php
/**
* Created by PhpStorm.
* User: julesgraus
* Date: 14/12/17
* Time: 09:27
*/
namespace App\Komma\Kms\Core\Attributes\Models;
class ImageProperty extends AbstractImageProperty
{
/**
* @const int CropFit Fits the image in width and height
*/
const Fit = 1;
const Crop = 2;
const Resize = 3;
/** @var string $name */
private $name;
/** @var int $width */
private $width;
/** @var int $height */
private $height;
/** @var int $cropMethod */
private $cropMethod;
/**
* ImageProperty constructor.
*/
public function __construct()
{
$this->width = $this->height = 0;
}
/**
* @return string Gets the name of this ImagePropertyInterface instance
*/
public function getName(): string
{
return $this->name;
}
/**
* Sets the name of this ImagePropertyInterface instance and returns itself
*
* @param string $name
* @return AbstractImageProperty
*/
public function setName(string $name): AbstractImageProperty
{
$this->name = $name;
return $this;
}
/**
* Sets the width of this ImagePropertyInterface and returns itself
*
* @param float $width
* @return AbstractImageProperty
*/
public function setWidth(float $width): AbstractImageProperty
{
$this->width = $width;
return $this;
}
/**
* Returns the width of this ImagePropertyInterface instance
*
* @return float
*/
public function getWidth(): float
{
return $this->width;
}
/**
* Sets the height of this ImagePropertyInterface and returns itself
*
* @param float $height
* @return AbstractImageProperty
*/
public function setHeight(float $height): AbstractImageProperty
{
$this->height = $height;
return $this;
}
/**
* Returns the height of this ImagePropertyInterface instance
*
* @return float
*/
public function getHeight(): float
{
return $this->height;
}
/**
* Sets the crop method of this ImagePropertyInterface and returns itself.
* Use one of the internal crop constants for the correct value
*
* @param int $method
* @return AbstractImageProperty
*/
public function setCropMethod(int $method): AbstractImageProperty
{
$this->cropMethod = $method;
return $this;
}
/**
* Returns the crop method of this ImagePropertyInterface instance
*
* @return int
*/
public function getCropMethod(): int
{
return $this->cropMethod;
}
/**
* Return an instance of the image property from an array
*
* @param $imagePropertyAsArray
* @return static
*/
public static function fromArray($imagePropertyAsArray)
{
if(
(!isset($imagePropertyAsArray['name']) || !is_string($imagePropertyAsArray['name'])) ||
(!isset($imagePropertyAsArray['cropMethod']) || !in_array($imagePropertyAsArray['cropMethod'], [self::Fit, self::Crop, self::Resize])) ||
(!isset($imagePropertyAsArray['width']) || is_int($imagePropertyAsArray['width'])) ||
(!isset($imagePropertyAsArray['height']) || is_int($imagePropertyAsArray['height']))
)
$instance = new self();
$instance->setName($imagePropertyAsArray['name']);
$instance->setCropMethod($imagePropertyAsArray['cropMethod']);
$instance->setHeight($imagePropertyAsArray['height']);
$instance->setWidth($imagePropertyAsArray['width']);
return $instance;
}
}