Esempio n. 1
0
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
namespace Flikore\Validator;

require '../autoload.php';
use Flikore\Validator\Validators as v;
// Use the ValidationCombo class to reunite validators.
$combo = new ValidationCombo();
// Add as many validators as you want
$combo->addValidator(new v\ExactLengthValidator(5));
$combo->addValidator(new v\NotEmptyValidator());
// Both conditions met
var_dump($combo->validate('12345'));
// bool(true)
// Not empty, but too short
var_dump($combo->validate('1234'));
// bool(false)
// Not empty, but too long
var_dump($combo->validate('123456'));
// bool(false)
// Empty
var_dump($combo->validate(''));
// bool(false)
Esempio n. 2
0
 public function testZeroValidator()
 {
     $v = new ValidationCombo();
     // no validator, anything is ok
     $this->assertTrue($v->validate('654'));
     $this->assertTrue($v->validate(654));
     $this->assertTrue($v->validate('sda'));
     $this->assertTrue($v->validate('sda123'));
     $this->assertTrue($v->validate(array(2)));
     $this->assertTrue($v->validate(new \stdClass()));
     $this->assertTrue($v->validate(''));
     $this->assertTrue($v->validate(null));
 }