From 9c3e1d4921a7ad07317548eb8662b91bff634c71 Mon Sep 17 00:00:00 2001 From: Ben Rowe Date: Wed, 15 Jun 2016 08:10:20 +1000 Subject: [PATCH] Add widget expression. Handles the output of the executed widget allowing it both to be echoed as well as still accessed like an object --- src/Expression.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/Expression.php diff --git a/src/Expression.php b/src/Expression.php new file mode 100644 index 0000000..d76f04d --- /dev/null +++ b/src/Expression.php @@ -0,0 +1,44 @@ +widget = $widget; + parent::__construct($html); + } + + public function getWidget() + { + return $this->widget; + } + + public function __call($method, array $params = []) + { + if (is_callable($this->widget, $method)) { + return call_user_func_array([$this->widget, $method], $params); + } + throw new InvalidArgumentException( + sprintf( + '"%s" does not have a method of "%s"', + get_class($this->widget), + $method + ) + ); + } +}