I've been struggling for the last day now getting the Symfony Yaml parser working in my application.
My composer.json looks like this;
{
"require": {
"symfony/class-loader": "2.4.*@dev",
"symfony/yaml": "2.4.*@dev",
"facebook/php-sdk": "dev-master"
},
"autoload": {
"psr-0": {
"MyApp": "src/"
}
}
I'm using this in my application:
use Symfony\Component\Yaml\Parser;
$parser = new Parser();
var_dump( $parser->parse( file_get_contents('config.yml') ) );
Then I get this error:
( ! ) Fatal error: Class 'Symfony\Component\Yaml\Yaml' not found in /Projects/my-app/web/index.php on line 16
The UniversalClassLoader (from "symfony/class-loader") works perfectly fine, and when I check what namespaces are loaded, the Symfony\Component\Yaml is the first one in the array.
My IDE (PHPStorm) is giving a squiggly line underneath the classname, "Multiple definitions exist". One is going to the real vendor folder, the other one is referring to a file inside the composer.phar file (read-only).
Does anyone know what I'm doing wrong?
Show your bootstrap code. Especially where the autoloader is being created.
In general, you should probably use the composer generated autoload file as opposed to the S2 one.
This works:
require_once __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\Yaml\Parser;
$parser = new Parser();
var_dump( $parser->parse( file_get_contents('config.yml') ) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With