<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

namespace Kufer\Web\Classes\Scripting3;

class ExprText extends Expr
{
  public $text;

  public function __construct(string $text)
  {
    $this->text = $text;
  }

  public function toString(): string
  {
    return $this->text;
  }

  public function toPHP(bool $isleaf, ParserHelper $phpcode, array $fnvars): string
  {
    $phptext = str_replace(array('\\', "'"), array('\\\\', "\\'"), $this->text);
    
    
    if ($isleaf) {
      return '$result.=\'' . $phptext . '\';';
    } else {
      return '\'' . $phptext . '\'';
    }
  }
}