Example #1
0
 /**
  * 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));
 }
Example #2
0
 /**
  * This method puts the name/value mapping to the collection.
  *
  * @access public
  * @param array $key                                        the key for the element to be mapped
  * @param Spring\Object\Factory $factory                    the factory to be used
  * @return boolean                                          whether the entry pair was set
  */
 public function putEntry(array $key, Spring\Object\Factory $factory)
 {
     return $this->register->putEntry($this->getKey($key), $factory);
 }