Skip to content

Instantly share code, notes, and snippets.

@jm42
jm42 / ArrayFilterInput.php
Last active August 29, 2015 14:06
Array Filter Input
<?php
class ArrayFilterInput implements \ArrayAccess
{
protected $input;
protected $cache = array();
public function __construct($input)
{
$this->input = $input;
@jm42
jm42 / example.php
Created September 21, 2014 15:33
Feature-like Language
<?php
$example = <<<EOS
This is the title, a free-form text
that can have as many lines
of text as I wish.
Play Wikipedia as jm
Spec main
@jm42
jm42 / benchmark.php
Created October 4, 2014 17:41
Benchmark `method_exists`
<?php
include 'Benchmark.php'; // https://github.com/BruceJillis/Benchmark
class Author {
public $firstName;
protected $lastName;
public function __construct($firstName, $lastName) {
$this->firstName = $firstName;
$this->lastName = $lastName;
@jm42
jm42 / utf8.php
Created October 4, 2014 17:47
Test UTF-8
<?php
$tests = array(
array(195, 169), // é
array(227, 130, 171), // カ
array(208, 150), // Ж
);
function unichr($inte) {
@jm42
jm42 / http.php
Created October 8, 2014 15:07
HTTP
<?php
class Request {
const METHOD_GET = 'GET';
const METHOD_POST = 'POST';
const METHOD_HEAD = 'HEAD';
private $method;
private $uri;
private $headers;
@jm42
jm42 / namedtuple.php
Created October 8, 2014 16:10
Named Tuple
<?php
class NamedTuple {
public static $__instances = array();
private $uuid;
private $values = array();
public function __construct() {
$found = false;
@jm42
jm42 / traba.php
Created October 10, 2014 00:43
Traversal Router
<?php
// This was the first test to create what then became Traba.
//
// https://github.com/guide42/traba
//
$request = array(
'path_info' => '/user/123/edit',
'query' => array(
@jm42
jm42 / config.php
Created October 18, 2014 01:39
Two-Step Configuration Idea
<?php
class Configurator implements ArrayAccess {
const PHASE_DEFAULT = 0;
private $config = [];
private $defaults = [];
private $queue;
private $hooks;
@jm42
jm42 / send.php
Created October 18, 2014 02:29
Response send
<?php
function send(Response $response) {
if (headers_sent()) {
return;
}
http_response_code($response->status);
foreach ($response->headers as $key => $value) {
@jm42
jm42 / loader.php
Created October 19, 2014 02:46
Basic Loader Interface with Delegate Lookup
<?php
interface LoaderInterface {
function load($resource);
function supports($resource);
}
abstract class Loader implements LoaderInterface {
private $delegate;
private $loading = [];