Skip to content

Instantly share code, notes, and snippets.

Warnar Boekkooi boekkooi

View GitHub Profile
@boekkooi
boekkooi / CustomPropertyAccessor.php
Last active Feb 13, 2019
Using a custom property path for symfony forms set / get path
View CustomPropertyAccessor.php
<?php
use Symfony\Component\PropertyAccess\PropertyAccessor;
use Symfony\Component\PropertyAccess\PropertyPath;
/**
* A property accessor that allows you to rewrite a property path for setters and getters.
*/
class CustomPropertyAccessor extends PropertyAccessor
{
/**
View JsonSerializableNormalizer.php
<?php
namespace Acme\Serializer\Normalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class JsonSerializableNormalizer implements NormalizerInterface
{
/**
* @inheritdoc
*/
View ExampleMailer.php
<?php
final class ExampleMailer extends Mailer
{
protected $parameters;
public function __construct(\Swift_Mailer $mailer, UrlGeneratorInterface $router, \Twig_Environment $twig, array $parameters)
{
parent::__construct($mailer, $router, $twig);
$this->parameters = $parameters;
@boekkooi
boekkooi / Collection.php
Created Sep 14, 2015
ValueObject + Broadway
View Collection.php
<?php
namespace Xoip\Component\ValueObject;
interface Collection extends \IteratorAggregate, \Countable
{
/**
* Adds an element at the end of the collection.
*
* @param ValueObject $object The object to add.
*
@boekkooi
boekkooi / ConstructorMapper.php
Last active Jul 1, 2018
Symfony Form DataMapper using object constructors
View ConstructorMapper.php
<?php
namespace Acme\Symfony\Form\DataMapper;
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
class ConstructorMapper extends PropertyPathMapper
{
@boekkooi
boekkooi / 0_README.md
Last active Aug 29, 2015
Openshift + Phalcon
View 0_README.md

Create your openshift application (https://github.com/boekkooi/openshift-cartridge-nginx, https://github.com/boekkooi/openshift-cartridge-php):

rhc create-app myapp http://cartreflect-claytondev.rhcloud.com/github/boekkooi/openshift-cartridge-nginx
rhc cartridge add -a myapp http://cartreflect-claytondev.rhcloud.com/reflect?github=boekkooi/openshift-cartridge-php

Now checkout the repo. Modify .openshift/nginx.conf.erb to look like this gists 1_nginx.conf.erb and add .openshift/action_hooks/build with the content of this gists 2_build (make sure to do chmod +x) also add .openshift/php-pecl.txt. with the content of 3_php-pecl.txt

Commit and push and you'r done.

@boekkooi
boekkooi / DataMapper.php
Created Feb 24, 2015
Event sourced form mapping
View DataMapper.php
<?php
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
/**
* Custom datamapper
* This uses normal getters to fill the form using PropertyPathMapper.
* But for setters it go's the custom route.
*/
View EventListener\EntityReferenceEventSubscriber.php
<?php
namespace Boekkooi\Bundle\FrameworkBundle\EventListener;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\ORM\Tools\AttachEntityListenersListener;
@boekkooi
boekkooi / deep_copy
Created Nov 28, 2014
Deep copy Array
View deep_copy
<?php
function arrayCopy(array $array)
{
$hashList = array();
$iterator = new \RecursiveIteratorIterator(
new \RecursiveArrayIterator($array),
\RecursiveIteratorIterator::SELF_FIRST
);
$iterator->rewind();
View gist:abdd30d472b7b6bd3227
<?php
const SIP_PATTERN = '~^
(?:(?<schema>sip(s)?):)?
(?:
(?<user>(?:[a-z0-9\-_\.!\~*\'\(\)]|%[0-9a-f]{2}|[&=\+$,;?\/])+) # user ( unreserved / escaped / user-unreserved )
(?::(?<password>(?:[a-z0-9\-_\.!\~*\'\(\)]|%[0-9a-f]{2}|[&=\+$,])+))? # password ( unreserved / escaped / "&" / "=" / "+" / "$" / "," )
@)? # userinfo
(?<host>
(?:[\pL\pN\pS-\.])+(?:\.?(?:[\pL]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
| # or
You can’t perform that action at this time.