Right now I can call services from controllers in the following way:
$this -> get('myservice') -> doSomething();
But I want to do this according to the factory method pattern, like this:
ServiceFactory :: createMyservice() -> doSomething();
The problem is that I can't pass parameters with the second method, they're null.
services.yml:
parameters:
services:
myservice:
class: AppBundle\Service\Myservice
factory: [Appbundle\Factory\ServiceFactory, createMyservice]
arguments:
- "%kernel.root_dir%"
ServiceFactory.php:
<?php
namespace AppBundle\Factory;
use AppBundle\Service\MyService;
class ServiceFactory
{
public static function createMyservice($rootDir)
{
var_dump($rootDir); // NULL
$object = new Myservice($rootDir);
return $object;
}
}
What's wrong?