承接 devian2011/seeder 相关项目开发

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

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

devian2011/seeder

Composer 安装命令:

composer create-project devian2011/seeder

包简介

Database seeder for test and fake data. Also it works with predefined values

README 文档

README

Installation

composer require devian2011/seeder

Usage

Simple usage

php ./vendor/bin/seeder.php seeder:fill-data --templates-dir=$(PWD)/examples --mode=predefined --params=$(PWD)/.env
Param Definition IsRequired
templates-dir Comma separated paths to directories which contains definitions for fixtures. true
params Path to env file. Also it supports get variables from $_ENV Global false

Advanced usage

You can use seeder in your code for extend expressions, change output wrapper or add event listeners.

Package uses symfony/expression-language
For create your own functions you can write extensions

$seeder = new \Devian2011\Seeder\Seeder(
    ['/path/to/notations/one', '/path/to/notations/two'], // Required param
    ['/path/to/env/file/.env', '/path/to/env/file/.env.local'] // optional param, it can be empty
);

$seeder->run(
    new \Devian2011\Seeder\Output\SymfonyConsoleOutput($output), // Output wrapper
    new class implements \Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface {
        public function getFunctions(){
            return [
                new \Symfony\Component\ExpressionLanguage\ExpressionFunction('plus', fn() -> return;, fn($ctx, $a , $b) -> return $a + $b)
            ]           
        }
    }, // Expression Language extensions
    [
        new class implements \Devian2011\Seeder\Events\EventHandlerInterface {
            public function getActions() : array 
            {
                return [\Devian2011\Seeder\SeederEvents::EVENT_SEEDER_CONFIG_LOADED] 
                // List of events You cann see all events in \Devian2011\Seeder\SeederEvents
            }
            public function handle(\Devian2011\Seeder\Events\EventInterface $event){
                echo $event->getMessage(); // Event handler
            }
        }
    ] // Array of event handlers
);

Configuration

Better way for configure seeds it uses yaml notations

Database connection configuration

Seeder must contain databases section which is used for connect to databases and mark database connections.

databases:
  - code: seeder # Unique database code. It must use in tables definitions
    dsn: "env('MARIADB_DSN')" # PDO dsn
    user: "env('MARIADB_USER')" # Database user
    password: "env('MARIADB_PASSWORD')" # Database password
    options: # PDO options for database connect 

Table configuration

For create fake data this package uses - fakerphp/faker

tables: # Required section name 
  users: # Table code (it can be overwritten by another config)
    database: seeder # Database connection code.
    name: users # Table name
    rowQuantity: 5 # Fixtures row count
    primaryKey: id # Primary key
    columns: # Columns which should
      - name: id # Column name
        value: "auto_increment" # If field with 'auto_increment' value it will not been filled
      - name: login
        value: "faker.email()" # Expression language has faker. For call faker functions you must write faker.METHOD(...$params)
      - name: password
        value: "faker.word()"
      - name: balance
        value: "400"
      - name: balance_old
        value: "context.balance - 200" # Package has context support. Context works with current row. For get column value for this row you must write context.column_name
        depends: # If column value depends on another columns. You must write **depends** section which have a list if dependant columns 
          - balance # This column depends on balance value
    relations: # If table has relation to another tables. You must set this block
      - name: role_id # Column name which should contain related value
        database: seeder # Database for relation table
        table: roles # Relation table
        column: id # Relation column
        type: manyToOne # Type of relation. Supports manyToOne and oneToOne relation
   
      - name: info_id
        database: seeder
        table: info
        column: id
        type: manyToOne
        fromDb: true # If column have relation with already loaded data. For it works, table with loaded data must have annotation
    fixed: # If we need to fill predefined data. Everything works like columns section 
      - - name: id
          value: 1
        - name: login
          value: admin
        - name: password
          value: 123456
        - name: balance
          value: 400
        - name: balance_old
          value: "context.balance - 100"
          depends:
            - balance
      - - name: id
          value: 2
        - name: login
          value: manager
        - name: password
          value: 654321
        - name: balance
          value: 200
        - name: balance_old
          value: "context.balance - 100"
          depends:
            - balance

devian2011/seeder 适用场景与选型建议

devian2011/seeder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 05 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-02