Skip to content

Instantly share code, notes, and snippets.

@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>
@simshaun
simshaun / README.md
Created August 9, 2012 20:25
A modified setter method template for PhpStorm that generates both an `add` and `set` method for arrays.
@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
{
@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 / bootstrap.php
Last active December 19, 2015 16:48
Kohana example of config in the database
Kohana::$config->attach(new Config_Database);
@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});
}
});
}