<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, 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 = strtr($this->text, array(
      '\'' => "\\'",
      '\\' => '\\\\'
    ));
    
    
    if ($isleaf) {
      return '$result.=\'' . $phptext . '\';';
    } else {
      return '\'' . $phptext . '\'';
    }
  }
}