besanek/const-validator

Simple tester for validating value given by constant.

dev-master 2013-09-03 16:47 UTC

This package is auto-updated.

Last update: 2024-11-10 21:44:10 UTC


README

Validating parameters defined by constants.

Simple example

Because simple example is better than a thousand words.

User entity (without PHPDoc, constructor, getters, etc.):

<?php

use ConstValidator\Validator as Constant;

class UserEntity {

    private $role;

    public function setRole($role)
    {
        if(!Constant::validate("UserEntity::ROLE_*", $role)){
            throw new Exception("Invalid role");
        }
        $this->role = $role;
    }

    const ROLE_MEMBER    = 'member';
    const ROLE_MODERATOR = 'moderator';
    const ROLE_ADMIN     = 'admin';
}