Skip to content

Instantly share code, notes, and snippets.

@AbmSourav
Last active August 31, 2021 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbmSourav/7b28333a7585043beb92e14ff90b021b to your computer and use it in GitHub Desktop.
Save AbmSourav/7b28333a7585043beb92e14ff90b021b to your computer and use it in GitHub Desktop.
A simplified way of Laravel's Facade...
<?php
abstract class Facade {
abstract protected static function getInstance();
public static function __callStatic($method, $arguments) {
$instance = static::getInstance();
if (! $instance) {
throw new Exception('Method not found');
}
return $instance->$method(...$arguments);
}
}
// Example:
class Test extends Facade {
private static $self;
protected static function getInstance() {
if (static::$self === null) {
static::$self = new Test;
}
return static::$self;
}
protected function check_validation($data) {
return 'Data is valid...';
}
}
Test::check_validation('Hi');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment