TYPO3 CMS  TYPO3_6-2
BooleanValidator.php
Go to the documentation of this file.
1 <?php
3 
20 
24  protected $supportedOptions = array(
25  // The default is set to NULL here, because we need to be backward compatible here, because this
26  // BooleanValidator is called automatically on boolean action arguments. If we would set it to TRUE,
27  // every FALSE value for an action argument would break.
28  // TODO with next patches: deprecate this BooleanValidator and introduce a BooleanValueValidator, like
29  // in Flow, which won't be called on boolean action arguments.
30  'is' => array(NULL, 'Boolean value', 'boolean|string|integer')
31  );
32 
33 
44  public function isValid($value) {
45  // see comment above, check if expectation is NULL, then nothing to do!
46  if ($this->options['is'] === NULL) {
47  return;
48  }
49  switch (strtolower((string)$this->options['is'])) {
50  case 'true':
51  case '1':
52  $expectation = TRUE;
53  break;
54  case 'false':
55  case '':
56  case '0':
57  $expectation = FALSE;
58  break;
59  default:
60  $this->addError('The given expectation is not valid.', 1361959227);
61  return;
62  }
63 
64  if ($value !== $expectation) {
65  if (!is_bool($value)) {
66  $this->addError('The given subject is not true.', 1361959230);
67  } else {
68  if ($expectation) {
69  $this->addError('The given subject is not true.', 1361959228);
70  } else {
71  $this->addError('The given subject is not false.', 1361959229);
72  }
73  }
74  }
75  }
76 
77 }
addError($message, $code, array $arguments=array(), $title='')