PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 9, 2022

[FIXED] Is there any way to access a Symfony secret value in userland code?

 February 09, 2022     php, symfony     No comments   

Issue

Despite making them appear to be environment variables, Symfony does not actually load secrets into the environment, so you can't access them via getenv() or $_ENV. Is there any way to access them other than via DI? I'm trying to have the secret name be stored as an entity property in a database, then have a service class read the appropriate secret's value for whichever entity is requested by the API client.


Solution

You can add your env values to your parameters in config/services.yaml like that (you can even have them be booleans, JSON or whatever) :

parameters:
    your_secret: '%env(YOUR_SECRET)%'
    your_bool: '%env(bool:YOUR_BOOL)%'
    your_json: '%env(json:YOUR_JSON)%'

Then you can, for example, retrieve it from a controller like so:

    $yourSecret = $this->getParameter('your_secret');


Answered By - Saphir
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing