Skip to content

Instantly share code, notes, and snippets.

View chalasr's full-sized avatar

Robin Chalas chalasr

View GitHub Profile
@chalasr
chalasr / DefaultController.php
Created April 6, 2016 12:32
Get parameters that have been changed during request from a controller in Symfony2+
<?php
namespace AcmeBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Loader\LoaderResolver;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
<VirtualHost *:80>
ServerName mixinkey.chalasdev.fr
DocumentRoot /var/www/html/projects/mixinkey/current/public
<Directory "/var/www/html/projects/mixinkey/current/public>
Options +FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, X-Requested-With, Content-Type"
@chalasr
chalasr / splat_operator.php
Last active April 11, 2016 13:26
function with dynamic number of type-hinted arguments using the splat operator PHP 5.6
<?php
function splat(array ...$args) {
foreach ($args as $arg) {
print_r($arg);
}
}
splat(['firstArray'], ['secondArray']);
// Output: Array( [0] => firstArray ) Array( [0] => secondArray )
@chalasr
chalasr / .htaccess.dev.dist
Created March 9, 2016 21:03
Symfony2 .htaccess for dev environment (apache2)
# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex app_dev.php
# By default, Apache does not evaluate symbolic links if you did not enable this
# feature in your server configuration. Uncomment the following line if you
# install assets as symlinks or if you experience problems related to symlinks
@chalasr
chalasr / is_serialized.php
Created March 7, 2016 17:36 — forked from cs278/is_serialized.php
PHP is_serialized() function.
<?php
/**
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/
/**
@chalasr
chalasr / AcmeExtension.php
Created February 29, 2016 22:09
Load configuration files depending on host in Symfony
// src/AcmeBundle/DependencyInjection/AcmeExtension.php
<?php
namespace AcmeBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
@chalasr
chalasr / DBALExceptionResponseListener.php
Created February 23, 2016 21:33
DBALExceptionResponseListener EventListener OnKernelResponse
<?php
// src/AcmeBundle/EventListner/DBALExceptionResponseListener.php
namespace AcmeBundle\EventListener;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Doctrine\DBAL\DBALException;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\Router\RouterInterface;
@chalasr
chalasr / LoginAuthenticationHandler.php
Last active January 11, 2020 11:23
FOSUserBundle Login Authentication Success Handler example.
<?php
namespace AppBundle\EventListener;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
@chalasr
chalasr / proceduralphp.md
Created February 10, 2016 00:30 — forked from InFog/proceduralphp.md
PHP Procedural Framework Manifesto

Procedural PHP Manifesto

We are web site developers (a.k.a. webmasters) and we just want to get stuff done. We don't need Object Orientation and we don't need Design Patters and other boring and not easy to learn and understand stuff to get in our way to get our sites up and running.

And that's why our values are:

  1. Procedural Code over Object Orientation
  • Classes with only static functions are ok, since it's just a way to keep functions in one place. And is still procedural
  1. Explicitly load what you need over autoloaders
  • Autoloaders are complex and can fail. Just include() what you need
@chalasr
chalasr / BaseEntity.php
Created February 5, 2016 10:30
Selective mapping inheritance in Doctrine2
<?php
namespace App\Util\Doctrine\Entity;
/**
* Base Entity.
*/
class BaseEntity
{
/**