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
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);
--- 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));
# 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]
@nicolas-grekas
nicolas-grekas / TraceableAdapter.php
Last active December 28, 2016 16:21
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.
*/
<?php
// A proposal for a future PHP version: builtin lazy variables
class foo
{
function __construct(PDO $db) {
$this->db = $db;
}
<?php
// composer require blackfire/php-sdk
// search for XXX in the snippet below
while (isset($_SERVER['HTTP_X_BLACKFIRE_QUERY'])) {
$probe = \BlackfireProbe::getMainInstance();
if (!$probe->disable()) {
break;
}
<?php
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;
function dump($var)
{
static $handler;
if (null === self::$handler) {
<?php
$foo = function (): foo {
return new foo();
};
$foo instanceof foo; // => true
$foo->toto = 123; // $foo() is evaluated and is swapped to its return value
@nicolas-grekas
nicolas-grekas / composer.json
Last active October 29, 2015 22:47
Global Debug Helpers for PHP
{
"name": "nicolas-grekas/debug-helpers",
"description": "Global Debug Helpers for PHP",
"require": {
"symfony/var-dumper": "2.8.*@dev"
},
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
@nicolas-grekas
nicolas-grekas / setup
Last active January 9, 2016 11:02
source ~/go/setup x.y.z
#!/bin/bash
go_version=$1
go_arch=linux-amd64
export GOPATH="$HOME/go"
if [ ! -e $GOPATH ]
then
mkdir $GOPATH