Open dafik opened 9 years ago
I think this can be done by an UnaryExpr
:
$expr = new UnaryExpr('!', $expr);
How about this:
<?php
namespace CodeGen\Expr;
use CodeGen\Renderable;
class UnaryExpr implements Renderable
{
/**
* @var string|Renderable
*/
public $operand;
/**
* @var string|Renderable
*/
public $expression;
protected $op = '->';
public function __construct($operand, $expression)
{
$this->operand = $operand;
$this->expression = $expression;
}
public function render(array $args = array())
{
$out = '';
if ($this->operand instanceof Renderable) {
$out .= $this->operand->render($args);
} else {
$out .= $this->operand;
}
if ($this->expression instanceof Renderable) {
$out .= $this->expression->render($args);
} else {
$out .= $this->expression;
}
return $out;
}
public function __toString()
{
return $this->render();
}
}
Looks good,
but protected $op
is not used.
new NotExpr($expr)
should produce
!$expr