Skip to content

Instantly share code, notes, and snippets.

@mablae
mablae / RecordResultForm.php
Created November 18, 2016 12:30 — forked from webdevilopers/RecordResultForm.php
Dynamically add Elements to Symfony Form Collection without Data
<?php
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
final class RecordResult extends AbstractType
<?php
/**
* This is the clock interface. It's really simple, you write it once, use it anywhere.
* Cool extra things you can do:
* - have it return custom value objects
* - separate method for currentDate() without time part
*/
interface Clock
{
@mablae
mablae / BlogPostHydrator.php
Last active July 19, 2016 15:03 — forked from Ocramius/BlogPostHydrator.php
Association lazy-loading with Zend\Db
<?php
use ProxyManager\Factory\LazyLoadingValueHolderFactory;
use Zend\Stdlib\Hydrator\HydratorInterface;
class BlogPostHydrator implements HydratorInterface
{
/**
* @var HydratorInterface
*/
@mablae
mablae / gist:8cd3e5b0732c88b2a90a
Created January 26, 2016 02:07 — forked from fbrnc/gist:4550079
Make Behat/Mink create a screenshot when a test fails
<?php
class FeatureContext extends MinkContext {
/**
* Take screenshot when step fails.
* Works only with Selenium2Driver.
*
* @AfterStep
*/

We create an index with:

  • two filters: synonyms_expand and synonyms_contract
  • two analyzers: synonyms_expand and synonyms_contract
  • three text fields:
    • text_1 uses the synonyms_expand analyzer at index and search time
    • text_2 uses the synonyms_expand analyzer at index time, but the standard analyzer at search time
    • text_3 uses the synonyms_contract analyzer at index and search time

.

# ========================================
# Testing n-gram analysis in ElasticSearch
# ========================================
curl -X DELETE localhost:9200/ngram_test
curl -X PUT localhost:9200/ngram_test -d '
{
"settings" : {
"index" : {
"analysis" : {
@mablae
mablae / gen-changelog.sh
Last active December 29, 2015 13:29
Creates a GIT Changelog based on Tags
#!/bin/bash
tags=()
for tag in $(git for-each-ref --sort='-refname:short' --format='%(refname:short)' refs/tags) ; do
tags+=($tag)
done
lastTag=0
totalTags=${#tags[*]}
@mablae
mablae / awesome-php.md
Last active December 15, 2015 00:09 — forked from ziadoz/awesome-php.md
Fix Url

Awesome PHP Libraries

A list of amazingly awesome PHP libraries that you should consider using (and some other shiny extras).

@mablae
mablae / dabblet.css
Created August 5, 2012 04:45
Untitled
h1 {
margin-top: 50px;
line-height: 45px;
position: relative;
display: block;
text-align: center;
}

Adding variables to twig output

Yesterday @userfriendly posted a interesting Question on Freenode/#symofony:

He asked about how to add class attributes to the <option> Tags of a EntityType.php form field. After looking at the code we found out that this is not possible at all with the native behavior of the EntityType or with any <select> field.

Then I had the idea to work the variables I can access without making changes to the Symfony2 Modules. Here is the solution: