Exemplo n.º 1
0
 /**
  * 
  *
  * @return MData
  */
 public function dataByAppendingData(MData $data)
 {
     return new MData($this->getBytes() . $data->getBytes());
 }
 /**
  * 
  */
 public function typeClassName()
 {
     if ($this->type() == MEntityDescriptionProperty::StringType) {
         return MString::className();
     } else {
         if ($this->type() == MEntityDescriptionProperty::IntegerType) {
             return MNumber::className();
         } else {
             if ($this->type() == MEntityDescriptionProperty::FloatType) {
                 return MNumber::className();
             } else {
                 if ($this->type() == MEntityDescriptionProperty::BooleanType) {
                     return MNumber::className();
                 } else {
                     if ($this->type() == MEntityDescriptionProperty::DateType) {
                         return MDate::className();
                     } else {
                         if ($this->type() == MEntityDescriptionProperty::BinaryType) {
                             return MData::className();
                         } else {
                             return S("");
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 /**
  * @internal
  *
  * @return bool
  */
 protected function _setValueForField(MApplicationControllerField $field, $value)
 {
     $object = null;
     try {
         if ($field->type() == MApplicationControllerField::StringType) {
             $object = S($value);
         } else {
             if ($field->type() == MApplicationControllerField::IntegerType) {
                 $object = MNumber::parseInt($value);
             } else {
                 if ($field->type() == MApplicationControllerField::FloatType) {
                     $object = MNumber::parseFloat($value);
                 } else {
                     if ($field->type() == MApplicationControllerField::BooleanType) {
                         $object = MNumber::parseBool($value);
                     } else {
                         if ($field->type() == MApplicationControllerField::DateType) {
                             $object = MDate::parse($value);
                         } else {
                             if ($field->type() == MApplicationControllerField::BinaryType) {
                                 $object = MData::parseBase64String(S($value));
                             } else {
                                 if ($field->type() == MApplicationControllerField::ArrayType) {
                                     $object = new MMutableArray();
                                     foreach ($value as $v) {
                                         $object->addObject(S($v));
                                     }
                                 } else {
                                     if ($field->type() == MApplicationControllerField::DictionaryType) {
                                         $object = new MMutableDictionary();
                                         foreach ($value as $k => $v) {
                                             $object->setObjectForKey(S($k), S($v));
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     } catch (Exception $e) {
         return false;
     }
     if (!$this->fieldValues) {
         $this->fieldValues = new MMutableDictionary();
     }
     if ($object) {
         $this->fieldValues->setObjectForKey($field, $object);
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 4
0
 /**
  * 
  *
  * @return void
  */
 public function appendData(MData $data)
 {
     $this->bytes .= $data->getBytes();
 }
Exemplo n.º 5
0
 /**
  * Sets the object which represents the value for a certain attribute of this object
  *
  * Attributes are the properties and relationships of this object. This method sets
  * the object which represents the value of that attribute.
  *
  * You cannot use this method to set the value of a ToMany relationship, for that
  * you should use MManagedObject::addObjectToRelationship and
  * MManagedObject::removeObjectFromRelationship
  *
  * @see MManagedObject::addObjectToRelationship
  * @see MManagedObject::removeObjectFromRelationship
  *
  * @param MEntityDescriptionAttribute $attribute The attribute which you'd like to set
  * the value of
  * @param MObject $object The Object representing the value for that attribute
  *
  * @return void
  */
 public function setObjectForAttribute(MEntityDescriptionAttribute $attribute, MObject $object = null)
 {
     $this->fireFault();
     if ($attribute instanceof MEntityDescriptionProperty) {
         if ($object) {
             if ($attribute->type() == MEntityDescriptionProperty::StringType) {
                 if (!$object instanceof MString) {
                     throw new MInvalidManagedObjectOperationException($this, Sf("Invalid type [%s], expected [%s]!", str($object->className()), str(MString::className())));
                 }
             } else {
                 if ($attribute->type() == MEntityDescriptionProperty::IntegerType) {
                     if (!$object instanceof MNumber) {
                         throw new MInvalidManagedObjectOperationException($this, Sf("Invalid type [%s], expected [%s]!", str($object->className()), str(MNumber::className())));
                     }
                 } else {
                     if ($attribute->type() == MEntityDescriptionProperty::FloatType) {
                         if (!$object instanceof MNumber) {
                             throw new MInvalidManagedObjectOperationException($this, Sf("Invalid type [%s], expected [%s]!", str($object->className()), str(MNumber::className())));
                         }
                     } else {
                         if ($attribute->type() == MEntityDescriptionProperty::BooleanType) {
                             if (!$object instanceof MNumber) {
                                 throw new MInvalidManagedObjectOperationException($this, Sf("Invalid type [%s], expected [%s]!", str($object->className()), str(MNumber::className())));
                             }
                         } else {
                             if ($attribute->type() == MEntityDescriptionProperty::DateType) {
                                 if (!$object instanceof MDate) {
                                     throw new MInvalidManagedObjectOperationException($this, Sf("Invalid type [%s], expected [%s]!", str($object->className()), str(MDate::className())));
                                 }
                             } else {
                                 if ($attribute->type() == MEntityDescriptionProperty::BinaryType) {
                                     if (!$object instanceof MData) {
                                         throw new MInvalidManagedObjectOperationException($this, Sf("Invalid type [%s], expected [%s]!", str($object->className()), str(MData::className())));
                                     }
                                 } else {
                                     throw new MInvalidManagedObjectOperationException($this, Sf("Unsupported type [%s]!", $attribute->type()));
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $this->updatedData->setObjectForKey($attribute->name(), $object);
     } else {
         if ($attribute instanceof MEntityDescriptionRelationship) {
             if ($attribute->to() == MEntityDescriptionRelationship::ToMany) {
                 throw new MInvalidManagedObjectOperationException($this, S("Could not set a ToMany relationship, please use add/remove"));
             }
             if (($oldArr = $this->relationships->objectForKey($attribute->name())) != null) {
                 if ($oldArr->lastObject()) {
                     $this->removeObjectFromRelationship($attribute, $oldArr->lastObject());
                 }
             }
             $this->addObjectToRelationship($attribute, $object);
         } else {
             throw new MManagedObjectException($this, S("Unknown attribute type!"));
         }
     }
 }
 /**
  * Parses one or more Managed Objects from inside the specified XML data
  * and inserts them into this Managed Object Context
  *
  * @param MData $data A data object containing the XML representation of the objects to be parsed
  * @param callable $callback A callback function which will be called every time a new
  * object is parsed and added into the Managed Object Context. The method signature for the
  * callback is callback(MManagedObject $object);
  *
  *
  * @return MArray An Array containing the parsed objects
  */
 public function parseObjectsFromData(MData $data, callable $callback = null)
 {
     $xml = simplexml_load_string($data->getBytes());
     return $this->parseObjectsFromXML($xml, $callback);
 }