/** * Retrieves an entry. * * @param string $id * * @return mixed */ public function get($id) { $this->assertIdIsNotEmpty($id); $this->assertEntryOrClassExists($id); $this->assertNoCircularDependency($id); $this->dependencies[$id] = true; if (!isset($this->objects[$id]) && isset($this->factories[$id])) { $this->objects[$id] = $this->factories[$id]($this); } if (isset($this->objects[$id])) { $object = $this->objects[$id]; } else { if (!isset($this->definitions[$id])) { $this->definitions[$id] = Definition::object($id); } $object = $this->makeObject($this->definitions[$id]); if ($this->definitions[$id]->isUnique()) { $this->objects[$id] = $object; } } unset($this->dependencies[$id]); return $object; }
public function testSet_withExistingIdAndReadonly_throwsException() { $this->subject->get(Service1::class); $this->setExpectedException('Neat\\Container\\Exception\\ReadonlyException'); $this->subject->set(Service1::class, Definition::object(Service2::class)); }
public function testProperty_withNonExistingProperty_throwsException() { $this->setExpectedException('Neat\\Container\\Exception\\UnexpectedValueException'); Definition::object(Service1::class)->property('property6', 'test'); }