Skip to content

Instantly share code, notes, and snippets.

@boekkooi
boekkooi / ConnectionKeepAlive.php
Last active October 19, 2023 23:17
Doctrine keep alive (MySQL server has gone away)
<?php
namespace Acme\Doctrine\DBAL;
use Doctrine\DBAL\Connection;
declare(ticks = 3000000);
class ConnectionKeepAlive
{
/**
@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 / 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 / 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 / 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 / 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 / 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;