Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of MVC-like architecture #55

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 5 additions & 6 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,18 @@ jobs:
-i "config/*" \
-i "CoordinatesResolver/*" \
-i "DataContainers/*" \
-i "Filters/*" \
-i "frontend/*" \
-x "frontend/src/*" \
-i "hb-events/*" \
-x "hb-events/src/*" \
-i "images/*" \
-i "log/*" \
-i "Rewrites/*" \
-i "scripts/*" \
-i "template-parts/*" \
-i "UI/*" \
-x "UI/AboutStructure/assets/src/*" \
-x "UI/Contacts/assets/src/*" \
-x "UI/Event/assets/src/*" \
-x "UI/Rentals/assets/src/*" \
-i "vendor/*" \
-i "ApplicationUrlTemplate.php" \
-i "webfonts/*" \
-i "Assets.php" \
-i "archive-novinky.php" \
-i "bootstrap.php" \
Expand All @@ -120,6 +118,7 @@ jobs:
-i "homepage-banner.php" \
-i "index.php" \
-i "PostTypeInitializer.php" \
-i "PropertyHandler.php" \
-i "screenshot.png" \
-i "single-novinky.php" \
-i "style.css"
Expand Down
28 changes: 0 additions & 28 deletions ApplicationUrlTemplate.php

This file was deleted.

12 changes: 11 additions & 1 deletion Assets.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php declare(strict_types = 1);
<?php

namespace HnutiBrontosaurus\Theme;

Expand All @@ -21,6 +21,15 @@ public static function script(string $name, WP_Theme $theme): void
);
}

public static function staticScript(string $name, WP_Theme $theme): void
{
wp_enqueue_script(
handle: 'hb-' . $name,
src: self::src($name, self::STATIC_JS_PATTERN, $theme),
ver: self::ver($name, self::STATIC_JS_PATTERN, $theme),
);
}

public static function style(string $name, WP_Theme $theme): void
{
wp_enqueue_style(
Expand All @@ -32,6 +41,7 @@ public static function style(string $name, WP_Theme $theme): void

private const CSS_PATTERN = '%s/frontend/dist/css/%s.css';
private const JS_PATTERN = '%s/frontend/dist/js/%s.js';
private const STATIC_JS_PATTERN = '%s/scripts/%s.js';

private static function src(string $for, string $pattern, WP_Theme $theme): string
{
Expand Down
2 changes: 1 addition & 1 deletion Configuration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php declare(strict_types = 1);
<?php

namespace HnutiBrontosaurus\Theme;

Expand Down
40 changes: 3 additions & 37 deletions Container.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php declare(strict_types = 1);
<?php

namespace HnutiBrontosaurus\Theme;

Expand All @@ -8,7 +8,6 @@
use HnutiBrontosaurus\BisClient\BisClient;
use HnutiBrontosaurus\BisClient\BisClientFactory;
use HnutiBrontosaurus\Theme\CoordinatesResolver\CoordinatesResolver;
use HnutiBrontosaurus\Theme\UI\Base\BaseFactory;
use Latte\Engine;
use function is_dir;
use function mkdir;
Expand All @@ -23,25 +22,9 @@ public function __construct(
) {}


private ?ApplicationUrlTemplate $applicationUrlTemplate = null;
public function getApplicationUrlTemplate(): ApplicationUrlTemplate
public function getConfiguration(): Configuration
{
if ($this->applicationUrlTemplate !== null) {
return $this->applicationUrlTemplate;
}

return $this->applicationUrlTemplate = ApplicationUrlTemplate::from($this->configuration->get('bis:applicationUrlTemplate'));
}


private ?BaseFactory $baseFactory = null;
public function getBaseFactory(): BaseFactory
{
if ($this->baseFactory !== null) {
return $this->baseFactory;
}

return $this->baseFactory = new BaseFactory($this->getEnableTracking());
return $this->configuration;
}


Expand Down Expand Up @@ -97,23 +80,6 @@ public function getEnableTracking(): bool
}


private ?Engine $latte = null;
public function getLatte(): Engine
{
if ($this->latte !== null) {
return $this->latte;
}

$cachePath = __DIR__ . '/temp/cache/latte';
self::createDirectoryIfNeeded($cachePath);

$latte = new Engine();
$latte->setTempDirectory($cachePath);

return $this->latte = $latte;
}


public function getSentryDsn(): ?string
{
return $this->configuration->has('sentry:dsn') && ($dsn = $this->configuration->get('sentry:dsn')) !== ''
Expand Down
2 changes: 1 addition & 1 deletion CoordinatesResolver/Coordinates.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php declare(strict_types = 1);
<?php

namespace HnutiBrontosaurus\Theme\CoordinatesResolver;

Expand Down
2 changes: 1 addition & 1 deletion CoordinatesResolver/CoordinatesResolver.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php declare(strict_types = 1);
<?php

namespace HnutiBrontosaurus\Theme\CoordinatesResolver;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php declare(strict_types = 1);
<?php

namespace HnutiBrontosaurus\Theme\UI\Courses;
namespace HnutiBrontosaurus\Theme\DataContainers;

use HnutiBrontosaurus\Theme\UI\PropertyHandler;
use HnutiBrontosaurus\Theme\Filters\CoursesFilters;
use HnutiBrontosaurus\Theme\PropertyHandler;


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php declare(strict_types = 1);
<?php

namespace HnutiBrontosaurus\Theme\UI\DataContainers\Events;
namespace HnutiBrontosaurus\Theme\DataContainers\Events;

use HnutiBrontosaurus\BisClient\Event\Response\Event;
use HnutiBrontosaurus\Theme\UI\PropertyHandler;
use HnutiBrontosaurus\Theme\PropertyHandler;


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php declare(strict_types = 1);
<?php

namespace HnutiBrontosaurus\Theme\UI\DataContainers\Events;
namespace HnutiBrontosaurus\Theme\DataContainers\Events;

use HnutiBrontosaurus\BisClient\Response\ContactPerson;
use HnutiBrontosaurus\Theme\UI\PropertyHandler;
use HnutiBrontosaurus\Theme\PropertyHandler;


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php declare(strict_types = 1);
<?php

namespace HnutiBrontosaurus\Theme\UI\DataContainers\Events;
namespace HnutiBrontosaurus\Theme\DataContainers\Events;

use HnutiBrontosaurus\BisClient\Event\Response\Event;
use HnutiBrontosaurus\Theme\UI\PropertyHandler;
use HnutiBrontosaurus\Theme\PropertyHandler;


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types = 1);
<?php

namespace HnutiBrontosaurus\Theme\UI\DataContainers\Events;
namespace HnutiBrontosaurus\Theme\DataContainers\Events;

use Brick\DateTime\LocalDate;
use Brick\DateTime\TimeZone;
Expand All @@ -10,13 +10,6 @@
use HnutiBrontosaurus\BisClient\Event\Program;
use HnutiBrontosaurus\BisClient\Event\Response\Event;
use HnutiBrontosaurus\BisClient\Event\Response\Tag;
use HnutiBrontosaurus\Theme\UI\Event\EventController;
use HnutiBrontosaurus\Theme\UI\Utils;
use function array_map;
use function get_site_url;
use function implode;
use function rtrim;
use function sprintf;


final /*readonly*/ class EventDC
Expand Down Expand Up @@ -56,10 +49,10 @@ public function __construct(Event $event, string $dateFormatHuman, string $dateF
$this->id = $event->getId();
$this->link = sprintf('%s/%s/%d/', // todo: use rather WP routing somehow
rtrim(get_site_url(), '/'),
EventController::PAGE_SLUG,
'akce',
$event->getId(),
);
$this->title = Utils::handleNonBreakingSpaces($event->getName());
$this->title = hb_handleNonBreakingSpaces($event->getName());

$coverPhotoPath = $event->getCoverPhotoPath();
$this->hasCoverPhoto = $coverPhotoPath !== null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php declare(strict_types = 1);
<?php

namespace HnutiBrontosaurus\Theme\UI\DataContainers\Events;
namespace HnutiBrontosaurus\Theme\DataContainers\Events;

use HnutiBrontosaurus\BisClient\Event\Response\Diet;
use HnutiBrontosaurus\BisClient\Event\Response\Event;
use HnutiBrontosaurus\BisClient\Event\Response\Food;
use HnutiBrontosaurus\Theme\UI\PropertyHandler;
use HnutiBrontosaurus\Theme\UI\Utils;
use HnutiBrontosaurus\Theme\PropertyHandler;


/**
Expand Down Expand Up @@ -70,17 +69,17 @@ public static function fromDTO(Event $event): self
$hasPresentation = $text !== null || \count($photos) > 0;

return new self(
Utils::handleNonBreakingSpaces($event->getPropagation()->getInvitationTextIntroduction()),
Utils::handleNonBreakingSpaces($event->getPropagation()->getInvitationTextPracticalInformation()),
hb_handleNonBreakingSpaces($event->getPropagation()->getInvitationTextIntroduction()),
hb_handleNonBreakingSpaces($event->getPropagation()->getInvitationTextPracticalInformation()),

$accommodation !== null,
$accommodation !== null ? Utils::handleNonBreakingSpaces($accommodation) : null,
$accommodation !== null ? hb_handleNonBreakingSpaces($accommodation) : null,

\count($food) > 0,
\array_map(static fn(Diet $food): string => $foodLabels[$food->toScalar()], $food),

$workDescription !== null,
$workDescription !== null ? Utils::handleNonBreakingSpaces($workDescription) : null,
$workDescription !== null ? hb_handleNonBreakingSpaces($workDescription) : null,
$workDays !== null,
$workDays,
$workHoursPerDay !== null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php declare(strict_types = 1);
<?php

namespace HnutiBrontosaurus\Theme\UI\DataContainers\Events;
namespace HnutiBrontosaurus\Theme\DataContainers\Events;

use HnutiBrontosaurus\BisClient\Event\Response\Image;
use HnutiBrontosaurus\Theme\UI\PropertyHandler;
use HnutiBrontosaurus\Theme\UI\Utils;
use HnutiBrontosaurus\Theme\PropertyHandler;


/**
Expand Down Expand Up @@ -35,7 +34,7 @@ public static function fromDTO(?string $text, array $photos): self
{
return new self(
$text !== null,
$text !== null ? Utils::handleNonBreakingSpaces($text) : null,
$text !== null ? hb_handleNonBreakingSpaces($text) : null,
\count($photos) > 0,
\array_map(fn(Image $photo): string => $photo->getMedium(), $photos),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php declare(strict_types = 1);
<?php

namespace HnutiBrontosaurus\Theme\UI\DataContainers\Events;
namespace HnutiBrontosaurus\Theme\DataContainers\Events;

use HnutiBrontosaurus\Theme\UI\PropertyHandler;
use HnutiBrontosaurus\Theme\PropertyHandler;


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php declare(strict_types = 1);
<?php

namespace HnutiBrontosaurus\Theme\UI\DataContainers\Events;
namespace HnutiBrontosaurus\Theme\DataContainers\Events;

use HnutiBrontosaurus\BisClient\Response\Location;
use HnutiBrontosaurus\Theme\UI\PropertyHandler;
use HnutiBrontosaurus\Theme\UI\Utils;
use HnutiBrontosaurus\Theme\PropertyHandler;


/**
Expand All @@ -27,7 +26,7 @@ public static function fromDTO(Location $place): self
{
$coordinates = $place->getCoordinates();
return new self(
Utils::handleNonBreakingSpaces($place->getName()),
hb_handleNonBreakingSpaces($place->getName()),
$coordinates !== null,
$coordinates !== null
? $coordinates->getLatitude() . ' ' . $coordinates->getLongitude() // e.g. 49.132456 16.123456
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php declare(strict_types = 1);
<?php

namespace HnutiBrontosaurus\Theme\UI\ForChildren;
namespace HnutiBrontosaurus\Theme\DataContainers;


use HnutiBrontosaurus\Theme\UI\PropertyHandler;
use HnutiBrontosaurus\Theme\Filters\ForChildrenFilters;
use HnutiBrontosaurus\Theme\PropertyHandler;


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php declare(strict_types = 1);
<?php

namespace HnutiBrontosaurus\Theme\UI\DataContainers;
namespace HnutiBrontosaurus\Theme\DataContainers;

use HnutiBrontosaurus\BisClient\Event\Response\Event;
use HnutiBrontosaurus\Theme\UI\DataContainers\Events\EventCollectionDC;
use HnutiBrontosaurus\Theme\UI\PropertyHandler;
use HnutiBrontosaurus\Theme\DataContainers\Events\EventCollectionDC;
use HnutiBrontosaurus\Theme\PropertyHandler;


/**
Expand Down
Loading
Loading