mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 13:57:10 +02:00
Optimized FixtureSources and menu
This commit is contained in:
@@ -21,7 +21,7 @@ final class DefaultController extends AbstractController
|
||||
public function homepage(): Response
|
||||
{
|
||||
return $this->redirectToRoute('infinito_api_rest_layer_read', [
|
||||
'identity' => HomepageFixtureSource::SLUG,
|
||||
'identity' => HomepageFixtureSource::getSlug(),
|
||||
'layer' => LayerType::SOURCE,
|
||||
'_format' => RESTResponseType::HTML,
|
||||
]);
|
||||
|
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Domain\FixtureManagement;
|
||||
|
||||
use Infinito\Entity\Meta\Right;
|
||||
use Infinito\DBAL\Types\Meta\Right\LayerType;
|
||||
use Infinito\DBAL\Types\ActionType;
|
||||
use Infinito\Entity\Source\SourceInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class EntityTemplateFactory extends Right
|
||||
{
|
||||
/**
|
||||
* @param SourceInterface $source
|
||||
*/
|
||||
public static function createStandartPublicRight(SourceInterface $source): Right
|
||||
{
|
||||
$right = new Right();
|
||||
$law = $source->getLaw();
|
||||
$right->setLaw($law);
|
||||
$law->getRights()->add($right);
|
||||
$right->setSource($source);
|
||||
$right->setLayer(LayerType::SOURCE);
|
||||
$right->setActionType(ActionType::READ);
|
||||
|
||||
return $right;
|
||||
}
|
||||
}
|
@@ -9,4 +9,17 @@ namespace Infinito\Domain\FixtureManagement\FixtureSource;
|
||||
*/
|
||||
abstract class AbstractFixtureSource implements FixtureSourceInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function getSlug(): string
|
||||
{
|
||||
$className = get_called_class();
|
||||
$exploded = explode('\\', $className);
|
||||
$shortname = $exploded[count($exploded) - 1];
|
||||
$key = str_replace('FixtureSource', '', $shortname);
|
||||
$lower = strtolower($key);
|
||||
|
||||
return $lower;
|
||||
}
|
||||
}
|
||||
|
@@ -23,4 +23,11 @@ interface FixtureSourceInterface
|
||||
* @return SlugAttributInterface
|
||||
*/
|
||||
public static function getSlug(): string;
|
||||
|
||||
/**
|
||||
* @see https://fontawesome.com
|
||||
*
|
||||
* @return string|null a fontawesome css class
|
||||
*/
|
||||
public static function getIcon(): string;
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ namespace Infinito\Domain\FixtureManagement\FixtureSource;
|
||||
|
||||
use Infinito\Entity\Source\SourceInterface;
|
||||
use Infinito\Entity\Source\Complex\UserSource;
|
||||
use Infinito\Domain\FixtureManagement\EntityTemplateFactory;
|
||||
|
||||
/**
|
||||
* This class containes the guest user.
|
||||
@@ -12,8 +13,6 @@ use Infinito\Entity\Source\Complex\UserSource;
|
||||
*/
|
||||
final class GuestUserFixtureSource extends AbstractFixtureSource
|
||||
{
|
||||
const SLUG = 'GUEST_USER';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
@@ -22,7 +21,8 @@ final class GuestUserFixtureSource extends AbstractFixtureSource
|
||||
public function getORMReadyObject(): SourceInterface
|
||||
{
|
||||
$userSource = new UserSource();
|
||||
$userSource->setSlug(self::SLUG);
|
||||
$userSource->setSlug(self::getSlug());
|
||||
EntityTemplateFactory::createStandartPublicRight($userSource);
|
||||
|
||||
return $userSource;
|
||||
}
|
||||
@@ -30,8 +30,8 @@ final class GuestUserFixtureSource extends AbstractFixtureSource
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function getSlug(): string
|
||||
public static function getIcon(): string
|
||||
{
|
||||
return self::SLUG;
|
||||
return 'fas fa-user';
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Domain\FixtureManagement\FixtureSource;
|
||||
|
||||
use Infinito\Entity\Source\SourceInterface;
|
||||
use Infinito\Entity\Source\Primitive\Text\TextSource;
|
||||
use Infinito\Domain\FixtureManagement\EntityTemplateFactory;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class HelpFixtureSource extends AbstractFixtureSource
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Infinito\Domain\FixtureManagement\FixtureSource\FixtureSourceInterface::getORMReadyObject()
|
||||
*/
|
||||
public function getORMReadyObject(): SourceInterface
|
||||
{
|
||||
$helpSource = new TextSource();
|
||||
$helpSource->setText('See https://github.com/KevinFrantz/infinito/issues.');
|
||||
$helpSource->setSlug(self::getSlug());
|
||||
EntityTemplateFactory::createStandartPublicRight($helpSource);
|
||||
|
||||
return $helpSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function getIcon(): string
|
||||
{
|
||||
return 'fas fa-question';
|
||||
}
|
||||
}
|
@@ -4,20 +4,13 @@ namespace Infinito\Domain\FixtureManagement\FixtureSource;
|
||||
|
||||
use Infinito\Entity\Source\SourceInterface;
|
||||
use Infinito\Entity\Source\Primitive\Text\TextSource;
|
||||
use Infinito\Entity\Meta\Right;
|
||||
use Infinito\DBAL\Types\Meta\Right\LayerType;
|
||||
use Infinito\DBAL\Types\ActionType;
|
||||
use Infinito\Domain\FixtureManagement\EntityTemplateFactory;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class HomepageFixtureSource extends AbstractFixtureSource
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const SLUG = 'HOMEPAGE';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
@@ -25,24 +18,16 @@ final class HomepageFixtureSource extends AbstractFixtureSource
|
||||
*/
|
||||
public function getORMReadyObject(): SourceInterface
|
||||
{
|
||||
$impressumSource = new TextSource();
|
||||
$impressumSource->setText('Welcome to infinito!');
|
||||
$impressumSource->setSlug(self::SLUG);
|
||||
$right = new Right();
|
||||
$right->setSource($impressumSource);
|
||||
$right->setLayer(LayerType::SOURCE);
|
||||
$right->setActionType(ActionType::READ);
|
||||
$right->setLaw($impressumSource->getLaw());
|
||||
$impressumSource->getLaw()->getRights()->add($right);
|
||||
$homepage = new TextSource();
|
||||
$homepage->setText('Welcome to infinito!');
|
||||
$homepage->setSlug(self::getSlug());
|
||||
EntityTemplateFactory::createStandartPublicRight($homepage);
|
||||
|
||||
return $impressumSource;
|
||||
return $homepage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function getSlug(): string
|
||||
public static function getIcon(): string
|
||||
{
|
||||
return self::SLUG;
|
||||
return 'fas fa-home';
|
||||
}
|
||||
}
|
||||
|
@@ -4,17 +4,13 @@ namespace Infinito\Domain\FixtureManagement\FixtureSource;
|
||||
|
||||
use Infinito\Entity\Source\SourceInterface;
|
||||
use Infinito\Entity\Source\Primitive\Text\TextSource;
|
||||
use Infinito\Entity\Meta\Right;
|
||||
use Infinito\DBAL\Types\Meta\Right\LayerType;
|
||||
use Infinito\DBAL\Types\ActionType;
|
||||
use Infinito\Domain\FixtureManagement\EntityTemplateFactory;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class ImpressumFixtureSource extends AbstractFixtureSource
|
||||
{
|
||||
const SLUG = 'IMPRINT';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
@@ -24,13 +20,8 @@ final class ImpressumFixtureSource extends AbstractFixtureSource
|
||||
{
|
||||
$impressumSource = new TextSource();
|
||||
$impressumSource->setText('Example Impressum');
|
||||
$impressumSource->setSlug(self::SLUG);
|
||||
$right = new Right();
|
||||
$right->setSource($impressumSource);
|
||||
$right->setLayer(LayerType::SOURCE);
|
||||
$right->setActionType(ActionType::READ);
|
||||
$right->setLaw($impressumSource->getLaw());
|
||||
$impressumSource->getLaw()->getRights()->add($right);
|
||||
$impressumSource->setSlug(self::getSlug());
|
||||
EntityTemplateFactory::createStandartPublicRight($impressumSource);
|
||||
|
||||
return $impressumSource;
|
||||
}
|
||||
@@ -38,8 +29,8 @@ final class ImpressumFixtureSource extends AbstractFixtureSource
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function getSlug(): string
|
||||
public static function getIcon(): string
|
||||
{
|
||||
return self::SLUG;
|
||||
return 'fas fa-address-card';
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Domain\FixtureManagement\FixtureSource;
|
||||
|
||||
use Infinito\Entity\Source\SourceInterface;
|
||||
use Infinito\Entity\Source\Primitive\Text\TextSource;
|
||||
use Infinito\Domain\FixtureManagement\EntityTemplateFactory;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class InformationFixtureSource extends AbstractFixtureSource
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Infinito\Domain\FixtureManagement\FixtureSource\FixtureSourceInterface::getORMReadyObject()
|
||||
*/
|
||||
public function getORMReadyObject(): SourceInterface
|
||||
{
|
||||
$informationSource = new TextSource();
|
||||
$informationSource->setText('See https://github.com/KevinFrantz/infinito/issues.');
|
||||
$informationSource->setSlug(self::getSlug());
|
||||
EntityTemplateFactory::createStandartPublicRight($informationSource);
|
||||
|
||||
return $informationSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function getIcon(): string
|
||||
{
|
||||
return 'fas fa-info';
|
||||
}
|
||||
}
|
@@ -8,13 +8,12 @@ use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Knp\Menu\ItemInterface;
|
||||
use Infinito\Event\Menu\MenuEvent;
|
||||
use Infinito\DBAL\Types\MenuEventType;
|
||||
use Infinito\Domain\FixtureManagement\FixtureSource\ImpressumFixtureSource;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Infinito\DBAL\Types\RESTResponseType;
|
||||
use Infinito\DBAL\Types\Meta\Right\LayerType;
|
||||
use Infinito\Controller\API\Rest\LayerController;
|
||||
use Infinito\Domain\FixtureManagement\FixtureSource\HomepageFixtureSource;
|
||||
use Infinito\Domain\FixtureManagement\FixtureSourceFactory;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@@ -52,29 +51,22 @@ class UserMenuSubscriber extends AbstractEntityMenuSubscriber implements EventSu
|
||||
public function onUserMenuConfigure(MenuEvent $event): void
|
||||
{
|
||||
$menu = $event->getItem();
|
||||
$menu->addChild($this->trans('home'), [
|
||||
'route' => self::LAYER_GET_ROUTE,
|
||||
'routeParameters' => [
|
||||
'identity' => HomepageFixtureSource::getSlug(),
|
||||
'_format' => RESTResponseType::HTML,
|
||||
'layer' => LayerType::SOURCE,
|
||||
],
|
||||
'attributes' => [
|
||||
'icon' => 'fas fa-home',
|
||||
],
|
||||
]);
|
||||
|
||||
$menu->addChild($this->trans('imprint'), [
|
||||
'route' => self::LAYER_GET_ROUTE,
|
||||
'routeParameters' => [
|
||||
'identity' => ImpressumFixtureSource::getSlug(),
|
||||
'_format' => RESTResponseType::HTML,
|
||||
'layer' => LayerType::SOURCE,
|
||||
],
|
||||
'attributes' => [
|
||||
'icon' => 'fas fa-address-card',
|
||||
],
|
||||
]);
|
||||
$fixtureSources = FixtureSourceFactory::getAllFixtureSources();
|
||||
foreach ($fixtureSources as $fixtureSource) {
|
||||
$slug = $fixtureSource::getSlug();
|
||||
$icon = $fixtureSource::getIcon();
|
||||
$menu->addChild($this->trans($slug), [
|
||||
'route' => self::LAYER_GET_ROUTE,
|
||||
'routeParameters' => [
|
||||
'identity' => $slug,
|
||||
'_format' => RESTResponseType::HTML,
|
||||
'layer' => LayerType::SOURCE,
|
||||
],
|
||||
'attributes' => [
|
||||
'icon' => $icon,
|
||||
],
|
||||
]);
|
||||
}
|
||||
if ($this->shouldShowFormatSelection($event)) {
|
||||
$this->generateShowDropdown($menu, $event, self::LAYER_GET_ROUTE);
|
||||
}
|
||||
@@ -169,7 +161,10 @@ class UserMenuSubscriber extends AbstractEntityMenuSubscriber implements EventSu
|
||||
*/
|
||||
private function shouldShowFormatSelection(Event $event): bool
|
||||
{
|
||||
foreach ([LayerController::IDENTITY_PARAMETER_KEY, LayerController::LAYER_PARAMETER_KEY] as $key) {
|
||||
foreach ([
|
||||
LayerController::IDENTITY_PARAMETER_KEY,
|
||||
LayerController::LAYER_PARAMETER_KEY,
|
||||
] as $key) {
|
||||
$attributs = $this->getRequestAttributs($event);
|
||||
if (!key_exists($key, $attributs) || '' === $attributs[$key]) {
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user