🎉 initial commit
This commit is contained in:
63
classes/Application/Generator/Article.php
Normal file
63
classes/Application/Generator/Article.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Application\Generator;
|
||||
|
||||
class Article extends WebsiteObjectGenerator
|
||||
{
|
||||
public function __construct(protected readonly string $seed)
|
||||
{
|
||||
parent::__construct($seed);
|
||||
}
|
||||
|
||||
private function getHeadline(): string
|
||||
{
|
||||
return $this->getGenerator()->sentence(8);
|
||||
}
|
||||
|
||||
private function getKicker(): string
|
||||
{
|
||||
return $this->getGenerator()->word();
|
||||
}
|
||||
|
||||
private function getTeaserImage(): array
|
||||
{
|
||||
return (new Image($this->getSeed()))->getImage(640, 480);
|
||||
}
|
||||
|
||||
private function getHeroImage(): array
|
||||
{
|
||||
return (new Image($this->getSeed()))->getImage(1920, 1080);
|
||||
}
|
||||
|
||||
private function getExcerpt(): string
|
||||
{
|
||||
return implode(' ', $this->getGenerator()->sentences(5));
|
||||
}
|
||||
|
||||
private function getUrl(): string
|
||||
{
|
||||
return '/article/test-' . $this->getSeed();
|
||||
}
|
||||
|
||||
public function getTeaserData(): array
|
||||
{
|
||||
return [
|
||||
'headline' => $this->getHeadline(),
|
||||
'kicker' => $this->getKicker(),
|
||||
'excerpt' => $this->getExcerpt(),
|
||||
'teaserImage' => $this->getTeaserImage(),
|
||||
'url' => $this->getUrl(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getFullData(): array
|
||||
{
|
||||
return [
|
||||
'headline' => $this->getHeadline(),
|
||||
'kicker' => $this->getKicker(),
|
||||
'excerpt' => $this->getExcerpt(),
|
||||
'heroImage' => $this->getHeroImage(),
|
||||
'url' => $this->getUrl(),
|
||||
];
|
||||
}
|
||||
}
|
23
classes/Application/Generator/Image.php
Normal file
23
classes/Application/Generator/Image.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Application\Generator;
|
||||
|
||||
use Application\Generator\WebsiteObjectGenerator;
|
||||
|
||||
class Image extends WebsiteObjectGenerator
|
||||
{
|
||||
public function __construct(protected readonly string $seed)
|
||||
{
|
||||
parent::__construct($seed);
|
||||
}
|
||||
|
||||
public function getImage(int $width = 1280, int $height = 720): array
|
||||
{
|
||||
return [
|
||||
'src' => 'https://picsum.photos/seed/' . $this->seed . "/$width/$height",
|
||||
'width' => $width,
|
||||
'height' => $height,
|
||||
'alt' => $this->getGenerator()->sentence(),
|
||||
];
|
||||
}
|
||||
}
|
30
classes/Application/Generator/WebsiteObjectGenerator.php
Normal file
30
classes/Application/Generator/WebsiteObjectGenerator.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Application\Generator;
|
||||
|
||||
use Faker\Factory;
|
||||
use Faker\Generator;
|
||||
|
||||
class WebsiteObjectGenerator
|
||||
{
|
||||
/**
|
||||
* @var Generator
|
||||
*/
|
||||
private Generator $generator;
|
||||
|
||||
public function __construct(private readonly string $seed)
|
||||
{
|
||||
$this->generator = Factory::create();
|
||||
$this->getGenerator()->seed($this->seed);
|
||||
}
|
||||
|
||||
protected function getGenerator(): Generator
|
||||
{
|
||||
return $this->generator;
|
||||
}
|
||||
|
||||
protected function getSeed(): string
|
||||
{
|
||||
return $this->seed;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user