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

namespace Kufer\Web\Classes\Scripting3;

class ParserExportadapter
{
  public $variables;
  public $stack;

  public function __construct(array $variables, array $stack)
  {
    $this->variables = $variables;
    $this->stack = $stack;
  }

  public function getVarValue($str, $export)
  {
    if (isset($this->variables[$str])) {
      return $this->variables[$str];
    }

    return '';
  }

  public function getStack()
  {
    return $this->stack;
  }

  public function getAryValue($stack, array $nameUndParam)
  {
    $nameParts = $nameUndParam;
    $name = $nameParts[0];
    foreach ($stack as $data) {
      if (is_array($data) && isset($data[$name])) {
        return $data[$name];
      } elseif (is_object($data) && isset($data->{$name})) {
        return $data->{$name};
      }
    }

    return '';
  }

  public function getAryValueForceArray($stack, array $nameUndParam)
  {
    $result = $this->getAryValue($stack, $nameUndParam);
    if (\is_string($result)) {
      return array();
    }

    return $result;
  }
}