Hi i'm new to zend framework. try to catch up on the service manager. base on the zend framework documentation , it said:
factories, an array of service name/factory class name pairs. The factories should be either classes implementing Zend\ServiceManager\FactoryInterface or invokable classes. If you are using PHP configuration files, you may provide any PHP callable as the factory.
invokables, an array of service name/class name pairs. The class name should be class that may be directly instantiated without any constructor arguments.
but i'm still don't quit understand the different beween them. when i should use as invokeable and when i should use factories? what is advantage use factories? thanks very much.
The invokables should be used to instantiate a sinmple object, which doesn't need any other dependencies etc in the contstructor.
You should use a factory when there's a little more complex logic behind instantiating the object. Moving the code into a factory will save you duplicating the code when ever you need an object back too.
Factory example:
AclFactory.php
}
If you want back a simple class/object back then you can just use an invokable, as there's no boiler-plate code needed to get the object back.
another Example, with controllers:
If you have a simple controller, with no requried dependencies, use an invokable:
But sometimes you want to add extra dependencies to the controller when you instantiate it: