The best way to think of this is that ServiceManager's get()
method takes a key value, not a class name. The key value needs to map to something that will result in a class instance being returned.
If the key is within the invokables
section, then the ServiceManager will try to instantiate the string that the key points to on the assumption that it's a classname:
'invokables' => array(
'some_name' => 'My\Mapper\SomeClassName',
),
If the key is within the factories
section, then the ServiceManager will execute the callback that the key points to and expect an object instance to be returned:
'factories' => array(
'some_name' => function($sm) { return new \My\Mapper\SomeClassName(); },
),
In general, you use a factory when you need to do something more than just instantiate a class - usually you need to set up the class with another dependency. If you just need to instantiate a class, use an invokable.