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:
@@ -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';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user