Skip to content

Instantly share code, notes, and snippets.

@ezzatron
Created January 1, 2012 13:50
Show Gist options
  • Save ezzatron/1547377 to your computer and use it in GitHub Desktop.
Save ezzatron/1547377 to your computer and use it in GitHub Desktop.
Situation where serialized attributes might be necessary in Typhoon
<?php
/**
* My awesome function that does amazing things
*/
function doSomeAwesomeStuff($foo)
{
// creating a custom type for the foo attribute
// passing some special matcher object which does the validation work
$fooType = new CustomType(array(
'matcher' => new Matcher,
));
// assert it with Typhoon
Typhoon::assert($fooType, $foo);
// now assume it fails...
// we need to throw a nice exception message
// something like Unexpected value of type 'string' - expected 'CustomType(matcher: '%O:7:"Matcher":0:{}%')'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment