{"id":20945083,"url":"https://github.com/vjik/yii2-rules-validator","last_synced_at":"2025-05-14T01:31:29.544Z","repository":{"id":62544840,"uuid":"278049059","full_name":"vjik/yii2-rules-validator","owner":"vjik","description":"Yii2 validator with nested rules","archived":false,"fork":false,"pushed_at":"2020-07-15T10:31:37.000Z","size":14,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-26T13:44:21.979Z","etag":null,"topics":[],"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/vjik.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}},"created_at":"2020-07-08T09:38:29.000Z","updated_at":"2020-09-17T17:48:32.000Z","dependencies_parsed_at":"2022-11-02T22:00:33.231Z","dependency_job_id":null,"html_url":"https://github.com/vjik/yii2-rules-validator","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vjik%2Fyii2-rules-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vjik%2Fyii2-rules-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vjik%2Fyii2-rules-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vjik%2Fyii2-rules-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vjik","download_url":"https://codeload.github.com/vjik/yii2-rules-validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225269316,"owners_count":17447507,"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","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":[],"created_at":"2024-11-18T23:46:38.332Z","updated_at":"2024-11-18T23:46:38.850Z","avatar_url":"https://github.com/vjik.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Yii2 validator with nested rules\n\n## Installation\n\nThe preferred way to install this extension is through [composer](https://getcomposer.org/download/):\n\n```\ncomposer require vjik/yii2-rules-validator\n```\n\n## Examples\n\n### Use in model\n\n```php\nclass MyModel extends Model\n{\n\n    public $country;\n\n    public function rules()\n    {\n        return [\n            [\n                'country',\n                RulesValidator::class,\n                'rules' =\u003e [\n                    ['trim'],\n                    ['string', 'max' =\u003e 191],\n                    ['validateCountry'],\n                ],\n            ],\n        ];\n    }\n\n    public function validateCountry($attribute, $params, $validator)\n    {\n        if (!in_array($this-\u003e$attribute, ['Russia', 'USA'])) {\n            $this-\u003eaddError($attribute, 'The country must be either \"Russia\" or \"USA\".');\n        }\n    }\n}\n```\n\n### Rule Inheritance \n\nRule class:\n\n```php\nclass MyRulesValidator extends RulesValidator\n{\n\n    protected function rules(): array\n    {\n        return [\n            ['trim'],\n            ['string', 'max' =\u003e 191],\n            ['validateCountry'],\n        ];\n    }\n\n    public function validateCountry($model, $attribute, $params, $validator)\n    {\n        if (!in_array($model-\u003e$attribute, ['Russia', 'USA'])) {\n            $model-\u003eaddError($attribute, 'The country must be either \"Russia\" or \"USA\".');\n        }\n    }\n}\n```\n\nModel:\n\n```php\nclass MyModel extends Model\n{\n\n    public $country;\n\n    public function rules()\n    {\n        return [\n            ['country', MyRulesValidator::class],\n        ];\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvjik%2Fyii2-rules-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvjik%2Fyii2-rules-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvjik%2Fyii2-rules-validator/lists"}