HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/brameda/brameda.nl/app/Komma/Kms/Core/Attributes/Models/AbstractImageProperty.php
<?php

namespace App\Komma\Kms\Core\Attributes\Models;

use Illuminate\Contracts\Support\Arrayable;
use JsonSerializable;

/**
 * Interface ImagePropertyInterface
 * @package App\Komma\Kms\Core\Attributes\Models
 */
abstract class AbstractImageProperty implements Arrayable, JsonSerializable
{
    /** @const int Thumb The smallest image size representing a thumbnail */
    const Thumb = 1;

    /** @const int Thumb Representing a small image */
    const Small = 2;

    /** @const int Thumb Representing a medium image */
    const Medium = 3;

    /** @const int Thumb Representing a large image */
    const Large = 4;

    /** @const int Thumb Representing the original image size */
    const Original = 5;

    /**
     * @return int[] All image sizes as an array of integers
     * @throws \ReflectionException
     */
    static function getAsArray() {
        return self::getAllImageSizes();
    }

    /**
     * Check if the passed image size is really an image size that is defined as a constant in this class.
     *
     * @param int $imageSize
     * @param bool $strict If true it will only consider an image size as valid if it is a string.
     * @return bool Returns true if the image size is a valid one, false otherwise
     * @throws \ReflectionException
     */
    static function isValidImageSize(int $imageSize, $strict = false) {
        return in_array($imageSize, self::getAllImageSizes(), $strict);
    }

    /**
     * Returns an array containing integers representing the defined image sizes.
     *
     * @return int[]
     * @throws \ReflectionException
     */
    private static function getAllImageSizes()
    {
        $thisClassAsReflectionClass = new \ReflectionClass(__CLASS__);
        return $thisClassAsReflectionClass->getConstants();
    }

    /**
     * @return string Gets the name of this ImagePropertyInterface instance
     */
    abstract public function getName(): string;

    /**
     * Sets the name of this ImagePropertyInterface instance and returns itself
     *
     * @param string $name
     * @return AbstractImageProperty
     */
    abstract public function setName(string $name): AbstractImageProperty;

    /**
     * Sets the width of this ImagePropertyInterface and returns itself
     *
     * @param float $width
     * @return AbstractImageProperty
     */
    abstract public function setWidth(float $width): AbstractImageProperty;

    /**
     * Returns the width of this ImagePropertyInterface instance
     *
     * @return float
     */
    abstract public function getWidth(): float;

    /**
     * Sets the height of this ImagePropertyInterface and returns itself.
     * 0 for auto if implemented in the cropper that uses this
     *
     * @param float $height
     * @return AbstractImageProperty
     */
    abstract public function setHeight(float $height): AbstractImageProperty;

    /**
     * Returns the height of this ImagePropertyInterface instance
     *
     * @return float
     */
    abstract public function getHeight(): float;

    /**
     * Sets the crop method of this ImagePropertyInterface and returns itself
     *
     * @param int $method
     * @return AbstractImageProperty
     */
    abstract public function setCropMethod(int $method): AbstractImageProperty;

    /**
     * Returns the crop method of this ImagePropertyInterface instance
     *
     * @return int
     */
    abstract public function getCropMethod(): int;



    /**
     * @return array
     */
    public function toArray()
    {
        return [
            'name' => $this->getName(),
            'cropMethod' => $this->getCropMethod(),
            'width' => $this->getWidth(),
            'height' => $this->getHeight(),
        ];
    }

    /**
     * Convert the object into something JSON serializable.
     *
     * @return array
     */
    public function jsonSerialize()
    {
        return $this->toArray();
    }

    /**
     * Return an instance of the image property from an array
     *
     * @param $imagePropertyAsArray
     * @return static
     */
    abstract public static function fromArray($imagePropertyAsArray);
}