Skip to content

Instantly share code, notes, and snippets.

@elishaukpong
Last active January 11, 2023 12:52
Show Gist options
  • Save elishaukpong/92b5643a08c3d2c89b8ca02d32db0afb to your computer and use it in GitHub Desktop.
Save elishaukpong/92b5643a08c3d2c89b8ca02d32db0afb to your computer and use it in GitHub Desktop.
<?php
/** CONCRETE CLASS DECLARATIONS **/
use App\Services;
class Greetings
{
public const FACADE_ACCESSOR = "greetings";
public function method1(): string
{
return 'Hello Method 1';
}
public function method2($greetings, $name): string
{
return "$greetings to you $name";
}
}
/** FACADE CLASS DECLARATIONS **/
use \Illuminate\Support\Facades\Facade;
use App\Services\Greetings;
class GreetingsFacade extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor(): string
{
return Greetings::FACADE_ACCESSOR;
}
}
/** PROVIDER CLASS DECLARATIONS **/
namespace App\Providers;
use App\Services\Compliment;
use Illuminate\Support\ServiceProvider;
use App\Services\Greetings;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->bind(Greetings::FACADE_ACCESSOR, fn() => new Greetings());
}
}
/** FACADE USAGE AND NON FACADE EQUIVALENT**/
GreetingsFacade::method1() -> (new Greetings())->method1();
GreetingsFacade::method2('Hello', 'Elisha') -> (new Greetings())->method2('Hello', 'Elisha');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment