Skip to content

Commit

Permalink
Add widget expression.
Browse files Browse the repository at this point in the history
Handles the output of the executed widget allowing it both to be echoed as well as still accessed like an object
  • Loading branch information
benrowe committed Jun 14, 2016
1 parent 76397e8 commit 9c3e1d4
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/Expression.php
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
)
);
}
}

0 comments on commit 9c3e1d4

Please sign in to comment.