Updated to latest symfony version

feature/symfony_upgrade
Hecht 3 years ago
parent de955465a2
commit 9e320f8920

@ -12,44 +12,44 @@
"doctrine/orm": "^2.7",
"friendsofsymfony/rest-bundle": "^3.0",
"phpdocumentor/reflection-docblock": "^5.2",
"sensio/framework-extra-bundle": "^5.1",
"symfony/asset": "5.1.*",
"symfony/console": "5.1.*",
"symfony/dotenv": "5.1.*",
"symfony/expression-language": "5.1.*",
"sensio/framework-extra-bundle": "^5.3",
"symfony/asset": "5.3.*",
"symfony/console": "5.3.*",
"symfony/dotenv": "5.3.*",
"symfony/expression-language": "5.3.*",
"symfony/flex": "^1.3.1",
"symfony/form": "5.1.*",
"symfony/framework-bundle": "5.1.*",
"symfony/http-client": "5.1.*",
"symfony/intl": "5.1.*",
"symfony/mailer": "5.1.*",
"symfony/mime": "5.1.*",
"symfony/form": "5.3.*",
"symfony/framework-bundle": "5.3.*",
"symfony/http-client": "5.3.*",
"symfony/intl": "5.3.*",
"symfony/mailer": "5.3.*",
"symfony/mime": "5.3.*",
"symfony/monolog-bundle": "^3.1",
"symfony/notifier": "5.1.*",
"symfony/process": "5.1.*",
"symfony/property-access": "5.1.*",
"symfony/property-info": "5.1.*",
"symfony/security-bundle": "5.1.*",
"symfony/serializer": "5.1.*",
"symfony/string": "5.1.*",
"symfony/translation": "5.1.*",
"symfony/twig-bundle": "^5.1",
"symfony/validator": "5.1.*",
"symfony/web-link": "5.1.*",
"symfony/yaml": "5.1.*",
"symfony/notifier": "5.3.*",
"symfony/process": "5.3.*",
"symfony/property-access": "5.3.*",
"symfony/property-info": "5.3.*",
"symfony/security-bundle": "5.3.*",
"symfony/serializer": "5.3.*",
"symfony/string": "5.3.*",
"symfony/translation": "5.3.*",
"symfony/twig-bundle": "^5.3",
"symfony/validator": "5.3.*",
"symfony/web-link": "5.3.*",
"symfony/yaml": "5.3.*",
"twig/extra-bundle": "^2.12|^3.0",
"twig/twig": "^2.12|^3.0"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3",
"symfony/browser-kit": "^5.1",
"symfony/css-selector": "^5.1",
"symfony/debug-bundle": "^5.1",
"symfony/browser-kit": "^5.3",
"symfony/css-selector": "^5.3",
"symfony/debug-bundle": "^5.3",
"symfony/maker-bundle": "^1.0",
"symfony/phpunit-bridge": "^5.1",
"symfony/stopwatch": "^5.1",
"symfony/var-dumper": "^5.1",
"symfony/web-profiler-bundle": "^5.1"
"symfony/phpunit-bridge": "^5.3",
"symfony/stopwatch": "^5.3",
"symfony/var-dumper": "^5.3",
"symfony/web-profiler-bundle": "^5.3"
},
"config": {
"optimize-autoloader": true,
@ -95,7 +95,7 @@
"extra": {
"symfony": {
"allow-contrib": false,
"require": "5.1.*"
"require": "5.3.*"
}
}
}

3474
composer.lock generated

File diff suppressed because it is too large Load Diff

@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping ../../vendor/doctrine/orm/doctrine-mapping.xsd ">
<entity name="App\Entity\Event">
<entity name="App\Entity\Event" repository-class="App\Repository\EventRepository">
<id name="id" type="integer">
<generator strategy="AUTO" />
</id>
@ -11,13 +11,13 @@
<field name="type" type="integer" nullable="false" />
<field name="version" type="integer" nullable="false" />
<one-to-many field="heroes" mapped-by="event" target-entity="EventHero">
<one-to-many field="battles" mapped-by="event" target-entity="EventBattle">
<cascade>
<cascade-persist />
<cascade-merge />
</cascade>
</one-to-many>
<one-to-many field="battles" mapped-by="event" target-entity="EventBattle">
<one-to-many field="teams" mapped-by="event" target-entity="EventTeam">
<cascade>
<cascade-persist />
<cascade-merge />

@ -4,25 +4,34 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping ../../vendor/doctrine/orm/doctrine-mapping.xsd ">
<entity name="App\Entity\EventBattle">
<entity name="App\Entity\EventBattle" repository-class="App\Repository\EventBattleRepository">
<id name="event" association-key="true" />
<id name="eid" type="integer" />
<id name="event_battle_id" type="integer" />
<field name="value" type="json" />
<many-to-one field="event" target-entity="Event" inversed-by="battles" />
<many-to-one field="event" target-entity="Event" inversed-by="battles">
<join-column on-delete="CASCADE" />
</many-to-one>
<many-to-many field="heroes" target-entity="EventHero">
<join-table name="event_battle_hero">
<join-columns>
<join-column name="event_id" referenced-column-name="event_id"></join-column>
<join-column name="event_battle_id" referenced-column-name="eid"></join-column>
<join-column name="event_id" referenced-column-name="event_id" on-delete="CASCADE"/>
<join-column name="event_battle_id" referenced-column-name="event_battle_id" on-delete="CASCADE"/>
</join-columns>
<inverse-join-columns>
<join-column name="event_id" referenced-column-name="event_id"></join-column>
<join-column name="event_hero_id" referenced-column-name="eid"></join-column>
<join-column name="event_id" referenced-column-name="event_id" on-delete="CASCADE" />
<join-column name="event_hero_id" referenced-column-name="event_hero_id" on-delete="CASCADE" />
</inverse-join-columns>
</join-table>
</many-to-many>
<many-to-one field="winningTeam" target-entity="EventTeam">
<join-columns>
<join-column name="event_id" referenced-column-name="event_id" on-delete="CASCADE" />
<join-column name="winning_team_id" referenced-column-name="event_team_id" on-delete="CASCADE" />
</join-columns>
</many-to-one>
</entity>

@ -3,14 +3,13 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping ../../vendor/doctrine/orm/doctrine-mapping.xsd ">
<entity name="App\Entity\EventHero">
<entity name="App\Entity\EventHero" repository-class="App\Repository\EventHeroRepository">
<id name="event" association-key="true" />
<id name="eid" type="integer" />
<id name="event_hero_id" type="integer" />
<embedded name="skills" class="Skillz" />
<field name="name" type="string" length="32" unique="true" />
<field name="team" type="integer" />
<many-to-one field="user" target-entity="User">
<join-column on-delete="SET NULL" />
@ -20,9 +19,16 @@
<join-column on-delete="SET NULL" />
</many-to-one>
<many-to-one field="event" target-entity="Event" inversed-by="heroes">
<many-to-one field="event" target-entity="Event">
<join-column on-delete="CASCADE" />
</many-to-one>
<many-to-one field="team" target-entity="EventTeam" inversed-by="heroes">
<join-columns>
<join-column name="event_id" referenced-column-name="event_id" on-delete="CASCADE "/>
<join-column name="event_team_id" referenced-column-name="event_team_id" on-delete="CASCADE" />
</join-columns>
</many-to-one>
</entity>
</doctrine-mapping>

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping ../../vendor/doctrine/orm/doctrine-mapping.xsd ">
<entity name="App\Entity\EventTeam" repository-class="App\Repository\EventTeamRepository">
<id name="event" association-key="true" />
<id name="event_team_id" type="integer" />
<field name="name" type="string" length="32" unique="true" />
<!-- TODO: many-to-one referencing clan (nullable) -->
<one-to-many field="heroes" mapped-by="team" target-entity="EventHero">
<cascade>
<cascade-persist />
<cascade-merge />
</cascade>
</one-to-many>
<many-to-one field="event" target-entity="Event" inversed-by="teams">
<join-column on-delete="CASCADE" />
</many-to-one>
</entity>
</doctrine-mapping>

@ -3,16 +3,18 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping ../../vendor/doctrine/orm/doctrine-mapping.xsd ">
<entity name="App\Entity\Hero">
<entity name="App\Entity\Hero" repository-class="App\Repository\HeroRepository">
<id name="id" type="integer">
<generator strategy="AUTO" />
</id>
<embedded name="skills" class="Skillz" />
<field name="name" type="string" length="32" unique="true"/>
<field name="name" type="string" length="32" unique="true" />
<many-to-one field="user" target-entity="User" />
<many-to-one field="user" target-entity="User">
<join-column on-delete="CASCADE" />
</many-to-one>
</entity>
</doctrine-mapping>

@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping ../../vendor/doctrine/orm/doctrine-mapping.xsd ">
<entity name="App\Entity\User">
<entity name="App\Entity\User" repository-class="App\Repository\UserRepository">
<id name="id" type="integer">
<generator strategy="AUTO" />
</id>

@ -19,6 +19,15 @@ security:
anonymous: true
lazy: true
logout: ~
std:
pattern: ^/main/
guard:
authenticators:
- App\Security\UrlAuthenticator
stateless: true
anonymous: true
lazy: true
logout: ~
main:
stateless: true
anonymous: true

@ -1,5 +1,11 @@
api_controllers:
prefix: api/
resource: ../../src/Controller/Api
type: annotation
controllers:
resource: ../../src/Controller/
prefix: main/{slug}/
resource: ../../src/Controller/Std
type: annotation
kernel:

@ -0,0 +1,12 @@
App\Entity\Event:
attributes:
id:
groups: ['Default']
type:
groups: ['event_list', 'event_show']
version:
groups: ['event_list', 'event_show']
battles:
groups: ['event_show']
teams:
groups: ['event_show']

@ -0,0 +1,10 @@
App\Entity\EventBattle:
attributes:
eid:
groups: ['Default']
heroes:
groups: ['event_battle_list', 'event_battle_show']
winningTeam:
groups: ['event_battle_list']
value:
groups: ['event_battle_show']

@ -0,0 +1,14 @@
App\Entity\EventHero:
attributes:
eid:
groups: ['Default']
name:
groups: ['event_hero_list']
skills:
groups: ['event_hero_show']
user:
groups: ['event_hero_show']
hero:
groups: ['event_hero_show']
team:
groups: ['event_hero_show']

@ -0,0 +1,8 @@
App\Entity\EventTeam:
attributes:
eid:
groups: ['Default']
name:
groups: ['event_team_list', 'event_team_show']
heroes:
groups: ['event_team_list', 'event_team_show']

@ -4,5 +4,6 @@ App\Entity\Hero:
groups: ['Default']
name:
groups: ['Default']
heros:
groups: ['UserWithHeroes']
skills:
groups: ['hero_show']

@ -0,0 +1,12 @@
App\Entity\Skillz:
attributes:
constitution:
groups: ['Default']
ki:
groups: ['Default']
strength:
groups: ['Default']
agility:
groups: ['Default']
stamina:
groups: ['Default']

@ -0,0 +1,50 @@
<?php
namespace App\Controller\Api;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
use App\Repository\EventRepository;
use App\Entity\Event;
use App\Repository\EventBattleRepository;
use App\Entity\EventBattle;
/**
*
* @Rest\Route("event/{eventId}/battle")
*/
class EventBattleController extends AbstractFOSRestController
{
protected EventBattleRepository $repository;
public function __construct(EventBattleRepository $repository)
{
$this->repository = $repository;
}
/**
*
* @Rest\Route("s")
* @Rest\View(serializerGroups={"Default", "event_battle_list"})
*/
public function cgetAction(int $eventId): array
{
return $this->repository->findBy([
'event' => $eventId
]);
}
/**
*
* @Rest\Route("/{eid}"))
* @Rest\View(serializerGroups={"Default", "event_battle_show"})
*/
public function getAction(int $eventId, int $eid): ?EventBattle
{
return $this->repository->findOneBy([
'event' => $eventId,
'eid' => $eid
]);
}
}

@ -0,0 +1,43 @@
<?php
namespace App\Controller\Api;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
use App\Repository\EventRepository;
use App\Entity\Event;
/**
*
* @Rest\Route("event")
*/
class EventController extends AbstractFOSRestController
{
protected EventRepository $eventRepository;
public function __construct(EventRepository $eventRepository)
{
$this->eventRepository = $eventRepository;
}
/**
*
* @Rest\Route("s")
* @Rest\View(serializerGroups={"Default", "event_list"})
*/
public function cgetAction(): array
{
return $this->eventRepository->findAll();
}
/**
*
* @Rest\Route("/{id}"))
* @Rest\View(serializerGroups={"Default", "event_show"})
*/
public function getAction(int $id): ?Event
{
return $this->eventRepository->find($id);
}
}

@ -0,0 +1,50 @@
<?php
namespace App\Controller\Api;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
use App\Repository\EventRepository;
use App\Entity\Event;
use App\Repository\EventHeroRepository;
use App\Entity\EventHero;
/**
*
* @Rest\Route("event/{eventId}/hero")
*/
class EventHeroController extends AbstractFOSRestController
{
protected EventHeroRepository $repository;
public function __construct(EventHeroRepository $repository)
{
$this->repository = $repository;
}
/**
*
* @Rest\Route("s")
* @Rest\View(serializerGroups={"Default", "event_hero_list"})
*/
public function cgetAction(int $eventId): array
{
return $this->repository->findBy([
'event' => $eventId
]);
}
/**
*
* @Rest\Route("/{eid}"))
* @Rest\View(serializerGroups={"Default", "event_hero_show"})
*/
public function getAction(int $eventId, int $eid): ?EventHero
{
return $this->repository->findOneBy([
'event' => $eventId,
'eid' => $eid
]);
}
}

@ -0,0 +1,50 @@
<?php
namespace App\Controller\Api;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
use App\Repository\EventRepository;
use App\Entity\Event;
use App\Repository\EventTeamRepository;
use App\Entity\EventTeam;
/**
*
* @Rest\Route("event/{eventId}/team")
*/
class EventTeamController extends AbstractFOSRestController
{
protected EventTeamRepository $repository;
public function __construct(EventTeamRepository $repository)
{
$this->repository = $repository;
}
/**
*
* @Rest\Route("s")
* @Rest\View(serializerGroups={"Default", "event_team_list"})
*/
public function cgetAction(int $eventId): array
{
return $this->repository->findBy([
'event' => $eventId
]);
}
/**
*
* @Rest\Route("/{eid}"))
* @Rest\View(serializerGroups={"Default", "event_team_show"})
*/
public function getAction(int $eventId, int $eid): ?EventTeam
{
return $this->repository->findOneBy([
'event' => $eventId,
'eid' => $eid
]);
}
}

@ -1,5 +1,5 @@
<?php
namespace App\Controller;
namespace App\Controller\Api;
use App\Repository\HeroRepository;
use FOS\RestBundle\Controller\Annotations as Rest;
@ -8,7 +8,7 @@ use App\Entity\Hero;
/**
*
* @Rest\Route("api/hero")
* @Rest\Route("hero")
*/
class HeroController extends AbstractFOSRestController
{

@ -1,5 +1,5 @@
<?php
namespace App\Controller;
namespace App\Controller\Api;
use App\Repository\UserRepository;
use FOS\RestBundle\Controller\Annotations as Rest;

@ -0,0 +1,19 @@
<?php
namespace App\Controller\Std;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
class LandingController extends AbstractController
{
/**
* @Route("/", name="landing")
*/
public function index()
{
return $this->render('landing/index.html.twig', [
'controller_name' => 'LandingController',
]);
}
}

@ -1,46 +1,35 @@
<?php
namespace App\DataFixtures;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use App\Entity\EventBattle;
use App\Entity\Event;
use Psr\Log\LoggerInterface;
use App\Entity\Hero;
class EventBattleFixtures extends Fixture implements DependentFixtureInterface
{
private LoggerInterface $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function load(ObjectManager $manager)
{
/**
*
* @var Event $event
*/
$event = $this->getReference(EventFixtures::REF_1);
$event1 = $this->getReference(EventFixtures::REF_1);
$eventTeam1 = $this->getReference(EventFixtures::REF_EVENT1_TEAM1);
$eventHero1 = $this->getReference(EventFixtures::REF_EVENT1_CHAR1);
$eventHero2 = $this->getReference(EventFixtures::REF_EVENT1_CHAR2);
$eventBattle = new EventBattle($event, 1);
$eventBattle->setEvent($event);
$eventBattle->addHero($event->getHeroes()[0]);
$eventBattle->addHero($event->getHeroes()[1]);
$eventBattle = new EventBattle($event1, 1);
$eventBattle->addHero($eventHero1);
$eventBattle->addHero($eventHero2);
$eventBattle->setWinningTeam($eventTeam1);
$manager->persist($eventBattle);
$manager->flush();
}
public function getDependencies()
{
return array(
EventHeroFixtures::class
EventFixtures::class
);
}
}

@ -1,32 +1,66 @@
<?php
namespace App\DataFixtures;
use App\Entity\Event;
use App\Entity\EventTeam;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use App\Entity\Event;
use App\Entity\EventHero;
class EventFixtures extends Fixture
class EventFixtures extends Fixture implements DependentFixtureInterface
{
public const REF_1 = 'event-1-reference';
public const REF_2 = 'event-2-reference';
public const REF_EVENT1_CHAR1 = 'event-1-char-1-reference';
public const REF_EVENT1_TEAM1 = 'event-1-team-1-reference';
public const REF_EVENT1_CHAR2 = 'event-1-char-2-reference';
public const REF_EVENT1_TEAM2 = 'event-1-team-2-reference';
public function load(ObjectManager $manager)
{
$event1 = new Event();
$event1->setType(Event::FREE_BATTLE);
$heroUser1 = $this->getReference(UserFixtures::ADMIN_USER_REFERENCE)->getHeroes()[0];
$heroUser2 = $this->getReference(UserFixtures::DUDE_USER_REFERENCE)->getHeroes()[0];
$event1 = new Event(Event::FREE_BATTLE);
$manager->persist($event1);
$event2 = new Event();
$event2->setType(Event::TOURNAMENT);
$event2 = new Event(Event::TOURNAMENT);
$manager->persist($event2);
$eventTeam1 = new EventTeam($event1, 1, "A Team");
$eventTeam2 = new EventTeam($event1, 2, "B Team");
$manager->persist($eventTeam1);
$manager->persist($eventTeam2);
$eventHero1 = new EventHero($event1, $heroUser1, $eventTeam1);
$eventHero2 = new EventHero($event1, $heroUser2, $eventTeam2);
$manager->persist($eventHero1);
$manager->persist($eventHero2);
$manager->flush();
$this->addReference(self::REF_1, $event1);
$this->addReference(self::REF_2, $event2);
$this->addReference(self::REF_EVENT1_CHAR1, $eventHero1);
$this->addReference(self::REF_EVENT1_CHAR2, $eventHero2);
$this->addReference(self::REF_EVENT1_TEAM1, $eventTeam1);
$this->addReference(self::REF_EVENT1_TEAM2, $eventTeam2);
}
public function getDependencies()
{
return array(
UserFixtures::class,
HeroFixtures::class
);
}
}

@ -1,44 +0,0 @@
<?php
namespace App\DataFixtures;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use App\Entity\EventHero;
use App\Entity\Hero;
use App\Entity\Event;
class EventHeroFixtures extends Fixture implements DependentFixtureInterface
{
public function load(ObjectManager $manager)
{
$heroUser1 = $this->getReference(UserFixtures::ADMIN_USER_REFERENCE)->getHeroes()[0];
$heroUser2 = $this->getReference(UserFixtures::DUDE_USER_REFERENCE)->getHeroes()[0];
$event1 = $this->getReference(EventFixtures::REF_1);
$eventHero1 = $this->createEventHero($event1, $heroUser1, 1);
$manager->persist($eventHero1);
$eventHero2 = $this->createEventHero($event1, $heroUser2, 2);
$manager->persist($eventHero2);
$manager->flush();
}
private function createEventHero(Event $event, Hero $hero, int $team)
{
return new EventHero($event, $hero, $team);
}
public function getDependencies()
{
return array(
UserFixtures::class,
HeroFixtures::class,
EventFixtures::class
);
}
}

@ -1,5 +1,4 @@
<?php
namespace App\DataFixtures;
use App\Entity\Hero;
@ -9,6 +8,7 @@ use Doctrine\Common\DataFixtures\DependentFixtureInterface;
class HeroFixtures extends Fixture implements DependentFixtureInterface
{
public function load(ObjectManager $manager)
{
$hero = new Hero();
@ -28,8 +28,7 @@ class HeroFixtures extends Fixture implements DependentFixtureInterface
public function getDependencies()
{
return array(
UserFixtures::class,
UserFixtures::class
);
}
}

@ -15,7 +15,8 @@ class Event
const LEAGUE_MATCHDAY = 4;
// Reserved value (was "wanted" battles)
const RESERVED_5 = 5;
const CLAN_BATTLE = 6;
private ?int $id;
@ -24,19 +25,16 @@ class Event
private int $version = 1;
private Collection $heroes;
private Collection $battles;
public function __construct()
private Collection $teams;
public function __construct(int $type = self::QUEST)
{
$this->heroes = new ArrayCollection();
$this->battles = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
$this->type = $type;
$this->teams = new ArrayCollection();
}
public function getType(): ?int
@ -51,35 +49,21 @@ class Event
return $this;
}
/**
* @return Collection|EventHero[]
*/
public function getHeroes(): Collection
public function getVersion(): ?int
{
return $this->heroes;
return $this->version;
}
public function addHero(EventHero $hero): self
public function setVersion(int $version): self
{
if (!$this->heroes->contains($hero)) {
$this->heroes[] = $hero;
$hero->setEvent($this);
}
$this->version = $version;
return $this;
}
public function removeHero(EventHero $hero): self
public function getId(): ?int
{
if ($this->heroes->contains($hero)) {
$this->heroes->removeElement($hero);
// set the owning side to null (unless already changed)
if ($hero->getEvent() === $this) {
$hero->setEvent(null);
}
}
return $this;
return $this->id;
}
/**
@ -113,14 +97,33 @@ class Event
return $this;
}
public function getVersion(): ?int
/**
* @return Collection|EventTeam[]
*/
public function getTeams(): Collection
{
return $this->version;
return $this->teams;
}
public function setVersion(int $version): self
public function addTeam(EventTeam $team): self
{
$this->version = $version;
if (!$this->teams->contains($team)) {
$this->teams[] = $team;
$team->setEvent($this);
}
return $this;
}
public function removeTeam(EventTeam $team): self
{
if ($this->teams->contains($team)) {
$this->teams->removeElement($team);
// set the owning side to null (unless already changed)
if ($team->getEvent() === $this) {
$team->setEvent(null);
}
}
return $this;
}

@ -7,66 +7,57 @@ use Doctrine\Common\Collections\Collection;
class EventBattle
{
private ?Event $event = null;
private int $eid = 0;
private Collection $heroes;
/**
*
* @var Event
*/
private $event = null;
private Collection $actions;
private int $event_battle_id = 0;
private array $value = [];
public function __construct(Event $event, int $eid)
{
$this->event = $event;
$this->eid = $eid;
$this->heroes = new ArrayCollection();
$this->actions = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
private Collection $heroes;
public function getEvent(): ?Event
{
return $this->event;
}
/**
*
* @var EventTeam
*/
private $winningTeam;
public function setEvent(?Event $event): self
public function __construct(Event $event, int $event_battle_id)
{
$this->event = $event;
return $this;
$this->event_battle_id = $event_battle_id;
$this->heroes = new ArrayCollection();
}
public function getHeroLhs(): ?EventHero
public function getValue(): ?array
{
return $this->heroLhs;
return $this->value;
}
public function setHeroLhs(?EventHero $heroLhs): self
public function setValue(array $value): self
{
$this->heroLhs = $heroLhs;
$this->value = $value;
return $this;
}
public function getHeroRhs(): ?EventHero
public function getEvent(): ?Event
{
return $this->heroRhs;
return $this->event;
}
public function setHeroRhs(?EventHero $heroRhs): self
public function setEvent(?Event $event): self
{
$this->heroRhs = $heroRhs;
$this->event = $event;
return $this;
}
/**
*
* @return Collection|EventHero[]
*/
public function getHeroes(): Collection
@ -76,7 +67,7 @@ class EventBattle
public function addHero(EventHero $hero): self
{
if (!$this->heroes->contains($hero)) {
if (! $this->heroes->contains($hero)) {
$this->heroes[] = $hero;
}
@ -92,21 +83,21 @@ class EventBattle
return $this;
}
public function getEid(): ?int
public function getWinningTeam(): ?EventTeam
{
return $this->eid;
return $this->winningTeam;
}
public function getValue(): ?array
public function setWinningTeam(?EventTeam $winningTeam): self
{
return $this->value;
$this->winningTeam = $winningTeam;
return $this;
}
public function setValue(array $value): self
public function getEventBattleId(): ?int
{
$this->value = $value;
return $this;
return $this->event_battle_id;
}
}

@ -1,55 +0,0 @@
<?php
namespace App\Entity;
class EventBattleActions
{
private ?int $id;
private int $timeInSeconds;
private array $action;
private ?EventBattle $battle;
public function getId(): ?int
{
return $this->id;
}
public function getTimeInSeconds(): ?int
{
return $this->timeInSeconds;
}
public function setTimeInSeconds(int $timeInSeconds): self
{
$this->timeInSeconds = $timeInSeconds;
return $this;
}
public function getAction(): ?array
{
return $this->action;
}
public function setAction(array $action): self
{
$this->action = $action;
return $this;
}
public function getBattle(): ?EventBattle
{
return $this->battle;
}
public function setBattle(?EventBattle $battle): self
{
$this->battle = $battle;
return $this;
}
}

@ -4,24 +4,40 @@ namespace App\Entity;
class EventHero
{
private int $eid = 0;
private int $event_hero_id = 0;
private string $name;
private int $team = 0;
private Skillz $skills;
private Hero $hero;
private User $user;
private Event $event;
public function __construct(Event $event, Hero $hero, int $team)
/**
*
* @var Hero
*/
private $hero;
/**
*
* @var User
*/
private $user;
/**
*
* @var Event
*/
private $event;
/**
*
* @var EventTeam
*/
private $team;
public function __construct(Event $event, Hero $hero, EventTeam $team)
{
$this->event = $event;
$this->eid = $hero->getId();
$this->event_hero_id = $hero->getId();
$this->name = $hero->getName();
$this->skills = $hero->getSkills();
$this->team = $team;
@ -34,9 +50,11 @@ class EventHero
return $this->skills;
}
public function getId(): ?int
public function setSkills(Skillz $skills): self
{
return $this->id;
$this->skills = $skills;
return $this;
}
public function getName(): ?string
@ -44,19 +62,23 @@ class EventHero
return $this->name;
}
public function getUser(): ?User
public function setName(string $name): self
{
return $this->user;
$this->name = $name;
return $this;
}
public function getEvent(): ?Event
public function getUser(): ?User
{
return $this->event;
return $this->user;
}
public function getTeam(): ?int
public function setUser(?User $user): self
{
return $this->team;
$this->user = $user;
return $this;
}
public function getHero(): ?Hero
@ -64,51 +86,40 @@ class EventHero
return $this->hero;
}
public function getEid(): ?int
{
return $this->eid;
}
public function setSkills(Skillz $skills): self
public function setHero(?Hero $hero): self
{
$this->skills = $skills;
$this->hero = $hero;
return $this;
}
public function setName(string $name): self
public function getEvent(): ?Event
{
$this->name = $name;
return $this;
return $this->event;
}
public function setTeam(int $team): self
public function setEvent(?Event $event): self
{
$this->team = $team;
$this->event = $event;
return $this;
}
public function setUser(?User $user): self
public function getTeam(): ?EventTeam
{
$this->user = $user;
return $this;
return $this->team;
}
public function setHero(?Hero $hero): self
public function setTeam(?EventTeam $team): self
{
$this->hero = $hero;
$this->team = $team;
return $this;
}
public function setEvent(?Event $event): self
public function getEventHeroId(): ?int
{
$this->event = $event;
return $this;
return $this->event_hero_id;
}
}

@ -0,0 +1,91 @@
<?php
namespace App\Entity;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
class EventTeam
{
/**
*
* @var Event
*/
private $event = null;
private int $event_team_id = 0;
private string $name = "";
private Collection $heroes;
public function __construct(Event $event, int $team_id, string $name)
{
$this->event = $event;
$this->event_team_id = $team_id;
$this->name = $name;
$this->heroes = new ArrayCollection();
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
*
* @return Collection|EventHero[]
*/
public function getHeroes(): Collection
{
return $this->heroes;
}
public function addHero(EventHero $hero): self
{
if (! $this->heroes->contains($hero)) {
$this->heroes[] = $hero;
$hero->setTeam($this);
}
return $this;
}
public function removeHero(EventHero $hero): self
{
if ($this->heroes->contains($hero)) {
$this->heroes->removeElement($hero);
// set the owning side to null (unless already changed)
if ($hero->getTeam() === $this) {
$hero->setTeam(null);
}
}
return $this;
}
public function getEvent(): ?Event
{
return $this->event;
}
public function setEvent(?Event $event): self
{
$this->event = $event;
return $this;
}
public function getEventTeamId(): ?int
{
return $this->event_team_id;
}
}

@ -1,14 +1,18 @@
<?php
namespace App\Entity;
class Hero
{
private ?int $id;
private ?string $name;
private ?User $user;
/**
*
* @var User
*/
private $user;
private Skillz $skills;
@ -17,9 +21,16 @@ class Hero
$this->skills = new Skillz();
}
public function getId(): ?int
public function getSkills(): Skillz
{
return $this->id;
return $this->skills;
}
public function setSkills(Skillz $skills): self
{
$this->skills = $skills;
return $this;
}
public function getName(): ?string
@ -34,6 +45,11 @@ class Hero
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
@ -45,16 +61,4 @@ class Hero
return $this;
}
public function getSkills(): Skillz
{
return $this->skills;
}
public function setSkills(Skillz $skills): self
{
$this->skills = $skills;
return $this;
}
}

@ -1,35 +0,0 @@
<?php declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20181118195745 extends AbstractMigration
{
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'sqlite', 'Migration can only be executed safely on \'sqlite\'.');
$this->addSql('CREATE TABLE hero (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, user_id INTEGER NOT NULL, name VARCHAR(32) NOT NULL)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_51CE6E865E237E06 ON hero (name)');
$this->addSql('CREATE INDEX IDX_51CE6E86A76ED395 ON hero (user_id)');
$this->addSql('CREATE TABLE user (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, username VARCHAR(32) NOT NULL, password VARCHAR(255) NOT NULL, api_token VARCHAR(255) DEFAULT NULL, roles CLOB NOT NULL --(DC2Type:json)
)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D649F85E0677 ON user (username)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D6497BA2F5EB ON user (api_token)');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'sqlite', 'Migration can only be executed safely on \'sqlite\'.');
$this->addSql('DROP TABLE hero');
$this->addSql('DROP TABLE user');
}
}

@ -0,0 +1,22 @@
<?php
namespace App\Repository;
use App\Entity\EventBattle;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
*
* @method EventBattle|null find($id, $lockMode = null, $lockVersion = null)
* @method EventBattle|null findOneBy(array $criteria, array $orderBy = null)
* @method EventBattle[] findAll()
* @method EventBattle[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class EventBattleRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, EventBattle::class);
}
}

@ -0,0 +1,22 @@
<?php
namespace App\Repository;
use App\Entity\EventHero;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
*
* @method EventHero|null find($id, $lockMode = null, $lockVersion = null)
* @method EventHero|null findOneBy(array $criteria, array $orderBy = null)
* @method EventHero[] findAll()
* @method EventHero[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class EventHeroRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, EventHero::class);
}
}

@ -0,0 +1,22 @@
<?php
namespace App\Repository;
use App\Entity\Event;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
*
* @method Event|null find($id, $lockMode = null, $lockVersion = null)
* @method Event|null findOneBy(array $criteria, array $orderBy = null)
* @method Event[] findAll()
* @method Event[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class EventRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Event::class);
}
}

@ -0,0 +1,22 @@
<?php
namespace App\Repository;
use App\Entity\EventTeam;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
*
* @method EventTeam|null find($id, $lockMode = null, $lockVersion = null)
* @method EventTeam|null findOneBy(array $criteria, array $orderBy = null)
* @method EventTeam[] findAll()
* @method EventTeam[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class EventTeamRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, EventTeam::class);
}
}

@ -1,5 +1,4 @@
<?php
namespace App\Repository;
use App\Entity\Hero;
@ -7,6 +6,7 @@ use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
*
* @method Hero|null find($id, $lockMode = null, $lockVersion = null)
* @method Hero|null findOneBy(array $criteria, array $orderBy = null)
* @method Hero[] findAll()
@ -14,37 +14,9 @@ use Doctrine\Persistence\ManagerRegistry;
*/
class HeroRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Hero::class);
}
// /**
// * @return Hero[] Returns an array of Hero objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('h')
->andWhere('h.exampleField = :val')
->setParameter('val', $value)
->orderBy('h.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?Hero
{
return $this->createQueryBuilder('h')
->andWhere('h.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}

@ -1,5 +1,4 @@
<?php
namespace App\Repository;
use App\Entity\User;
@ -7,6 +6,7 @@ use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
*
* @method User|null find($id, $lockMode = null, $lockVersion = null)
* @method User|null findOneBy(array $criteria, array $orderBy = null)
* @method User[] findAll()
@ -14,37 +14,9 @@ use Doctrine\Persistence\ManagerRegistry;
*/
class UserRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, User::class);
}
// /**
// * @return User[] Returns an array of User objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('u')
->andWhere('u.exampleField = :val')
->setParameter('val', $value)
->orderBy('u.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?User
{
return $this->createQueryBuilder('u')
->andWhere('u.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}

@ -0,0 +1,88 @@
<?php
namespace App\Security;
use App\Repository\UserRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Guard\AbstractGuardAuthenticator;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use App\Entity\User;
class UrlAuthenticator extends AbstractGuardAuthenticator
{
/**
* Called on every request to decide if this authenticator should be
* used for the request.
* Returning false will cause this authenticator
* to be skipped.
*/
public function supports(Request $request)
{
return str_starts_with($request->getPathInfo(), "/main/");
}
/**
* Called on every request.
* Return whatever credentials you want to
* be passed to getUser() as $credentials.
*/
public function getCredentials(Request $request)
{
$result = preg_replace('#/main/([^/]+)/#i', '$1', $request->getPathInfo());
return $result === $request->getPathInfo() ? null : $result;
}
public function getUser($credentials, UserProviderInterface $userProvider)
{
if (null === $credentials) {
return null;
}
$user = new User();
$user->setUsername($credentials);
return $user;
}
public function checkCredentials($credentials, UserInterface $user)
{
// check credentials - e.g. make sure the password is valid
// no credential check is needed in this case
// return true to cause authentication success
return true;
}
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
{
// on success, let the request continue
return null;
}
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
$message = strtr($exception->getMessageKey(), $exception->getMessageData());
// or to translate this message
// $this->translator->trans($exception->getMessageKey(), $exception->getMessageData())
// This should translated by FOSRestBundle!
throw new AccessDeniedHttpException($message);
}
/**
* Called when authentication is needed, but it's not sent
*/
public function start(Request $request, AuthenticationException $authException = null)
{
throw new UnauthorizedHttpException('', 'Authentication Required');
}
public function supportsRememberMe(): bool
{
return false;
}
}

@ -26,6 +26,9 @@
"doctrine/dbal": {
"version": "v2.8.0"
},
"doctrine/deprecations": {
"version": "v0.5.3"
},
"doctrine/doctrine-bundle": {
"version": "2.0",
"recipe": {
@ -108,6 +111,9 @@
"facebook/webdriver": {
"version": "1.6.0"
},
"friendsofphp/proxy-manager-lts": {
"version": "v1.0.5"
},
"friendsofsymfony/rest-bundle": {
"version": "2.2",
"recipe": {
@ -359,6 +365,9 @@
"symfony/panther": {
"version": "v0.2.0"
},
"symfony/password-hasher": {
"version": "v5.3.8"
},
"symfony/phpunit-bridge": {
"version": "4.3",
"recipe": {
@ -395,6 +404,9 @@
"symfony/polyfill-php80": {
"version": "v1.18.1"
},
"symfony/polyfill-php81": {
"version": "v1.23.0"
},
"symfony/process": {
"version": "v4.1.7"
},

@ -0,0 +1,20 @@
{% extends 'base.html.twig' %}
{% block title %}Hello LandingController!{% endblock %}
{% block body %}
<style>
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
</style>
<div class="example-wrapper">
<h1>Hello {{ controller_name }}! ✅</h1>
This friendly message is coming from:
<ul>
<li>Your controller at <code><a href="{{ '/home/pascal/git/animegame/src/Controller/Std/LandingController.php'|file_link(0) }}">src/Controller/Std/LandingController.php</a></code></li>
<li>Your template at <code><a href="{{ '/home/pascal/git/animegame/templates/landing/index.html.twig'|file_link(0) }}">templates/landing/index.html.twig</a></code></li>
</ul>
</div>
{% endblock %}

@ -0,0 +1,34 @@
<?php
namespace App\Tests\Controller;
use App\DataFixtures\UserFixtures;
class EventControllerTest extends RestTestBase
{
/**
* This test verifies that requesting
*/
public function testRetrieveUser()
{
$this->createRequestBuilder()
->setMethod('GET')
->setUri('/api/events')
->setAcceptType('application/json')
->addServerParameter('HTTP_X-AUTH-TOKEN', UserFixtures::ADMIN_USER_REFERENCE)
->request();
$response = $this->client->getResponse();
$this->assertTrue($response->headers->contains('Content-Type', 'application/json'), 'the "Content-Type" header is "' . $response->headers->get('Content-Type') . '"' // optional message shown on failure
);
$this->assertEquals(200, $response->getStatusCode(), 'Status code was ' . $response->getStatusCode() . ' but expected 200: ' . $response->getContent());
$data = json_decode($response->getContent());
// Expect two events
$this->assertEquals(2, count($data));
}
}
Loading…
Cancel
Save