Add speakers bundle

This commit is contained in:
Oliver Davies 2019-05-20 23:40:00 +01:00
parent d13347da60
commit 31da26af26
6 changed files with 77 additions and 0 deletions

14
app/SculpinKernel.php Normal file
View file

@ -0,0 +1,14 @@
<?php
use App\Speakers\SculpinSpeakersBundle;
use Sculpin\Bundle\SculpinBundle\HttpKernel\AbstractKernel;
class SculpinKernel extends AbstractKernel
{
protected function getAdditionalSculpinBundles(): array
{
return [
SculpinSpeakersBundle::class,
];
}
}

View file

@ -17,5 +17,15 @@
"generate": "sculpin generate --clean --no-interaction",
"prod": "composer run-script generate -- --env prod",
"watch": "composer run-script --timeout=0 generate -- --server --watch"
},
"autoload": {
"psr-4": {
"App\\Speakers\\": "src/Speakers/src"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\Speakers\\": "src/Speakers/tests"
}
}
}

View file

@ -0,0 +1,4 @@
services:
App\Speakers\TwigExtension\SpeakersExtension:
tags:
- { name: twig.extension }

View file

@ -0,0 +1,17 @@
<?php
namespace App\Speakers\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;
class SculpinSpeakersExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../'));
$loader->load('services.yml');
}
}

View file

@ -0,0 +1,9 @@
<?php
namespace App\Speakers;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class SculpinSpeakersBundle extends Bundle
{
}

View file

@ -0,0 +1,23 @@
<?php
namespace App\Speakers\TwigExtension;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class SpeakersExtension extends AbstractExtension
{
public function getFunctions()
{
return [
new TwigFunction('speakerSessions', [$this, 'getSpeakerSessions'])
];
}
public function getSpeakerSessions($speaker, $sessions): array
{
return collect($sessions)->filter(function ($session) use ($speaker): bool {
return collect($session['speakers'])->contains($speaker['name']);
})->values()->toArray();
}
}