Parameter in parameter in services.yml - symfony

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.

Related

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.

how to coerce meteor iron:router params to an integer?

I often have code that forces params to be an integer, i was wondering if there's a better way with IR to handle this frequent case:
#route 'units',
path: "/units/:book?"
name: 'units'
waitOn: ->
book = parseInt(#params.book)
PubSubMan.subscribe "Tiles", {book: book}
This is a pain as the parseInt(#params.book) has to be done in find queries that use the params too, and i also need to guard against non-numbers, etc etc.
Seems that sort of type casting could be a router level option but could't find anything in the docs
Something like
this.route('units', {
path: /^\/units\/(\d+)/
});
Make sure to try with/without last slash in the path and update regular expression to your needs.
You can access parameter with:
this.params[0]
I could not get Roman's suggestion to work, as a regular expression object does not seem to be allowed as a path. I get the error described here:
https://github.com/iron-meteor/iron-router/issues/887
Exception in template helper: Error: Cannot currently resolve a regular expression path
Instead, I found this to be useful: https://github.com/pillarjs/path-to-regexp#custom-match-parameters
In short, I would try the following:
this.route('units', {
path: '/units/:book(\\d+)?'
});
And then you can use this.params.book as you normally would.

URL available only for administrator

How can I set that URL`s which have new in name are available only for ROLE_ADMINISTRATOR?
I`m sure that I must set it in security.yml access_control
But how to set for example
www.mydomain.com/user/new
www.mydomain.com/user/2/edit
only for ROLE_ADMINISTRATOR
{ path: ^/.*/new, role: ROLE_ADMINISTRATOR } doesn`t work :(
Symfony 2 will select the first pattern that matches. So, if a pattern above the one you shared gives access to that path (say something like ^/user) then the role of that line will be allowed.
Ensure that you have the restrictive paths above all of the others.
Also, I'm not sure if Symfony allows . to match /, so you might want to try ^/[\s\S]*/new (or even just /new$ if the new is always at the end) if it isn't just a problem with ordering.

How to access nested parameter values in Symfony2

I created a parameter in my parameters file:
parameters:
category:
var: test
I can access this in PHP by fetching it like this:
$var = $this->container->getParameter('category');
$var = $var['var'];
But how can I access this parameter in my config.yml? For example, I want to pass this parameter to all my twig files as a global twig variable:
twig:
globals:
my_var: %category.var% # throws ParameterNotFoundException
(Sidequestion:
I assumed I could access it via getParamter('category.var'), but got an error there. Do you know a nicer way than my two-liner? $this->container->getParameter('category')['var'] works, but is a syntax error according to my IDE.)
$this->container->getParameter('category')['var']
..is actually a pretty good way to go. Which version of PHP is your IDE using for its syntax checking? Somebody please correct me, but I think this behavior was made valid in 5.3 or 5.4.

How to access arrays in symfony's configuration files?

Does the symfony2 can handle only flat parameters?
Say we have:
services:
manager:
class: blabla
arguments: [%app.vat%]
and in app.yml :
parameters:
app.vat: 24.5
it works, but
parameters:
app:
vat: 24.5
does not work. Is there some special syntax to access arrays or this is not possible?
This is indeed possible. You can access the values from your example in your code like this:
$config = $this->get('service_container')->getParameter('app.vat');
If this is still not working you should try to rename "app" into something else (e.g. "application"). Symfony preserves the name "app" on many places and handles it in a special way.

Resources