Skip to content

Instantly share code, notes, and snippets.

View nicolas-grekas's full-sized avatar
✔️
Green-keeping the Symfony CI

Nicolas Grekas nicolas-grekas

✔️
Green-keeping the Symfony CI
View GitHub Profile
Symfony\Component\Cache\Tests\Marshaller\DefaultMarshallerTest::testNativeUnserializeNotFoundClass

Failed asserting that exception of type "UnserializationFailedException" matches expected exception "DomainException". Message was: "An Exception was thrown during unserialization" at src/Symfony/Component/Cache/Marshaller/DefaultMarshaller.php:96 src/Symfony/Component/Cache/Marshaller/DefaultMarshaller.php:74 src/Symfony/Component/Cache/Tests/Marshaller/DefaultMarshallerTest.php:62

Symfony\Component\Messenger\Tests\Transport\Serialization\PhpSerializerTest::testDecodingFailsWithBadFormat

Failed asserting that exception of type "UnserializationFailedException" matches expected exception "Symfony\Component\Messenger\Exception\MessageDecodingFailedException". Message was: "An Exception was thrown during unserialization" at src/Symfony/Component/Messenger/Transport/Serialization/PhpSerializer.php:78 src/Symfony/Component/Messenger/Transport/Serialization/PhpSerializer.php:54

@nicolas-grekas
nicolas-grekas / unserializing.diff
Created September 20, 2022 17:13
Places where unserialize() is try/catched in Symfony 6.2
diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php
index 003680a5c0..e6b0265a45 100644
--- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php
+++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php
@@ -95,21 +95,21 @@ class Deprecation
break;
}
}
if (!isset($line['object']) && !isset($line['class'])) {
@nicolas-grekas
nicolas-grekas / Ulid.php
Last active March 5, 2020 21:10
A class to generate compliant "ulid"
<?php
class Ulid
{
private static $time = -1;
private static $rand = [];
public function generate(bool $lowercase = false)
{
if (\PHP_INT_SIZE !== 8) {
@nicolas-grekas
nicolas-grekas / async.php
Last active November 6, 2019 08:30
Symfony HttpClient benchmarks
<?php
require 'vendor/autoload.php';
$start = microtime(true);
/* GUZZLE * /
$client = new GuzzleHttp\Client();
$promises = [];
@nicolas-grekas
nicolas-grekas / PhpConverter.php
Created April 16, 2019 14:54
From Yaml to PHP-DSL
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
@nicolas-grekas
nicolas-grekas / secrets.yaml
Created April 6, 2019 13:08
secrets.yaml
parameters:
env(SECRETS_FILE): .secrets.php
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
bind:
$someSecret: '%env(key:KEY3:require:SECRETS_FILE)%'
@nicolas-grekas
nicolas-grekas / AutowirePass.diff
Created November 8, 2018 10:54
Autowiring aliases for named parameters
--- a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php
+++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php
@@ -193,7 +193,7 @@ class AutowirePass extends AbstractRecursivePass
continue;
}
- $type = ProxyHelper::getTypeHint($reflectionMethod, $parameter, true);
+ $type = ltrim(ProxyHelper::getTypeHint($reflectionMethod, $parameter, false), '\\');
if (!$type) {
@nicolas-grekas
nicolas-grekas / message-bus.php
Last active October 18, 2018 07:21
A middleware stack that doesn't double the stack size
<?php
error_reporting(-1);
require 'vendor/autoload.php';
/**
* This is the core interface. It already allows building dispatchers *and middlewareHandlers*.
*/
interface MessageBusInterface
{
@nicolas-grekas
nicolas-grekas / rfc-secure-unserialize.md
Last active July 26, 2020 10:07
RFC for a Secure Unserialization Mechanism in PHP

RFC for a Secure Unserialization Mechanism in PHP

Scope

PHP serialization/unserialization has several drawbacks [^1].

On the serialization side, the Serializable interface:

  • breaks hard and soft references inside serialized data structures;
@nicolas-grekas
nicolas-grekas / interceptor.php
Last active September 11, 2017 15:02
Wondering about dynamic proxies in PHP
<?php
// Very early draft. Not applicable yet.
// TODO: specify behavior for __destruct()
// Only public methods/properties can be intercepted, final ones also
// Magic methods are intercepted as regular ones
// Undefined properties/methods access are excluded from interception
// method_exists()/property_exists()/isset() are excluded from interception