Skip to content

Instantly share code, notes, and snippets.

@instabledesign
instabledesign / Readme.md
Created January 24, 2024 10:46
PHP Symfony dépendance logger

Le logger est une dépendance qui peux être considérer comme optionnel.

Il est donc préférable de l'injecter par setter en utilisant le LoggerAwareInterface + LoggerAwareTrait

Il faut ensuite de systématiquement utiliser la syntaxe $this->logger?->...

ℹ️ l'autowire de symfony injecte le logger sur les classe qui implement LoggerAwareInterface https://github.com/symfony/symfony/blob/6.4/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L673-L674

Cette pratique permet d'alleger les définitions de service et aussi de simplifier les Tests

@instabledesign
instabledesign / main.go
Created November 5, 2019 16:33
Gracefull shutdown with timeout
package main
import (
"context"
"fmt"
"net"
"net/http"
"os"
"os/signal"
"time"
package signal
import (
"os"
"os/signal"
)
// This is a really small signal subscriber
// Signal subscriber that allows you to attach a callback to an `os.Signal` notification.
// Usefull to react to any os.Signal.
@instabledesign
instabledesign / signal_dispatcher.go
Created June 13, 2019 14:36
Golang simple signal dispatcher
package signal_dispatcher
import (
"os"
"os/signal"
)
type SignalSubscriber interface {
GetSubscribesSignals() *map[os.Signal]bool
Notify(os.Signal)
@instabledesign
instabledesign / testing-guidelines.md
Last active October 12, 2018 09:15
Testing guidelines

Testing guidelines

  • use mock, spy and stub on your dependancies
  • count call expectation (and when it should not be called)
  • (try) dont mock what you don't own
  • use dataprovider
  • test edge case (when function need integer test it with negative / positive / 0 and Infinity)
  • test all exit cases (return, exception)
  • you can use dummy object to test abstract code
  • caution with date, filesystem, external ressources
@instabledesign
instabledesign / DateTimeNotConvertable.php
Last active August 5, 2019 18:35
[Doctrine] Convert the DateTime to store it in UTC DateTime.
#src/AppBundle/Doctrine/DBAL/DateTimeNotConvertable.php
<?php
namespace AppBundle\Doctrine\DBAL;
/**
* Class DateTimeNotConvertable
* This class was use to skip the automatic DBAL DateTimeUTC transformation
* see AppBundle\Doctrine\DBAL\Types\UTCDateTimeType
*/
@instabledesign
instabledesign / keywords_class_name.txt
Last active February 3, 2021 10:34
Keywords class name
Adapter
Authenticator
Accessor
Builder
Checker
Consolidator
Controller
Container
Collector
Compiler
@instabledesign
instabledesign / Greatest.php
Created September 2, 2015 11:54
Doctrine ORM Function GREATEST
#src/AppBundle/Doctrine/ORM/Functions/Greatest.php
<?php
namespace AppBundle\Doctrine\ORM\Functions;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\AST\PathExpression;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
<?php
/*
* This file is part of the Twig Extension TruncateHtmlExtension.
*
* Author Leon Radley <leon@radley.se>
* Rewrite by Instabledesign
*
*
* Truncate Html string without stripping tags