squirrelphp/entities-bundle
Composer 安装命令:
composer require squirrelphp/entities-bundle
包简介
Symfony integration of squirrelphp/entities - automatic integration of generated repositories for existing entities.
README 文档
README
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
- Create entities with attributes as explained in squirrelphp/entities
- Run
vendor/bin/squirrel_repositories_generate --source-dir=srcto generate the repositories for your entities - those will be gitignored (add or change the --source-dir entries depending on where your entities are) - Add the directories of your entities to the
squirrel_entitiesconfiguration so repositories are found and initialized automatically when the Symfony service container is compiled. - Use the generated repository classes as type hints in your code and let Symfony autowire these services.
- Add
vendor/bin/squirrel_repositories_generate --source-dir=srcto your composer.json inscriptsforpost-install-cmdandpost-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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 squirrelphp/entities-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
The bundle for easy using json-rpc api on your project
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
Bundle Symfony DaplosBundle
统计信息
- 总下载量: 3.37k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 4
其他信息
- 授权协议: MIT
- 更新时间: 2019-04-23