/** * Optional * * This allows the OPTIONAL flag to be set through the fluent Facade. The * presence of this method means that no validator with a base name of * "Optional" could ever by set through the Facade. Hopefully this isn't * likely to happen... * * NOTE: Currently, this does not work when the field whose flag is to be * toggled is actually a pattern. It only works with plain field names and * arrays of field names. * * @param bool Optional flag value. Default: true * @returns Zend_Validate_Builder_FluentAdder * @throws Zend_Validate_Exception */ public function optional($value = true) { foreach ($this->_rowIds as $id) { $value && $this->_builder->addFlags($id, Zend_Validate_Builder::OPTIONAL); } return $this; }
public function testAddFlagsMergesFlags() { $mockVal1 = $this->getMock('Zend_Validate_Abstract'); $zvb = new Zend_Validate_Builder(); $i0 = $zvb->add($mockVal1, 'test1'); $zvb->addFlags($i0, Zend_Validate_Builder::OPTIONAL); $this->assertEquals(Zend_Validate_Builder::OPTIONAL, $zvb->getFlags($i0)); $zvb->addFlags($i0, Zend_Validate_Builder::PATTERN); $this->assertEquals(Zend_Validate_Builder::PATTERN | Zend_Validate_Builder::OPTIONAL, $zvb->getFlags($i0)); }