Skip to content

Instantly share code, notes, and snippets.

View webmozart's full-sized avatar

Bernhard Schussek webmozart

View GitHub Profile
@webmozart
webmozart / README.md
Last active July 22, 2018 13:38
Composer Resource Integration
@webmozart
webmozart / array-validation-error-mapping.php
Last active June 25, 2023 23:30
A little experiment: Validating (potentially multi-leveled) arrays with the Symfony2 Validator component and returning the errors in the same data structure as the validated array by using the Symfony2 PropertyAccess component.
<?php
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\Validator\Constraints\All;
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\Collection;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Optional;
use Symfony\Component\Validator\Constraints\Required;
@webmozart
webmozart / .gitattributes
Last active July 22, 2018 13:39
Automatically replacing variables in PHP files when doing "git add"
*.php filter=subvars
<?php
use Symfony\Component\Form\Forms;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ApplicationFormType extends AbstractType
<form>
<div form-attrs>
<ul>form errors</ul>
<!-- field row: -->
<div>
<label field-label-attrs>label</label>
<ul>field errors</ul>
<input field-attrs />
</div>
<!-- nested form row: -->
@webmozart
webmozart / Issue6190Controller.php
Created December 6, 2012 10:39
Symfony Issue 6190
<?php
namespace Webmozart\TestBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Webmozart\TestBundle\Form\Issue6190EntityType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
@webmozart
webmozart / git-find-merge
Created November 15, 2012 14:32
Script to find the merge and PR a commit occurred in
#!/bin/bash
COMMIT=$1
BRANCH=$2
if [ -z $BRANCH ]; then
BRANCH="master"
fi
perl -ne 'print if ($seen{$_} .= @ARGV) =~ /10$/' \
<(git rev-list --ancestry-path --oneline $COMMIT..$BRANCH) \
@webmozart
webmozart / composer.json
Created August 4, 2012 11:51
DON'T USE THIS GIST! Please clone https://github.com/bschussek/standalone-forms instead.
{
"require": {
"symfony/form": "2.1.*",
"symfony/validator": "2.1.*",
"symfony/templating": "2.1.*",
"symfony/framework-bundle": "2.1.*"
},
"minimum-stability": "dev"
}
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
/**
* https://github.com/symfony/symfony/issues/2677
*
<?php
$builder->add(
$builder->create('Author', 'hidden')
->appendClientTransformer(new EntityToIdTransformer(
new EntityChoiceList($em, 'Name\Space\Author')
))
)