<?php $o = new weeStringValidator(array('max' => 42)); $o->setValue($sValue); if ($o->hasError()) { // $sValue has a length greater than 42. echo $o->getError(); } else { // $sValue is valid, its length is smaller than or equal to 42, doSomething($sValue); }
<?php class CastableInput_testStringValidator { public function __toString() { return '42'; } } // weeStringValidator should throw a DomainException if the value is neither a scalar, the null value, an array, // an instance of Printable or an object castable to string. $o = new weeStringValidator(); try { $o->setValue(new stdClass()); $this->fail(_WT('weeStringValidator should throw a DomainException when the value is an object which is neither an instance of Printable nor an object castable to string.')); } catch (DomainException $e) { } try { $o->setValue(true); } catch (DomainException $e) { $this->fail(_WT('weeStringValidator should not throw a DomainException when the value is a boolean.')); } try { $o->setValue(null); } catch (DomainException $e) { $this->fail(_WT('weeStringValidator should not throw a DomainException when the value is null.')); } try { $o->setValue(array()); } catch (DomainException $e) { $this->fail(_WT('weeStringValidator should not throw a DomainException when the value is an array.'));
<?php weeStringValidator::test($s, array('min' => 1)) or burn('UnexpectedValueException', 'The given string is empty.');