Add YAML validation file in Symfony 4 - symfony

How can I add a file in /config/validation.yaml as a mapping validation in order to avoid using annotations in my DTOs?

Is quite simple.
Just add in validator.yaml file the following:
framework:
validation:
email_validation_mode: html5
mapping:
paths:
- '%kernel.project_dir%/src/<path to validation file>'

Related

Parameter in parameter in services.yml

I am using symfony5 and what I want to achive is to use a parameter in another parameter. Is it possible? Of course I've searchd for it, but did not find a solution. For example:
media:
extendions:
- pdf
path: '%kernel.project_dir%/media/'
incomingPdf:
#path: '%kernel.project_dir%/media/incoming/pdf'
path: '#=parameter("media")["path"]incoming/pdf'
It says, expressions is not allowed in parameters.
In incomingPdf I want to use defined media['path']s value.

Symfony pagerfanta - can't translate the text in final pagination

I'm trying to translate from english the next and previous in pagination.
I've tried creating normal pagerfanta.cs.yaml with Previous: "Předchozí" Next: "Následující" and pagerfanta even has its own translations so it should work by itself, but copying the original pagerfanta.cs.xliff to the translations folder doesn't work either.
In services.yaml I have:
parameters:
locale: 'en'
and in translation.yaml:
framework:
default_locale: cs
translator:
default_path: '%kernel.project_dir%/translations'
fallbacks:
- '%locale%'
Symfony debug toolbar also doesn't even catch any translations should take place.
Any ideas why it's not working?
You should install pagerfanta/twig package in order to use translatable templates. Then create a new config file at config/packages/babdev_pagerfanta.yaml containing
babdev_pagerfanta:
default_view: twig
default_twig_template: '#BabDevPagerfanta/twitter_bootstrap5.html.twig'
By selecting twig as default_view, the translations are going to be handled properly.

What is the difference between global definitions section and components section?

What is the difference between the global definitions section and the components section in Swagger 2.0?
I came across a Swagger definition YAML file which is marked as swagger: '2.0'.
It has one section called definitions just below parameters. This is similar to what is described in
https://swagger.io/docs/specification/2-0/basic-structure/
under the "Input and Output Models" section.
Also further down the file, it has the components section with the schemas section underneath it. That is similar to what is described in
https://swagger.io/docs/specification/components/
This looks like OAS3.
However, this specific YAML file has both sections. I am not exactly sure whether definitions is for Swagger 2.0 and components and schemas is in OAS 3.0. Is that so?
Can both definitions and components be used in the same YAML file of type swagger: '2.0' or should we stick to either definitions or components?
# definitions section looks like this
definitions:
User:
properties:
id:
type: integer
name:
type: string
# Both properties are required
required:
- id
- name
# components section looks like this
components:
schemas:
Address:
type: object
properties:
line1:
type: string
city:
type: string
I am not exactly sure whether definitions is for Swagger 2.0 and components and schemas is in OAS 3.0. Is that so?
Yes, exactly.
The definitions section is used in OpenAPI 2.0 files (swagger: '2.0').
The components section is used in OpenAPI 3.x (openapi: 3.x.x).
Can both definitions and components be used in the same YAML file of type swagger: '2.0' or should we stick to either definitions or components?
No, you can't mix 2.0 and 3.x syntax in the same file. If your file is swagger: '2.0' you must use 2.0 syntax. If it's openapi: 3.0.0 you must use 3.0 syntax.

Symfony2 - FOSUserBundle - Add _locale in url

I would like to overwrite default routing of FOSUserBundle for Symfony2 to get a result like this:
www.mysite.com/en/login
www.mysite.com/es/login
www.mysite.com/fr/login
www.mysite.com/en/profile
www.mysite.com/es/profile
www.mysite.com/fr/profile
Thanks for your help.
Look at this link. I think it is exactly what you need.
[...] to add a prefix before the _locale string (e.g. /admin/en/dashboard), you can add the “i18n_prefix” option.
# app/config/routing.yml
dashboard:
...
options: { i18n_prefix: admin }

How to use us/en instead of en_US with JMSI18nRoutingBundle

I'm using JMSI18nRoutingBundle for locale routing on our new site, but our existing site uses language + country in the following format and I need to keep the URLs looking the same.
example.com/us/en/hello (en_US)
example.com/be/fr/bonjour (fr_BE)
Is there any way to do this using config? If not, where is the best place to start customizing?
It doesn't look it's possible to do through config, but it can be done by replacing default implementation of PatternGenerationStrategyInterface by your own implementation.
You can check out default implementation that bundle uses here.
After you create your own implementation, just make bundle use your own implementation by setting the config parameter. If you're using YAML for example:
parameters:
jms_i18n_routing.pattern_generation_strategy.class: YourBundle\YourImplementationClass
Hint: you can basically copy/paste from default implementation and change line 69 to use str_replace('_', '/', $locale) instead of just $locale. That way, newly generated route pattern will contain a / if locale contains an _.
Not very elegant solution, but bundle unfortunately doesn't provide enough configuration to make it prettier.

Resources