Пример #1
0
 /**
  * Returns the Object which represents the value for an attribute of this object
  *
  * Attributes are the properties and relationships of this object. This method
  * returns an object or a collection of objects, in the case of a relationship,
  * which represent the value of that attribute
  *
  * @see MManagedObject::setObjectForAttribute()
  * @see MEntityDescriptionAttribute
  * @see MEntityDescriptionProperty
  * @see MEntityDescriptionRelationship
  *
  * @param MEntityDescriptionAttribute $attribute The attribute which you'd like to
  * retrieve the value for
  *
  * @return MObject|MArray An object or an Array containing a collection of Objects
  * that represent the value of the requested attribute
  */
 public function objectForAttribute(MEntityDescriptionAttribute $attribute)
 {
     $object = null;
     $this->fireFault();
     if ($attribute instanceof MEntityDescriptionProperty) {
         $object = $this->updatedData->objectForKey($attribute->name());
         if ($object == null) {
             $object = $this->data->objectForKey($attribute->name());
         }
     } else {
         if ($attribute instanceof MEntityDescriptionRelationship) {
             $objects = new MMutableArray();
             if (($arr = $this->relationships->objectForKey($attribute->name())) != null) {
                 $objects->appendArray($arr);
             }
             if (($arr = $this->insertedRelationships->objectForKey($attribute->name())) != null) {
                 $objects->appendArray($arr);
             }
             if (($arr = $this->removedRelationships->objectForKey($attribute->name())) != null) {
                 $objects->subtractArray($arr);
             }
             if ($attribute->to() == MEntityDescriptionRelationship::ToOne) {
                 $object = $objects->lastObject();
             } else {
                 $object = $objects;
             }
         } else {
             throw new MManagedObjectException($this, S("Unknown attribute type!"));
         }
     }
     return $object;
 }