Skip to content

Instantly share code, notes, and snippets.

@kastaneda
Created October 31, 2013 16:07
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 kastaneda/7252339 to your computer and use it in GitHub Desktop.
Save kastaneda/7252339 to your computer and use it in GitHub Desktop.
<?php
class MyDevelopmentServiceManager
{
protected $factories = array(
'Foo' => '\MyModule\Foo',
'Bar' => '\MyModule\Bar',
);
protected $instances;
protected function getNewInstance($name)
{
if (!isset($this->factories[$name]) {
throw new Exception('...!');
}
return new $this->factories[$name];
}
public function getInstance($name)
{
if (!isset($this->instances[$name])) {
$this->instances[$name] = $this->getNewInstance($name);
}
return $this->instances[$name];
}
}
class MyProductionServiceManager
{
protected function getNewInstance($name)
{
switch($name) {
// DO NOT MODIFY: AUTO-GENERATED CODE!
case 'Foo':
retun new \MyModule\Foo;
case 'Bar':
retun new \MyModule\Foo;
default:
throw new Exception('...!');
}
}
public function getInstance($name)
{
if (!isset($this->instances[$name])) {
$this->instances[$name] = $this->getNewInstance($name);
}
return $this->instances[$name];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment