Setting defaults for number_format in Symfony 2 - symfony

The twig documentation describes how to set the default parameters for the number_format extension. How can I set this in Symfony 2?

Symfony2 does not give access to core extension of twig. You can create a kernel.request event listener, inject twig service and in onKernelRequest method of the listener you have to add
$this->twig->getExtension('core')->setNumberFormat(3, ',', '.');

Since Symfony 2.7, through Symfony 4.2-dev I'm running on, this can now be configured.
# app/config/config.yml
twig:
number_format:
decimals: 3
decimal_point: ','
thousands_separator: '.'
See Symfony blog post: https://symfony.com/blog/new-in-symfony-2-7-default-date-and-number-format-configuration

Related

How to get all translations message domains in Symfony

TL;DR: I would like to programmatically get all Message Translations Domains of an application made with Symfony 3.4.
An example of expected result:
$domains = $this->get('translator')->getDomains();
//$domains = ['home', 'messages', ...]
But i don't find a method returning application domains in translator service.
Is there an another service returning all application domains?
Thanks!
Ok i found the solution:
$this->getContainer()->get('translator')->getCatalogue()->getDomains();
This solution works for bundles if you store their translations as Symfony 3.4 recommend it : in bundles/Resources/translations/ folder.
Otherwise you should precise the path in in config.yml:
framework:
translator:
...
paths:
- '%kernel.project_dir%/xxx/translations'

Symfony2 FosUser override login_check

I'm working with Symfony and FosUserBundle and I need to insert a log in my database if login is ok and before the redirection to my secured area.
I already overrode SecurityController for loginAction, but where can I insert my log ?
I don't think it's in loginAction, but I don't know how can I override login_check ?
Any ideas ?
You can doing the work indirectly with symfony layer framework. If it's good for you that use symfony you can :
use the DefaultAuthenticationSuccessHandler class symfony and read this : DefaultAuthenticationSuccessHandler
declare a service symfony with function 'onAuthenticationSuccess'
After that you can work with all symfony tools for logging all of you want.
I already use this method with FOSUserBundle.

Add annotation with bundled entity in Symfony

I have a some entities in a Symfony bundle which has its own field configuration in the bundle.
For example: FOSUserBundle.
Now, I want to add some more configuration through annotation or xml.
For example: I want to apply some serialization parameters or Assert validation or Gedmo parameters. How can I achieve this without rewriting the whole entity?

Create bundle without default controller and route

Is this possible to create bundle without default controller and route?
Yes, it is. Only required file in the bundle is the bundle class.
Read more in the official documentation: http://symfony.com/doc/current/book/page_creation.html#the-bundle-system

Symfony2 - how to assign Doctrine Entity as Route resource?

I want to dynamically change my routes based on settings was stored in database, how I can do this in Symfony2?
You can use this bundle to replace Symfony default routing system to a dynamic one.

Resources