1

I am looking to add symfony's yaml component to Silex however I am having issues with adding the 5.3 version. Adding the none namespaced version works fine but I would rather have the namespaced version from https://github.com/symfony/Yaml. This is my service provider:

public function register(Application $app)
{
    if (isset($app['classPath'])) {
        $app['autoloader']->registerNamespace('Symfony\Component\Yaml', $app['classPath']);
    }
}

But when I do this is code:

use Symfony\Component\Yaml\Yaml;
Yaml::load(__DIR__ . '/../configuration/application.yml');

I receive the error of:

Fatal error: Class 'Symfony\Component\Yaml\Yaml' not found in /mnt/hgfs/silex/web/index.php on line 20

Full Correct Answer: gregoire made a comment about registering the Symfony namespace, not the Symfony\Comonent\Yaml so I basically recreated the directory structure for the namespace and registed the root of the to the Symfony namespace and that works great.

ryanzec
  • 27,284
  • 38
  • 112
  • 169
  • you should check http://stackoverflow.com/questions/7486599/how-to-use-a-yaml-config-file-in-silex-framework – Pascal Dec 06 '11 at 14:45
  • That talks about adding the non namespaced version of Yaml which I have already implemented successfully. Like I said I would rather have the namespaced version on Yaml for consistency sake (everything else is namespaced). If there is no way to include the namespaced Yaml with silex, then I guess I will have to use the older version. – ryanzec Dec 06 '11 at 14:50
  • 1
    Aren't you supposed to register the Symfony namespace (and not Symfony\Component\Yaml)? – greg0ire Dec 06 '11 at 15:21
  • @gregoire You are correct. Post an answer saying that so I can give you credit for the correct answer. – ryanzec Dec 06 '11 at 16:00
  • @ryanzec You can answer your own question and accept the answer. – jnrbsn Apr 10 '12 at 19:12

1 Answers1

2

Now that silex is using composer, I am just using composer to include it.

ryanzec
  • 27,284
  • 38
  • 112
  • 169