Skip to content

Instantly share code, notes, and snippets.

Avatar

Charles Sprayberry cspray

View GitHub Profile
@cspray
cspray / README.md
Last active August 6, 2022 14:45
Amp Injector Overview
View README.md

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
cspray / class-string-rfc.md
Last active May 31, 2022 00:28
RFC: Introduce a class-string type
View class-string-rfc.md

RFC: Introduce a class-string type

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

Introduction

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.

View inject-secrets.php
<?php
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
cspray / callable-interface.php
Last active April 1, 2022 21:24
A spike for having CallableInterfaces in PHP
View callable-interface.php
<?php
// In PHP internals, maybe this is an abstract class instead?
// Maybe an attribute?
#[Attribute]
class FunctionalInterface {}
#[FunctionalInterface]
interface MyAction {
@cspray
cspray / 000-java-php-diff.md
Last active April 21, 2021 04:59
A list of differences I've noticed between PHP and Java.
View 000-java-php-diff.md

Java vs. PHP

As is pretty obvious by my blog, GitHub repos and my job I'm a PHP developer. I'm also pretty adept with JavaScript and SQL. Lately I've been getting back into Java development a little more seriously. This gist is a series of short articles about some of the differences I've noticed between PHP and Java.

To be specific my Java development recently has been web development using Google App Engine. I am intending to create a RESTful API utilizing the language.

The differences discussed are not intended to be an indictment against either language. Some things about PHP I really like, some things about PHP I really dislike. The same goes for Java. Some things PHP is really good for and other things Java is really good for. This is not meant to be a religious war between languages.

I realize that in a way this is comparing apples and oranges. PHP is a dynamic, interpreted (althought yes it is still compiled) scripting language while Jav

View enum-compass-values.php
<?php
namespace YourNamespace\Enums;
use Cspray\Yape\Enum;
use Cspray\Yape\EnumTrait;
final class Compass implements Enum {
use EnumTrait;
View enum-example.php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use YourNamespace\Enums\Compass;
$north = Compass::North();
$south = Compass::South();
$east = Compass::East();
$west = Compass::West();
View keybase.md

Keybase proof

I hereby claim:

  • I am cspray on github.
  • I am cspray (https://keybase.io/cspray) on keybase.
  • I have a public key ASDgKvQd1ACmkJh6ME2WlXVdnigsEpwUUTk4BZF5Xbbjrwo

To claim this, I am signing this object:

@cspray
cspray / EchoCommand.php
Last active September 22, 2019 13:48
cspray/websocket-commands Quick Start
View EchoCommand.php
<?php
namespace MyApp\Command;
use Amp\Promise;
use Amp\Websocket\Client;
use Cspray\WebsocketCommands\ClientPayload;
use Cspray\WebsocketCommands\WebsocketCommand;
use function Amp\Promise\call;
View expecting-exception-async.txt
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