PHPackages                             wscore/datamapper - 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. [Database &amp; ORM](/categories/database)
4. /
5. wscore/datamapper

ActiveLibrary[Database &amp; ORM](/categories/database)

wscore/datamapper
=================

DataMapper.

0.1.0(12y ago)055[2 issues](https://github.com/asaokamei/WScore.DataMapper/issues)1PHP

Since Aug 25Pushed 12y ago1 watchersCompare

[ Source](https://github.com/asaokamei/WScore.DataMapper)[ Packagist](https://packagist.org/packages/wscore/datamapper)[ RSS](/packages/wscore-datamapper/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (5)Used By (1)

WScore.DataMapper
=================

[](#wscoredatamapper)

A simple data mapper component.

Entity
------

[](#entity)

Entity is a class that roughly represents a record of a database table.

The class is not pure; one needs to extend an EntityAbstract and set a modelName to use it in this component. For example

```
namespace Tasks\Entity;

class Task extends EntityAbstract
{
    const STATUS_ACTIVE = '1';
    const STATUS_DONE   = '9';

    public static $_modelName = '\App\Tasks\Model\Tasks';
    public $task_id = null;
    public $memo = '';
    public $status = self::STATUS_ACTIVE;
}
```

Properties should be defined as public for PDO to populate the value.

A public static variable $\_modelName should reference to the model class to handle this entity.

Models
------

[](#models)

Model class(es) determines how an entity object be

- saved to a database,
- represented in html forms,
- validated its value.

The models is consisted of several classes:

- WScore\\DataMapper\\Model a master controller model for all other models.
- WScore\\DataMapper\\Model\\Persistence manages how to access database layer.
- WScore\\DataMapper\\Model\\Presentation manages html form presentation, as well as validation.
- WScore\\DataMapper\\Model\\Property a hidden object to control attribute of each properties for Persistence and Presentation models.

```
class Tasks extends Model
{
    /** @var string     name of database table     */
    protected $table = 'task';

    /** @var string     name of primary key        */
    protected $id_name = 'task_id';

    public function __construct()
    {
        parent::__construct();
        $csv = file_get_contents( __DIR__ . '/tasks.csv' );
        $this->property->prepare( $csv );
    }
}
```

All models are PHP code.

Possible to overwrite/hack/rewrite any of the models to suite need.

Attributes of entity's properties is defined by CSV.

TODO: Presentation model simply returns information about html form and validation. maybe model should be responsible to construct form and perform validation.

Role
----

[](#role)

A simple wrapper for entities to provide use-case specific methods called interactions.

Following shows an example to load post data into entity, validate value, and save to database.

```
$task = $this->em->fetch( 'Tasks\Entity\Task' );
$role = $this->role->applyDataIO( $task );
$role->load( $_POST );
if( $role->validate() ) {
    $active = $this->role->applyActive( $role );
    $active->save();
}
```

Relation
--------

[](#relation)

defines how entity is related to other entities.

Available relations are: HasOne, Joined, and JoinBy.

Some relation, such as isJoined, requires models to be defined.

Property Annotation
-------------------

[](#property-annotation)

write down the following annotations in PHP or CSV.

- column:

    database column name.
- title:

    human readable name for the column.
- type:

    type of the column; string, number, char (i.e. only ascii code), datetime, date, time, created\_at (i.e. datetime), updated\_at (i.e. datetime), etc.
- dbDef:

    database definition. not really used.
- notNull:

    not null or not. not really used.
- default:

    specify the default value used for validation. maybe used for presentation html as default value.
- required:

    used for validation. will be used for presentation for html form, marked as required.
- protected:

    indicates the column will not be mass-assigned.
- presentedAs:

    overwrites types for presentation html. specify types such as textarea, radio, check, etc.
- style:

    form/tags style.
- validateAs:

    overwrites types for validation rule. specify types such as tel, mail, etc.
- pattern:

    regular expression

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

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

Total

2

Last Release

4625d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8ed783829e6fa0bd4b0def8c04ccfdfb2fc99f9e61e4a9470acad9e5abc5fcac?d=identicon)[asaokamei](/maintainers/asaokamei)

---

Top Contributors

[![asaokamei](https://avatars.githubusercontent.com/u/747030?v=4)](https://github.com/asaokamei "asaokamei (287 commits)")

### Embed Badge

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

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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