Skip to content

Instantly share code, notes, and snippets.

View jdreesen's full-sized avatar

Jacob Dreesen jdreesen

View GitHub Profile
@Wirone
Wirone / Pie-PHP.Dockerfile
Last active November 26, 2024 18:17
Using PIE (Extensions Installer for PHP) in Docker builds
FROM php:8.4-cli AS php-debian
RUN apt-get -q update \
# Pie requires ZIP extension to be installed (checked with Box requirements when executing Pie's PHAR)
&& apt-get -yq install gnupg libzip-dev libzip4 \
&& docker-php-ext-install zip \
# Official docs includes one-liner that uses `latest` release, but URL gives 404.
# Anyway, it's probably better to use fixed version of Pie to have stable builds.
&& curl -L --output /usr/bin/pie https://github.com/php/pie/releases/download/0.2.0/pie.phar \
&& chmod +x /usr/bin/pie \
@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 / LogMiddleware.php
Last active August 6, 2024 22:19
UUID processor for symfony
<?php
namespace App\Middleware;
use App\Middleware\Stamp\LogStamp;
use App\Monolog\Processor\UuidProcessor;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
use Symfony\Component\Messenger\Middleware\StackInterface;
@lyrixx
lyrixx / CHANGELOG-3.0.md
Last active November 5, 2024 14:51
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 January 22, 2025 09:32
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 February 6, 2025 08:01
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;