/**
  * @see ValueValidator::validate()
  *
  * @param DataValue $value The value to validate
  *
  * @throws InvalidArgumentException
  * @return Result
  */
 public function validate($value)
 {
     if (!$value instanceof DataValue) {
         throw new InvalidArgumentException('DataValue expected');
     }
     $arrayValue = $value->getArrayValue();
     $result = $this->validator->validate($arrayValue);
     return $result;
 }
 /**
  * @see ValueValidator::validate()
  *
  * @param array $data The data array to validate
  *
  * @return Result
  * @throws InvalidArgumentException
  */
 public function validate($data)
 {
     if (!is_array($data)) {
         //XXX: or should this just be reported as invalid?
         throw new InvalidArgumentException('DataValue is not represented as an array');
     }
     if (!isset($data[$this->field])) {
         return Result::newError(array(Error::newError('Required field ' . $this->field . ' not set', $this->field, 'missing-field', array($this->field))));
     }
     $fieldValue = $data[$this->field];
     $result = $this->validator->validate($fieldValue);
     // TODO: include the field name in the error report
     return $result;
 }
 /**
  * @param ValueParser $parser
  * @param string $value
  * @param ValueValidator|null $validator
  *
  * @return array
  */
 private function parseStringValue(ValueParser $parser, $value, ValueValidator $validator = null)
 {
     $result = array('raw' => $value);
     try {
         $parseResult = $parser->parse($value);
     } catch (ParseException $parseError) {
         $this->addParseErrorToResult($result, $parseError);
         return $result;
     }
     if ($parseResult instanceof DataValue) {
         $result['value'] = $parseResult->getArrayValue();
         $result['type'] = $parseResult->getType();
     } else {
         $result['value'] = $parseResult;
     }
     if ($validator) {
         $validatorResult = $validator->validate($parseResult);
         $validationStatus = $this->validatorErrorLocalizer->getResultStatus($validatorResult);
         $result['valid'] = $validationStatus->isOK();
         if (!$validationStatus->isOK()) {
             $result['error'] = 'ValidationError';
             $this->errorReporter->addStatusToResult($validationStatus, $result);
             $result['validation-errors'] = $this->getValidatorErrorCodes($validatorResult->getErrors());
         }
     }
     return $result;
 }
 /**
  * Returns the list of allowed values, or false if there is no such restriction.
  *
  * @since 1.0
  *
  * @return array|boolean false
  */
 public function getAllowedValues()
 {
     $allowedValues = array();
     // TODO: properly implement this
     $this->validator->setOptions($this->options);
     if ($this->validator !== null && method_exists($this->validator, 'getWhitelistedValues')) {
         $allowedValues = $this->validator->getWhitelistedValues();
         if ($allowedValues === false) {
             $allowedValues = array();
         }
     }
     return $allowedValues;
 }