Created
September 28, 2012 07:38
-
-
Save madapaja/3798483 to your computer and use it in GitHub Desktop.
Ray.Di issue13
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 DbInterface {} | |
class DefaultDb extends DbInterface {} | |
class Storage { | |
public $db; | |
/** | |
* @Inject | |
*/ | |
function __construct(DbInterface $db) | |
{ | |
$this->db = $db; | |
} | |
} | |
class SingletonModule extends AbstractModule | |
{ | |
protected function configure() | |
{ | |
$this->bind('DbInterface')->to('DefaultDb')->in(Scope::SINGLETON); | |
} | |
} | |
$injector = Injector::create([new SingletonModule], false); | |
$storage = $injector->getInstance('Storage'); | |
$dbA = $storage->db; | |
$storage = $injector->getInstance('Storage'); | |
$dbB = $storage->db; | |
$dbA === $dbB // テストのケースはこちら | |
$dbA = $injector->getInstance('DbInterface'); | |
$dbB = $injector->getInstance('DbInterface'); | |
$dbA !== $dbB // issueのケース |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do i get mailer php?