public static function getConfig() { $config = new ConfigurationBuilder(); $config->addInvokable("IndependentService", IndependentService::getClass()); $config->addFactory("DependentService", __CLASS__); return $config->getConfig(); }
public function testGetWithSharedServiceWorks() { ServiceManager::setConfig([ConfigurationBuilder::INVOKABLES => ["StandardService" => IndependentService::getClass(), "SharedService" => IndependentService::getClass()], ConfigurationBuilder::SHARED => ["SharedService" => true], ConfigurationBuilder::SHARED_BY_DEFAULT => false]); $a = ServiceManager::getInstance()->get("SharedService"); $b = ServiceManager::getInstance()->get("SharedService"); $this->assertSame($a, $b); $c = ServiceManager::getInstance()->get("StandardService"); $d = ServiceManager::getInstance()->get("StandardService"); $this->assertNotSame($c, $d); }