Skip to content

Instantly share code, notes, and snippets.

View mannion007's full-sized avatar

James Mannion mannion007

View GitHub Profile
@mannion007
mannion007 / gist:edf733d5fe2a9310613df515648606a6
Last active November 12, 2019 17:20
Validating against a schema at runtime
<?php
/** ...Make the request, decode the response */
$validator->validate($decodedResponse, json_decode('details.json'));
if (!empty($validator->getErrors())) {
throw new InvalidResponseException(
sprintf('Invalid Net Verify response for [%s]: [%s]', $type, implode(',', $errorMessages))
);
<?php
/**
* @author James Mannion <mannion007@gmail.com>
* @link https://www.jamse.net
*/
/**
* Interface CarInterface
*/
interface CarInterface
{
@mannion007
mannion007 / example.php
Last active October 8, 2016 16:05
Surprising behaviour of try/catch/finally block with return statements
<?php
function exceptionThrower()
{
try {
throw new \Exception('Bang!');
} catch(\Exception $e) {
echo 'An exception happened but I caught it!' . PHP_EOL;
return 5;
} finally {
@mannion007
mannion007 / iterator_aggregate.php
Last active September 23, 2016 20:42
Example use of IteratorAggregate interface to make a private array within the class iterable. Featuring gaming consoles because why not.
<?php
/**
* A class which contains a private list of gaming consoles.
* Can be looped as the class implements IteratorAggregate
*
* Class ConsoleCollection
*/
class ConsoleCollection implements \IteratorAggregate
{