定制 smurfworks/model-finder 二次开发

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

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

smurfworks/model-finder

最新稳定版本:v1.0.0

Composer 安装命令:

composer require smurfworks/model-finder

包简介

Laravel package for finding models and building a utility index in existing Laravel projects.

README 文档

README

Laravel package for finding models and building a utility index in existing Laravel projects.

Key features

  • Configure discovery of one or more namespaces to scan for Model classes
  • Ignore discovery of specific models
  • Discover available scopes and relations
  • Discover information about attributes
  • Apply custom meta to individual scopes, relations and models via PHP8 attributes

About

This utility repository was created as a provided service for common functionality that I needed between multiple projects, both open source and proprietary - so it made sense to open source and release it so it can be used as a dependency in both contexts.

An example of model finder being used as a dependency an open source package: https://www.github.com/SmurfWorks/Sieve

Install

composer require smurfworks/model-finder

Laravel should automatically discover the service provider and add an alias. The provider will only scan models once per request as it's a singleton service that will cache the result.

Usage

/**
 * Get the index (implement laravel caching around this as you need)
 *
 * @var array $index
 */
$index = app('model-finder')->discover();

dd($index);
// Trimmed for verbosity (...)
array:3 [
 "SmurfWorks\ModelFinderTests\SampleModels\User" => array:4 [
    "meta" => array:2 [
      "name" => "User"
      "describe" => "A user record represents a person's access to this system"
    ]
    "attributes" => array:9 [
      "id" => array:4 [
        "type" => "integer"
        "default" => null
        "fillable" => false
        "hidden" => false
      ]
      "name" => array:4 [
        "type" => "string"
        "default" => null
        "fillable" => true
        "hidden" => false
      ]
      "email" => array:4 [
        "type" => "string"
        "default" => null
        "fillable" => true
        "hidden" => false
      ]
      "password" => array:4 [
        "type" => "string"
        "default" => null
        "fillable" => true
        "hidden" => false
      ]

      ...
    ]
    "relations" => array:1 [
      "role" => array:3 [
        "type" => "BelongsTo"
        "model" => "SmurfWorks\ModelFinderTests\SampleModels\User\Role"
        "meta" => array:2 [
          "name" => "User role"
          "describe" => "The user's system role"
        ]
      ]
    ]
    "scopes" => array:2 [
      "activated" => array:1 [
        "meta" => array:2 [
          "name" => "Activated users"
          "describe" => "Activated users have set a password."
        ]
      ]
      "subscribed" => array:1 [
        "meta" => array:2 [
          "name" => "Subscribed"
          "describe" => "Users that are opted in to receive the newsletter."
        ]
      ]
    ]
  ]
  "SmurfWorks\ModelFinderTests\SampleModels\User\Permission" => array:4 [
    "meta" => array:2 [
      "name" => "User permission"
      "describe" => null
    ]

    ...
  ]

  ...
]

Testing

The testing namespace contains schema migrations to setup some simple tables, and respective sample models. Because a part of the model finding queries the schema for table data, the unit tests will run these migrations to test model discovery.

./vendor/bin/phpunit

Contributions

Contributions and issue reporting are welcome but this project is mostly the foundation for other projects I work on, so be warned there may be a significant amount of arbitrary decision making when proceeding.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固