Skip to content

Instantly share code, notes, and snippets.

@boekkooi
boekkooi / Regex
Last active August 29, 2015 14:09
PHP RFC3986 regex
<?php
const PATTERN_RFC3986 = '~^
(?<scheme>[a-z][a-z0-9+-\.]*)
://
(?:
(?<userinfo>
([a-z0-9\-\._\~!\$&\'()*+,;=:]|%[0-9a-f]{2})*
)@ # *( unreserved / pct-encoded / sub-delims / ":" )
)?
@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
@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();
<?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 / 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.
*/
@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 / 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 / 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 / using
Created January 22, 2014 06:50
Django - A hack to apply custom templates to tags registered using inclusion_tag, this is related to https://code.djangoproject.com/ticket/9093
import sys
import ctypes
import types
from django.template import TemplateSyntaxError, Token, TOKEN_BLOCK
from django.template.defaulttags import register
if sys.version_info < (3,):
cb_func_code = 'func_code'
cb_func_closure = 'func_closure'
@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
*/