承接 codeage/entitygenerator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

codeage/entitygenerator

Composer 安装命令:

composer require codeage/entitygenerator

包简介

Prettify your source code using model-entity-manager layer architecture.

README 文档

README

About

I wrote this bundle to simplify my life when creating new Entity in Symfony2 project. I was using architecture of "3 layers" which split your ORM logic into few files:

  • Model - Contains only fields data and its getters and setters (and add, or remove if needed :D )
  • Entity - Main file that is used to create Entity object, this file store internal Entity logic. eg. when you want to modify your data in some way.
  • Manager - And the Manager file which should be treated as "Repository" of given Entity and you should put here every QueryBuilder that concerns it.

For now this bundle supports mapping only in XML format. I think it's good practice to separate all these layers to improve readability of your code.

What is more important, every Manager gets it own Service so you are able to call it in easy way. More about it in Usage section.

Installation

Easy as pie :) Add to your composer.json file in require section:

"codeage/entitygenerator": "1.*"

And update your vendors!

Now the only thing left to do is enable this bundle in your AppKernel file, to do it, add:

new CodeAge\EntityGeneratorBundle\EntityGeneratorBundle(),

As of version 1.1.0 traits were added to AbstractEntity in order to use methods (that I will add someday :) ) even when you cannot extend AbstractEntity for some reason, eg. if you are using FOSUserBundle and you need to extend their User Entity.

Usage

To create new entity use command below:

$ php app/console ca:entity:generate

#for Symfony3
$ php bin/console ca:entity:generate

Then you will be asked about name of your new entity, but you need to proceed it with bundle name in which it will be created (Command should autocomplete name of bundle :) ). eg.

UserBundle:User

Where UserBunlde is bundle name and User is your new entity name.

From now on, you will be asked to provide field name, its type (default is string) and its parameters. String for example can be configured with length and nullable value.

There is also "entity" type which is used to create relation field. (Note: For now only one-direction relations are available)

When you add all needed fields you will be asked to confirm generation of your entity, and several files will be created in your bundle directory (as described in about section :) )

In your controller you can now call your manager in this way:

function indexAction($id){
    $userManager = $this->get(UserManager::SERVICE); /* @var $userManager UserManager */
    $user = $userManager->find($id); /* @var $user User */
}

And that's it! As I said before, manager is used just like repository, so you can create some usefull queries in there to use insetad of "find" like in example here, but you can also use all respoitory-like methods as well eg.

  • findBy
  • findAll
  • findOneBy

And what about insertions, updates and deletes?

Insert

$userManager = $this->get(UserManager::SERVICE); /* @var $userManager UserManager */
$user = new User();
$user->setName('SomeNameOFUser');

$userManager->persist($user)
       ->flush();

Update

$userManager = $this->get(UserManager::SERVICE); /* @var $userManager UserManager */
$user = $userManager->find($id); /* @var $user User */
//Assume that there is a user with this id :)

$user->setName('NewNameForUser');
$userManager->update($user); //Done! But you can pass false as second parameter to disable force-flush :)

Delete/Remove

$userManager = $this->get(UserManager::SERVICE); /* @var $userManager UserManager */
$user = $userManager->find($id); /* @var $user User */
$userManager->remove($user); //Done! But you still can disable force-flush

Planned changes:

  • Use traits instead of simple inheritance, for simplifying implementation of FOSUserBundle :)
  • Printing list of all possible types for field
  • Print all entity configuration when asking if user confirm generation
  • Ability to modify field after adding it
  • Get all types from DBAL
  • Enum types generator

codeage/entitygenerator 适用场景与选型建议

codeage/entitygenerator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 38 次下载、GitHub Stars 达 3, 最近一次更新时间为 2015 年 10 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「generator command symfony model entity manager service」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 codeage/entitygenerator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 codeage/entitygenerator 我们能提供哪些服务?
定制开发 / 二次开发

基于 codeage/entitygenerator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 38
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-26