mario-legenda/entity-filter
最新稳定版本:1.0.0
Composer 安装命令:
composer require mario-legenda/entity-filter
包简介
Filters collection of entities and transformers them into array
关键字:
README 文档
README
Filters Doctrine enitites and transformers them into arrays. Examples speak for themselves, so read on.
Installation
$ composer require mario-legenda/entity-filter
Basic usage
Let's say we have a User entity that has 25 fields that describe a certain user, like name, lastname,
social security number etc. If you want only 10 of those fields, you would have to manually call each and
every method and place them in some variables. Code is as follows...
$user = new User();
$name = $user->getName()
$lastname = $user->getLastname();
... 8 remaining fields
This creates some ugly code. If you wish to put the values of those fields in an array, the code is even uglier.
$user = new User();
$userData['name'] = $user->getName();
$userData['lastname'] = $user->getName();
... 8 remainig fields
Now, you could say that you can query the database with DQL, but in some cases, you need a clean entity if, for example, you wish to update the User to the database. This is the situtation where this tool comes in handy.
$user = new User();
$entityFilter = new EntityFilter();
$filtered = $entityFilter
->setEntity($user)
->configure(array(
'id', 'name', 'lastname', 'ssn'
))
->setDataVar('user')
->getFiltered();
$filtered is an array that holds id, name and other values that you ask from it. EntityFilter::setDataVar()
sets the value of an array key that holds the array with the specified values from the User entity. Default
is data.
I hope that someone finds this helpfull.
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-07