berthott/laravel-targetable

Laravel 辅助工具,用于通过特性定位类

3.0.3 2023-06-30 08:54 UTC

This package is auto-updated.

Last update: 2024-09-30 01:37:40 UTC


README

Laravel 辅助工具,通过特性定位类。

安装

$ composer require berthott/laravel-targetable

使用方法

  • 创建自己的服务,继承 berthott\Targetable\Services\TargetableService
  • 传递您想定位的特性以及您选择的配置名称
class TestService extends TargetableService
{
    public function __construct()
    {
        parent::__construct(YourTrait::class, 'your-config');
    }
}
  • 有关如何利用此服务的更多详细信息,请查看 tests/BasicTargetable
  • 您可以使用接口而不是特性,通过在 TargetableService 上使用 Mode::Contract 作为第三个参数来实现

选项

要更改默认选项,请将以下选项添加到您的库配置文件中

  • namespace: 字符串或包含一个或多个应监视配置特性的命名空间的数组。默认为 App\Models
  • namespace_mode: 定义命名空间搜索模式。 ClassFinder::STANDARD_MODE 仅查找完全匹配的命名空间,ClassFinder::RECURSIVE_MODE 将查找所有子命名空间。默认为 ClassFinder::STANDARD_MODE
  • prefix: 定义路由前缀。默认为 api

您的配置可能如下所示

<?php

use HaydenPierce\ClassFinder\ClassFinder;

return [

    /*
    |--------------------------------------------------------------------------
    | Model Namespace Configuration
    |--------------------------------------------------------------------------
    |
    | string or array with one ore multiple namespaces that should be monitored 
    | for the configured trait. Defaults to App\Models.
    |
    */

    'namespace' => 'App\Models',

    /*
    |--------------------------------------------------------------------------
    | Model Namespace Search Option
    |--------------------------------------------------------------------------
    |
    | Defines the search mode for the namespaces. ClassFinder::STANDARD_MODE
    | will only find the exact matching namespace, ClassFinder::RECURSIVE_MODE
    | will find all subnamespaces. Defaults to ClassFinder::STANDARD_MODE.
    | 
    | Beware: ClassFinder::RECURSIVE_MODE might cause some testing issues.
    |
    */

    'namespace_mode' => ClassFinder::STANDARD_MODE,

    /*
    |--------------------------------------------------------------------------
    | Route Prefix
    |--------------------------------------------------------------------------
    |
    | Defines the route prefix. Defaults to 'api'.
    |
    */

    'prefix' => 'api',
];

兼容性

与 Laravel 10.x 进行了测试。

许可

许可文件。版权 © 2023 Jan Bladt。