Created
July 29, 2016 03:22
-
-
Save mdmunir/c46bb362267a060daca3311de3320ea4 to your computer and use it in GitHub Desktop.
Facade Emulator
This file contains hidden or 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 | |
| namespace app\classes; | |
| /** | |
| * Description of Db | |
| * | |
| * @author Misbahul D Munir <[email protected]> | |
| * @since 1.0 | |
| */ | |
| class Db extends Facade | |
| { | |
| } |
This file contains hidden or 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 | |
| namespace app\classes; | |
| use yii\helpers\StringHelper; | |
| /** | |
| * Description of Facade | |
| * | |
| * @author Misbahul D Munir <[email protected]> | |
| * @since 1.0 | |
| */ | |
| class Facade | |
| { | |
| private static $_providers = []; | |
| /** | |
| * @return \yii\base\Object | |
| */ | |
| protected static function provider() | |
| { | |
| return \Yii::$app->get(lcfirst(StringHelper::basename(get_called_class()))); | |
| } | |
| public static function __callStatic($name, $arguments) | |
| { | |
| $instance = static::instance(); | |
| return call_user_func_array([$instance, $name], $arguments); | |
| } | |
| public static function instance() | |
| { | |
| $class = get_called_class(); | |
| if (isset(self::$_providers[$class])) { | |
| return self::$_providers[$class]; | |
| } else { | |
| return self::$_providers[$class] = static::provider(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment