@param mixed $value
@param State $state

@return mixed
@throws MarkupException
515758
private function resolveValue($value, State $state)
    {
        if ($value instanceof FuncContext) {
            return $this->call($value, $state);
        }

        if ($value instanceof ArrayContext) {
            $array = [];

            foreach ($value->values as $key => $val) {
                $array[$key] = $this->resolveValue($val, $state);
            }

            return $array;
        }

        return $value;
    }
131150
protected function createState(array $state_definition)
    {
        $state_implementor = isset($state_definition['class']) ? $state_definition['class'] : State::CLASS;
        $this->loadStateImplementor($state_implementor);

        $state = $this->service_locator->make(
            $state_implementor,
            [
                ':name' => $state_definition['name'],
                ':type' => $state_definition['type'],
                ':options' => $state_definition['options'],
            ]
        );

        if (!$state instanceof StateInterface) {
            throw new RuntimeError(
                sprintf(
                    'Configured implementor "%s" for state "%s" must implement: %s',
                    $state_implementor,
                    $state_definition['name'],
                    StateInterface::CLASS
                )
            );
        }

        return $state;
    }
214189
public function set_state($state) {
        if ($state <= $this->state) {
            return false;
        }
        $this->state = $state;
        return true;
    }
382618
private function getMethod(State $state, $class, $method)
    {
        $refClass = $this->getClass($state, $class);

        if (!isset($refClass->methods[$method])) {
            throw new MarkupException(sprintf('method %s::%s does not exist', $class, $method));
        }

        return $refClass->methods[$method];
    }
271933
protected function renderLabel($state)
    {
        $icon = $this->renderIcon($state);
        $encodeProperty = "encode" . ucfirst($state) . "Text";
        $textProperty = "{$state}Text";

        $label = $this->$encodeProperty ? Html::encode($this->$textProperty) : $this->$textProperty;
        $label .= $icon;

        $html = [];
        $html[] = Html::beginTag('span', ['class' => "{$state}Label"]);
        $html[] = $label;
        $html[] = Html::endTag('span');

        return implode("\n", $html);
    }
929027
public function postProcess(&$state)
    {
        $delimiters = &$state->delimiters;
        $max = count($state->delimiters);

        for ($i = $max - 1; $i >= 0; $i--) {
            $startDelim = &$delimiters[$i];

            if ($startDelim->marker !== '_' && $startDelim->marker !== '*') {
                continue;
            }

            // Process only opening markers
            if ($startDelim->end === -1) {
                continue;
            }

            $endDelim = &$delimiters[$startDelim->end];

            // If the previous delimiter has the same marker and is adjacent to this one,
            // merge those into one strong delimiter->
            //
            // `<em><em>whatever</em></em>` -> `<strong>whatever</strong>`
            //
            $isStrong = $i > 0 &&
                $delimiters[$i - 1]->end === $startDelim->end + 1 &&
                $delimiters[$i - 1]->token === $startDelim->token - 1 &&
                $delimiters[$startDelim->end + 1]->token === $endDelim->token + 1 &&
                $delimiters[$i - 1]->marker === $startDelim->marker;

            $ch = $startDelim->marker;

            $token         = &$state->tokens[$startDelim->token];
            $token->type    = $isStrong ? 'strong_open' : 'em_open';
            $token->tag     = $isStrong ? 'strong' : 'em';
            $token->nesting = 1;
            $token->markup  = $isStrong ? $ch . $ch : $ch;
            $token->content = '';

            $token         = &$state->tokens[$endDelim->token];
            $token->type    = $isStrong ? 'strong_close' : 'em_close';
            $token->tag     = $isStrong ? 'strong' : 'em';
            $token->nesting = -1;
            $token->markup  = $isStrong ? $ch . $ch : $ch;
            $token->content = '';

            if ($isStrong) {
                $state->tokens[$delimiters[$i - 1]->token]->content = '';
                $state->tokens[$delimiters[$startDelim->end + 1]->token]->content = '';
                $i--;
            }
        }
    }
655681
protected function setState($key, $value)
    {
        $this->getStateStorage()->set($this->getStateKeyPrefix() . $key, $value);
        return $this;
    }
1234445
public function filter($value)
    {
        $normalized = preg_replace('/\s+/', ' ', strtolower(trim($value)));
        if (array_key_exists($normalized, $this->states) === true) {
            return $this->states[$normalized];
        }
        if (
            $this->getConfig('includeTerritories') === true &&
            array_key_exists($normalized, $this->territories) === true
        ) {
            return $this->territories[$normalized];
        }
        if ($this->getConfig('abortOnInvalidInput') === true) {
            throw new \UnexpectedValueException('Input value can not be mapped to a state name.');
        }
        return $value;
    }
648722
protected function packValue($value): string
    {
        if ($value instanceof DeclarationInterface) {
            //No indentation here
            return $value->render();
        }

        if (is_null($value)) {
            return "null";
        }

        if (is_bool($value)) {
            return ($value ? "true" : "false");
        }

        if (is_object($value) && method_exists($value, '__set_state')) {
            return var_export($value, true);
        }

        if (!is_string($value) && !is_numeric($value)) {
            throw new SerializeException("Unable to pack non scalar value");
        }

        if (is_string($value) && class_exists($value)) {
            $reflection = new \ReflectionClass($value);
            if ($value === $reflection->getName()) {
                return '\\' . $reflection->getName() . '::class';
            }
        }

        return var_export($value, true);
    }
251343
public static function setValidationState( $state = true)
	{
		$previousState = XBRL::$validating;
		XBRL::$validating = $state;
		return $previousState;
	}
929890
public function getState($state, $default = NULL)
    {
        $state = isset($this->states[$state]) ? $this->states[$state] : $default;
        return $state;
    }
679384
public function execute(ProcessState $state)
    {
        $input = $state->getInput();
        $options = $this->getOptions($state);
        if (\is_array($input)) {
            if (!array_key_exists('id', $input)) {
                throw new \UnexpectedValueException('Expecting an array with the "id" key');
            }
            $input = $input['id'];
        }

        /** @var FamilyInterface $family */
        $family = $options['family'];
        /** @var DataRepository $repository */
        $repository = $this->entityManager->getRepository($family->getDataClass());
        $data = $repository->find($input);

        if (!$data instanceof DataInterface) {
            throw new \UnexpectedValueException("Data not found for id '{$input}'");
        }
        if ($data instanceof ContextualDataInterface && null !== $options['context']) {
            $data->setCurrentContext($options['context']);
        }
        $this->dataLoader->loadSingle($data, $options['load_depth']);

        $state->setOutput($data);
    }
583573
protected function stateToString($state)
    {
        switch ($state) {
            case self::STATE_CANCEL:
                return "cancel";
            case self::STATE_COMPLETE:
                return "complete";
            case self::STATE_NOT_RUN: // a string like 'foo' matches here?
                return "not run";
            case self::STATE_TIMEOUT:
                return "timeout";
            case self::STATE_MAX_INPUTS_REACHED:
                return "max valid input attempts reached";
            default:
                throw new NodeException("Bad state for node");
        }
    }
730188
public function saveState($key, $value = null)
    {
        if (is_null($value)) {
            $value = $this;
        } else if (is_callable($value)) {
            $value = call_user_func($callback, $this);
        }
        
        self::$states[$key] = $value;
        return $this;
    }
234189
public function value($value, $states = [])
    {
        if ($caster = $this->caster()) {
            return $caster($value, $states);
        }
        switch (true) {
            case is_null($value):
                return 'NULL';
            case is_bool($value):
                return $value ? 'TRUE' : 'FALSE';
            case is_string($value):
                return $this->quote($value);
            case is_array($value):
                $cast = function($value) use (&$cast) {
                    $result = [];
                    foreach ($value as $k => $v) {
                        if (is_array($v)) {
                            $result[] = $cast($v);
                        } else {
                            $result[] = $this->value($v);
                        }
                    }
                    return '{' . join(',', $result) . '}';

                };
                return $cast($value);
        }
        return (string) $value;
    }
1178931
protected function setState($state)
    {
        if (!array_key_exists($state, $this->stateDirectives)) {
            throw new InvalidArgumentException("Invalid state {$state}");
        }
        $this->state = $state;
        return $this;
    }
197621
public static function execute($value, ContextInterface $context): array
    {
        $context->getStates()->setState(static::STATE_HAS_BEEN_CALLED, true);

        return static::createSuccessReply($value);
    }