Last updated: 26 Feb 25 16:00:06 (UTC)

Snippets — PHP, Symfony & Composer

Misc

Tests type : Unit / Intégration / Application, fonctionnel

  • Problème d’infra → RuntimeException
  • Problème de code → LogicException

Résoudre conflit composer au merge : accept their et composer update --lock

doctrine:
    dbal:
        connections:
            default:
                profiling_collect_backtrace: true # Stats and backtrace for queries
doctrine:
    dbal:
        connections:
            default:
                profiling_collect_backtrace: true # Stats and backtrace for queries

PHP

Get the extension of a file:

$ext = pathinfo($path, PATHINFO_EXTENSION);
$ext = pathinfo($path, PATHINFO_EXTENSION);

Symfony

Warning and note: the property accessor will get static methods and properties.

Get the kernel and the current environment:

$this->container->get('kernel')->getEnvironment();
$this->container->get('kernel')->getEnvironment();

Get the current route name:

$routeName = $request->attributes->get('_route');
$routeName = $request->attributes->get('_route');

more at symfony.com/doc/routing.html

Open your favorite IDE from an error edit env.local: SYMFONY_FRAMEWORK_IDE='phpstorm://open?file=%f&line=%l&/home/app/>/Users/jerome/Projets/app/'

Twig

Force Twig to set the form widget already rendered (because you already use a sub part of it in the page):

{% do form.x.setRendered %}
{% do form.x.setRendered %}

Get the name of the current route:

{{ app.request.attributes.get('_route') }}
{{ app.request.attributes.get('_route') }}

In Twig use “starts with” in your conditions:

{% if var starts with 'data' %} ...
{% if var starts with 'data' %} ...

Ternary syntax:

{{ condition ? 'yes' : 'no' }} {{ condition ? 'yes' }} {{ condition ?: 'no' }}
{{ condition ? 'yes' : 'no' }} {{ condition ? 'yes' }} {{ condition ?: 'no' }}

Composer

More stuff coming soon!

Other / oldies

Permission problem? Try:

setfacl -dR -m u:www-data:rwx -m u:$(whoami):rwx dir
setfacl -R -m u:www-data:rwX -m u:$(whoami):rwX dir
setfacl -dR -m u:www-data:rwx -m u:$(whoami):rwx dir
setfacl -R -m u:www-data:rwX -m u:$(whoami):rwX dir