コード例 #1
0
ファイル: Command.php プロジェクト: airmoi/filemaker
 /**
  * Pre-validates either a single field or the entire command.
  *
  * This method uses the pre-validation rules that are enforceable by the
  * PHP engine -- for example, type rules, ranges, and four-digit dates.
  * Rules such as "unique" or "existing," or validation by calculation
  * field, cannot be pre-validated.
  *
  * If you pass the optional $fieldName argument, only that field is
  * pre-validated. Otherwise, the command is pre-validated as if execute()
  * were called with "Enable record data pre-validation" selected in
  * FileMaker Server Admin Console. If pre-validation passes, validate()
  * returns TRUE. If pre-validation fails, then validate() throws a
  * \airmoi\FileMaker\FileMakerValidationException object containing details about what failed
  * to pre-validate.
  *
  * @param string $fieldName Name of field to pre-validate. If empty,
  *                          pre-validates the entire command.
  *
  * @return bool TRUE, if pre-validation passes.
  * @throws FileMakerException
  * @throws FileMakerValidationException
  */
 public function validate($fieldName = null)
 {
     if (!is_a($this, Add::class) && !is_a($this, Edit::class)) {
         return true;
     }
     $layout = $this->fm->getLayout($this->_layout);
     $validationErrors = new FileMakerValidationException($this->fm);
     if ($fieldName === null) {
         foreach ($layout->getFields() as $fieldName => $field) {
             if (!isset($this->_fields[$fieldName]) || !count($this->_fields[$fieldName])) {
                 $values = array(0 => null);
             } else {
                 $values = $this->_fields[$fieldName];
             }
             foreach ($values as $value) {
                 try {
                     $field->validate($value);
                 } catch (FileMakerValidationException $e) {
                     foreach ($e->getErrors() as $error) {
                         $validationErrors->addError($error[0], $error[1], $error[2]);
                     }
                 }
             }
         }
     } else {
         $field = $layout->getField($fieldName);
         if (!isset($this->_fields[$fieldName]) || !count($this->_fields[$fieldName])) {
             $values = array(0 => null);
         } else {
             $values = $this->_fields[$fieldName];
         }
         foreach ($values as $value) {
             try {
                 $field->validate($value);
             } catch (FileMakerValidationException $e) {
                 foreach ($e->getErrors() as $error) {
                     $validationErrors->addError($error[0], $error[1], $error[2]);
                 }
             }
         }
     }
     if ($validationErrors->numErrors()) {
         if ($this->fm->getProperty('errorHandling') === 'default') {
             return $validationErrors;
         }
         throw $validationErrors;
     }
     return true;
 }
コード例 #2
0
 /**
  * @covers \airmoi\FileMaker\FileMakerValidationException::getErrors
  * @depends testAddError
  */
 public function testGetMessage(FileMakerValidationException $exception)
 {
     $this->assertEquals(2, sizeof(explode("\n", $exception->getMessage())));
 }
コード例 #3
0
ファイル: Field.php プロジェクト: airmoi/filemaker
 public function checkTimeValidity($value, $rule, FileMakerValidationException $validationError, $shortHoursFormat)
 {
     if ($shortHoursFormat) {
         $format = 12;
     } else {
         $format = 24;
     }
     preg_match('#([0-9]{1,2})[:]([0-9]{1,2})[:]?([0-9]{1,2})?#', $value, $matches);
     $hours = $matches[1];
     $minutes = $matches[2];
     if (count($matches) >= 4) {
         $seconds = $matches[3];
     }
     if ($hours < 0 || $hours > $format) {
         $validationError->addError($this, $rule, $value);
     } elseif ($minutes < 0 || $minutes > 59) {
         $validationError->addError($this, $rule, $value);
     } elseif (isset($seconds)) {
         if ($seconds < 0 || $seconds > 59) {
             $validationError->addError($this, $rule, $value);
         }
     }
 }