Add showcase code
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pcm\BadgeBundle\Dev\Controller;
|
||||
|
||||
use Pcm\BadgeBundle\Enum\BadgeColour;
|
||||
use Pcm\BadgeBundle\Interface\BadgeableInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
final class ShowcaseController extends AbstractController
|
||||
{
|
||||
#[Route('/', name: 'showcase')]
|
||||
public function __invoke(): Response
|
||||
{
|
||||
$colours = array_map(fn (BadgeColour $c) => strtolower($c->name), BadgeColour::cases());
|
||||
|
||||
$samples = [
|
||||
new SampleBadgeable('Investigation', BadgeColour::BLUE),
|
||||
new SampleBadgeable('Interrogation', BadgeColour::RED),
|
||||
new SampleBadgeable('Shootout', BadgeColour::BLACK),
|
||||
new SampleBadgeable('Sip Whiskey', BadgeColour::FOREST),
|
||||
new SampleBadgeable('Unknown', BadgeColour::GREY),
|
||||
];
|
||||
|
||||
$iconSamples = [
|
||||
new SampleIconBadge('Investigation', BadgeColour::BLUE, 'mdi:magnify'),
|
||||
new SampleIconBadge('Interrogation', BadgeColour::RED, 'bi:cassette-fill'),
|
||||
new SampleIconBadge('Shootout', BadgeColour::BLACK, 'mdi:gun'),
|
||||
new SampleIconBadge('Sip Whiskey', BadgeColour::FOREST, 'flowbite:whiskey-glass-outline'),
|
||||
new SampleIconBadge('Unknown', BadgeColour::GREY, 'carbon:unknown'),
|
||||
];
|
||||
|
||||
return $this->render('showcase.html.twig', [
|
||||
'colours' => $colours,
|
||||
'samples' => $samples,
|
||||
'icon_samples' => $iconSamples
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
final readonly class SampleBadgeable implements BadgeableInterface
|
||||
{
|
||||
public function __construct(public string $label, private BadgeColour $colour)
|
||||
{
|
||||
}
|
||||
|
||||
public function getBadgeColour(): BadgeColour
|
||||
{
|
||||
return $this->colour;
|
||||
}
|
||||
|
||||
public function getBadgeIcon(): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
final readonly class SampleIconBadge implements BadgeableInterface
|
||||
{
|
||||
public function __construct(public string $label, private BadgeColour $colour, private string $icon)
|
||||
{
|
||||
}
|
||||
|
||||
public function getBadgeColour(): BadgeColour
|
||||
{
|
||||
return $this->colour;
|
||||
}
|
||||
|
||||
public function getBadgeIcon(): ?string
|
||||
{
|
||||
return $this->icon;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pcm\BadgeBundle\Dev;
|
||||
|
||||
use Pcm\BadgeBundle\PcmBadgeBundle;
|
||||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
|
||||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
||||
use Symfony\Bundle\TwigBundle\TwigBundle;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
|
||||
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
|
||||
use Symfony\UX\Icons\UXIconsBundle;
|
||||
use Symfony\UX\TwigComponent\TwigComponentBundle;
|
||||
|
||||
final class Kernel extends BaseKernel
|
||||
{
|
||||
use MicroKernelTrait;
|
||||
|
||||
public function registerBundles(): iterable
|
||||
{
|
||||
return [
|
||||
new FrameworkBundle(),
|
||||
new TwigBundle(),
|
||||
new TwigComponentBundle(),
|
||||
new UXIconsBundle(),
|
||||
new PcmBadgeBundle(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getProjectDir(): string
|
||||
{
|
||||
return \dirname(__DIR__);
|
||||
}
|
||||
|
||||
public function getCacheDir(): string
|
||||
{
|
||||
return $this->getProjectDir().'/var/cache/'.$this->environment;
|
||||
}
|
||||
|
||||
public function getLogDir(): string
|
||||
{
|
||||
return $this->getProjectDir().'/var/log';
|
||||
}
|
||||
|
||||
private function configureContainer(ContainerConfigurator $container): void
|
||||
{
|
||||
$container->extension('framework', [
|
||||
'secret' => 'dev',
|
||||
'router' => ['utf8' => true],
|
||||
'test' => false,
|
||||
'http_method_override' => false,
|
||||
'handle_all_throwables' => true,
|
||||
'php_errors' => ['log' => true],
|
||||
]);
|
||||
|
||||
$container->extension('twig', [
|
||||
'default_path' => $this->getProjectDir().'/templates',
|
||||
]);
|
||||
|
||||
// Default config for the bundle. Tweak to preview different base classes.
|
||||
$container->extension('pcm_badge', []);
|
||||
|
||||
// Fetch icons on-demand from iconify.design so no JS toolchain is needed.
|
||||
$container->extension('ux_icons', [
|
||||
'icon_dir' => '%kernel.project_dir%/var/icons',
|
||||
'iconify' => ['enabled' => true, 'on_demand' => true],
|
||||
]);
|
||||
|
||||
$container->services()
|
||||
->defaults()
|
||||
->autowire()
|
||||
->autoconfigure()
|
||||
->load(__NAMESPACE__.'\\Controller\\', __DIR__.'/Controller/')
|
||||
->public()
|
||||
;
|
||||
}
|
||||
|
||||
private function configureRoutes(RoutingConfigurator $routes): void
|
||||
{
|
||||
$routes->import(__DIR__.'/Controller/', 'attribute');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user