百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

pheasant

> 编程语言
开源

一款轻量级的数据映射器,旨在利用 PHP 5.3+

100 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一款轻量级的数据映射器,旨在利用 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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

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