{"id":15284035,"url":"https://github.com/lfbn/base-model","last_synced_at":"2026-04-13T07:02:47.238Z","repository":{"id":57014409,"uuid":"120968548","full_name":"lfbn/base-model","owner":"lfbn","description":"This is a Base Model that can be extended to define Models. It helps handling data validation, and extracting data.","archived":false,"fork":false,"pushed_at":"2018-02-26T23:42:52.000Z","size":68,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-28T23:23:03.077Z","etag":null,"topics":["mockery","model","php","phpunit"],"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/lfbn.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-09T23:57:19.000Z","updated_at":"2018-02-25T23:41:50.000Z","dependencies_parsed_at":"2022-08-21T14:31:04.646Z","dependency_job_id":null,"html_url":"https://github.com/lfbn/base-model","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfbn%2Fbase-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfbn%2Fbase-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfbn%2Fbase-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfbn%2Fbase-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lfbn","download_url":"https://codeload.github.com/lfbn/base-model/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245138156,"owners_count":20566877,"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":["mockery","model","php","phpunit"],"created_at":"2024-09-30T14:48:52.462Z","updated_at":"2026-04-13T07:02:47.164Z","avatar_url":"https://github.com/lfbn.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About Base Model\n\n- [Features](#features)\n- [Installation](#installation)\n- [Examples](#examples)\n\nThis is a Base Model that can be extended to define Models. It helps handling data validation, and data conversion.\n\n## Features\n \n* Validation of properties. All, except the isNotEmpty, doesn't validate the data if it is empty. The following validator are available:\n  * isNotEmpty\n  * isNumeric\n  * isInteger\n  * isFloat\n  * isString\n  * isBoolean\n  * isTrue\n  * isFalse\n  * isNull\n  * isNotNull\n  * isArray\n  * isEmail\n* Model to array and JSON, preserving hidden attributes.\n* Define attributes using arrays of data.\n* Can define, when validation fails, if an exception is thrown.\n* Can define if data should be validated or not.\n\n## Installation\n\n```bash\ncomposer require lfbn/base-model\n```\n\n## Examples\n\n### How to use it\n\nDefine your model extending the AbstractBaseModel, then implement a public method getValidationRules. This method should define the properties you want to validate.\n\nHere is an example:\n\n```php\nclass User extends AbstractBaseModel\n{\n\n    /**\n     * @var int\n     */\n    protected $id;\n\n    /**\n     * @var string\n     */\n    protected $name;\n\n    /**\n     * @var float\n     */\n    protected $height;\n\n    /**\n     * @var boolean\n     */\n    protected $active;\n\n    /**\n     * @return int\n     */\n    public function getId(): int\n    {\n        return $this-\u003eid;\n    }\n\n    /**\n     * @param int $id\n     */\n    public function setId(int $id): void\n    {\n        $this-\u003eid = $id;\n    }\n\n    /**\n     * @return string\n     */\n    public function getName(): string\n    {\n        return $this-\u003ename;\n    }\n\n    /**\n     * @param string $name\n     */\n    public function setName(string $name): void\n    {\n        $this-\u003ename = $name;\n    }\n\n    /**\n     * @return float\n     */\n    public function getHeight(): float\n    {\n        return $this-\u003eheight;\n    }\n\n    /**\n     * @param float $height\n     */\n    public function setHeight(float $height): void\n    {\n        $this-\u003eheight = $height;\n    }\n\n    /**\n     * @return bool\n     */\n    public function isActive(): bool\n    {\n        return $this-\u003eactive;\n    }\n\n    /**\n     * @param bool $active\n     */\n    public function setActive(bool $active): void\n    {\n        $this-\u003eactive = $active;\n    }\n\n    /**\n     * @return array\n     */\n    public function getValidationRules()\n    {\n        return [\n            ['property' =\u003e 'id', 'validator' =\u003e 'isNotEmpty'],\n            ['property' =\u003e 'id', 'validator' =\u003e 'isInteger'],\n            ['property' =\u003e 'height', 'validator' =\u003e 'isFloat'],\n            ['property' =\u003e 'active', 'validator' =\u003e 'isBoolean']\n        ];\n    }\n}\n```\n\n## How to know if is valid?\n\nYou need to call the `validate()` method\n\n```php\n$user = new User();\n$user-\u003evalidate();\n```\n\n## Can I use my own validator?\n\nYes. It only needs to implement the interface IValidator.\n\n```php\n$user = new User();\n$myValidator = new MyValidator();\n$user-\u003esetValidator($myValidator);\n```\n\n## Can I use my own converter?\n\nYes. It only needs to implement the interface IConverter.\n\n```php\n$user = new User();\n$myConverter = new MyConverter();\n$user-\u003esetConverter($myConverter);\n```\n\n## About\n\n### Requirements\n\n- Base Model works with PHP 7 or above.\n\n### Running Tests\n\nYou can run the tests executing the following command. Before you can run these, be sure to run `composer install`.\n\n```bash\ncomposer test\n```\n\n### Submitting bugs and feature requests\n\nBugs and feature request are tracked on [GitHub](https://github.com/lfbn/base-model/issues)\n\n### License\n\nBase Model is licensed under the MIT License - see the `LICENSE` file for details","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flfbn%2Fbase-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flfbn%2Fbase-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flfbn%2Fbase-model/lists"}