rockeinstein/eloquent-zf2
Composer 安装命令:
composer require rockeinstein/eloquent-zf2
包简介
Eloquent ORM module for Zend Framework 2
README 文档
README
Eloquent ORM module for Zend Framework 2.
Features
Eloquent ModelandCapsulesuppot out of the box.Validatorsfor forms:RecordExistsandNoRecordExists(equivalent ofZend\Validator\Db\RecordExistsandZend\Validator\Db\noRecordExists).Authenticationadapters (Abstractimplementation supporting AuthenticationService and two implementationsCallbackCheckAdapterandCredentialTreatmentAdapter).
Planned Features
- Multi-connection configuration support.
- Caching support.
- Paginator support.
- Logger support.
- Session Handlers (not sure if needed yet).
- Migration support (via ZFTool).
Install
$ composer require edvinasme/eloquent-zf2:dev-master
Setup
- Add
EloquentZF2to themodulesarray inconfig/application.config.php - You can now retrieve EloquentZF2 via SM:
$sm->get('EloquentZF2')This gives you access to Eloquent Query Builder, Schema Builder etc. (see http://laravel.com/docs/database for more information) - Copy
vendor/edvinasme/eloquent-zf2/config/database.eloquent.config.php.disttoconfig/autoload/database.eloquent.config.phpand add database credentials.
Models
Your models should extend Illuminate\Database\Eloquent\Model for example:
<?php namespace Album\Model; // skipping some code here use Illuminate\Database\Eloquent\Model as EloquentZF2Model; class Album extends EloquentZF2Model implements InputFilterAwareInterface {
Validators
When populating InputFilter (usually in Model's getInputFilter() method), you
can use EloquentZF2\Validator\RecordExists or EloquentZF2\Validator\NoRecordExists
validators which will check records existance in the database and validate the
field accordingly.
The following option keys are supported:
table=> The database table to validate againstschema=> The schema (database) to check for a matchfield=> The field to check for a matchexclude=> An optional where clause or field/value pair to exclude from the queryconnection=> An optional database connection name to use
An example below checks table users, field login with form input's value
while excluding records where login = test@example.org:
$inputFilter->add($factory->createInput(array( 'name' => 'email ', 'required' => true, 'validators' => array( array( 'name' => 'EloquentZF2\Validator\noRecordExists', 'options' => array( 'table' => 'users', 'field' => 'login', 'exclude' => array( 'field' => 'login', 'value' => 'text@example.org', ), ), ), ), ) ) );
Authentication
To help you implement Authentication with EloquentZF2 in a similar way as with
ZendDB, there is an Abstract Authentication Adapter provided
(Authentication\\Adapter\EloquentDb.php) and two adapters implemented:
Authentication\Adapter\CallbackCheckAdapter.php- lets you supply a custom callback function. This is useful when you want to check credentials with e.g. bcrypt. Defaults to simple ($a == $b) comparison if callback function is not provided. See example below.Authentication\Adapter\CredentialTreatmentAdapter.php- lets you supply SQL statement, function or routine (e.g. MD5(?), PASSWORD(?) etc.) which should be applied to given gredential before checking it. Defauls to '?' which would be same as (passwordField=password) comparison. See example below.
Both of these Adapters are implemented in a very similar way as Zend's Authentication adapters and they are compatible with Authentication Service. Please refer to Zend's Authentication Service Documentation for more information.
CallbackCheckAdapter.php Example
This is example using Bcrypt (Zend's implementation). This would usually go in your controller's login action:
/* SomeController.php */ // use CallbackCheckAdapter as AuthAdapter use EloquentZF2\Authentication\Adapter\CallbackCheckAdapter as AuthAdapter; // ... controller code skipped ... public function loginAction() { // ... skipping validation and form code ... // define custom callback function (bcrypt) $callback = function($a, $b) { $bcrypt = new \Zend\Crypt\Password\Bcrypt(array('cost' => '14')); return $bcrypt->verify($b, $a); }; // init auth adapter $authAdapter = new AuthAdapter('default', 'users', 'login', 'password', $callback); // set auth credentials (assuming it was posted by form) $authAdapter ->setIdentity($request->getPost('login')) ->setCredential($request->getPost('password')); // authenticate $authResult = $authAdapter->authenticate();
CredentialTreatmentAdapter.php Example
This is example using MD5(?). This would usually go in your controller's login action:
/* SomeController.php */ // use CallbackCheckAdapter as AuthAdapter use EloquentZF2\Authentication\Adapter\CredentialTreatmentAdapter as AuthAdapter; // ... controller code skipped ... public function loginAction() { // ... skipping validation and form code ... $callback = 'MD5(?)'; // init auth adapter $authAdapter = new AuthAdapter('default', 'users', 'login', 'password', $callback); // set auth credentials (assuming it was posted by from) $authAdapter ->setIdentity($request->getPost('login')) ->setCredential($request->getPost('password')); // authenticate $authResult = $authAdapter->authenticate(); }
rockeinstein/eloquent-zf2 适用场景与选型建议
rockeinstein/eloquent-zf2 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 02 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「database」 「orm」 「zend」 「zf2」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rockeinstein/eloquent-zf2 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rockeinstein/eloquent-zf2 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rockeinstein/eloquent-zf2 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Dibi is Database Abstraction Library for PHP
Kinikit - PHP Application development framework MVC component
Store your language lines in the database, yaml or other sources
PHP Database ORM for Symfony1. Do NOT use for new projects: please move to a newest Symfony release and Doctrine2
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-02-01