forci/static-data-bundle
Composer 安装命令:
composer require forci/static-data-bundle
包简介
Static Data Import for applications that need pre-defined entities with IDs
README 文档
README
composer require forci/static-data-bundle
Add the bundle to your bundles array
new \Forci\Bundle\StaticData\ForciStaticDataBundle(),
Configure your bundles. These are the bundles that have StaticData that needs to be imported
forci_static_data: bundles: - App # Note: Your bundle can be configured as a string or full-blown config. # You can also specify your entity manager if not "default" or if you have many # For advanced usage, please refer to the Configuration file of this bundle. - Api - bundle: Frontend # Note: When looking up classes, this bundle converts slashes to namespace separators directory: Some/Directory em: some_other_em - Admin
The Static Data bundle will look into each bundle's configured directory (StaticData by default) and pick all *Data.php files.
Then, if there is a service with an ID equal to the FQCN, or if the class is a subclass of Forci\Bundle\StaticData\StaticData\StaticData, it will be constructed and added to a ``Forci\Bundle\StaticData\StaticData\DataCollection`.
Note, that this only happens on-demand and will NOT slow down your application's performance besides having to load another bundle and process its configs.
Usage
By default, you need to place your StaticData files in BundleRootDir/StaticData. Take a look at the below example for a bundle named App (Please notice the missing Bundle suffix! if you're using it, you need to specify the full bundle name in your config, eg AppBundle)
<?php // src/App/StaticData/RoleData.php namespace App\StaticData; use App\Entity\Role; use Forci\Bundle\StaticData\StaticData\StaticData; class RoleData extends StaticData { public function doLoad() { $records = [ Role::ID_ADMINISTRATOR => [ 'name' => 'Administrator', 'role' => 'ROLE_ADMIN' ], Role::ID_TRANSLATOR => [ 'name' => 'Translator', 'role' => 'ROLE_TRANSLATOR' ], ]; foreach ($records as $id => $role) { if (!$this->find(Role::class, $id)) { $entity = new Role(); $entity->setId($id); $entity->setName($role['name']); $entity->setRole($role['role']); $this->persist($entity); } } } }
All you need to do is run the ./bin/console forci_static_data:load command.
You can also add this command to your deployment flow. This way, adding new static entities is a breeze.
This is especially useful when development happens by multiple developers, in multiple different branches and you want to keep migrations clean.
Having multiple branches and doing refactoring in these often leads to unexpected crashes upon deployment to production due to the way DoctrineMigrationsBundle works.
If you would like to import the static data for only one bundle, run ./bin/console forci_static_data:load -b YourBundle or ./bin/console forci_static_data:load --bundle=YourBundle
Advanced Usage
This bundle registers two services:
forci_static_data.data_finder- instance ofForci\Bundle\StaticData\StaticData\DataFinderforci_static_data.data_loader- instance ofForci\Bundle\StaticData\StaticData\DataLoader
You can use those to find and/or load your static data in any way you would like - you can embed it in your own commands.
forci/static-data-bundle 适用场景与选型建议
forci/static-data-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.46k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 01 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「Fixture」 「wucdbm」 「static data」 「forci」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 forci/static-data-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 forci/static-data-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 forci/static-data-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Behat redis context for testing
Fixtures replacement with a straightforward definition syntax
Fixtures documentation generator
The bundle for easy using json-rpc api on your project
Yii2 library to run fixtures the ActiveRecord Dao
A Symfony ~3.0 Bundle that eases logging users to your Symfony application.
统计信息
- 总下载量: 10.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-01-20