/** * This method returns an object for the specified element. * * @access public * @param string $idref the id ref of the object to get * @param array $idrefs a buffer to keeps track of idrefs to * help prevent circular references * @return mixed the object * @throws Throwable\Parse\Exception indicates that a problem occurred * when parsing */ public function getObjectFromIdRef($idref, $idrefs = null) { if ($idrefs !== null) { $this->idrefs = $idrefs; } if ($this->isId($idref)) { // TODO uncomment session code //$session_key = __CLASS__ . '::' . $this->context . '::' . $id; //$object = $this->session->get($session_key, null); $object = null; if ($object !== null) { return $object; } else { if ($this->singletons->hasKey($idref)) { return $this->singletons->getValue($idref); } } $elements = $this->find($idref); if (!empty($elements)) { if (isset($this->idrefs[$idref])) { // checks for circular references throw new Throwable\Parse\Exception('Unable to process Spring XML. Discovered a circular reference on id ":id".', array(':id' => $idref)); } $this->idrefs[$idref] = count($this->idrefs); // stack level $element = $elements[0]; $object = $this->getObjectFromElement($element); $attributes = $element->attributes(); unset($this->idrefs[$idref]); if (isset($attributes['scope'])) { $scope = $this->valueOf($attributes['scope']); switch ($scope) { // TODO uncomment session code //case 'session': // $this->session->set($session_key, $object); // return $object; case 'singleton': $this->singletons->putEntry($idref, $object); return $object; case 'prototype': return $object; default: throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid "scope" token, but got ":token".', array(':token' => $scope)); } } else { $this->singletons->putEntry($idref, $object); return $object; } } return null; } throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid "id" token, but got ":token".', array(':token' => $idref)); }
/** * This method determines whether the specified name exists in the collection. * * @access public * @param array $key the key for the element to be tested * @return boolean whether the specified name exists */ public function hasKey(array $key) { return $this->register->hasKey($this->getKey($key)); }