*/ private static $extends = []; /** * Register a custom extend. */ public static function extend(string $name, Closure $extend): void { static::$extends[$name] = $extend; } /** * Checks if extend is registered. */ public static function hasExtend(string $name): bool { return array_key_exists($name, static::$extends); } /** * Dynamically handle calls to the class. * * @param array $parameters * * @return mixed */ public function __call(string $method, array $parameters) { if (!static::hasExtend($method)) { throw new BadMethodCallException("$method is not a callable method name."); } /** @var Closure $extend */ $extend = static::$extends[$method]->bindTo($this, static::class); return $extend(...$parameters); } }