✨ Cockpit integration
This commit is contained in:
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Application\Models;
|
||||
|
||||
use Application\AppEnvironment;
|
||||
use Exception;
|
||||
use JMS\Serializer\Annotation\SerializedName;
|
||||
use JMS\Serializer\Annotation\Type;
|
||||
|
||||
@@ -44,12 +46,12 @@ class Image
|
||||
private array $colors;
|
||||
|
||||
#[SerializedName('width')]
|
||||
#[Type('string')]
|
||||
private string $width;
|
||||
#[Type('int')]
|
||||
private int $width;
|
||||
|
||||
#[SerializedName('height')]
|
||||
#[Type('string')]
|
||||
private string $height;
|
||||
#[Type('int')]
|
||||
private int $height;
|
||||
|
||||
#[SerializedName('altText')]
|
||||
#[Type('string')]
|
||||
@@ -62,4 +64,56 @@ class Image
|
||||
#[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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user