Skip to content

Instantly share code, notes, and snippets.

View .vimrc
" force utf-8 mode
scriptencoding utf-8
" i got 99 problems, but utf-8...
set encoding=utf-8
" https://github.com/junegunn/vim-plug
call plug#begin('~/.vim/plugged')
Plug 'airblade/vim-gitgutter'
View EmailAddress.php
<?php
declare(strict_types=1);
namespace Acme\Domain\Type;
use function Assert\that;
class EmailAddress
{
/** @var string */
@shadowhand
shadowhand / # php - 2018-04-04_13-56-32.txt
Created Apr 4, 2018
php on macOS 10.13.3 - Homebrew build logs
View # php - 2018-04-04_13-56-32.txt
Homebrew build logs for php on macOS 10.13.3
Build date: 2018-04-04 13:56:32
@shadowhand
shadowhand / array_chunk_fixed.php
Created May 25, 2017
Array chunking for SplFixedArray
View array_chunk_fixed.php
<?php
// Copyright (c) 2017 Woody Gilk (@shadowhand)
// MIT License
/**
* A chunking function for SplFixedArray
*
* Operates the same as array_chunk() but without $preserve_keys, for obvious reasons.
*
View JsonStreamParser.php
<?php
namespace Acme;
use Bcn\Component\Json\Reader;
use Generator;
class JsonStreamParser
{
/**
@shadowhand
shadowhand / NamedDTO.php
Created Dec 10, 2016
Using named constructors for data transfer objects
View NamedDTO.php
<?php
namespace Acme;
class DataTransfer
{
public static function forUser(
$user_id
) {
return new static($user_id);
@shadowhand
shadowhand / session-life-cycle.md
Created Nov 29, 2016 — forked from mindplay-dk/session-life-cycle.md
Complete overview of the PHP SessionHandler life-cycle
View session-life-cycle.md

This page provides a full overview of PHP's SessionHandler life-cycle - this was generated by a set of test-scripts, in order to provide an exact overview of when and what you can expect will be called in your custom SessionHandler implementation.

Each example is a separate script being run by a client with cookies enabled.

To the left, you can see the function being called in your script, and to the right, you can see the resulting calls being made to a custom session-handler registed using session_set_save_handler().

@shadowhand
shadowhand / NamedCallable.php
Last active Nov 18, 2016
Execute any method, static or instance, as a callable
View NamedCallable.php
<?php
namespace Acme;
class NamedCallable
{
private $invoke;
private $prefix;
public function __construct(callable $invoke, callable $prefix)
@shadowhand
shadowhand / RouteInterface.php
Last active May 16, 2017
Routing interfaces for standards discussion
View RouteInterface.php
<?php
interface RouteInterface
{
/**
* Get the HTTP method this route handles.
*
* @return string
*/
public function getMethod();
View delegates.php
// current proposal
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{
// ...
return $delegate->process($request);
}
// alternative
public function process(ServerRequestInterface $request, DelegateInterface $next)
{