Skip to content

Instantly share code, notes, and snippets.

View artyuum's full-sized avatar
🎯

Dynèsh Hassanaly artyuum

🎯
  • France
View GitHub Profile
@artyuum
artyuum / TimestampSubscriber.php
Last active November 5, 2021 10:29
Adding a timestampable feature to your entities in Symfony
<?php
namespace App\EventSubscriber;
use App\Entity\Traits\TimestampableTrait;
use DateTime;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Events;
use Doctrine\Persistence\Event\LifecycleEventArgs;
@artyuum
artyuum / FieldCreationHelper.php
Last active February 8, 2021 06:19
A simple helper to ease with the creation of custom fields on Drupal without having to use YAML files as they are less convenient.
<?php
namespace Drupal\artyuum\Helper;
use Drupal;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
@artyuum
artyuum / ConstraintViolationHelper.php
Last active February 8, 2021 06:22
Converts Validator constrains violations to a simple key => value array (field => error messages)
<?php
class ConstraintViolationHelper
{
/**
* Gets the validator errors.
*/
public static function toArray(ConstraintViolationListInterface $violations): ?array
{
$errors = null;
@artyuum
artyuum / HashidsDoctrineParamConverter.php
Last active August 6, 2021 20:52
A ParamConverter to use HashIds with Doctrine + Symfony.
<?php
namespace App\ParamConverter;
use Doctrine\ORM\EntityManagerInterface;
use Hashids\HashidsInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@artyuum
artyuum / TokenRepository.php
Last active September 30, 2020 19:14
Doctrine deleteBy() criteria
<?php
class TokenRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Token::class);
}
public function deleteBy(array $criteria)