/** * * * @return MNumberOutOfRangeException */ public function __construct(MNumber $number, MNumber $lowerBound, MNumber $upperBound, MException $previous = null) { parent::__construct(Sf("Number [%s] out of range [%s-%s]", $number->toString()->stringValue(), $lowerBound->toString()->stringValue(), $upperBound->toString()->stringValue()), MException::NUMBER_OUT_OF_RANGE_EXCEPTION_CODE, $previous); $this->number = $number; $this->lowerBound = $lowerBound; $this->upperBound = $upperBound; }
/** * */ 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(""); } } } } } } }
/** * @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; } }
/** * @internal * * Used internally to parse the Model from it's model file * * @return void */ protected function parse() { $xmlModels = simplexml_load_file($this->modelFile()->path()->stringValue()); if (!$this->version()) { $this->version = S((string) $xmlModels->{'current-version'}); } $model = null; foreach ($xmlModels->model as $m) { if (S((string) $m['version'])->equals($this->version())) { $model = $m; } } if ($model != null) { $relationshipsToLink = new MMutableDictionary(); foreach ($model->entity as $entity) { $newEntity = new MEntityDescription(S((string) $entity['name']), S((string) $entity['plural']), S((string) $entity['class'])); foreach ($entity->property as $property) { $newProperty = new MEntityDescriptionProperty($newEntity, S((string) $property['name'])); if ((string) $property['type'] != null) { $newProperty->setType((string) $property['type']); } if ((string) $property['defaultValue'] != null) { $defaultValue = null; if ($newProperty->type() == MEntityDescriptionProperty::StringType) { $defaultValue = new MString((string) $property['defaultValue']); } else { if ($newProperty->type() == MEntityDescriptionProperty::IntegerType) { $defaultValue = MNumber::parseInt((string) $property['defaultValue']); } else { if ($newProperty->type() == MEntityDescriptionProperty::FloatType) { $defaultValue = MNumber::parseFloat((string) $property['defaultValue']); } else { if ($newProperty->type() == MEntityDescriptionProperty::BooleanType) { $defaultValue = MNumber::parseBool((string) $property['defaultValue']); } else { if ($newProperty->type() == MEntityDescriptionProperty::DateType) { $defaultValue = MDate::parseString((string) $property['defaultValue']); } else { if ($newProperty->type() == MEntityDescriptionProperty::BinaryType) { // BinaryType's defaultValue is ignored, always null } else { throw new MModelParseErrorException($this->modelFile(), Sf("Invalid data type '%s'", $newProperty->type())); } } } } } } $newProperty->setDefaultValue($defaultValue); } } foreach ($entity->relationship as $relationship) { $newRelationship = new MEntityDescriptionRelationship($newEntity, S((string) $relationship['name']), S((string) $relationship['type'])); $newRelationship->setSingular(S((string) $relationship['singular'])); if (strtolower((string) $relationship['to']) == "many") { $newRelationship->setTo(MEntityDescriptionRelationship::ToMany); } else { $newRelationship->setTo(MEntityDescriptionRelationship::ToOne); } if ($relationship['inverse'] != null) { $relationshipsToLink->setObjectForKey($newRelationship, S((string) $relationship['inverse'])); } } $this->addEntity($newEntity); } // Link relationships to their respective inverse relationships foreach ($relationshipsToLink->allKeys()->toArray() as $relationship) { $inverse = $relationshipsToLink->objectForKey($relationship); $inverseEntity = $this->entityWithName($relationship->type()); if ($inverseEntity) { $inverseRelationship = $inverseEntity->attributeWithName($inverse); if ($inverseRelationship) { $relationship->setInverseRelationship($inverseRelationship); } else { throw new MModelParseErrorException($this->modelFile(), Sf("Could not find the relationship named '%s' in entity '%s'", $inverse, $relationship->type())); } } else { throw new MModelParseErrorException($this->modelFile(), Sf("[%s->%s] Inverse relationship's entity named '%s' not defined in this model version", $relationship->entity()->name(), $relationship->name(), $relationship->type())); } } } else { throw new MModelVersionNotFoundException($this->modelFile()); } }
/** * * * @return MNumber */ public function numberBySumming(MNumber $number) { return new MNumber($this->value() + $number->value()); }
/** * 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!")); } } }
/** * Asserts if a number is within a certain range * * This function asserts that the specified number is smaller than * max and greater than min. If it is not, this function throws * an MNumberOutOfRangeException * * @param MNumber $number The number to assert * @param MNumber $min The minimum value for the number * @param MNumber $max The maximum value for the number * * @return void */ function MAssertRange(MNumber $number, MNumber $min, MNumber $max) { if (!$number->isWithinBounds($min, $max)) { import('mango.system.exceptions.MNumberOutOfRangeException'); throw new MNumberOutOfRangeException($number, $min, $max); } }