Skip to content

Instantly share code, notes, and snippets.

@jakzal
jakzal / FeatureContext.php
Last active September 16, 2018 07:22
Generating schema before Behat scenarios in Symfony2
<?php
namespace Behat\CommonContext;
use Behat\BehatBundle\Context\BehatContext;
use Behat\Behat\Event\ScenarioEvent;
use Doctrine\ORM\Tools\SchemaTool;
/**
* Provides hooks for building and cleaning up a database schema with Doctrine.
@jakzal
jakzal / composer.json
Created January 16, 2012 16:12
composer.json - example of external repository
"repositories": {
"antimattr/google-bundle": {
"package": {
"name": "antimattr/google-bundle",
"version": "master",
"source": {
"url": "git://github.com/antimattr/GoogleBundle.git",
"type": "git",
"reference": "master"
},
@jakzal
jakzal / fix-permissions.sh
Created February 10, 2012 17:33
Symfony2 permission fix
#/bin/sh
setfacl -R -m u:apache:rwx app/cache app/logs
setfacl -R -d -m u:apache:rwx app/cache app/logs
setfacl -R -m u:kuba:rwx app/cache app/logs
setfacl -R -d -m u:kuba:rwx app/cache app/logs
setfacl -R -m mask:rwx app/cache app/logs
setfacl -R -d -m mask:rwx app/cache app/logs
@jakzal
jakzal / BlockActionExtension.php
Created February 20, 2012 13:43
Twig extension to render parts of content as actions
<?php
namespace PSS\Bundle\ContentBundle\Twig\Extension;
use Symfony\Bundle\FrameworkBundle\Templating\Helper\ActionsHelper;
class BlockActionExtension extends \Twig_Extension
{
/**
* @var \Symfony\Bundle\FrameworkBundle\Templating\Helper\ActionsHelper $actionsHelper
@jakzal
jakzal / behat-ci.sh
Created June 18, 2012 23:02
Runs all Behat scenarios in a Symfony project on CI
#!/bin/sh
# ./bin/behat-ci.sh
project_dir=$(dirname $(readlink -f $0))"/.."
logs_path=${1:-"./build/logs/behat"}
reports_path=${2:-"./build/behat"}
cd $project_dir
@jakzal
jakzal / FunctionCache.php
Created July 20, 2012 14:16
Function cache
<?php
namespace Zalas\Cache;
use Doctrine\Common\Cache\AbstractCache;
/**
* This class can be used to cache the result and output of function and method calls.
*
* Loosly based on sfFuncionCache: http://trac.symfony-project.org/browser/branches/1.4/lib/cache/sfFunctionCache.class.php
@jakzal
jakzal / tests.sh
Created August 2, 2012 14:08
Running tests for each Symfony component separately
#!/bin/bash
SYMFONY_PATH="src/Symfony"
OUTPUT_PATH="../symfony.dev/web/coverage"
component=$1||''
if [ -f phpunit.xml ]; then
echo "phpunit.xml file already exists. Remove it to continue."
@jakzal
jakzal / compile-check.php
Created September 4, 2012 21:09
Compile Symfony's check.php into a phar
<?php
$phar = new \Phar('symfony-check.phar', 0, 'symfony-check.phar');
$phar->startBuffering();
$files = array(
'app/check.php',
'app/SymfonyRequirements.php',
'vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/skeleton/app/SymfonyRequirements.php'
);
@jakzal
jakzal / UserType.php
Last active October 10, 2015 14:48
Using Symfony2 form events to prevent overwriting not submitted fields with empty values
<?php
namespace Acme\Bundle\UserBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
class UserType extends AbstractType