From 529b542092a735308e564e8af3ff7783e3db6e6c Mon Sep 17 00:00:00 2001 From: Giuseppe Criscione <18699708+giuscris@users.noreply.github.com> Date: Sat, 19 Nov 2022 22:37:50 +0100 Subject: [PATCH] Add trait `Methods` --- formwork/src/Traits/Methods.php | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 formwork/src/Traits/Methods.php diff --git a/formwork/src/Traits/Methods.php b/formwork/src/Traits/Methods.php new file mode 100644 index 00000000..5809b510 --- /dev/null +++ b/formwork/src/Traits/Methods.php @@ -0,0 +1,37 @@ +methods[$method]); + } + + /** + * Call a method defined in the `$method` property + */ + protected function callMethod(string $method, array $arguments) + { + return $this->methods[$method](...$arguments); + } + + public function __call(string $name, array $arguments) + { + if ($this->hasMethod($name)) { + return $this->callMethod($name, $arguments); + } + throw new BadMethodCallException(sprintf('Call to undefined method %s::%s()', static::class, $name)); + } +}