PHPackages                             yapo/yapo - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. yapo/yapo

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

yapo/yapo
=========

310PHP

Since Feb 24Pushed 12y ago1 watchersCompare

[ Source](https://github.com/zealotrunner/Yapo)[ Packagist](https://packagist.org/packages/yapo/yapo)[ RSS](/packages/yapo-yapo/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (2)Used By (0)

Yapo
====

[](#yapo)

Yet Another PHP ORM

[![Latest Stable Version](https://camo.githubusercontent.com/8ae97055115f4a906e9c8d54a3e2011639ee218a21247f53f18890ef80d745a9/68747470733a2f2f706f7365722e707567782e6f72672f7961706f2f7961706f2f762f737461626c652e706e67)](https://packagist.org/packages/yapo/yapo)[![Build Status](https://camo.githubusercontent.com/f921468278c11e615340d62b79a508c184c4b835fc21d4b875ba5c46742ee9ff/68747470733a2f2f7472617669732d63692e6f72672f7a65616c6f7472756e6e65722f5961706f2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/zealotrunner/Yapo)[![Coverage Status](https://camo.githubusercontent.com/e678bd03ed1d128d4c5267d20a2ae6c25b7fef1d838629553c287d1415a1b07d/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f7a65616c6f7472756e6e65722f5961706f2f62616467652e706e67)](https://coveralls.io/r/zealotrunner/Yapo)[![Dependencies Status](https://camo.githubusercontent.com/cf06e224793204ffb7f814d61d6d4576c3fcc69f99ebb3999d9cc49dc8a8db37/68747470733a2f2f646570656e64696e672e696e2f7a65616c6f7472756e6e65722f5961706f2e706e67)](http://depending.in/zealotrunner/Yapo)[![License](https://camo.githubusercontent.com/3fc0233b3b6a52cebfc383c4a919d11f3ad20d5c512e6527237c03bbfc14f38c/68747470733a2f2f706f7365722e707567782e6f72672f7961706f2f7961706f2f6c6963656e73652e706e67)](https://packagist.org/packages/yapo/yapo)

Usage
-----

[](#usage)

```
$_ = Company::_();

$company = Company::get(10);        // SELECT * FROM `company` WHERE `id` = 10

$companies = Company::filter(       // SELECT * FROM `company`
    $_('name')->like('%oo%'),       // WHERE ( `name` LIKE '%oo%'
    $_('is_public')->eq(true)       // AND `is_pubilc` = 1 )
)->or(
    $_('employees')->gt('10000')    // OR ( `employees` > 10000 )
);

foreach ($companies as $company) {
    echo $company->name;
    echo $company->ceo->name;       // SELECT * FROM `employee` WHERE
                                    // `id` = {$company->ceo}
    echo $company->ceo->sex->text();
}

$companies_ceo_born_after_1972 = Company::filter(
    $_('ceo')->_('born')->gt(1972)

    // SELECT `id` FROM `company` WHERE ( `ceo_id`
    //     IN (SELECT `id` FROM `employee` WHERE `born` > '1972'))
);
```

Model Definition
----------------

[](#model-definition)

```
class Company extends Yapo\Yapo {

    public static function table() {
        return 'CompanyTable';
    }

    protected static function define_fields($define) {

        $define('name')             ->as('name'); // ->of('CompanyTable');

        $define('founded')          ->as('founded'); // ->of('CompanyTable');

        $define('symbol')           ->as('nasdaq_symbol'); // ->of('CompanyTable');

        $define('description')      ->as('description')->of('CompanyDetailTable')
                                    ->using('id');

        $define('ceo')              ->as('Employee')
                                    ->using('ceo');

        $define('employees')        ->as('Employee')
                                    ->with('company');

        $define('brief')            ->as(function($row) {
                                        return "{$row['name']}, founded in {$row['founded']}.";
                                    }); // ->of('CompanyTable');

        $define('special')          ->as('special')->switch(array(
                                        '0' => 'Company',
                                        '1' => 'SpecialCompany'
                                    ));
    }

    // define instance methods
    public function introduce() {
        return $this->brief;
    }

}

/*
 * SpecialCompany is a submodel
 */
class SpecialCompany extends Company {

    protected static function define_fields($define) {
        // inherit all fields defined in Company

        $define('why')          ->as('why')->of('SpecialCompanyTable')
                                ->using('id');

    }

    // overwrite Company::introduce()
    public function introduce() {
        return "[{$this->why}] {$this->brief}";
    }
}
```

```
class Employee extends Yapo\Yapo {

    public static function table() {
        return 'EmployeeTable';
    }

    protected static function define_fields($define) {

        $define('name')             ->as('name');

        $define('sex')              ->as('sex')
                                    ->enum(array(
                                        0 => '?',
                                        1 => 'Male',
                                        2 => 'Female'
                                    ));

        $define('company')          ->as('Company')->using('company_id');
    }

}
```

```
class CompanyTable extends Yapo\YapoTable {

    public static function master() {
        return new Yapo\YapoConfig(
            $dsn      = TEST_DSN,
            $user     = TEST_USER,
            $password = TEST_PASS,
            $table    = 'company',
            $pk       = 'id'
        );
    }
}

class CompanyDetailTable extends Yapo\YapoTable {

    public static function master() {
        return new Yapo\YapoConfig(
            $dsn      = TEST_DSN,
            $user     = TEST_USER,
            $password = TEST_PASS,
            $table    = 'company_detail',
            $pk       = 'id'
        );
    }
}

class SpecialCompanyTable extends Yapo\YapoCachedTable {

    public static function master() {
        return new Yapo\YapoConfig(
            $dsn      = TEST_DSN,
            $user     = TEST_USER,
            $password = TEST_PASS,
            $table    = 'special_company',
            $pk       = 'id'
        );
    }
}

class EmployeeTable extends Yapo\YapoTable {

    public static function master() {
        return new Yapo\YapoConfig(
            $dsn      = TEST_DSN,
            $user     = TEST_USER,
            $password = TEST_PASS,
            $table    = 'employee',
            $pk       = 'id'
        );
    }
}
```

---

1. local fields

    ```
     $define('symbol')       ->as('n_symbol');

         Company
     ---------------
     |             |
     |  *n_symbol* |
     |             |
     ---------------

    ```
2. another model as a field

    ```
     //
     $define('ceo')          ->as('Employee')
                             ->using('ceo_id');

         Company           *Employee*
     ---------------     --------------
     |             |     |            |
     |    ceo_id   | - > |            |
     |             |     |            |
     ---------------     --------------

     //
     $define('employees')    ->as('Employee')
                             ->with('company');

         Company           *Employee*
     ---------------     --------------
     |             |     |            |
     |             | < - |  company   |
     |             |     |            |
     ---------------     --------------

    ```
3. another column as a field

    ```
     //
     $define('description')  ->as('description')
                             ->of('CompanyDetailTable')
                             ->using('id');

        Company           CompanyDetailTable
     ---------------     -------------------
     |             |     |                 |
     |     id      | - > |  *description*  |
     |             |     |                 |
     ---------------     -------------------

     // ...

    ```

Test
----

[](#test)

Install [Composer](https://github.com/composer/composer)

```
cd yapo
curl -sS https://getcomposer.org/installer | php
php composer.phar install --dev
php composer.phar dumpautoload -o
```

Prepare for testing

```
./tests/generate_test_sqlite
```

Test

```
./vendor/bin/phpunit tests/YapoTest.php
```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/534380?v=4)[Sean Zheng](/maintainers/zealotrunner)[@zealotrunner](https://github.com/zealotrunner)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[dompdf/php-font-lib

A library to read, parse, export and make subsets of different types of font files.

1.8k45.3M11](/packages/dompdf-php-font-lib)[pear/pear_exception

The PEAR Exception base class.

9885.4M123](/packages/pear-pear-exception)[illuminate/config

The Illuminate Config package.

10944.5M2.5k](/packages/illuminate-config)[consolidation/site-alias

Manage alias records for local and remote sites.

6152.1M28](/packages/consolidation-site-alias)

PHPackages © 2026

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