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);