Skip to content

Instantly share code, notes, and snippets.

View cspray's full-sized avatar

Charles Sprayberry cspray

View GitHub Profile
cspray / database-test-case.php
Last active April 5, 2023 19:19
PHPUnit DatabaseTest Example
use PHPUnit\Framework\TestCase;
class DatabaseTest extends TestCase {
private static $dbConnection;
public static function setUpBeforeClass() : void {
cspray /
Last active August 6, 2022 14:45
Amp Injector Overview

Amp Injector Overview

This document details the high-level technical workings of the amphp/injector project. Specifically, this document has 2 primary goals:

  1. Serve as a basis for more thorough documentation in the amphp/injecto repo proper.
  2. Serve as a technical guide for integrating with cspray/annotated-container.

How it Works

Amphp Injector is split into a set of systems to define and construct your container. Composing these systems together allows you to wire an object graph with the following functionalities:

cspray /
Last active May 31, 2022 00:28
RFC: Introduce a class-string type

RFC: Introduce a class-string type

  • Version: 0.3
  • Last Substantial Updates: 2022-05-04
  • Target Version: PHP


There are many scenarios in which userland code might need to pass parameters to a method or assign a value to a property that is intended to represent a class. Currently the only way to type-hint that a provided value represents a fully-qualified class-name (FQCN) is through userland code. This RFC proposes adding a new internal type that would verify provided values are FQCN.

use Cspray\AnnotatedContainer\Attribute\Service;
use Cspray\AnnotatedContainer\Attribute\Inject;
use Cspray\AnnotatedContainer\ParameterStore;
use Cspray\Typiphy\Type;
class MySecretParameterStore implements ParameterStore {
public function getName() : string {
cspray / callable-interface.php
Last active April 1, 2022 21:24
A spike for having CallableInterfaces in PHP
// In PHP internals, maybe this is an abstract class instead?
// Maybe an attribute?
class FunctionalInterface {}
interface MyAction {
namespace YourNamespace\Enums;
use Cspray\Yape\Enum;
use Cspray\Yape\EnumTrait;
final class Compass implements Enum {
use EnumTrait;
require_once __DIR__ . '/vendor/autoload.php';
use YourNamespace\Enums\Compass;
$north = Compass::North();
$south = Compass::South();
$east = Compass::East();
$west = Compass::West();

Keybase proof

I hereby claim:

  • I am cspray on github.
  • I am cspray ( on keybase.
  • I have a public key ASDgKvQd1ACmkJh6ME2WlXVdnigsEpwUUTk4BZF5Xbbjrwo

To claim this, I am signing this object:

cspray / EchoCommand.php
Last active September 22, 2019 13:48
cspray/websocket-commands Quick Start
namespace MyApp\Command;
use Amp\Promise;
use Amp\Websocket\Client;
use Cspray\WebsocketCommands\ClientPayload;
use Cspray\WebsocketCommands\WebsocketCommand;
use function Amp\Promise\call;
PHPUnit 6.5.14 by Sebastian Bergmann and contributors.
E.F 3 / 3 (100%)
Time: 132 ms, Memory: 4.00MB
There was 1 error:
1) Amp\PHPUnit\Test\AsyncTestCaseTest::testThatMethodRunsInLoopContext
Error: Loop exceptionally stopped without resolving the promise