Skip to content

Instantly share code, notes, and snippets.

Nicolas Grekas nicolas-grekas

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
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));
View services.yml
# example 1: add a tag or a setter based on implemented interfaces:
services:
_instanceof:
Psr\Log\LoggerAwareInterface:
calls:
- [setLogger, ['@logger']]
Symfony\Component\EventDispatcher\EventSubscriberInterface:
tags: [kernel.event_subscriber]
View TraceableAdapter.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.
*/
You can’t perform that action at this time.