Skip to content

Instantly share code, notes, and snippets.

View tomphp's full-sized avatar

Tom Oram tomphp

View GitHub Profile
@tomphp
tomphp / ob1saver.php
Last active August 29, 2015 13:58
Interface typing
<?php
/*
* Since we don't have method over loading, shouldn't this be possible?
*/
interface Object1Saver
{
public function save(Object1 $obj);
}
<?php
/*
* Say you have an entity class which has no need to expose its internal data
* fields in the business layer like so:
*/
class LibraryBook
{
/** @var string */
@tomphp
tomphp / closure-test.php
Last active August 29, 2015 14:06
Testing Closures
<?php
interface Item
{
public function runAction();
}
interface SomeCollection
{
public function foreachItem(callable $fn);
@tomphp
tomphp / gist:7cebee49783f8f13a314
Last active August 29, 2015 14:07
Clojure Value Objects
// Given
(defn make-customer [name email]
{:name name, :email email})
// Examples
(def customer1 (make-customer "Tom" "email@address.com"))
// vs...
Feature: View a widget
# Approach 1
Scenario: View a widget's attributes
Given there is a widget named "the widget" with attribute1 "attr 1 val" and attribute2 "attr 2 val" and attribute3 "attr 3 val"
Then the widget named "the widget" should have attribute1 value "attr 1 val" and attribute2 value "attr 2 val" and attribute3 "attr 3 val"
# Approach 2
Scenario: View a widget's attributes
Given there is a widget named "the widget"
@tomphp
tomphp / gist:aa988344c4a77d52b3d5
Last active August 29, 2015 14:18
Example of navigating HAL APIs
<?php
// An example of navigating HAL enabled JSON APIs in Behat tests
// using https://github.com/tomphp/hal-client
use TomPHP\HalClient\Client;
class APIContext
{
// ...
@tomphp
tomphp / example.php
Last active December 19, 2015 10:29
How to set up the annotation builder so it can use the hydrator manager
<?php
/*
* This is the setup required to make an annotation builder able to load
* a hydrator from annotation via the HydratorManager.
*/
$annotationBuilder = new \Zend\Form\Annotation\AnnotationBuilder();
$factory = new \Zend\Form\Factory($serviceLocator->get('FormElementManager'));
$annotationBuilder->setFormFactory($factory);
<?php
class BaseClass
{
private $var;
public function __construct($injector)
{
$this->var = $injector;
}
<?php
public function getFileScanner($fileName)
{
if ($this->fileScanner && $this->fileScanner->getFile() == $fileName) {
return $this->fileScanner;
}
$this->fileScanner = new FileScanner($fileName);
<?php
namespace Test;
class MyClass
{
public function someFunction(
MyType $param1,
LongTypeName $param2,
array $param3