Skip to content

Instantly share code, notes, and snippets.

View baldurrensch's full-sized avatar

Baldur Rensch baldurrensch

  • Sourceability LLC
  • Irvine, CA
View GitHub Profile
@baldurrensch
baldurrensch / DemoController.php
Created January 2, 2013 18:49
How to use the All Validator
<?php
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\All;
// This is reduced to the bare minimum. Missing Namespace and other imports
class DemoController extends Controller
{
function testAction()
{
@baldurrensch
baldurrensch / CustomHandler.php
Created December 21, 2012 15:29
This is a handler for the JMS serializer to handle parent and child type serialization. You need to set the type of your collection as `@Type("\Acme\MyBundle\Model\ChildType")`, so that the serializer picks up the handler correctly. Also remember that you need to hook up the handler as a service (and give it the correct tag).
<?php
namespace Acme\MyBundle\Serializer\Handler;
use JMS\Serializer\Handler\SubscribingHandlerInterface;
use JMS\Serializer\EventDispatcher\Event;
use JMS\Serializer\GraphNavigator;
use JMS\Serializer\XmlSerializationVisitor;
use JMS\Serializer\GenericSerializationVisitor;
@baldurrensch
baldurrensch / TimeReportingTestListener.php
Created December 19, 2012 17:53
A PHP Unit Listener that records individual test time runs and can print out warnings if a test is slower then some critical threshold
<?php
namespace Hautelook\ApiBundle\Tests;
use PHPUnit_Framework_TestListener;
use PHPUnit_Framework_Test;
use PHPUnit_Framework_TestSuite;
use PHPUnit_Framework_AssertionFailedError;
use Exception;
[12:05][brensch@Baldur-Renschs-MacBook-Pro:~/code/www-halo](master)$ sudo vagrant provision
Password:
[default] Running provisioner: Vagrant::Provisioners::Puppet...
[default] Running Puppet with /tmp/vagrant-puppet/manifests/ecom.pp...
notice: /Stage[main]/Hautelook/Host[memcache03]/ip: ip changed '10.0.200.31' to '127.0.0.1'
notice: /Stage[main]/Hautelook/File[ca-bundle.crt]/content: content changed '{md5}661bdf31600c25dd28e1a69c6991c476' to '{md5}c4290b9deb70d0bef2f88b67fc68c8ec'
notice: /Stage[main]/Hautelook/Host[memcache04]/ip: ip changed '10.0.200.31' to '127.0.0.1'
[~/code]$ git clone https://github.com/TheFootballSocialClub/FSCHateoasBundle.git Hateoas
Cloning into 'Hateoas'...
remote: Counting objects: 1487, done.
remote: Compressing objects: 100% (655/655), done.
remote: Total 1487 (delta 837), reused 1351 (delta 711)
Receiving objects: 100% (1487/1487), 186.06 KiB | 203 KiB/s, done.
Resolving deltas: 100% (837/837), done.
[~/code]$ cd Hateoas
[~/code/Hateoas]$ composer install --dev [master]
Loading composer repositories with package information
<?php
namespace Gregwar\CaptchaBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
/**
<?php
namespace Hautelook\ApiBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* This is the class that validates and merges configuration from your app/config files
*
service1:
- option1
service2:
- option2
# I basically want to get this as 'approximately'
array('service1' => array('option1'), 'service2' => array('option2'))
@baldurrensch
baldurrensch / HautelookDoctrineExclusionStrategy.php
Created November 20, 2012 21:36
JMS Serializer Exclusion Strategy to limit level of serialization
<?php
namespace Hautelook\ApiBundle\Serializer\Handler;
use JMS\SerializerBundle\Serializer\Exclusion\ExclusionStrategyInterface;
use JMS\SerializerBundle\Metadata\ClassMetadata;
use JMS\SerializerBundle\Metadata\PropertyMetadata;
class HautelookDoctrineExclusionStrategy implements ExclusionStrategyInterface
{
@baldurrensch
baldurrensch / PhpassEncoder.php
Created November 18, 2012 17:14
How to use Phpass in Symfony
<?php
namespace Acme\DemoBundle\Security\Service;
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
use Hautelook\Phpass\PasswordHash;
/**
* A password encoder that uses Phpass for encoding