Skip to content

Instantly share code, notes, and snippets.

View terox's full-sized avatar
🎯
Focusing

David Pérez Terol terox

🎯
Focusing
View GitHub Profile
@extolabs
extolabs / Form.php
Created May 12, 2011 16:19
Form Errors Symfony
private function getAllFormErrors($children, $template = true) {
foreach ($children as $child) {
if ($child->hasErrors()) {
$vars = $child->createView()->getVars();
$errors = $child->getErrors();
foreach ($errors as $error) {
$this->allErrors[$vars["name"]][] = $this->convertFormErrorObjToString($error);
}
}
@yosymfony
yosymfony / TwigFactory.php
Last active December 22, 2015 18:09
A Twig factory
<?php
require_once '/path/to/lib/Twig/Autoloader.php';
/**
* A factory for create Twig instances
*
* @author Victor Puertas <vpgugr@gmail.com>
*
* Usage:
* <code>
@javiereguiluz
javiereguiluz / gist:a66f084a4f2cf11cf0ee
Last active August 27, 2016 17:47
Discussion about the different solutions to display a flash message

The problem to solve

We want to show a flash message as the result of executing some controller. This message will only last for the next request.

Proposed Solution #1

I propose to use the new addFlash() method available in the base controller of Symfony 2.6:

@xsist10
xsist10 / Dispatch1.php
Last active January 21, 2017 17:28
An event dispatcher in a tweet
<?php
// Version 1
// Minified
// class Dispatch{function add($e,$l){$this->l[$e][]=$l;}function trigger($e,$d){foreach ($this->l[$e] as $l)call_user_func_array($l, $d);}}
class Dispatch{
function add($e, $l) {
$this->l[$e][] = $l;
@mickaelandrieu
mickaelandrieu / RedirectToAdminZoneListener.php
Last active February 23, 2017 10:51
Redirect to another action, regarding to the role (Symfony)
<?php
namespace AppBundle\EventListener;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\Routing\Router;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
<?php
namespace Acme\YourBundle\Serializer;
use JMS\Serializer\Context;
use JMS\Serializer\JsonSerializationVisitor;
use JMS\Serializer\Metadata\ClassMetadata;
/*
* Copyright 2014 Paul Ferrett <paul@paulferrett.com>
@alkema
alkema / deploy.rb
Created July 9, 2011 20:01
Capistrano task for a Node.js app with github Forever and NPM.
set :application, "appname"
set :deploy_to, "/var/www"
set :scm, :git
set :repository, "git@github.com:user/app.git"
default_run_options[:pty] = true
set :user, "www-data"
set :domain, "foo.tld"
set :normalize_asset_timestamps, false
@dework
dework / FormErrors.php
Last active October 9, 2017 09:04
Symfony 2 Get All Form Errors
<?php
namespace Chyrius\SiteBundle\Form;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\Form;
/**
* @todo Обрабатывать так же ошибки детей-детей
*/
class FormErrors
@webmozart
webmozart / .gitattributes
Last active July 22, 2018 13:39
Automatically replacing variables in PHP files when doing "git add"
*.php filter=subvars
@brtriver
brtriver / BasicAuthControllerProvider.php
Created February 4, 2012 20:36
Simple Basic Auth Controller for Silex.
<?php
namespace Silex\Provider;
use Silex\Application;
use Silex\SilexEvents;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;