Skip to content

Instantly share code, notes, and snippets.

@madapaja
Created September 28, 2012 07:38
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 madapaja/3798483 to your computer and use it in GitHub Desktop.
Save madapaja/3798483 to your computer and use it in GitHub Desktop.
Ray.Di issue13
<?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のケース
@Innocent2014
Copy link

How do i get mailer php?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment