Skip to content

Instantly share code, notes, and snippets.

@Swader
Created October 7, 2012 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Swader/3848547 to your computer and use it in GitHub Desktop.
Save Swader/3848547 to your computer and use it in GitHub Desktop.
Using ZF2 Service Manager
public function getServiceConfig()
{
return array(
'factories' => array(
'Pizza' => function ($sm) {
/** @var $sm \Zend\ServiceManager\ServiceManager */
$oObject = new \Application\Model\Pizza();
return $oObject;
},
'Ingredient' => function ($sm) {
/** @var $sm \Zend\ServiceManager\ServiceManager */
$oObject = new \Application\Model\Ingredient();
return $oObject;
},
'PizzaIngredient' => function ($sm) {
/** @var $sm \Zend\ServiceManager\ServiceManager */
$oObject = new \Application\Model\PizzaIngredient();
return $oObject;
},
'Pizzas' => function ($sm) {
/** @var $sm \Zend\ServiceManager\ServiceManager */
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$table = new \Application\Model\Tables\Pizzas(
$dbAdapter,
$sm->get('Pizza')
);
return $table;
},
'Ingredients' => function ($sm) {
/** @var $sm \Zend\ServiceManager\ServiceManager */
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$table = new \Application\Model\Tables\Ingredients(
$dbAdapter,
$sm->get('Ingredient')
);
return $table;
},
'PizzaIngredients' => function ($sm) {
/** @var $sm \Zend\ServiceManager\ServiceManager */
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$table = new \Application\Model\Tables\PizzaIngredients(
$dbAdapter,
$sm->get('PizzaIngredient')
);
return $table;
},
),
'shared' => array(
'Pizza' => false,
'Ingredient' => false,
'PizzaIngredient' => false
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment