/** * @see DataValueChecker::supportsDataValue * * @param DataValue $dataValue * @return boolean */ public function supportsDataValue(DataValue $dataValue) { return $dataValue->getType() === $this->minValue->getType(); }
/** * @dataProvider instanceProvider * @param DataValue $value * @param array $arguments */ public function testToArray(DataValue $value, array $arguments) { $array = $value->toArray(); $this->assertInternalType('array', $array); $this->assertTrue(array_key_exists('type', $array)); $this->assertTrue(array_key_exists('value', $array)); $this->assertEquals($value->getType(), $array['type']); $this->assertEquals($value->getArrayValue(), $array['value']); }
/** * Validates the given data value using the given data type. * * @param DataValue $dataValue * @param string $dataTypeId * * @return Result */ public function validateDataValue(DataValue $dataValue, $dataTypeId) { $dataValueType = $this->dataTypeFactory->getType($dataTypeId)->getDataValueType(); if ($dataValue instanceof UnDeserializableValue) { $result = Result::newError(array(Error::newError('Bad snak value: ' . $dataValue->getReason(), null, 'bad-value', array($dataValue->getReason())))); } elseif ($dataValueType != $dataValue->getType()) { $result = Result::newError(array(Error::newError('Bad value type: ' . $dataValue->getType() . ', expected ' . $dataValueType, null, 'bad-value-type', array($dataValue->getType(), $dataValueType)))); } else { $result = Result::newSuccess(); } //XXX: DataTypeValidatorFactory should expose only one validator, which would be a CompositeValidator foreach ($this->validatorFactory->getValidators($dataTypeId) as $validator) { $subResult = $validator->validate($dataValue); //XXX: Some validators should be fatal and cause us to abort the loop. // Others shouldn't. if (!$subResult->isValid()) { //TODO: Don't bail out immediately. Accumulate errors from all validators. // We need Result::merge() for this. return $subResult; } } return $result; }
/** * @see ValueFormatter::format * * Formats the given value by finding an appropriate formatter among the ones supplied * to the constructor, and applying it. * * If $dataTypeId is given, this will first try to find an appropriate formatter based on * the data type. If none is found, this falls back to finding a formatter based on the * value's type. * * @see TypedValueFormatter::formatValue * * @param DataValue $value * @param string|null $dataTypeId * * @throws FormattingException * @return string */ public function formatValue(DataValue $value, $dataTypeId = null) { $formatter = $this->getFormatter($value->getType(), $dataTypeId); $text = $formatter->format($value); return $text; }
/** * Get Wikibase value type name for ontology * * @param DataValue $val * * @return string */ public function getValueTypeName(DataValue $val) { return ucfirst($val->getType()) . 'Value'; }
/** * @param DataValue $value * * @return boolean */ private function isUnDeserializableValue(DataValue $value) { return $value->getType() === UnDeserializableValue::getType(); }