-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handles the output of the executed widget allowing it both to be echoed as well as still accessed like an object
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Benrowe\Laravel\Widgets; | ||
|
||
use Arrilot\Widgets\AbstractWidget; | ||
use Illuminate\Support\HtmlString; | ||
|
||
/** | ||
* Represents the widget after it has been executed. | ||
* | ||
* This expression allows the widets to be outputted (aka echo'd) or | ||
* allows access to the public methods of the widget inside the view. | ||
* | ||
* @package Benrowe\Laravel\Widgets | ||
*/ | ||
class Expression extends HtmlString | ||
{ | ||
protected $widget; | ||
|
||
public function __construct($html, AbstractWidget $widget) | ||
{ | ||
$this->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 | ||
) | ||
); | ||
} | ||
} |