Last active
January 11, 2023 12:52
-
-
Save elishaukpong/92b5643a08c3d2c89b8ca02d32db0afb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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