Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the decoupled symfony components?

Any information on how to use symfony's decoupled components?

I'm rereading the docs but there's nothing on the topic besides a general message of "They are very very decoupled" and 1 tutorial that makes use of Request and Response.

There's also one badly ranked answer of Using symfony2 routing component (outside of symfony2)

Also having a look at a tutorial for the standalone Form component doesn't actually excite me how pleasant this is.

I need the routing, yaml, and session.

like image 851
antitoxic Avatar asked Oct 20 '11 17:10

antitoxic


3 Answers

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.

like image 94
Alessandro Desantis Avatar answered Nov 07 '22 03:11

Alessandro Desantis


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.

like image 7
richsage Avatar answered Nov 07 '22 02:11

richsage


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.

like image 5
Tal Ater Avatar answered Nov 07 '22 02:11

Tal Ater