Skip to content

Instantly share code, notes, and snippets.

View cspray's full-sized avatar

Charles Sprayberry cspray

View GitHub Profile
@cspray
cspray / 000-java-php-diff.md
Last active July 5, 2023 12:29
A list of differences I've noticed between PHP and Java.

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

@cspray
cspray / database-test-case.php
Last active April 5, 2023 19:19
PHPUnit DatabaseTest Example
<?php
use PHPUnit\Framework\TestCase;
class DatabaseTest extends TestCase {
private static $dbConnection;
public static function setUpBeforeClass() : void {
@cspray
cspray / README.md
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
cspray / class-string-rfc.md
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 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.

<?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
<?php
// In PHP internals, maybe this is an abstract class instead?
// Maybe an attribute?
#[Attribute]
class FunctionalInterface {}
#[FunctionalInterface]
interface MyAction {
<?php
namespace YourNamespace\Enums;
use Cspray\Yape\Enum;
use Cspray\Yape\EnumTrait;
final class Compass implements Enum {
use EnumTrait;
<?php
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 (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
<?php
namespace MyApp\Command;
use Amp\Promise;
use Amp\Websocket\Client;
use Cspray\WebsocketCommands\ClientPayload;
use Cspray\WebsocketCommands\WebsocketCommand;
use function Amp\Promise\call;