PHPackages                             lfbn/base-model - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. lfbn/base-model

ActiveLibrary[Testing &amp; Quality](/categories/testing)

lfbn/base-model
===============

This is a Base Model that can be extended to define Models. It helps handling data validation, and extracting data.

1.0.5(8y ago)05MITPHPPHP ^7.1

Since Feb 13Pushed 8y ago1 watchersCompare

[ Source](https://github.com/lfbn/base-model)[ Packagist](https://packagist.org/packages/lfbn/base-model)[ Docs](https://github.com/lfbn/base-model)[ RSS](/packages/lfbn-base-model/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (6)Dependencies (8)Versions (6)Used By (0)

About Base Model
================

[](#about-base-model)

- [Features](#features)
- [Installation](#installation)
- [Examples](#examples)

This is a Base Model that can be extended to define Models. It helps handling data validation, and data conversion.

Features
--------

[](#features)

- Validation of properties. All, except the isNotEmpty, doesn't validate the data if it is empty. The following validator are available:
    - isNotEmpty
    - isNumeric
    - isInteger
    - isFloat
    - isString
    - isBoolean
    - isTrue
    - isFalse
    - isNull
    - isNotNull
    - isArray
    - isEmail
- Model to array and JSON, preserving hidden attributes.
- Define attributes using arrays of data.
- Can define, when validation fails, if an exception is thrown.
- Can define if data should be validated or not.

Installation
------------

[](#installation)

```
composer require lfbn/base-model
```

Examples
--------

[](#examples)

### How to use it

[](#how-to-use-it)

Define your model extending the AbstractBaseModel, then implement a public method getValidationRules. This method should define the properties you want to validate.

Here is an example:

```
class User extends AbstractBaseModel
{

    /**
     * @var int
     */
    protected $id;

    /**
     * @var string
     */
    protected $name;

    /**
     * @var float
     */
    protected $height;

    /**
     * @var boolean
     */
    protected $active;

    /**
     * @return int
     */
    public function getId(): int
    {
        return $this->id;
    }

    /**
     * @param int $id
     */
    public function setId(int $id): void
    {
        $this->id = $id;
    }

    /**
     * @return string
     */
    public function getName(): string
    {
        return $this->name;
    }

    /**
     * @param string $name
     */
    public function setName(string $name): void
    {
        $this->name = $name;
    }

    /**
     * @return float
     */
    public function getHeight(): float
    {
        return $this->height;
    }

    /**
     * @param float $height
     */
    public function setHeight(float $height): void
    {
        $this->height = $height;
    }

    /**
     * @return bool
     */
    public function isActive(): bool
    {
        return $this->active;
    }

    /**
     * @param bool $active
     */
    public function setActive(bool $active): void
    {
        $this->active = $active;
    }

    /**
     * @return array
     */
    public function getValidationRules()
    {
        return [
            ['property' => 'id', 'validator' => 'isNotEmpty'],
            ['property' => 'id', 'validator' => 'isInteger'],
            ['property' => 'height', 'validator' => 'isFloat'],
            ['property' => 'active', 'validator' => 'isBoolean']
        ];
    }
}
```

How to know if is valid?
------------------------

[](#how-to-know-if-is-valid)

You need to call the `validate()` method

```
$user = new User();
$user->validate();
```

Can I use my own validator?
---------------------------

[](#can-i-use-my-own-validator)

Yes. It only needs to implement the interface IValidator.

```
$user = new User();
$myValidator = new MyValidator();
$user->setValidator($myValidator);
```

Can I use my own converter?
---------------------------

[](#can-i-use-my-own-converter)

Yes. It only needs to implement the interface IConverter.

```
$user = new User();
$myConverter = new MyConverter();
$user->setConverter($myConverter);
```

About
-----

[](#about)

### Requirements

[](#requirements)

- Base Model works with PHP 7 or above.

### Running Tests

[](#running-tests)

You can run the tests executing the following command. Before you can run these, be sure to run `composer install`.

```
composer test
```

### Submitting bugs and feature requests

[](#submitting-bugs-and-feature-requests)

Bugs and feature request are tracked on [GitHub](https://github.com/lfbn/base-model/issues)

### License

[](#license)

Base Model is licensed under the MIT License - see the `LICENSE` file for details

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

4

Last Release

3048d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6152567?v=4)[Luís Nóbrega](/maintainers/lfbn)[@lfbn](https://github.com/lfbn)

---

Top Contributors

[![lfbn](https://avatars.githubusercontent.com/u/6152567?v=4)](https://github.com/lfbn "lfbn (1 commits)")

---

Tags

mockerymodelphpphpunitvalidationmodel

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/lfbn-base-model/health.svg)

```
[![Health](https://phpackages.com/badges/lfbn-base-model/health.svg)](https://phpackages.com/packages/lfbn-base-model)
```

###  Alternatives

[phpro/grumphp

A composer plugin that enables source code quality checks.

4.3k16.7M997](/packages/phpro-grumphp)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.6k38.2k](/packages/matomo-matomo)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k101.9M622](/packages/beberlei-assert)[craftcms/cms

Craft CMS

3.6k3.6M3.0k](/packages/craftcms-cms)[infyomlabs/laravel-generator

InfyOm Laravel Generator

3.8k2.4M13](/packages/infyomlabs-laravel-generator)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k13](/packages/tempest-framework)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
