一款轻量级的数据映射器,旨在利用 PHP 5.3+
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.
ROADMAP for more details on future plans.
InstallingEasiest way is to install via composer http://packagist.org/packages/lox/pheasant.
composer require lox/pheasantEach 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.
…Many variations of finders are available for locating objects:
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', ]]);
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.
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 usersCode can be triggered before and after create, update and delete operations.
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:
Transactions can be created globally:
'First Post!'));
$post->save();
});
Or transactions can be invoked on an instance:
'First Post!'));
$post->transaction(function($obj) {
$obj->save();
});
Many thanks to @dhotson, @michaeldewildt, @rbone, @harto, @jorisleker, @tombb, @Jud, @bjornpost, @creativej
暂无开放 Issues,或尚未同步最近议题。