Create snippets skeleton
This commit is contained in:
@ -11,9 +11,9 @@ class HomeController extends AbstractController
|
||||
#[Route('/', name: 'home')]
|
||||
public function home(): Response
|
||||
{
|
||||
return $this->redirectToRoute('task_view');
|
||||
// return $this->render('simple.html.twig', [
|
||||
// 'text' => 'Welcome!'
|
||||
// ]);
|
||||
// return $this->redirectToRoute('task_view');
|
||||
return $this->render('simple.html.twig', [
|
||||
'text' => 'Welcome!'
|
||||
]);
|
||||
}
|
||||
}
|
29
src/Controller/SnipController.php
Normal file
29
src/Controller/SnipController.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Snip;
|
||||
use App\Repository\SnipRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
#[Route('/snip', name: 'snip')]
|
||||
class SnipController extends AbstractController
|
||||
{
|
||||
#[Route('/', name: '_index')]
|
||||
public function index(SnipRepository $repository): Response
|
||||
{
|
||||
return $this->render('snip/index.html.twig', [
|
||||
'snips' => $repository->findAll(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/singe/{snip}', name: '_single')]
|
||||
public function single(Snip $snip): Response
|
||||
{
|
||||
return $this->render('snip/single.html.twig', [
|
||||
'snip' => $snip,
|
||||
]);
|
||||
}
|
||||
}
|
0
src/Entity/.gitignore
vendored
0
src/Entity/.gitignore
vendored
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\EmailRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: EmailRepository::class)]
|
||||
class Email
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
}
|
22
src/Entity/Helpers/EnableableTrait.php
Normal file
22
src/Entity/Helpers/EnableableTrait.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Helpers;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
trait EnableableTrait
|
||||
{
|
||||
#[ORM\Column(options: ['default' => true])]
|
||||
private bool $enabled = true;
|
||||
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
public function setEnabled(bool $enabled): static
|
||||
{
|
||||
$this->enabled = $enabled;
|
||||
return $this;
|
||||
}
|
||||
}
|
54
src/Entity/Helpers/TrackedTrait.php
Normal file
54
src/Entity/Helpers/TrackedTrait.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Helpers;
|
||||
|
||||
use App\Entity\User;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
trait TrackedTrait
|
||||
{
|
||||
#[ORM\Column]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?DateTime $createdAt = null;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?User $createdBy = null;
|
||||
|
||||
public function getCreatedBy(): ?User
|
||||
{
|
||||
return $this->createdBy;
|
||||
}
|
||||
|
||||
public function setCreatedBy(?User $createdBy): self
|
||||
{
|
||||
$this->createdBy = $createdBy;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): ?DateTime
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
public function setCreatedAt(DateTime $createdAt): self
|
||||
{
|
||||
$this->createdAt = $createdAt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCode(): string
|
||||
{
|
||||
return date_format($this->createdAt, "ymd");
|
||||
}
|
||||
|
||||
public function setCreatedAtTodayNoSeconds(): self
|
||||
{
|
||||
$this->setCreatedAt(DateTime::createFromFormat('Y-m-d H:i', date('Y-m-d H:i')));
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
38
src/Entity/Snip.php
Normal file
38
src/Entity/Snip.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Entity\Helpers\TrackedTrait;
|
||||
use App\Repository\SnipRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: SnipRepository::class)]
|
||||
class Snip
|
||||
{
|
||||
use TrackedTrait;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $name = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
27
src/Form/SnipType.php
Normal file
27
src/Form/SnipType.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Snip;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class SnipType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('name')
|
||||
->add('createdAt')
|
||||
->add('createdBy')
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Snip::class,
|
||||
]);
|
||||
}
|
||||
}
|
66
src/Repository/SnipRepository.php
Normal file
66
src/Repository/SnipRepository.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Snip;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Snip>
|
||||
*
|
||||
* @method Snip|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Snip|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Snip[] findAll()
|
||||
* @method Snip[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class SnipRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Snip::class);
|
||||
}
|
||||
|
||||
public function save(Snip $entity, bool $flush = false): void
|
||||
{
|
||||
$this->getEntityManager()->persist($entity);
|
||||
|
||||
if ($flush) {
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
public function remove(Snip $entity, bool $flush = false): void
|
||||
{
|
||||
$this->getEntityManager()->remove($entity);
|
||||
|
||||
if ($flush) {
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Snip[] Returns an array of Snip 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): ?Snip
|
||||
// {
|
||||
// return $this->createQueryBuilder('s')
|
||||
// ->andWhere('s.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
Reference in New Issue
Block a user