Skip to content

Instantly share code, notes, and snippets.

@jm42
jm42 / gist:d66ce79428dd7ffd5992
Created August 15, 2014 02:19
PHP Stream Filter
<?php
use php_user_filter as StreamFilter;
use Composer\Autoload\ClassLoader;
require __DIR__ . '/vendor/autoload.php';
class MyFilter extends StreamFilter
{
const FILTER_ID = 'my_filter';
@jm42
jm42 / driver.php
Created August 16, 2014 17:40
Vago Database Abstraction
<?php
namespace Vago\Driver;
/**
* Connection interface.
*/
interface Connection
{
/**
@jm42
jm42 / aspect_stub.php
Created August 16, 2014 18:53
Aspect Stub
<?php
class Wallet {
protected $balance;
public function __construct($initial=0.0) {
$this->balance = $initial;
}
public function add($money) {
$this->balance += $money;
}
@jm42
jm42 / froebel.php
Created August 16, 2014 22:39
Search Indexing
<?php
namespace Froebel;
use Froebel\Hash\Hash;
use Froebel\Storage\Storage;
class Engine
{
protected $hashes;
@jm42
jm42 / froebel_import.php
Created August 16, 2014 22:41
Import Data
<?php
namespace Froebel\Import;
use Froebel\Engine;
use Froebel\Import\Reader\Reader;
class Workflow
{
public $engine;
@jm42
jm42 / using.php
Created August 21, 2014 02:17
Simulating using/with in PHP
<?php
class Singleton // https://github.com/Trismegiste/Php-Is-Magic
{
public static function getInstance()
{
static $instances = array();
$key = get_called_class();
if (!array_key_exists($key, $instances)) {
$instances[$key] = new $key();
@jm42
jm42 / hierarchical.php
Created September 4, 2014 19:46
Request Stack
<?php
class Request
{
public $controller;
public $vars;
public function __construct(array $vars = array())
{
$this->vars = $vars;
}
@jm42
jm42 / lazy_request.php
Created September 6, 2014 22:07
Lazy Request
<?php
abstract class Lazy implements \ArrayAccess {
private $input;
private $cache = array();
public function __construct($input) {
static $inputs = array(
INPUT_POST, INPUT_GET, INPUT_COOKIE,
INPUT_ENV, INPUT_SERVER, INPUT_SESSION
@jm42
jm42 / http_interfaces.php
Created September 15, 2014 15:46
HTTP Interfaces
<?php
namespace Aix\HTTP;
interface Request
{
const METHOD_GET = 'GET';
const METHOD_HEAD = 'HEAD';
const METHOD_POST = 'POST';
const METHOD_PUT = 'PUT';
@jm42
jm42 / http_request.php
Created September 15, 2014 15:49
HTTP Interfaces Example Implementation
<?php
namespace Ex\HTTP;
use Aix\HTTP\Request as BaseRequest;
class Request implements BaseRequest
{
private $method;