/** * Returns true if the <i>$object</i> has the right data type assigned in * the construct, otherwise false. * * @param mixed $object * @return boolean */ public function isValidType($object) { if ($this->type == null || $object == null) { return true; } if (is_object($object) && get_class($object) == $this->type) { return true; } return MDataType::getType($object) == $this->type; }
/** * Checks the type of the arguments of the method caller with the type passed * in <i>$dataTypes</i>.<br> * If the number of elements in <i>$dataTypes</i> isn't the same of the number * of the arguments of the caller, it will throw an exception.<br> * If the type mismatch then it will be throw a {@link MWrongTypeException MWrongTypeException}. * * @param array|int $dataTypes,... unlimited OPTIONAL The possible values of the elements of the array are: case * MDataType::INT, MDataType::LONG, MDataType::BOOLEAN, MDataType::FLOAT: return * "MDataType::FLOAT, MDataType::DOUBLE, MDataType::STRING, MDataType::NULL, * MDataType::__ARRAY, MDataType::OBJECT, MDataType::RESOURCE, MDataType::MIXED * @throws \Exception|MWrongTypeException */ public static function mustBe($dataTypes) { $params = func_get_args(); if (isset($params[0]) && is_array($params[0])) { $dataTypeArray = $params[0]; } else { $dataTypeArray = $params; } $trace = debug_backtrace(); $caller = $trace[1]; $args = $caller["args"]; for ($i = 0; $i < count($args); $i++) { $dataType = $dataTypeArray[$i]; if ($dataType === MDataType::MIXED || $dataType === MDataType::OBJECT) { continue; } if ($dataType & MDataType::getType($args[$i])) { continue; } $callerName = isset($caller["class"]) ? $caller["class"] . "::" . $caller["function"] : $caller["function"]; $mustBe = MDataType::getTypeName($dataType); $itIs = MDataType::getTypeName(MDataType::getType($args[$i])); $message = "Argument " . ($i + 1) . " passed to " . $callerName . " must be of the type " . $mustBe . ", " . $itIs . " given, called in " . $caller["file"] . " on line " . $caller["line"] . " and defined"; throw new MWrongTypeException($message); } }
/** * If param <i>$name</i> is an int: returns the field at position index. * If the index is out of range, function returns a null * value. <br /> * <br /> * If param <i>$name</i> is a string: returns the field called name. * * @param int|string $name * @return MSqlField|null */ public function getField($name) { if ($this->contains($name) === false) { return null; } $value = $this->record[$name]; $type = MDataType::getType($value); $field = new MSqlField($name, $type); $field->setValue($value); return $field; }