This "project" is a simple CLI slugger
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 \ |
<?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()); |
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.
<?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; |
- removed
EntityChoiceList
- removed
$manager
(2nd) and$class
(3th) arguments ofORMQueryBuilderLoader
- removed passing a query builder closure to
ORMQueryBuilderLoader
- removed
loader
andproperty
options of theDoctrineType
- deprecated interface
Symfony\Component\HttpKernel\Log\LoggerInterface
has been removed
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 #
I had an interesting use-case with a customer for which I provide consulting services: they needed multiple fields to be marked as "optional".
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",
<?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; |
<?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; |