Skip to content

Instantly share code, notes, and snippets.

@sukei
sukei / Router.php
Created February 19, 2014 15:21
A Router in a Tweet
<?php
/**
* The Router class is a fast and lightweight router (yes it is). It can handle
* a path and call the matching controller. If there is no match, then an
* exception will be throwned.
*
* ...and it fits in a tweet.
*
* @author Quentin Schuler aka Sukei <qschuler@neosyne.com>
@sukei
sukei / Container.php
Last active April 20, 2022 08:44
A Service Container in a Tweet
<?php
/**
* The Container class is a lightweight service container.
*
* ...and it fits in a tweet.
*
* @author Quentin Schuler aka Sukei <qschuler@neosyne.com>
*/
class Container{private $s;function set($k,$c){$this->s[$k]=$c;}function get($k){return(is_a($v=$this->s[$k],'Closure'))?$v($this):$v;}}
@sukei
sukei / Template.php
Last active August 24, 2021 12:05
A Template Engine in a Tweet
<?php
/**
* The render function is a lightweight template engine, that allows string
* interpolation and output escaping.
*
* ...and it fits in a tweet.
*
* @author Quentin Schuler aka Sukei <qschuler@neosyne.com>
*/
@sukei
sukei / Signal.php
Last active August 24, 2021 11:08
An Observer in a Tweet
<?php
/**
* The Signal class is the smallest and fastest observer written in PHP 5.6 and
* using some new features such as the variadic functions and the arguments
* unpacking.
*
* ...and it fits in a tweet.
*
* @author Quentin Schuler aka Sukei <qschuler@neosyne.com>