commit
245f301602
@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Command;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Connection;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
class PopulateDBEmojiAvailableCommand extends Command
|
||||||
|
{
|
||||||
|
|
||||||
|
protected static $defaultName = 'app:popDBEmojiAvai';
|
||||||
|
|
||||||
|
private Connection $connection;
|
||||||
|
|
||||||
|
public function __construct(Connection $connection)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->connection = $connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->setDescription('Populate the database.');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
|
||||||
|
// On supprime la table si elle existe déjà
|
||||||
|
$this->connection->executeStatement('DROP TABLE IF EXISTS stock_emoji');
|
||||||
|
|
||||||
|
// On crée la table
|
||||||
|
$this->connection->executeStatement('
|
||||||
|
CREATE TABLE stock_emoji (
|
||||||
|
id INT PRIMARY KEY,
|
||||||
|
code VARCHAR(255) NOT NULL
|
||||||
|
)
|
||||||
|
');
|
||||||
|
|
||||||
|
// On peuple la table
|
||||||
|
$this->connection->executeStatement("INSERT INTO stock_emoji (id, code) VALUES
|
||||||
|
(1,'🤖'),
|
||||||
|
(2,'😺'),
|
||||||
|
(3,'🧠'),
|
||||||
|
(4,'👻'),
|
||||||
|
(5,'🧟'),
|
||||||
|
(6,'🐶'),
|
||||||
|
(7,'👽'),
|
||||||
|
(8,'🧛'),
|
||||||
|
(9,'🎃'),
|
||||||
|
(10,'🐸'),
|
||||||
|
(11,'⚡'),
|
||||||
|
(12,'💀'),
|
||||||
|
(13,'🔥'),
|
||||||
|
(14,'🧙'),
|
||||||
|
(15,'🌪️'),
|
||||||
|
(16,'😎'),
|
||||||
|
(17,'😁'),
|
||||||
|
(18,'🌟'),
|
||||||
|
(19,'😈')
|
||||||
|
");
|
||||||
|
|
||||||
|
$output->writeln('Base de données peuplée.');
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$output->writeln('<error>Erreur : ' . $e->getMessage() . '</error>');
|
||||||
|
return Command::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Repository\StockEmojiRepository;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
#[ORM\Entity(repositoryClass: StockEmojiRepository::class)]
|
||||||
|
class StockEmoji
|
||||||
|
{
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
private ?int $id = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255)]
|
||||||
|
private ?string $code = null;
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCode(): ?string
|
||||||
|
{
|
||||||
|
return $this->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCode(string $code): self
|
||||||
|
{
|
||||||
|
$this->code = $code;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\StockEmoji;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<StockEmoji>
|
||||||
|
*
|
||||||
|
* @method StockEmoji|null find($id, $lockMode = null, $lockVersion = null)
|
||||||
|
* @method StockEmoji|null findOneBy(array $criteria, array $orderBy = null)
|
||||||
|
* @method StockEmoji[] findAll()
|
||||||
|
* @method StockEmoji[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||||
|
*/
|
||||||
|
class StockEmojiRepository extends ServiceEntityRepository
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, StockEmoji::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * @return StockEmoji[] Returns an array of StockEmoji objects
|
||||||
|
// */
|
||||||
|
// public function findByExampleField($value): array
|
||||||
|
// {
|
||||||
|
// return $this->createQueryBuilder('s')
|
||||||
|
// ->andWhere('s.exampleField = :val')
|
||||||
|
// ->setParameter('val', $value)
|
||||||
|
// ->orderBy('s.id', 'ASC')
|
||||||
|
// ->setMaxResults(10)
|
||||||
|
// ->getQuery()
|
||||||
|
// ->getResult()
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public function findOneBySomeField($value): ?StockEmoji
|
||||||
|
// {
|
||||||
|
// return $this->createQueryBuilder('s')
|
||||||
|
// ->andWhere('s.exampleField = :val')
|
||||||
|
// ->setParameter('val', $value)
|
||||||
|
// ->getQuery()
|
||||||
|
// ->getOneOrNullResult()
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
|
}
|
Loading…
Reference in new issue