Git Product home page Git Product logo

laravel-facade-generator's Introduction

Facade generator for Laravel

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,
],

laravel-facade-generator's People

Contributors

nsunaoka avatar sunaoka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

m8e

laravel-facade-generator's Issues

Facades generated Names

I think that Facades class names should have a suffix Facade (Facades\BusinessFacade) like Service (Services\BusinessService) classes. Providers are cool like they are now (Providers\BusinessServiceProvider). Also, in laravel 8 the test class is generated automatically, maybe it should be optional.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.