Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

pheasant

> 编程语言
Open source

A lightweight data mapper designed to take advantage of PHP 5.3+

100 stars0 likes0 views
WebsiteGitHub

About

A lightweight data mapper designed to take advantage of PHP 5.3+

Pheasant

Pheasant is an object relational mapper written to take advantage of PHP 7. Simple relationships are supported, with the emphasis being on scalability and performance over complexity.

Pheasant doesn't attempt to abstract the database and makes heavy use of MySQL/Innodb features.

Status of Development

Running in production on 99designs.com. See ROADMAP for more details on future plans. Installing

Easiest way is to install via composer http://packagist.org/packages/lox/pheasant.

bash
composer require lox/pheasant

Persisting Objects

Each domain object has a set of properties and relationships that are defined in the configure method. Each domain object delegates to a mapper object for the actual saving and loading of objects.

…

Magical Finders

Many variations of finders are available for locating objects:

php
Comment;

// to prevent the n+1 query issue, eager load the relation:
$users = User::all()->includes(['Comment']); // $users[0]->Comment will not hit db

// eager loading also has support for eager loading sub-relations
$users = User::all()->includes(['Comment' => [ 'Like', ]]);

Collection Scoping

Scoping allows you to specify commonly-used queries which can be referenced as method calls on Collection objects. All scope methods will return a Pheasant::Collection object which will allow for further methods (such as other scopes) to be called on it.

To define a simple scope, we first define a scopes method in our DomainObject that returns an associative array in "methodName" => $closure form.

php
use \Pheasant;
Class User extends DomainObject
{
  public function scopes()
  {
    return array(
      'active' => function($collection){
        $collection->filter('last_login_date >= ?', strtotime('30 days ago'));
      },
    );
  }
}

// Scopes may be used by invoking them like methods
User::all()->active()
//=> Returns all active users

Events

Code can be triggered before and after create, update and delete operations.

php
 new Types\SequenceType(),
      'title'       => new Types\StringType(255),
      'timecreated' => new Types\IntegerType(11),
      ));
  }

  public function beforeCreate($post)
  {
    $d->timecreated = time();
  }
}

Optionally, domain objects provide the following implicit hooks which can be overriden:

  • afterCreate
  • beforeUpdate, afterUpdate

Transactions

Transactions can be created globally:

php
'First Post!'));
  $post->save();
});

Or transactions can be invoked on an instance:

php
'First Post!'));

$post->transaction(function($obj) {
  $obj->save();
});

Contributors

Many thanks to @dhotson, @michaeldewildt, @rbone, @harto, @jorisleker, @tombb, @Jud, @bjornpost, @creativej

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHP

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言