Created
October 31, 2013 16:07
-
-
Save kastaneda/7252339 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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