定制 sunaoka/laravel-facade-generator 二次开发

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

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

sunaoka/laravel-facade-generator

最新稳定版本:v1.8.0

Composer 安装命令:

composer require --dev sunaoka/laravel-facade-generator

包简介

Provide command line generation of facade layer files.

README 文档

README

Latest Stable Version License PHP from Packagist Laravel Test codecov

It is an artisan console command that generates services, service providers and facades.

Installation

composer require --dev sunaoka/laravel-facade-generator

Usage

php artisan make:facade [Facade Name]

Configurations

php artisan vendor:publish --tag=facade-generator-config
<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Class names suffix
    |
    | Sets the string to be suffixed to the class name.
    |--------------------------------------------------------------------------
    */
    'suffix' => [
        'facade'   => '',
        'service'  => 'Service',
        'provider' => 'ServiceProvider',
    ],

    /*
    |--------------------------------------------------------------------------
    | Generate test
    |
    | If `false`, no test will be generated.
    |--------------------------------------------------------------------------
    */

    'test' => true,
];

Example

php artisan make:facade Foo

Generated: app/Facades/Foo.php

<?php

namespace App\Facades;

use Illuminate\Support\Facades\Facade;

/**
 * Class Foo
 *
 * @method static \Mockery\MockInterface spy() Convert the facade into a Mockery spy.
 * @method static \Mockery\MockInterface partialMock() Initiate a partial mock on the facade.
 * @method static \Mockery\Expectation   shouldReceive(string|array ...$methodNames) Initiate a mock expectation on the facade.
 * @method static void                   swap($instance) Hotswap the underlying instance behind the facade.
 * @method static void                   clearResolvedInstance(string $name) Clear a resolved facade instance.
 * @method static void                   clearResolvedInstances() Clear all of the resolved instances.
 * 
 * @see \App\Services\FooService
 */
class Foo extends Facade
{
    /**
     * Get the registered name of the component.
     *
     * @return string
     */
    protected static function getFacadeAccessor()
    {
        return 'Foo';
    }
}

Generated: app/Providers/FooServiceProvider.php

<?php

namespace App\Providers;

use App\Services\FooService;
use Illuminate\Support\ServiceProvider;

class FooServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind('Foo', FooService::class);
    }
}

Generated: app/Services/FooService.php

<?php

namespace App\Services;

class FooService
{
}

and called artisan make:test to create tests/Feature/FooServiceTest.php.

Laravel 5.8 to 10.x

You must add a providers and an aliases in config/app.php.

'providers' => [
    App\Providers\FooServiceProvider::class,
],

'aliases' => [
    'Foo' => App\Facades\Foo::class,
],

Laravel 11.x

You must add a providers in bootstrap/providers.php.

return [
    App\Providers\FooServiceProvider::class,
];

and, You must add an aliases in config/app.php.

'aliases' => [
    'Foo' => App\Facades\Foo::class,
],

统计信息

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

GitHub 信息

  • Stars: 16
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-01-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固