Skip to content

Instantly share code, notes, and snippets.

View havvg's full-sized avatar

Toni Uebernickel havvg

View GitHub Profile
@havvg
havvg / .gitconfig
Created March 21, 2015 13:25
apply PHP-CS-Fixer on all changed files in the staging area
[alias]
fix-staged = "!git diff-index --cached --name-status HEAD | grep -ve '^D' | cut -f2 | xargs -n1 php-cs-fixer fix"
@havvg
havvg / services.yml
Created October 17, 2014 15:32
TraceableEventDispatcher using service decorator
services:
event_dispatcher:
class: Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher
arguments:
- @container
traceable_event_dispatcher:
public: false
class: Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher
decorates: event_dispatcher
@havvg
havvg / AppKernel.php
Created October 16, 2014 11:35
Monolog ErrorHandler in Symfony2 apps
<?php
use Monolog\ErrorHandler;
use Psr\Log\LogLevel;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\DependencyInjection\ContainerInterface;
class AppKernel extends Kernel
{
@havvg
havvg / Foo.php
Created July 18, 2013 15:36
allow instantiation of optional typed parameter
<?php
class Foo
{
public function bar(Response $response = new Response())
{
// ..
}
// Instead of:
@havvg
havvg / services.yml
Last active December 18, 2015 19:09
Symfony2: using Swift_FailoverTransport with Swift_SpoolTransport
services:
# A spooling implementation.
acme.spool.queued:
class: Acme\Mailer\QueuedSpool
# The transport using the spool above.
acme.transport.spool:
class: Swift_SpoolTransport
arguments:
- '@acme.spool.queued'
<?php
use Symfony\Component\DomCrawler\Crawler;
class CrawlerTest extends \PHPUnit_Framework_TestCase
{
public function testAttribute()
{
$xml = <<<XML
<div>
<?php
class AcmeController implements ContainerAwareInterface
{
use ContainerAwareTrait;
use RedirectTrait;
public function indexAction()
{
return $this->redirect('some_route', [
@havvg
havvg / common_prefix.php
Created April 5, 2013 15:08
Calculate the common prefix of two strings.
<?php
// The smallest length of all strings, limited at 10 characters.
$limit = min(strlen($origin), strlen($destination), 10);
// Increment $i as long as the characters at its ($i) position match.
for ($i = 0; $i < $limit && $origin[$i] === $destination[$i]; $i++);
// $i now contains the length of the common prefix
@havvg
havvg / ModelCriteriaMapper.php
Created December 28, 2012 16:14
A DataMapper mapping a Propel ModelCriteria to a Symfony2 form type. see https://github.com/havvg/symfony/tree/feature/model-criteria-mapper
<?php
namespace Symfony\Bridge\Propel1\Form\DataMapper;
use Symfony\Component\Form\DataMapperInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
/**
* A DataMapper mapping a ModelCriteria to a form type.
*
[remote "upstream"]
url = git://github.com/fabpot/Sami.git
fetch = +refs/heads/*:refs/remotes/upstream/*
# Github pull requests
fetch = +refs/pull/*/head:refs/gh-pull/remotes/upstream/*
fetch = +refs/pull/*/merge:refs/gh-merge/remotes/upstream/*