Skip to content

Instantly share code, notes, and snippets.

View jdreesen's full-sized avatar

Jacob Dreesen jdreesen

View GitHub Profile
@oplanre
oplanre / TSGen.php
Last active May 28, 2024 12:22
Simple TS interface generator (php impl)
<?php
class TSGen
{
public static function fromJSON(string $json, string $interfaceName): string
{
try {
return self::generateInterface(json_decode($json, true, 512, JSON_THROW_ON_ERROR), $interfaceName);
} catch (JsonException $e) {
throw new InvalidArgumentException("Error parsing JSON: " . $e->getMessage());
@lyrixx
lyrixx / README.md
Last active April 11, 2024 21:52
slugger CLI

Slugger

This "project" is a simple CLI slugger

image

@francislavoie
francislavoie / TimestampOutput.md
Last active April 28, 2024 08:10
A Symfony OutputInterface decorator that inserts timestamps on every line

A Symfony OutputInterface decorator that inserts timestamps on every line

I'm kinda proud of this, but it took me way too long to come up with the right solution 😅 I also couldn't find anyone on the internet who wrote something like this, so I'm sharing it in case others find it useful.

This can be used to wrap an $output in any CLI command, it will intercept all the newlines being printed out and insert the current time at the start of every line.

Easier said than done, because if we just naively insert dates after each newline, then the timestamp of a line would be the time from the previous message, not the current line being printed. So to correct that, we need to keep track of whether the previous write inserted a final newline, and if so prepend a date; and we need to skip adding a date on the last newline of that write.

Usage:

@lyrixx
lyrixx / CHANGELOG-3.0.md
Last active June 3, 2024 07:53
Symfony CHANGELOG

Bridge/Doctrine

  • removed EntityChoiceList
  • removed $manager (2nd) and $class (3th) arguments of ORMQueryBuilderLoader
  • removed passing a query builder closure to ORMQueryBuilderLoader
  • removed loader and property options of the DoctrineType

Bridge/Monolog

  • deprecated interface Symfony\Component\HttpKernel\Log\LoggerInterface has been removed
@DaveLiddament
DaveLiddament / PHP generics notation for static analysis.md
Created October 30, 2022 14:13
PHP generics notation for static analysis

Notation for generics to PHP: #<>

Disclaimer: I assume someone has already suggested this and there are good reasons it hasn't happened!

Inspired by a conversation with @pronskiy after my talk "PHP Generics Today (Almost)" at IPC Munich

Examples:

class Queue #
@Ocramius
Ocramius / handling-optional-input-fields-with-type-safe-abstractions.md
Last active March 17, 2023 12:06
Handling optional input parameters in PHP with `vimeo/psalm` and `azjezz/psl`

Handling optional input parameters in PHP with vimeo/psalm and azjezz/psl

I had an interesting use-case with a customer for which I provide consulting services: they needed multiple fields to be marked as "optional".

Example: updating a user

We will take a CRUD-ish example, for the sake of simplicity.

For example, in the following scenario, does a null $description mean "remove the description",

@lyrixx
lyrixx / ContainerTest.php
Last active May 22, 2024 11:23
Test applications services can boot
<?php
namespace Tests\Integration;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
@lyrixx
lyrixx / test.php
Last active July 18, 2024 09:51
Symfony Playgound with its Container and a custom configuration
<?php
use App\Kernel;
require __DIR__.'/vendor/autoload_runtime.php';
use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@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.

@yariksheptykin
yariksheptykin / pimcore-demo.sh
Last active December 9, 2021 14:40
Spin up pimcore demo
#!/usr/bin/env bash
set -eu
# A bash script to spin up pimcore demo locally using docker.
# The script follows the README instructions for docker.
# See: https://github.com/pimcore/demo
# Usage:
# curl -s https://gist.githubusercontent.com/yariksheptykin/9eaa93910c5ef9360697a507cd01488a/raw/pimcore-demo.sh | bash -s [up|down] <project-name>