Skip to content

Instantly share code, notes, and snippets.

View b-b3rn4rd's full-sized avatar

Bernard Baltrusaitis b-b3rn4rd

  • Bendigo Bank
  • Melbourne
View GitHub Profile
@b-b3rn4rd
b-b3rn4rd / FormErrors.php
Last active August 29, 2015 14:05
Symfony2 - get form errors as a flat array
<?php
namespace Interprac\Bundle\UtilityBundle\Form;
use Symfony\Component\Form\Form;
class FormErrors
{
public function getArray(Form $form, $style = 'KO')
{
<?php
namespace Acme\DemoBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Role\SwitchUserRole;
@b-b3rn4rd
b-b3rn4rd / helpers.php
Last active October 5, 2015 22:03
Convert single level array that uses "dot" notation into nested array (opposite to array_dot)
<?php
/**
* Do an opposite of what array_dot does
*
* @param array $array
* @param string $delimiter
* @return array "undotted" nested array
*/
function array_undot(array $array, $delimiter = '.')
@b-b3rn4rd
b-b3rn4rd / Job.php
Created June 9, 2012 03:50
Zend_Queue background job abstract class
<?php
/**
* Zend_Queue background job abstract class
*
* @author Bernard Baltrusaitis <bernard@runawaylover.info>
*/
abstract class My_Job
{
/**
*
@b-b3rn4rd
b-b3rn4rd / Repository.php
Last active October 6, 2015 20:38
Custom Doctrine Repository
<?php
namespace My\Doctrine;
use Doctrine\ORM\EntityRepository;
/**
* Custom Repository extending basic EntityRepository functionality
*
* @author Bernard Baltrusaitis <bernard@runawaylover.info>
@b-b3rn4rd
b-b3rn4rd / example2.git
Last active November 2, 2015 03:24
List local tracking branches with removed remote-tracking branches
git branch -vv | grep ": gone]" | awk '{ print $1 }'
@b-b3rn4rd
b-b3rn4rd / UpdateCommand.php
Last active December 20, 2015 19:09
Allow 'orm:schema-tool:update' to filter entities
<?php
namespace My\Doctrine\ORM\Tools\Console\Command\SchemaTool;
use Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand as UpdateCommand2,
Symfony\Component\Console\Input\InputArgument,
Symfony\Component\Console\Input\InputOption,
Symfony\Component\Console\Input\InputInterface,
Symfony\Component\Console\Output\OutputInterface,
Doctrine\ORM\Tools\SchemaTool,
Doctrine\ORM\Tools\Console\MetadataFilter;
@b-b3rn4rd
b-b3rn4rd / Form.php
Created October 3, 2013 06:31
Get flatten Zend_Form error messages
<?php
class My_Form extends \Zend_Form
{
/**
* Flatten Zend_Form error messages
*
* @param \Zend_Form|null $form
* @param array|null $messages
* @param int $i
* @return array
@b-b3rn4rd
b-b3rn4rd / ArrayObject.php
Last active December 29, 2015 09:49
Accessing array properties through magic getters and setters.
<?php
namespace My;
use Doctrine\Common\Util\Inflector;
/**
* Allow to access array properties using getters/setters
*
* @method null set${Property}(mixed $value) set array property
* @method mixed get${Property}() get array property
* @author Bernard Baltrusaitis <bernard@runawaylover.info>
@b-b3rn4rd
b-b3rn4rd / ArrayObjectHydrator.php
Created January 6, 2014 10:06
Custom hydrator for Doctrine2, allows to access array elements using getters, similar to the ObjectHydrator
<?php
namespace My\Doctrine\Hydration;
use Doctrine\ORM\Internal\Hydration\ArrayHydrator,
My\ArrayObject as ArrayObject;
/**
* Custom Doctrine2 hydrator, allows to access array properties using getters like
* in ObjectHydrator
*