Updated to latest symfony version
							parent
							
								
									de955465a2
								
							
						
					
					
						commit
						9e320f8920
					
				
											
												
													File diff suppressed because it is too large
													Load Diff
												
											
										
									
								| @ -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> | ||||
| @ -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'] | ||||
| @ -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\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,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,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; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @ -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,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); | ||||
|     } | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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…
					
					
				
		Reference in New Issue