120 lines
2.2 KiB
PHP
120 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Application\Models;
|
|
|
|
use Application\AppEnvironment;
|
|
use Exception;
|
|
use JMS\Serializer\Annotation\SerializedName;
|
|
use JMS\Serializer\Annotation\Type;
|
|
|
|
class Image
|
|
{
|
|
use Meta;
|
|
|
|
#[SerializedName('path')]
|
|
#[Type('string')]
|
|
private string $path;
|
|
|
|
#[SerializedName('title')]
|
|
#[Type('string')]
|
|
private string $title;
|
|
|
|
#[SerializedName('mime')]
|
|
#[Type('string')]
|
|
private string $mime;
|
|
|
|
#[SerializedName('type')]
|
|
#[Type('string')]
|
|
private string $type;
|
|
|
|
#[SerializedName('description')]
|
|
#[Type('string')]
|
|
private string $description;
|
|
|
|
#[SerializedName('tags')]
|
|
#[Type('array')]
|
|
private array $tags;
|
|
|
|
#[SerializedName('size')]
|
|
#[Type('string')]
|
|
private string $size;
|
|
|
|
#[SerializedName('colors')]
|
|
#[Type('array')]
|
|
private array $colors;
|
|
|
|
#[SerializedName('width')]
|
|
#[Type('int')]
|
|
private int $width;
|
|
|
|
#[SerializedName('height')]
|
|
#[Type('int')]
|
|
private int $height;
|
|
|
|
#[SerializedName('altText')]
|
|
#[Type('string')]
|
|
private string $altText;
|
|
|
|
#[SerializedName('thumbhash')]
|
|
#[Type('string')]
|
|
private string $thumbhash;
|
|
|
|
#[SerializedName('folder')]
|
|
#[Type('string')]
|
|
private string $folder;
|
|
|
|
/**
|
|
* Return the URL to the original asset.
|
|
*
|
|
* @return string
|
|
* @throws Exception
|
|
*/
|
|
public function getImageUrl(): string
|
|
{
|
|
$apiPath = AppEnvironment::getInstance()->getVariable('COCKPIT_API_PATH');
|
|
$url = parse_url($apiPath, PHP_URL_SCHEME) . '://';
|
|
$url .= parse_url($apiPath, PHP_URL_HOST) . '/storage/uploads';
|
|
$url .= $this->path;
|
|
|
|
return $url;
|
|
}
|
|
|
|
/**
|
|
* Return original image width in pixel.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function getWidth(): int
|
|
{
|
|
return $this->width;
|
|
}
|
|
|
|
/**
|
|
* Return original image height in pixel.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function getHeight(): int
|
|
{
|
|
return $this->height;
|
|
}
|
|
|
|
/**
|
|
* Get teaser data array ready to be used within the template.
|
|
*
|
|
* @return array
|
|
* @throws Exception
|
|
*/
|
|
public function getTeaserData(): array
|
|
{
|
|
return [
|
|
'src' => $this->getImageUrl(),
|
|
'width' => $this->getWidth(),
|
|
'height' => $this->getHeight(),
|
|
'alt' => $this->altText,
|
|
];
|
|
}
|
|
}
|