Skip to content

Instantly share code, notes, and snippets.

Avatar

Simon Kollross skollro

View GitHub Profile
View Temporary.php
<?php
class Temporary
{
public static function file($contents, $callback)
{
$path = tempnam(sys_get_temp_dir(), 'php_');
file_put_contents($path, $contents);
try {
View FakeSoapClient.php
<?php
class FakeSoapClient extends \SoapClient
{
protected $response;
protected $customizer;
public static function wsdl($wsdl)
{
return new self($wsdl);
View Match.php
<?php
class Match
{
protected $value;
protected $result;
protected $hasMatch;
public function __construct($value)
{
@skollro
skollro / join.php
Last active Apr 29, 2017
A join collection macro
View join.php
<?php
Collection::macro('join', function ($items, callable $callback) {
return $this->flatMap(function ($value) use ($items, $callback) {
return $items->filter(function ($item) use ($value, $callback) {
return $callback($value, $item);
})->map(function ($item) use ($value) {
return new Collection([$value, $item]);
});
});