Skip to content

Instantly share code, notes, and snippets.

@codenamegary
codenamegary / datacontain-validator.php
Created February 19, 2014 22:01
Just a random example of how a ContainerBuilder for DataContain might be implemented, needs work
<?php
class Entity extends DataContain\Container {
/**
* @var DataContain\DefinitionContainer
*/
protected $attributes;
public function __construct(array $data = array(), DataContain\DefinitionContainer $attributes = null)
@codenamegary
codenamegary / data-contain-play.php
Created February 18, 2014 22:01
Example of how to use DataContain to make entities.
<?php
include __DIR__.DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'autoload.php';
class Entity extends DataContain\Container {
/**
* @var DataContain\DefinitionContainer
*/
protected $attributes;
@codenamegary
codenamegary / php-scalars.php
Last active January 4, 2016 09:48
Scalar Type Hinting in PHP
<?php
// See: http://nikic.github.io/2012/03/06/Scalar-type-hinting-is-harder-than-you-think.html
// And RFC: https://wiki.php.net/rfc/scalar_type_hinting_with_cast
//
// Basically the same implementation as outlined in the RFC but with a concept for scalar
// magic to be added to objects at some point in the future.
class MyObjectWithScalarMagic {
<?php
use Validator;
use RuleSet;
use Filters;
use Rule;
use Constraints;
class ValidationBuilder {
@codenamegary
codenamegary / gist:7495415
Created November 16, 2013 03:04
#laravel IRC pong
$players = array();
@codenamegary
codenamegary / gist:7015030
Last active December 25, 2015 17:39 — forked from s3gfau1t/gist:7014684
ERMAHGERD IF/ELSE! $raceWriter('Message to console or file.');
<?php
$velocities = array("turtle", "donkey", "rabbit");
$mode = isset($argv[1]) ? $argv[1] : 'console';
$file = isset($argv[2]) ? $argv[2] : '';
$fp = null;
$raceWriters = array(
'file' => function($output)use($file, $fp){
if(!$fp) $fp = fopen($file, 'a+');
<?php
$velocities = array("turtle", "donkey", "rabbit");
$players = array(
'1' => array(
'name' => 'Foo',
'velocity' => $velocities[rand(0,2)],
'actions' => array(),
),
'2' => array(
<?php
$velocities = array("turtle", "donkey", "rabbit");
$players = array(
'1' => array(
'name' => 'Foo',
'velocity' => $velocities[rand(0,2)],
'actions' => array(),
),
'2' => array(
@codenamegary
codenamegary / gist:7013392
Last active December 25, 2015 17:29 — forked from s3gfau1t/gist:7013352
Added actions and actionsFunc
<?php
$velocities = array("turtle", "donkey", "rabbit");
$players = array(
'1' => array(
'name' => 'Foo',
'velocity' => $velocities[rand(0,2)]),
'actions' => array(),
'2' => array(
'name' => 'Bar',
<?php
$velocities = array("turtle", "donkey", "rabbit");
$players = array(
'1' => array(
'name' => 'Foo',
'velocity' => $velocities[rand(0,2)]),
'2' => array(
'name' => 'Bar',
'velocity' => $velocities[rand(0,2)]),