Symfony4 - Casting env variable issue - symfony

apparently, Symfony cast env variable is not working on symfony 4.0.
I have this configuration:
cache:
session:
enabled: "%env(bool:SESSION_CACHE_ENABLED)%"
But I get this error:
Invalid type for path "cache.session.enabled". Expected boolean, but got string.
What is my problem? I'm using symfony version 4.0
Thanks
EDIT
Probably, it is a problem of the plugins. That's what I think: Symfony 4 is now based on .env config variable, that are STRING as default; to handle this, S4 is able to use "casting" env var
'%env(bool:myvar)%'
And it works; if you do a var_dump within a controller, you can see that the variable is a boolean.
Most of current plugins, also those who supports S4, are not able to use this syntax, so, they see that variable as STRING, and the validator return an error.
These plugins should be fixed or, actually, I can duplicate the .yml file on each package/{env}/ dir with separated configuration ( the situation that I would avoid with .env )

The problem is fixed in symfony 4.1 https://github.com/symfony/symfony/issues/22151

Related

Some env vars in .env are not available in debug:conter --env-vars

My .env file has the following entries, but FOO is not listed when I run bin/console debug:container --env-vars. Note however that $_ENV['FOO'] exists when I dump the variable.
FOO=1
AUTH0_CLIENT_ID=clientid
AUTH0_CLIENT_SECRET=secret
AUTH0_DOMAIN=myapp.us.auth0.com
What determines if an env var defined in .env will be available in the container?
Not really sure if this is worthy of an answer but I suppose it might help.
The Symfony .env files are really just one possible sources of $_ENV variables. There are lots of other env variables floating around and of course in production, you might not use .env at all.
So rather than save access to all env variables, the Symfony configuration system only saves those that are actually used. So in this case:
# config/services.yaml
parameters:
foo: '%env(resolve:FOO)%'
Will result in:
bin/console debug:container --env-vars
APP_SECRET n/a "84dc6de50e6f2f7af3db3f78f886840f"
DATABASE_URL n/a "mysql://db_user:db_password#127.0.0.1:3306/db_name?serverVersion=5.7"
FOO n/a "1"
MAILER_DSN n/a n/a
VAR_DUMPER_SERVER "127.0.0.1:9912" n/a
For a fresh 5.1 project.
Off-topic but vaguely interesting to me at least, the above command also generates a warning
[WARNING] The following variables are missing:
* MAILER_DSN
MAILER_DSN is commented out in the default .env file. So I guess it is possible to use env values during configuration even if none are defined at compile time. Good way to check for spelling errors I guess.

Symfony 5 - error : The service "uri_signer" has a dependency on a non-existent parameter "kernel.secret". Did you mean this: "kernel.charset"?

The service "uri_signer" has a dependency on a non-existent parameter "kernel.secret". Did you mean this: "kernel.charset"?
I'm trying to setup a new Symfony project on symfony 5.
Saw the same issue here, but it's different for me, I don't have config.yml or parameters.yml.
How i can fixe this issue ?
kernel.secret dependency on APP_SECRET .env parameter
<parameter key="kernel.secret">%env(APP_SECRET)%</parameter>
search in vendor folder.
Maybe your code base not define APP_SECRET in .env, .env.local or env.test depending on your environment

Symfony 2.8 route annotation failing

Have looked through SO at various Symfony routing issues but no-one seems to have the same issue as this.
Yesterday, routing worked without issue.
Today I am getting errors regarding values being required for arguments with defaults set
This is an example route that is causing me a problem
#Route("/summary/{staffId}", name="task_instance_summary", requirements={"staffId":"\d+"},defaults={"staffId":"0"})
The method definition:
public function summaryAction(Request $request, $staffId)
and of course the error:
"Controller "PlanXL\TaskBundle\Controller\InstanceController::summaryAction()" requires that you provide a value for the "$staffId" argument (because there is no default value or because there is a non optional argument after this one).")
Debug output:
[router] Route "task_instance_summary"
Name task_instance_summary
Path /task/instance/summary/{staffId}
Path Regex #^/task/instance/summary(?:/(?P\d+))?$#s
Host ANY
Host Regex
Scheme ANY
Method ANY
Class Symfony\Component\Routing\Route
Defaults _controller: PlanXLTaskBundle:Instance:summary
staffId: 0
Requirements staffId: \d+
Options compiler_class: Symfony\Component\Routing\RouteCompiler
I have already cleared the cache (even though I am working on dev) but I can't see why I am getting an error. The router can obviously see the default value when I run the debug so why not when called through my application?
Try it;
public function summaryAction(Request $request, $staffId = 0)

sf2 : Unknown "asset" function in "#Twig/Exception/exception_full.html.twig" at line 4

I'm using Symfony 3.1
I have this error when I run app_dev.php :
Unknown "asset" function in "#Twig/Exception/exception_full.html.twig"
at line 4.
I already checked my config.yml, and it contains these values :
framework:
assets:
base_path: ~
...
I don't know what to do... I hope someone can help me. Thank you !
EDIT : Problem solved. I had to remove custom twig filters in my config.yml... :)
Try to set:
assets: ~
Issue about same problem
https://github.com/symfony/symfony/issues/17291
Edit:
Please also check that`s symfony assets component was installed.
The symfony/asset component is required, even in 3.0, by the FrameworkBundle
As you can see:
https://github.com/symfony/framework-bundle/blob/master/composer.json
Another way run update symfony to latest version and update all depend

Symfony2 Composer and environment variables

I would like to set the configuration of my symfony2 project using environment variables.
In the server I have defined:
SYMFONY__DATABASE__USER
SYMFONY__DATABASE__PASSWORD
SYMFONY__DATABASE__NAME
SYMFONY__DATABASE__HOST
SYMFONY__DATABASE__DRIVER
My parameters.yml.dist looks like this:
#app/config/parameters.yml.dist
parameters:
database_host: "%database.host%"
database_port: ~
database_name: "%database.name%"
database_user: "%database.user%"
database_password: "%database.password%"
database_driver: "%database.driver%"
when I run composer I get an exception
composer install --dev --no-interaction --prefer-source
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
You have requested a non-existent parameter "database.driver". Did you mean one of these: "database_user", "database_driver"?
These variables are defined in the server so I can modify the parameters.yml.dist to define these values. But this does not seams the right way, because wat I really want to use are the environment variables.
Note: I want to read this environment variables in travis, heroku and my vagrant machine. I only want to have in the repository the vagrant machine variables.
Which is the proper way to do this?
How should look my parameters.yml.dist?
Looks you are doing everything okay.
Here is the complete documentation for Setting Environment Variables which I believe you already read.
What is important to note is this:
Also, in order for your console to work (which does not use Apache),
you must export these as shell variables. On a Unix system, you can
run the following:
$ export SYMFONY__DATABASE__USER=user
$ export SYMFONY__DATABASE__PASSWORD=secret
I remember once I have a similar issue, I was setting everything on APACHE, but when running commands it wasn't working because I forgot to EXPORT the variables on the system.
Be aware that using export is a temp solution, if you reset your server those values will be lost, you will need to setup in a permanent way according to your OS.
I think you solved this long time ago, but the problem is actually that you have 2 _ between DATABASE and USER and the parser for this have a string replace function that replaces every __ with a . .
For your example to work you should have written like this:
SYMFONY__DATABASE_USER -> database_user
SYMFONY__DATABASE__USER -> database.user
You can try this bundle if your system version is >= 2.6.2:
This bundle provides a way to read parameters from environment
variables at runtime. The value defined in the container parameter is
used as fallback when the environment variable is not available.

Resources