0

I have a plain PHP class and I want to read one of the parameter from config.yml file. I dont have a container instance to read and get the param value. How can I achieve this in a plain PHP class? Important thing is that I can not make a service of my php class.

1
  • what is the question exactly, can you add an example, it is not clear Commented Aug 31, 2015 at 13:50

1 Answer 1

4

It's actually very easy, since YAML is component on it's own:

use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Parser;

$yaml = new Parser();

try {
    $yamlData = $yaml->parse(file_get_contents('/path/to/config.yml'));

    // adjust what you need to read here.
    $paramValue = $yamlData['your_key']['sub_key'];

} catch (ParseException $e) {
    printf("Unable to parse the YAML string: %s", $e->getMessage());
}

Source: Reading YAML Files

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.