I am using the Command pattern, and trying to copy zf2-style service configurations by using closures in an attempt to load the command objects dependencies within the closure. For example, in my command factory:
protected function getCommandConfig(){
return [
'view-details-command' => function () {
$userFactory = new My\Model\User\Factory();
$editUserForm = new My\Form\User\Edit();
$editUserForm ->setInputFilter(new My\InputFilter\EditUser());
$command = new My\Command\ViewUserDetailsCommand($userFactory, $editUserForm);
return $command;
}
];
}
... which is pretty much identical to how ZF2 initialises objects in the service manager. However, when i run this, such as as $command = $this->getCommandConfig()[$commandName]
i get a closure object returned, with an exception raised when i call a method on what i am expecting to be a command object ("Call to undefined method Closure::foobar...."). What should i be doing to use this sort of configuration? (I am not using the entire ZF2 stack).