Skip to content

Instantly share code, notes, and snippets.

@simshaun
simshaun / AppBundle\File\AbstractFile.php
Last active August 4, 2016 21:07
Makes use of Flysystem for fs abstraction and is setup in a manner that lets me easily swap out local files (single-server apps) with remote files (e.g. S3, for multi-server apps) by tweaking the service definitions. The Avatar file is just an example of how I might handle an image. Validation is enforced before this handler is called.
<?php
namespace AppBundle\File;
use AppBundle\File\Namer\NamerInterface;
use AppBundle\File\UrlGenerator\FileUrlGeneratorInterface;
use League\Flysystem\Filesystem;
abstract class AbstractFile
{
@simshaun
simshaun / config.yml
Created July 23, 2015 19:34
Symfony2 form help text
twig:
form:
resources:
- "Form/form_theme.html.twig"
@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 / 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 / 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 / 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 / gist:7592631
Created November 22, 2013 00:37
TinyMCE 4.0.11 - Automatically remove width and height attributes from img elements inserted via the img plugin
setup: function (editor) {
editor.on('init', function(args) {
editor = args.target;
editor.on('NodeChange', function(e) {
if (e && e.element.nodeName.toLowerCase() == 'img') {
tinyMCE.DOM.setAttribs(e.element, {'width': null, 'height': null});
}
});
}
@simshaun
simshaun / bootstrap.php
Last active December 19, 2015 16:48
Kohana example of config in the database
Kohana::$config->attach(new Config_Database);
@simshaun
simshaun / FileInspector.php
Created April 25, 2013 18:53
This is a bad example (it was thrown together) of getting a namespace and class names that are in a file. It doesn't support multiple namespaces and it makes assumptions about the src. It would need rewritten to make it flexible (probably looping through token_get_all to construct all of the necessary information).
<?php
class FileInspector
{
protected $filename;
protected $namespace;
protected $contents;
public function __construct($filename) {
if ( ! $this->contents = @file_get_contents($filename)) {
@simshaun
simshaun / FooAddressType.php
Created February 21, 2013 18:34
Example of a re-using a FormType in other forms
<?php
namespace S2\FooBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use S2\FooBundle\Form\Type\PartialAddressType;
use Symfony\Component\Form\FormBuilderInterface;
class FooAddressType extends AbstractType
{