I'm in the middle of migrating some Silex code to a Symfony project..I was wondering what the Symfony equivalent is for registering Pimple services like these:
$app['service.test1'] = $app->protect(...)
$app['service.test2'] = $app->share(...)
Any other pointers are appreciated as well.
I'd check out the docs on the service container for a basic understanding of services.
According to this answer share
was removed in new versions of Silex. share
seems to equate to regular service definitions you'll read about in the symfony docs.
I've never used anything like protect
in Symfony, I suppose you could declare a class with and use the __invoke
method for your function.
class Adder
{
public function __invoke($a, $b) {
return $a + $b;
}
}
Then inside YourBundle/Resources/config/services.yml
services:
adder:
class: MyNamespace\Adder
And you could use it like so:
$adder = $this->container->get('adder');
$result = $adder(1,2);
Register your services with the Service Container. Symfony doesn't use Pimple.