Skip to content

Instantly share code, notes, and snippets.

✔️
Green-keeping the Symfony CI

Nicolas Grekas nicolas-grekas

✔️
Green-keeping the Symfony CI
Block or report user

Report or block nicolas-grekas

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nicolas-grekas
nicolas-grekas / Ulid.php
Last active Mar 5, 2020
A class to generate compliant "ulid"
View Ulid.php
<?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 Nov 6, 2019
Symfony HttpClient benchmarks
View async.php
<?php
require 'vendor/autoload.php';
$start = microtime(true);
/* GUZZLE * /
$client = new GuzzleHttp\Client();
$promises = [];
View PhpConverter.php
<?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.
*/
View 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 Nov 8, 2018
Autowiring aliases for named parameters
View AutowirePass.diff
--- 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 Oct 18, 2018
A middleware stack that doesn't double the stack size
View message-bus.php
<?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 Jul 18, 2019
RFC for a Secure Unserialization Mechanism in PHP
View rfc-secure-unserialize.md

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 Sep 11, 2017
Wondering about dynamic proxies in PHP
View interceptor.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
View date-caster.diff
diff --git a/src/Symfony/Component/VarDumper/Caster/DateCaster.php b/src/Symfony/Component/VarDumper/Caster/DateCaster.php
index 61d24b1..b078ecd 100644
--- a/src/Symfony/Component/VarDumper/Caster/DateCaster.php
+++ b/src/Symfony/Component/VarDumper/Caster/DateCaster.php
@@ -23,17 +23,15 @@ class DateCaster
public static function castDate(\DateTimeInterface $d, array $a, Stub $stub, $isNested, $filter)
{
$prefix = Caster::PREFIX_VIRTUAL;
+ $location = $d->getTimezone()->getLocation();
+ $fromNow = (new \DateTime())->diff($d);
View instanceof.diff
--- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
+++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
@@ -157,6 +157,16 @@ class YamlFileLoader extends FileLoader
if (!is_array($content['services'])) {
throw new InvalidArgumentException(sprintf('The "services" key should contain an array in %s. Check your YAML syntax.', $file));
}
+
+ if (isset($content['services']['_instanceof'])) {
+ if (!is_array($types = $content['services']['_instanceof'])) {
+ throw new InvalidArgumentException(sprintf('The "_instanceof" key must contain an array, "%s" given in "%s".', gettype($types), $file));
You can’t perform that action at this time.