当前位置: 首页>>代码示例>>PHP>>正文


PHP Format::isFloat方法代码示例

本文整理汇总了PHP中qtism\common\utils\Format::isFloat方法的典型用法代码示例。如果您正苦于以下问题:PHP Format::isFloat方法的具体用法?PHP Format::isFloat怎么用?PHP Format::isFloat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qtism\common\utils\Format的用法示例。


在下文中一共展示了Format::isFloat方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: unmarshall

 /**
  * Unmarshall a DOMElement object corresponding to a QTI weight element.
  * 
  * @param DOMElement $element A DOMElement object.
  * @return QtiComponent A Weight object.
  * @throws UnmarshallingException If the mandatory attributes 'identifier' or 'value' are missing from $element but also if 'value' cannot be converted to a float value or 'identifier' is not a valid QTI Identifier.
  */
 protected function unmarshall(DOMElement $element)
 {
     // identifier is a mandatory value.
     if (($identifier = static::getDOMElementAttributeAs($element, 'identifier', 'string')) !== null) {
         if (($value = static::getDOMElementAttributeAs($element, 'value', 'string')) !== null) {
             if (Format::isFloat($value)) {
                 try {
                     $object = new Weight($identifier, floatval($value));
                     return $object;
                 } catch (InvalidArgumentException $e) {
                     $msg = "The value of 'identifier' from element '" . $element->localName . "' is not a valid QTI Identifier.";
                     throw new UnmarshallingException($msg, $element, $e);
                 }
             } else {
                 $msg = "The value of attribute 'value' from element '" . $element->localName . "' cannot be converted into a float.";
                 throw new UnmarshallingException($msg, $element);
             }
         } else {
             $msg = "The mandatory attribute 'value' is missing from element '" . $element->localName . "'.";
             throw new UnmarshallingException($msg, $element);
         }
     } else {
         $msg = "The mandatory attribute 'identifier' is missing from element '" . $element->localName . "'.";
         throw new UnmarshallingException($msg, $element);
     }
 }
开发者ID:swapnilaptara,项目名称:tao-aptara-assess,代码行数:33,代码来源:WeightMarshaller.php

示例2: unmarshallChildrenKnown

 /**
  * @see \qtism\data\storage\xml\marshalling\OperatorMarshaller::unmarshallChildrenKnown()
  */
 protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children)
 {
     $object = new Equal($children);
     if (($toleranceMode = static::getDOMElementAttributeAs($element, 'toleranceMode')) !== null) {
         $toleranceMode = ToleranceMode::getConstantByName($toleranceMode);
         $object->setToleranceMode($toleranceMode);
     }
     if (($tolerance = static::getDOMElementAttributeAs($element, 'tolerance')) !== null) {
         $tolerance = explode(" ", $tolerance);
         if (count($tolerance) < 1) {
             $msg = "No 'tolerance' could be extracted from element '" . $element->localName . "'.";
             throw new UnmarshallingException($msg, $element);
         } elseif (count($tolerance) > 2) {
             $msg = "'tolerance' attribute not correctly formatted in element '" . $element->localName . "'.";
             throw new UnmarshallingException($msg, $element);
         } else {
             $finalTolerance = array();
             foreach ($tolerance as $t) {
                 $finalTolerance[] = Format::isFloat($t) ? floatval($t) : $t;
             }
             $object->setTolerance($finalTolerance);
         }
     }
     if (($includeLowerBound = static::getDOMElementAttributeAs($element, 'includeLowerBound', 'boolean')) !== null) {
         $object->setIncludeLowerBound($includeLowerBound);
     }
     if (($includeUpperBound = static::getDOMElementAttributeAs($element, 'includeUpperBound', 'boolean')) !== null) {
         $object->setIncludeUpperBound($includeUpperBound);
     }
     return $object;
 }
开发者ID:nagyist,项目名称:qti-sdk,代码行数:34,代码来源:EqualMarshaller.php

示例3: stringToDatatype

 /**
  * Transform a string representing a QTI valueType value in a
  * the correct datatype.
  *
  * @param string $string The QTI valueType value as a string.
  * @param integer $baseType The QTI baseType that defines the datatype of $string.
  * @return mixed A converted object/primitive type.
  * @throws \InvalidArgumentException If $baseType is not a value from the BaseType enumeration.
  * @throws \UnexpectedValueException If $string cannot be transformed in a Value expression with the given $baseType.
  */
 public static function stringToDatatype($string, $baseType)
 {
     if (in_array($baseType, BaseType::asArray())) {
         $value = null;
         switch ($baseType) {
             case BaseType::BOOLEAN:
                 if (Format::isBoolean($string)) {
                     $value = Format::toLowerTrim($string) == 'true' ? true : false;
                     return $value;
                 } else {
                     $msg = "'{$string}' cannot be transformed into boolean.";
                     throw new UnexpectedValueException($msg);
                 }
                 break;
             case BaseType::INTEGER:
                 if (Format::isInteger($string)) {
                     $value = intval($string);
                     return $value;
                 } else {
                     $msg = "'{$string}' cannot be transformed into integer.";
                     throw new UnexpectedValueException($msg);
                 }
                 break;
             case BaseType::FLOAT:
                 if (Format::isFloat($string)) {
                     $value = floatval($string);
                     return $value;
                 } else {
                     $msg = "'{$string}' cannot be transformed into float.";
                     throw new UnexpectedValueException($msg);
                 }
                 break;
             case BaseType::URI:
                 if (Format::isUri($string)) {
                     return $string;
                 } else {
                     $msg = "'{$string}' is not a valid URI.";
                     throw new UnexpectedValueException($msg);
                 }
                 break;
             case BaseType::IDENTIFIER:
                 if (Format::isIdentifier($string)) {
                     return $string;
                 } else {
                     $msg = "'{$string}' is not a valid QTI Identifier.";
                     throw new UnexpectedValueException($msg);
                 }
                 break;
             case BaseType::INT_OR_IDENTIFIER:
                 if (Format::isIdentifier($string)) {
                     return $string;
                 } elseif (Format::isInteger($string)) {
                     return intval($string);
                 } else {
                     $msg = "'{$string}' is not a valid QTI Identifier nor a valid integer.";
                     throw new UnexpectedValueException($msg);
                 }
                 break;
             case BaseType::PAIR:
                 if (Format::isPair($string)) {
                     $pair = explode(" ", $string);
                     return new Pair($pair[0], $pair[1]);
                 } else {
                     $msg = "'{$string}' is not a valid pair.";
                     throw new UnexpectedValueException($msg);
                 }
                 break;
             case BaseType::DIRECTED_PAIR:
                 if (Format::isDirectedPair($string)) {
                     $pair = explode(" ", $string);
                     return new DirectedPair($pair[0], $pair[1]);
                 } else {
                     $msg = "'{$string}' is not a valid directed pair.";
                     throw new UnexpectedValueException($msg);
                 }
                 break;
             case BaseType::DURATION:
                 if (Format::isDuration($string)) {
                     return new Duration($string);
                 } else {
                     $msg = "'{$string}' is not a valid duration.";
                     throw new UnexpectedValueException($msg);
                 }
                 break;
             case BaseType::FILE:
                 throw new \RuntimeException("Unsupported baseType: file.");
                 break;
             case BaseType::STRING:
                 return '' . $string;
                 break;
//.........这里部分代码省略.........
开发者ID:hutnikau,项目名称:qti-sdk,代码行数:101,代码来源:Utils.php


注:本文中的qtism\common\utils\Format::isFloat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。