Move all files to 2019/
This commit is contained in:
parent
f59a1843de
commit
0b536af737
94 changed files with 0 additions and 0 deletions
4
2019/src/Schedule/services.yml
Normal file
4
2019/src/Schedule/services.yml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
services:
|
||||
App\Schedule\TwigExtension\ScheduleExtension:
|
||||
tags:
|
||||
- { name: twig.extension }
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Schedule\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
|
||||
class SculpinScheduleExtension extends Extension
|
||||
{
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../'));
|
||||
$loader->load('services.yml');
|
||||
}
|
||||
}
|
||||
30
2019/src/Schedule/src/Model/Session.php
Normal file
30
2019/src/Schedule/src/Model/Session.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Schedule\Model;
|
||||
|
||||
use Tightenco\Collect\Support\Collection;
|
||||
|
||||
class Session
|
||||
{
|
||||
private $data;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function getSlot(): int
|
||||
{
|
||||
return (int) $this->data['slot'];
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->data['title'];
|
||||
}
|
||||
|
||||
public function getSpeakers(): Collection
|
||||
{
|
||||
return collect($this->data['speakers']);
|
||||
}
|
||||
}
|
||||
9
2019/src/Schedule/src/SculpinScheduleBundle.php
Normal file
9
2019/src/Schedule/src/SculpinScheduleBundle.php
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace App\Schedule;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class SculpinScheduleBundle extends Bundle
|
||||
{
|
||||
}
|
||||
29
2019/src/Schedule/src/TwigExtension/ScheduleExtension.php
Normal file
29
2019/src/Schedule/src/TwigExtension/ScheduleExtension.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace App\Schedule\TwigExtension;
|
||||
|
||||
use App\Schedule\Model\Session;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
class ScheduleExtension extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new TwigFunction('sessionInSlot', [$this, 'getSessionInSlot']),
|
||||
];
|
||||
}
|
||||
|
||||
public function getSessionInSlot(int $slotId, array $sessions): ?Session
|
||||
{
|
||||
return collect($sessions)->map(function ($session): ?Session {
|
||||
return new Session($session);
|
||||
})->first(function (?Session $session) use ($slotId): bool {
|
||||
return $session->getSlot() == $slotId;
|
||||
});
|
||||
}
|
||||
}
|
||||
38
2019/src/Schedule/tests/ScheduleTest.php
Normal file
38
2019/src/Schedule/tests/ScheduleTest.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests\Schedule;
|
||||
|
||||
use App\Schedule\Model\Session;
|
||||
use App\Schedule\TwigExtension\ScheduleExtension;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ScheduleTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \App\Schedule\TwigExtension\ScheduleExtension
|
||||
*/
|
||||
private $extension;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->extension = new ScheduleExtension();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function get_a_session_for_a_slot()
|
||||
{
|
||||
$sessions = [
|
||||
['title' => 'The Real State of Drupal', 'slot' => 4],
|
||||
['title' => 'Using Ansible for automation', 'slot' => 1],
|
||||
['title' => 'Introduction to Views', 'slot' => 3],
|
||||
['title' => 'Doing Good with Drupal', 'slot' => 2],
|
||||
];
|
||||
|
||||
$session = $this->extension->getSessionInSlot(3, $sessions);
|
||||
|
||||
$this->assertInstanceOf(Session::class, $session);
|
||||
$this->assertSame('Introduction to Views', $session->getTitle());
|
||||
}
|
||||
}
|
||||
4
2019/src/Speakers/services.yml
Normal file
4
2019/src/Speakers/services.yml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
services:
|
||||
App\Speakers\TwigExtension\SpeakersExtension:
|
||||
tags:
|
||||
- { name: twig.extension }
|
||||
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
9
2019/src/Speakers/src/SculpinSpeakersBundle.php
Normal file
9
2019/src/Speakers/src/SculpinSpeakersBundle.php
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace App\Speakers;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class SculpinSpeakersBundle extends Bundle
|
||||
{
|
||||
}
|
||||
56
2019/src/Speakers/src/TwigExtension/SpeakersExtension.php
Normal file
56
2019/src/Speakers/src/TwigExtension/SpeakersExtension.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace App\Speakers\TwigExtension;
|
||||
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
class SpeakersExtension extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new TwigFunction('speakersForSession', [$this, 'getSessionSpeakers']),
|
||||
new TwigFunction('sessionsForSpeaker', [$this, 'getSpeakerSessions']),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the speakers for a session.
|
||||
*
|
||||
* @param array|object $session
|
||||
* @param array $speakers
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSessionSpeakers($session, array $speakers): array
|
||||
{
|
||||
return collect($speakers)
|
||||
->filter(function ($speaker) use ($session): bool {
|
||||
return collect($session['speakers'])->contains($speaker['title']);
|
||||
})
|
||||
->values()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sessions for a speaker.
|
||||
*
|
||||
* @param array|object $speaker
|
||||
* @param array $sessions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSpeakerSessions($speaker, array $sessions): array
|
||||
{
|
||||
return collect($sessions)
|
||||
->filter(function ($session) use ($speaker): bool {
|
||||
return collect($session['speakers'])->contains($speaker['title']);
|
||||
})
|
||||
->values()
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
73
2019/src/Speakers/tests/SpeakerTest.php
Normal file
73
2019/src/Speakers/tests/SpeakerTest.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests\Speakers;
|
||||
|
||||
use App\Speakers\TwigExtension\SpeakersExtension;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SpeakerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \App\Speakers\TwigExtension\SpeakersExtension
|
||||
*/
|
||||
private $extension;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->extension = new SpeakersExtension();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function get_sessions_for_a_speaker()
|
||||
{
|
||||
$speaker = ['title' => 'Oliver Davies'];
|
||||
|
||||
$sessions = [
|
||||
['title' => 'Introduction to Views', 'speakers' => ['Tom Metcalfe']],
|
||||
['title' => 'Test Driven Drupal', 'speakers' => ['Oliver Davies']],
|
||||
];
|
||||
|
||||
$sessions = $this->extension->getSpeakerSessions($speaker, $sessions);
|
||||
|
||||
$this->assertCount(1, $sessions);
|
||||
$this->assertSame('Test Driven Drupal', $sessions[0]['title']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function get_speakers_for_a_session()
|
||||
{
|
||||
$speakers = [
|
||||
['title' => 'Oliver Davies'],
|
||||
['title' => 'Phil Thomas'],
|
||||
['title' => 'Tom Metcalfe'],
|
||||
['title' => 'Ross Gratton'],
|
||||
['title' => 'Dan McNamara'],
|
||||
];
|
||||
|
||||
$session1 = [
|
||||
'title' => 'Drupal in a microservice savannah',
|
||||
'speakers' => [
|
||||
'Phil Thomas',
|
||||
'Ross Gratton',
|
||||
],
|
||||
];
|
||||
|
||||
$session2 = [
|
||||
'title' => 'The Real State of Drupal',
|
||||
'speakers' => ['Dan McNamara'],
|
||||
];
|
||||
|
||||
tap($this->extension->getSessionSpeakers($session1, $speakers), function (array $speakers) {
|
||||
$this->assertCount(2, $speakers);
|
||||
$this->assertSame('Phil Thomas', $speakers[0]['title']);
|
||||
$this->assertSame('Ross Gratton', $speakers[1]['title']);
|
||||
});
|
||||
|
||||
tap($this->extension->getSessionSpeakers($session2, $speakers), function (array $speakers) {
|
||||
$this->assertCount(1, $speakers);
|
||||
$this->assertSame('Dan McNamara', $speakers[0]['title']);
|
||||
});
|
||||
}
|
||||
}
|
||||
4
2019/src/Sponsors/services.yml
Normal file
4
2019/src/Sponsors/services.yml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
services:
|
||||
App\Sponsors\TwigExtension\SponsorsExtension:
|
||||
tags:
|
||||
- { name: twig.extension }
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Sponsors\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
|
||||
class SculpinSponsorsExtension extends Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../'));
|
||||
$loader->load('services.yml');
|
||||
}
|
||||
}
|
||||
33
2019/src/Sponsors/src/Model/Sponsor.php
Normal file
33
2019/src/Sponsors/src/Model/Sponsor.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace App\Sponsors\Model;
|
||||
|
||||
class Sponsor
|
||||
{
|
||||
const LEVEL_GOLD = 'gold';
|
||||
const LEVEL_SILVER = 'silver';
|
||||
const LEVEL_BRONZE = 'bronze';
|
||||
|
||||
/** @var array */
|
||||
private $data = [];
|
||||
|
||||
private function __construct(array $sponsorData)
|
||||
{
|
||||
$this->data = $sponsorData;
|
||||
}
|
||||
|
||||
public static function create(array $sponsorData): self
|
||||
{
|
||||
return new static($sponsorData);
|
||||
}
|
||||
|
||||
public function isConfirmed(): bool
|
||||
{
|
||||
return $this->data['confirmed'] ?? false;
|
||||
}
|
||||
|
||||
public function getData(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
9
2019/src/Sponsors/src/SculpinSponsorsBundle.php
Normal file
9
2019/src/Sponsors/src/SculpinSponsorsBundle.php
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace App\Sponsors;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class SculpinSponsorsBundle extends Bundle
|
||||
{
|
||||
}
|
||||
34
2019/src/Sponsors/src/TwigExtension/SponsorsExtension.php
Normal file
34
2019/src/Sponsors/src/TwigExtension/SponsorsExtension.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Sponsors\TwigExtension;
|
||||
|
||||
use App\Sponsors\Model\Sponsor;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
class SponsorsExtension extends AbstractExtension
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'app.sponsors';
|
||||
}
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new TwigFunction('getSponsors', [$this, 'getSponsors'])
|
||||
];
|
||||
}
|
||||
|
||||
public function getSponsors(array $sponsorData, string $level): array
|
||||
{
|
||||
return collect($sponsorData[$level])
|
||||
->map(function ($sponsor) {
|
||||
return Sponsor::create($sponsor);
|
||||
})
|
||||
->filter->isConfirmed()
|
||||
->map->getData()
|
||||
->values()
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
54
2019/src/Sponsors/tests/SponsorsTest.php
Normal file
54
2019/src/Sponsors/tests/SponsorsTest.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests\Sponsors;
|
||||
|
||||
use App\Sponsors\Model\Sponsor;
|
||||
use App\Sponsors\TwigExtension\SponsorsExtension;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SponsorsTest extends TestCase
|
||||
{
|
||||
/** @var SponsorsExtension */
|
||||
private $extension;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->extension = new SponsorsExtension();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function get_sponsors_by_level()
|
||||
{
|
||||
$data = [
|
||||
Sponsor::LEVEL_GOLD => [
|
||||
['name' => 'Microserve', 'confirmed' => true],
|
||||
],
|
||||
Sponsor::LEVEL_SILVER => [
|
||||
['name' => 'Drupalize.me', 'confirmed' => true],
|
||||
],
|
||||
];
|
||||
|
||||
$sponsors = $this->extension->getSponsors($data, Sponsor::LEVEL_SILVER);
|
||||
|
||||
$this->assertCount(1, $sponsors);
|
||||
$this->assertSame('Drupalize.me', $sponsors[0]['name']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function only_confirmed_sponsors_are_returned()
|
||||
{
|
||||
$data = [
|
||||
Sponsor::LEVEL_GOLD => [
|
||||
['name' => 'Acquia', 'confirmed' => false],
|
||||
['name' => 'Microserve', 'confirmed' => true],
|
||||
],
|
||||
];
|
||||
|
||||
$sponsors = $this->extension->getSponsors($data, Sponsor::LEVEL_GOLD);
|
||||
|
||||
$this->assertCount(1, $sponsors);
|
||||
$this->assertSame('Microserve', $sponsors[0]['name']);
|
||||
}
|
||||
}
|
||||
Reference in a new issue