Skip to content

Instantly share code, notes, and snippets.

@Heyfara
Heyfara / ApiKeyAuthenticator.php
Last active August 13, 2023 09:26
Symfony authentication API token
<?php
namespace App\Security\Authenticator;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
@Heyfara
Heyfara / BlockRenderer.php
Last active February 25, 2021 17:45
Use twig template blocks to render email using Symfony Mailer component
<?php
namespace App\Mailer;
use League\HTMLToMarkdown\HtmlConverter;
use Symfony\Component\Mime\BodyRendererInterface;
use Symfony\Component\Mime\Exception\InvalidArgumentException;
use Symfony\Component\Mime\Message;
use Twig\Environment;
use Symfony\Bridge\Twig\Mime\WrappedTemplatedEmail;
@Heyfara
Heyfara / IdGenerator.php
Created November 8, 2018 22:09
Doctrine id generator for creating Youtube-like hash
<?php
namespace App\Doctrine;
use Doctrine\ORM\Id\AbstractIdGenerator;
use Doctrine\ORM\EntityManager;
/**
* Class used to generate ids using base64 strings
* like youtube videos id for example
@Heyfara
Heyfara / RegistrationController.php
Created November 8, 2018 22:05
Automatically log user after registration
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
class RegistrationController
{
public function registerAction(Request $request)
@Heyfara
Heyfara / mac_os_upgrade_php.sh
Last active February 22, 2017 18:07
Mac OS X Sierra PHP upgrade
// Remplace 7.0 by the version number you want
curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0
export PATH=/usr/local/php5/bin:$PATH