Skip to content

Instantly share code, notes, and snippets.

@simshaun
simshaun / gist:9198574
Last active August 29, 2015 13:56
Symfony2 change form data in event
$builder->addEventListener(
FormEvents::PRE_SUBMIT,
function (FormEvent $event) {
$data = $event->getData();
if (isset($data['url'])) {
$url = (string) $data['url'];
if (empty($url)) {
$url = isset($data['title']) ? (string) $data['title'] : null;
@simshaun
simshaun / example.php
Created February 26, 2014 00:11
Sample stand-alone Assetic usage
$name = 'js';
$outputPath = 'assets/js/cache';
$assets = array(
'file1.js',
'file2.js',
);
$filterManager = null;
// $filterManager = new \Assetic\FilterManager();
// $filterManager->set('cssrewrite', new \Assetic\Filter\CssRewriteFilter());
@simshaun
simshaun / AdminBarVoter.php
Created March 31, 2014 18:37
Example Symfony2 security voter
<?php
namespace S2\AppBundle\Security\Voter;
use FOS\UserBundle\Model\UserInterface;
use JMS\DiExtraBundle\Annotation as DI;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
/**
@simshaun
simshaun / gist:81216edee0854f84615e
Last active August 29, 2015 14:01
Pingdom IPs / up to date as of 5/12-2014
95.141.32.46
95.211.217.68
91.109.115.41
83.170.113.210
188.138.118.144
174.34.224.167
72.46.140.106
76.72.172.208
184.75.210.226
78.40.124.16
@simshaun
simshaun / config.yml
Created July 23, 2015 19:34
Symfony2 form help text
twig:
form:
resources:
- "Form/form_theme.html.twig"
@simshaun
simshaun / a1.php
Created March 29, 2011 17:31
Overload A1 to integrate Bonafide
<?php defined('SYSPATH') OR die('No direct access allowed.');
abstract class A1 extends A1_Core {
/**
* @param Bonafide
*/
protected $_bonafide;
/**
@simshaun
simshaun / gist:3015038
Created June 29, 2012 01:02
Using reflection to obtain method signatures
<?php
/**
* Necessary because $param->getClass() requires the class to be loaded.
* We don't want to have to load every class.
*/
function getClassName(ReflectionParameter $param) {
preg_match('/\[\s\<\w+?>\s([\w]+)/s', $param->__toString(), $matches);
return isset($matches[1]) ? $matches[1] : null;
}
@simshaun
simshaun / gist:3015112
Created June 29, 2012 01:24
More reflection
<?php
class Color {}
class UnitOfWeight {}
interface Vehicle {
/**
* I'm a docblock!
*/
public function setColor(Color $color, $foo = 'foo', $bar = array('bar1', 'bar2'), $bool = false);
@simshaun
simshaun / gist:3094656
Created July 12, 2012 00:19
Simple Twig extension that provides a new function and filter for templates, {{ get_some_html() }} {{ 5500|price }}
<?php
namespace S2\MyFancyBundle\Templating;
use Symfony\Component\DependencyInjection\ContainerInterface;
class MyHtmlExtension extends \Twig_Extension
{
private $aFancyService;
@simshaun
simshaun / gist:3190426
Created July 27, 2012 20:52
DomDocument stuff. Showing how to get a node value without recursing
<?php
$xml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<document>
<item>
<identifier>4</identifier>
<name>Blah</name>
</item>
<item>
<identifier>18</identifier>