定制 squirrelphp/entities-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

squirrelphp/entities-bundle

Composer 安装命令:

composer require squirrelphp/entities-bundle

包简介

Symfony integration of squirrelphp/entities - automatic integration of generated repositories for existing entities.

README 文档

README

Build Status Test Coverage PHPStan Packagist Version PHP Version Software License

Integration of squirrelphp/entities into Symfony through bundle configuration, also needs squirrelphp/queries-bundle as a basis for connecting to databases and executing queries.

Installation

composer require squirrelphp/entities-bundle

Configuration

Enable the bundle in your Symfony configuration by adding Squirrel\EntitiesBundle\SquirrelEntitiesBundle to the list of bundles, and make sure to enable Squirrel\QueriesBundle\SquirrelQueriesBundle and configure connections through QueriesBundle, which is the basis for this bundle.

Configure the directories where the bundle will look for repositories like this in Symfony / YAML:

squirrel_entities:
    directories:
        - '%kernel.project_dir%/src'
        - '%kernel.project_dir%/possibleOtherDirectory'

It will go through these directories recusively, finding all entities, generating repositories and creating services for the repositories. The details on how to work with the repositories can be found in the documentation for the underlying library squirrelphp/entities.

Overriding table names and connection names

If you are reusing entities from other projects and only want to change the connection name and/or the table name of an entity, you can override it through configuration:

squirrel_entities:
    connection_names:
        Application\Entity\User: 'postgres_connection'
        Application\Entity\Session: 'sqlite_connection'
    table_names:
        Application\Entity\User: 'differentdatabase.users'
        Application\Entity\Session: 'sessions_table'

This can also come in handy if you want to change connection names and table names for testing or development, while the attribute values are for the production system. Just use the fully qualified entity class name as the key. If you specify an empty string as connection name the default connection is used (if a default connection was defined through QueriesBundle).

Workflow with entities and repositories

At this point you should have already configured squirrelphp/queries-bundle with your database(s).

While developing

  1. Create entities with attributes as explained in squirrelphp/entities
  2. Run vendor/bin/squirrel_repositories_generate --source-dir=src to generate the repositories for your entities - those will be gitignored (add or change the --source-dir entries depending on where your entities are)
  3. Add the directories of your entities to the squirrel_entities configuration so repositories are found and initialized automatically when the Symfony service container is compiled.
  4. Use the generated repository classes as type hints in your code and let Symfony autowire these services.
  5. Add vendor/bin/squirrel_repositories_generate --source-dir=src to your composer.json in scripts for post-install-cmd and post-update-cmd (at the top of these lists). Whenever you do an install or update the repositories are recreated.

In production

If you run composer install in production, just make sure you have added squirrel_repositories_generate to your composer.json as described in point number 5 in While developing, so every time you deploy the repositories are recreated.

If you have some specific deployment workflow, you can call vendor/bin/squirrel_repositories_generate --source-dir=src explicitely to generate the repositories. Just make sure you do it before the Symfony container is compiled (or before clearing it with cache:clear or cache:warmup), otherwise the repository classes will be missing and autowiring code with the repository classes will not work.

squirrelphp/entities-bundle 适用场景与选型建议

squirrelphp/entities-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.37k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 04 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 squirrelphp/entities-bundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 3.37k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 4

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-04-23