ozziest/defencer

This package is abandoned and no longer maintained. No replacement package was suggested.

Defencer is a simple way to separate validation before method of repository.

1.3.0 2015-06-18 06:10 UTC

README

Defencer is a simple way to separate validations before method of repository.

Installation

To install through composer, simply put the following in your composer.json file:

{
    "require": {
        "ozziest/defencers": "dev-master",
    }
}

Usage

try {
    UserRepository::insert('John Doe');
} catch (Exception $e) {
    echo $e->getMessage();
}

Repository Definition

class UserRepository extends \Ozziest\Defencer\Defencer {

    /**
     * Get Defencer
     *
     * @return Array
     */ 
    public function getDefencers()
    {
        return array(
                'insert' => array(
                        'UserRepositoryValidation@name'
                    )
            );
    }

    /**
     * Insert 
     *
     * @param  string       $name 
     * @return null
     */
    public function _insert($name)
    {
        echo "Inserted: $name";
    }

}
class UserRepositoryValidation extends \Ozziest\Defencer\Validator {

    public $fields = array(
            'name', 'age'
        );

    /**
     * Name 
     * 
     * @throw Exception
     */
    public function name()
    {
        if ($this->name == '') {
            throw new \Exception('Name is required!');
        }
    }

}

Licence

MIT