{"id":32471222,"url":"https://github.com/rougin/valla","last_synced_at":"2026-01-11T10:45:22.196Z","repository":{"id":303032828,"uuid":"1014193293","full_name":"rougin/valla","owner":"rougin","description":"A simple validation package in PHP.","archived":false,"fork":false,"pushed_at":"2025-10-26T02:35:23.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-26T04:19:42.353Z","etag":null,"topics":["php-validation","php-validator"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rougin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-05T08:24:23.000Z","updated_at":"2025-10-26T02:35:27.000Z","dependencies_parsed_at":"2025-07-05T09:35:10.247Z","dependency_job_id":"c9728b7a-350c-4aa1-a5ac-ff6099a631e1","html_url":"https://github.com/rougin/valla","commit_stats":null,"previous_names":["rougin/validia","rougin/valla"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rougin/valla","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rougin%2Fvalla","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rougin%2Fvalla/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rougin%2Fvalla/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rougin%2Fvalla/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rougin","download_url":"https://codeload.github.com/rougin/valla/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rougin%2Fvalla/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281139035,"owners_count":26450138,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-26T02:00:06.575Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php-validation","php-validator"],"created_at":"2025-10-26T16:57:01.264Z","updated_at":"2026-01-11T10:45:22.190Z","avatar_url":"https://github.com/rougin.png","language":"PHP","readme":"# Valla\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]][link-license]\n[![Build Status][ico-build]][link-build]\n[![Coverage Status][ico-coverage]][link-coverage]\n[![Total Downloads][ico-downloads]][link-downloads]\n\nA simple validation package based on [Valitron](https://github.com/vlucas/valitron).\n\n``` php\nuse Rougin\\Valla\\Check;\n\nclass UserCheck extends Check\n{\n    protected $labels = array(\n        'name' =\u003e 'Name',\n        'email' =\u003e 'Email',\n    );\n\n    protected $rules = array(\n        'name' =\u003e 'required',\n        'email' =\u003e 'required|email',\n    );\n}\n```\n\n## Installation\n\nInstall the package using [Composer](https://getcomposer.org/):\n\n``` bash\n$ composer require rougin/valla\n```\n\n## Basic usage\n\nThe core of `Valla` is the `Check` class which is used to create a set of validation rules:\n\n``` php\nuse Rougin\\Valla\\Check;\n\nclass UserCheck extends Check\n{\n    /**\n     * @var array\u003cstring, string\u003e\n     */\n    protected $labels =\n    [\n        'age' =\u003e 'Age',\n        'email' =\u003e 'Email',\n        'name' =\u003e 'Name',\n    ];\n\n    /**\n     * @var array\u003cstring, string\u003e\n     */\n    protected $rules =\n    [\n        'age' =\u003e 'required|numeric',\n        'email' =\u003e 'required|email',\n        'name' =\u003e 'required',\n    ];\n}\n```\n\nThe `$labels` property defines user-friendly names for the fields, which will be used in error messages:\n\n``` php\nuse Rougin\\Valla\\Check;\n\nclass UserCheck extends Check\n{\n    /**\n     * @var array\u003cstring, string\u003e\n     */\n    protected $labels =\n    [\n        'age' =\u003e 'Age',\n        'email' =\u003e 'Email',\n        'name' =\u003e 'Name',\n    ];\n\n    // ...\n}\n```\n\nWhile the `$rules` property specifies the validation rules for each field:\n\n``` php\nuse Rougin\\Valla\\Check;\n\nclass UserCheck extends Check\n{\n    // ...\n\n    /**\n     * @var array\u003cstring, string\u003e\n     */\n    protected $rules =\n    [\n        'age' =\u003e 'required|numeric',\n        'email' =\u003e 'required|email',\n        'name' =\u003e 'required',\n    ];\n}\n```\n\n\u003e [!NOTE]\n\u003e A list of available rules can be found in the [Valitron documentation](https://github.com/vlucas/valitron#validation-rules).\n\nOnce the `Check` class is created, it can be used to validate an array of data, such as data from a HTTP request:\n\n``` php\n$check = new UserCheck;\n\n$data = /* e.g., data from a request */;\n\nif (! $check-\u003evalid($data))\n{\n    // Get all available errors\n    $errors = $check-\u003eerrors();\n\n    // Or get only the first error\n    echo $check-\u003efirstError();\n\n    return;\n}\n\n// Data has passed validation\n```\n\n## Labels, rules\n\nFor more complex scenarios, the `labels` and `rules` methods can be overridden to define them dynamically:\n\n``` php\nuse Rougin\\Valla\\Check;\n\nclass UserCheck extends Check\n{\n    /**\n     * Returns the specified labels.\n     *\n     * @return array\u003cstring, string\u003e\n     */\n    public function labels()\n    {\n        $this-\u003elabels['is_company'] = 'Is a Company?';\n\n        return $this-\u003elabels;\n    }\n\n    /**\n     * Returns the specified rules based on the data.\n     *\n     * @param array\u003cstring, mixed\u003e $data\n     *\n     * @return array\u003cstring, string\u003e\n     */\n    public function rules($data)\n    {\n        if (array_key_exists('is_company', $data))\n        {\n            $this-\u003erules['company_name'] = 'required';\n        }\n\n        return $this-\u003erules;\n    }\n}\n```\n\n## Using PSR-7 requests\n\nIf using `ServerRequestInterface` from [PSR-7](https://www.php-fig.org/psr/psr-7/), the `Request` class provides a convenient way to validate request data:\n\n``` php\nuse Rougin\\Valla\\Request;\n\nclass UserCheck extends Request\n{\n    /**\n     * @var array\u003cstring, string\u003e\n     */\n    protected $aliases =\n    [\n        'username' =\u003e 'name',\n        'email_add' =\u003e 'email',\n        'new_age' =\u003e 'age',\n    ];\n\n    // ...\n}\n```\n\nThe `Request` class provides two methods for validation: `isParamsValid` for validating query parameters and `isParsedValid` for validating the parsed body:\n\n``` php\n$check = new UserCheck;\n\n// Should return the ServerRequestInterface ---\n$request = Http::getServerRequest();\n// --------------------------------------------\n\n// Checks against data from \"getQueryParams\" ---\nif ($check-\u003eisParamsValid($request))\n{\n    // Query parameters are valid\n}\n// ---------------------------------------------\n\n// Checks against data from \"getParsedBody\" ---\nif ($check-\u003eisParsedValid($request))\n{\n    // Parsed body is valid\n}\n// --------------------------------------------\n```\n\nWhen an alias is specified, it will be used to look for the field in the `ServerRequestInterface` data. For example, if the request data contains a `username` field, it will be validated against the rules defined for the `name` field.\n\n## Overriding the `valid` method\n\nWhen extending the `Request` class and overriding the `valid` method, the `setAlias` method must be called to apply the defined aliases:\n\n``` php\nuse Rougin\\Valla\\Request;\n\nclass UserCheck extends Request\n{\n    // ...\n\n    public function valid($data)\n    {\n        // Always include this if aliases are defined ---\n        $data = $this-\u003esetAlias($data);\n        // ----------------------------------------------\n\n        $valid = parent::valid($data);\n\n        if (! $valid)\n        {\n            return count($this-\u003eerrors) === 0;\n        }\n\n        // Add extra custom validation conditions here\n\n        return count($this-\u003eerrors) === 0;\n    }\n}\n```\n\n## Changelog\n\nPlease see [CHANGELOG][link-changelog] for more recent changes.\n\n## Contributing\n\nSee [CONTRIBUTING][link-contributing] on how to contribute to the project.\n\n## License\n\nThe MIT License (MIT). Please see [LICENSE][link-license] for more information.\n\n[ico-build]: https://img.shields.io/github/actions/workflow/status/rougin/valla/build.yml?style=flat-square\n[ico-coverage]: https://img.shields.io/codecov/c/github/rougin/valla?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/rougin/valla.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-version]: https://img.shields.io/packagist/v/rougin/valla.svg?style=flat-square\n\n[link-build]: https://github.com/rougin/valla/actions\n[link-changelog]: https://github.com/rougin/valla/blob/master/CHANGELOG.md\n[link-contributing]: https://github.com/rougin/valla/blob/master/CONTRIBUTING.md\n[link-coverage]: https://app.codecov.io/gh/rougin/valla\n[link-downloads]: https://packagist.org/packages/rougin/valla\n[link-license]: https://github.com/rougin/valla/blob/master/LICENSE.md\n[link-packagist]: https://packagist.org/packages/rougin/valla\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frougin%2Fvalla","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frougin%2Fvalla","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frougin%2Fvalla/lists"}