How to use the decoupled symfony components? How to use the decoupled symfony components? symfony symfony

How to use the decoupled symfony components?


The first component you should use is ClassLoader. You can also use spl_autoload_register, but you're using Symfony, so why shouldn't you use its own autoloading library? Add the following at the top of the script:

use Symfony\Component\ClassLoader\UniversalClassLoader;require_once '/path/to/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';$loader = new UniversalClassLoader();$loader->register();$loader->registerNamespaces(array(    'Symfony' => '/path/to/symfony/src',));

Using the Yaml component is really easy:

use Symfony\Component\Yaml\Parser;$data = Parser::parse('yaml string');

For the other components, you'll have to read the API documentation, as there are no tutorials yet.


Interestingly, Fabien Potencier just published a blog post which contains snippets of how to use the most common components. See the second half of this post for details.


I've written a tutorial which might help you, on using decoupled Symfony components in your project.

It shows how to use the console component as an example, but the logic is the same for other components.