Skip to content

Instantly share code, notes, and snippets.

View romaricdrigon's full-sized avatar

Romaric Drigon romaricdrigon

  • Lausanne, Switzerland
View GitHub Profile
@romaricdrigon
romaricdrigon / UnauthorizedAjaxListener.php
Created August 21, 2013 07:13
Symfony2 + AngularJS de-authentification handling
<?php
namespace Acme\DemoBundle\EventListener;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
@romaricdrigon
romaricdrigon / formController.js
Created August 21, 2013 07:46
Using AngularJS on Symfony2 forms
// An example controller binded to the form
function FormCntl($scope, $compile) {
// Consider using FosJsRouting bundle, if you want to use a Symfony2 route
$scope.formUrl = "http://url-to-fetch-my-form";
// Data from the form will be binded here
$scope.data = {};
// Method called when submitting the form
$scope.submit = function() {
@romaricdrigon
romaricdrigon / MyContext.php
Created August 30, 2013 09:57
Screenshots on Behat failed steps
<?php
namespace Acme\Behat\Context;
use Behat\Behat\Context\BehatContext;
use Behat\MinkExtension\Context\MinkContext;
use Behat\Behat\Event\StepEvent;
class MyContext extends BehatContext
{
@romaricdrigon
romaricdrigon / minified.js
Created November 5, 2013 11:55
Symfony2 DebugToolbar Bookmarklet
javascript:(function(){var e=window.location.href.match(/.+\/app_dev\.php/);if(e){var t=new XMLHttpRequest;t.open("GET",document.location,false);t.send(null);var n=t.getResponseHeader("X-Debug-Token");var r=e[0]+"/_profiler/"+n;window.location.href=r}})()
@romaricdrigon
romaricdrigon / index.html
Last active October 31, 2023 13:03
Minimal HTML boilerplate
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Title</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
</head>
<body>
@romaricdrigon
romaricdrigon / app-MicroKernel.php
Created August 26, 2016 13:46
Symfony 2.8 MicroKernel
<?php
// app/MicroKernel.php
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
@romaricdrigon
romaricdrigon / ApiTokenAuthenticator.php
Last active August 30, 2016 12:18
Symfony 2.8 Guard component
<?php
namespace AppBundle\Security;
use KnpU\Guard\AbstractGuardAuthenticator;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\User\User;
@romaricdrigon
romaricdrigon / TestServicesCommand.php
Created September 7, 2016 07:59
Command to test that all services within a Symfony project build successfully
<?php
namespace AppBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@romaricdrigon
romaricdrigon / docker-compose.yml
Last active October 12, 2018 17:32
Minimal docker LAMP setup
version: '2'
volumes:
mysqldata: ~
services:
php:
image: php:7.2-apache
depends_on:
- mysql
@romaricdrigon
romaricdrigon / Dockerfile
Last active January 10, 2019 09:56
LAMP setup for Symfony
FROM php:7.2-apache
# Dépendences nécessaires pour les extensions PHP, plus Wget/Git/SSH
RUN apt-get update && apt-get install --no-install-recommends -yq ${BUILD_PACKAGES} \
build-essential \
wget \
ssh \
git \
libmcrypt-dev \
libicu-dev \