Provide command line generation of facade layer files.
sunaoka/laravel-facade-generator is a Laravel package for provide command line generation of facade layer files..
It currently has 16 GitHub stars and 2.018 downloads on Packagist (latest version v1.8.0).
Install it with composer require sunaoka/laravel-facade-generator.
Discover more Laravel packages by sunaoka
or browse all Laravel packages to compare alternatives.
Last updated
It is an artisan console command that generates services, service providers and facades.
composer require --dev sunaoka/laravel-facade-generator
php artisan make:facade [Facade Name]
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,
];
php artisan make:facade Foo
<?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';
}
}
<?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);
}
}
<?php
namespace App\Services;
class FooService
{
}
and called artisan make:test to create tests/Feature/FooServiceTest.php.
You must add a providers and an aliases in config/app.php.
'providers' => [
App\Providers\FooServiceProvider::class,
],
'aliases' => [
'Foo' => App\Facades\Foo::class,
],
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,
],