PHPackages                             vitalyspirin/simplephpactiverecord - 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. vitalyspirin/simplephpactiverecord

ActiveLibrary

vitalyspirin/simplephpactiverecord
==================================

Extension of PHP ActiveRecord with added automatically generated validators

1.0.1(9y ago)038MITHTMLPHP &gt;=5.4.0

Since Aug 15Pushed 9y ago1 watchersCompare

[ Source](https://github.com/vitalyspirin/simplephpactiverecord)[ Packagist](https://packagist.org/packages/vitalyspirin/simplephpactiverecord)[ Docs](https://github.com/vitalyspirin/SimplePHPActiveRecord)[ RSS](/packages/vitalyspirin-simplephpactiverecord/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

SimplePHPActiveRecord
=====================

[](#simplephpactiverecord)

Extension of PHP ActiveRecord (phpactiverecord.org) with automatically generated validators.

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

[](#installation)

```
composer require vitalyspirin/simplephpactiverecord

```

Quick Start
-----------

[](#quick-start)

```
class T1 extends \vitalyspirin\simplephpactiverecord\SimpleActiveRecord
{
    public static $validates_presence_of = [];
    public static $validates_size_of = [];
    public static $validates_numericality_of = [];
    public static $validates_uniqueness_of = [];
    public static $validates_inclusion_of = [];
    public static $validates_format_of = [];
}
```

There is no need to hardcode validators since they will be added automatically by class constructor based on table schema. However in current version relations (based on foreign keys) will not be added.

Static properties (validators) have to be added to every child model extending SimpleActiveRecord class because in PHP it's impossible to create static properties dynamically.

Instance of such class is created in a usual way:

```
$t1 = new T1();
```

If table schema changed then validators will be adjusted automatically.

Examples
--------

[](#examples)

Let's say we have the following SQL schema:

```
CREATE TABLE person
(
  person_id         INT PRIMARY KEY AUTO_INCREMENT,
  person_firstname  VARCHAR(35) NOT NULL,
  person_lastname   VARCHAR(35) NOT NULL,
  person_gender     ENUM('male', 'female'),
  person_dob        DATE NULL,
  person_salary     DECIMAL UNSIGNED
);
```

then if we run the following code:

```
class Person extends \vitalyspirin\simplephpactiverecord\SimpleActiveRecord
{
    static $table_name = 'person';

    public static $validates_presence_of = [];
    public static $validates_size_of = [];
    public static $validates_numericality_of = [];
    public static $validates_uniqueness_of = [];
    public static $validates_inclusion_of = [];
    public static $validates_format_of = [];
}

$person = new Person();

echo "validates_presence_of:";
var_dump($person::$validates_presence_of);

echo "validates_size_of:";
var_dump($person::$validates_size_of);

echo "validates_numericality_of:";
var_dump($person::$validates_numericality_of);

echo "validates_inclusion_of:";
var_dump($person::$validates_inclusion_of);
```

we will get the following output:

```
validates_presence_of:array(2) {
  [0] =>
  array(1) {
    [0] =>
    string(16) "person_firstname"
  }
  [1] =>
  array(1) {
    [0] =>
    string(15) "person_lastname"
  }
}
validates_size_of:array(2) {
  [0] =>
  array(2) {
    [0] =>
    string(16) "person_firstname"
    'maximum' =>
    int(35)
  }
  [1] =>
  array(2) {
    [0] =>
    string(15) "person_lastname"
    'maximum' =>
    int(35)
  }
}
validates_numericality_of:array(1) {
  [0] =>
  array(3) {
    [0] =>
    string(13) "person_salary"
    'greater_than_or_equal_to' =>
    int(0)
    'allow_null' =>
    bool(true)
  }
}
validates_inclusion_of:array(1) {
  [0] =>
  array(3) {
    [0] =>
    string(13) "person_gender"
    'in' =>
    array(2) {
      [0] =>
      string(4) "male"
      [1] =>
      string(6) "female"
    }
    'allow_null' =>
    bool(true)
  }
}

```

You can also see tests in [SimpleActiveRecordTest.php](tests/unit/SimpleActiveRecordTest.php) for simple examples.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 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 ~2 days

Total

2

Last Release

3552d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/402aacecdf4a5524cb6506fa9d8c332891936d011edb603650c72c73dbb4d930?d=identicon)[vitalyspirin](/maintainers/vitalyspirin)

---

Top Contributors

[![vitalyspirin](https://avatars.githubusercontent.com/u/7786743?v=4)](https://github.com/vitalyspirin "vitalyspirin (24 commits)")

---

Tags

active-recordactiverecordphp-activerecordsimpleactiverecordsimple active recordphpactiverecord

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/vitalyspirin-simplephpactiverecord/health.svg)

```
[![Health](https://phpackages.com/badges/vitalyspirin-simplephpactiverecord/health.svg)](https://phpackages.com/packages/vitalyspirin-simplephpactiverecord)
```

###  Alternatives

[cycle/active-record

Provides a simple way to work with your database using Active Record pattern and Cycle ORM

671.3k3](/packages/cycle-active-record)

PHPackages © 2026

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