Cockpit integration

This commit is contained in:
2024-11-07 21:34:32 +01:00
parent d3eccf99f0
commit a4b336b3fd
8 changed files with 153 additions and 41 deletions

View File

@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Application\Controller;
use Application\Content\CockpitApi;
@@ -8,7 +10,6 @@ use GuzzleHttp\Exception\GuzzleException;
class ArticleController extends MainController
{
/**
* @throws Exception
* @throws GuzzleException
@@ -17,15 +18,20 @@ class ArticleController extends MainController
{
$article = (new CockpitApi())->getArticle($this->getRouteParams('id'));
$this->getBreadcrumbs()->addBreadcrumb(
$article->getTitle(),
$article->getUrl()
);
$this->pushToStash('article', [
'subtitle' => $this->faker->sentence(2),
'subtitle' => 'TODO: Subtitle',
'title' => $article->getTitle(),
'lead' => $this->faker->paragraph(),
'lead' => $article->getExcerpt(),
'text' => $article->getText(),
'image' => [
'src' => 'https://picsum.photos/seed/' . $this->faker->randomDigit() . '/1920/1080',
'width' => 1920,
'height' => 1080,
'src' => $article->getImage()->getImageUrl(),
'width' => $article->getImage()->getWidth(),
'height' => $article->getImage()->getHeight(),
'alt' => 'lorem ipsum',
],
]);

View File

@@ -1,27 +1,33 @@
<?php
declare(strict_types=1);
namespace Application\Controller;
use Application\Generator\Article;
use Application\Helper\NumberHash;
use Application\Content\CockpitApi;
use Exception;
use GuzzleHttp\Exception\GuzzleException;
class HomeController extends MainController
{
/**
* @throws Exception
* @throws GuzzleException
*/
protected function action(): void
{
$this->pushToStash('articles', $this->generateArticles());
$this->pushToStash('articles', $this->getArticles());
}
private function generateArticles(): array
/**
* @throws GuzzleException
*/
private function getArticles(): array
{
$return = [];
for ($i = 0; $i < 10; $i++) {
$return[] = (new Article(NumberHash::numHash("home_$i")))->getTeaserData();
foreach ((new CockpitApi())->getArticles() as $article) {
$return[] = $article->getTeaserData();
}
return $return;

View File

@@ -10,8 +10,6 @@ use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use Twig\Loader\FilesystemLoader;
use Faker\Factory;
use Faker\Generator;
abstract class MainController
{
@@ -50,13 +48,6 @@ abstract class MainController
*/
private array $route_parameters = array();
/**
* Fake data generator.
*
* @var Generator
*/
protected Generator $faker;
/**
* Breadcrumbs.
*
@@ -73,8 +64,6 @@ abstract class MainController
public function __invoke(array $parameters = array()): void
{
$this->route_parameters = $parameters;
$this->faker = Factory::create();
$this->faker->seed(1234567);
$this->preAction();
$this->action();
$this->postAction();
@@ -150,7 +139,7 @@ abstract class MainController
$this->pushToStash(
'meta',
[
'title' => $this->faker->domainName(),
'title' => 'News Page | Your #1 News Source',
],
self::STASH_GLOBAL
);