Skip to content

Instantly share code, notes, and snippets.

@boekkooi
boekkooi / CustomPropertyAccessor.php
Last active December 23, 2020 02:49
Using a custom property path for symfony forms set / get path
<?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
{
/**
@boekkooi
boekkooi / JsonSerializableNormalizer.php
Created January 7, 2016 15:29
JsonSerializableNormalizer
<?php
namespace Acme\Serializer\Normalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class JsonSerializableNormalizer implements NormalizerInterface
{
/**
* @inheritdoc
*/
@boekkooi
boekkooi / ExampleMailer.php
Last active November 18, 2015 13:27
PHP Twig Mailer
<?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 September 14, 2015 08:30
ValueObject + Broadway
<?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 December 11, 2020 02:28
Symfony Form DataMapper using object constructors
<?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 August 29, 2015 14:17
Openshift + Phalcon

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 February 24, 2015 15:53
Event sourced form mapping
<?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.
*/
<?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 November 28, 2014 09:35
Deep copy Array
<?php
function arrayCopy(array $array)
{
$hashList = array();
$iterator = new \RecursiveIteratorIterator(
new \RecursiveArrayIterator($array),
\RecursiveIteratorIterator::SELF_FIRST
);
$iterator->rewind();
@boekkooi
boekkooi / gist:abdd30d472b7b6bd3227
Created November 26, 2014 09:03
RFC3261 Uri Regex
<?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