Convert a SpanContext to header string

@param SpanContext $context
@return string
327212
public function serialize(SpanContext $context)
    {
        $spanHex = str_pad($context->spanId(), 16, "0", STR_PAD_LEFT);
        $traceOptions = $context->enabled() ? self::OPTION_ENABLED : 0;
        return pack("CCH*CH*CC", 0, 0, $context->traceId(), 1, $spanHex, 2, $traceOptions);
    }
1010980
public function render($context = [])
    {
        if ($element = $this->getElement()) {
            $class = $element->getAttribute('class', false);
            $class .= $class
                ? ' form-control'
                : 'form-control';
            $this->getElement()->setAttribute('class', $class);
        }

        return parent::render($context);
    }
1067102
public static function toSerializationContext(array $context): SerializationContext
    {
        $ctx = new SerializationContext();

        if (isset($context['groups'])) {
            $ctx->setGroups($context['groups']);
        }

        return $ctx;
    }
943516
private function getSegment( $context )
	{
		if ( is_string( $context ) )
		{
			if ( ! isset( $this->contexts[ $context ] ) ) return null;
			$context = $this->contexts[ $context ];
		}

		if ( isset( $context['segment'] ) ) return $context['segment'];
		if ( isset( $context['entity']['segment'] ) ) return $context['entity']['segment'];

		return null;
	}
1015708
public function render($context)
    {
        if ($this->place || $this->place == self::RESET_CONTEXT) {
            return sprintf('<img src="%s" alt="%s" />', $this->path, $this->alt);
        } elseif ($this->place == self::PRE_CONTEXT) {
            return sprintf('<img src="%s" alt="%s" />', $this->path, $this->alt) . $context;
        } else {
            return $context . sprintf('<img src="%s" alt="%s" />', $this->path, $this->alt);
        }
    }
1295868
protected function mergeContextHeaders($context)
    {
        $headers = $this->headers->asArray();
        
        if($context === null ) {
            return $headers;
        }
        
        $cookieUpdates = $context->cookies()->updates();
        if(empty($cookieUpdates)) {
            return $headers;
        }
        
        $cookieHeaders = array();
        foreach($cookieUpdates as $update) {
            $cookieHeaders[] = $update->asHeader();
        }
        
        foreach($headers as $name => $value) {
            if(strtolower($name) === 'set-cookie') {
                foreach($cookieHeaders as $header) {
                    $headers[$name][] = $header;
                }
                return $headers;
            }
        }
        
        $headers['Set-Cookie'] = $cookieHeaders;
        return $headers;
    }
972219
public function inject(SpanContext $spanContext, &$carrier)
    {
        $carrier[self::TRACE_ID_NAME] = dechex($spanContext->getTraceId());
        $carrier[self::SPAN_ID_NAME] = dechex($spanContext->getSpanId());
        if ($spanContext->getParentId() != null) {
            $carrier[self::PARENT_ID_NAME] = dechex($spanContext->getParentId());
        }
        $carrier[self::FLAGS_NAME] = (int) $spanContext->getFlags();
    }
222204
public function getContext(TemplateContextInterface $context = null)
    {
        $context = new TemplateContext($context);
        $context->setData($this->getData());
        $context->setParameters($this->getParameters());

        return $context;
    }
404130
private function buildXMLAttributesString(Context $context) {
		$result = '';
		$matches = null;
		$attributes = $this->attributes;

		$runtimeAttributes = $context->getRuntimeAttributes();

		foreach($runtimeAttributes as $attributeName=>$runtimeAttr) {
			$attributes[$attributeName] = $runtimeAttr;
		}

		foreach($attributes as $attribute=>$value) {

			if( ! $context->view->isFigPrefix($attribute)) {
                // a flag attribute is to be processed differently because
                // it isn't a key=value pair.

                if ($value instanceof Flag) {
                    // Flag attribute: there is no value. We print only the name of the flag.
                    $result .= " $attribute";
                } else {

				    // We're potentially in presence of:
                    // - a plain scalar
                    // - an AdHoc instance
                    // - an array of the above.
                    // - an inline conditional attribute: InlineCondAttr

                    if ($value instanceof InlineCondAttr) {
                        /** @var InlineCondAttr $inlineCondAttr */
                        $inlineCondAttr = $value;
                        if ($this->evaluate($context, $inlineCondAttr->cond)) {
                            $value = $this->evaluate($context, $inlineCondAttr->val);
                        }
                        else {
                            continue;
                        }
                    }

                    if (! is_array($value)) {
                        $value = [$value];
                    }
                    $combined = '';
                    foreach ($value as $part) {
                        if ($part instanceof AdHoc) {
                            $evaluatedValue = $this->evaluate($context, $part->string);

                            if($evaluatedValue instanceof ViewElement) {
                                $evaluatedValue = $evaluatedValue->render($context);
                            }
                            if(is_array($evaluatedValue)) {
                                if(empty($evaluatedValue)) {
                                    $evaluatedValue = '';
                                } else {
                                    $message = 'Adhoc {' . $part->string . '} of attribute ' . $attribute . ' in tag "' . $this->name . '" evaluated to array.';
                                    throw new TagRenderingException($this->getTagName(), $this->getLineNumber(), $message);
                                }
                            } else if (is_object($evaluatedValue)
                                && ($evaluatedValue instanceof \DOMNode)) {

                                // Treat the special case of DOMNode descendants,
                                // for which we can evalute the text contents
                                $evaluatedValue = $evaluatedValue->nodeValue;
                            }

                            //The outcome of the evaluatedValue, coming from DB or other, might contain non-standard HTML characters.
                            //We assume that the FIG library targets HTML rendering.
                            //Therefore, let's have the outcome comply with HTML.
                            if(is_object($evaluatedValue)) {
                                //TODO: Log some warning!
                                $evaluatedValue = '### Object of class: ' . get_class($evaluatedValue) . ' ###';
                            } else {
                                $evaluatedValue = htmlspecialchars($evaluatedValue);
                            }

                            $part = $evaluatedValue;
                        }

                        // Append to what we had already (and if $part was a string in the first place,
                        // we use its direct value;
                        $combined .= $part;


                    }
                    $value = $combined;

                    $result .= " $attribute=\"$value\"";
				}
            }

        }
		return $result;
	}
1250519
public final static function fromPhpContext(PhpContext $phpContext)
    {
        if ($phpContext->isCliInvocation()) {
            $request = new CliRequest();
        } else {
            $contentType = (isset($_SERVER["CONTENT_TYPE"])) ? strtolower($_SERVER["CONTENT_TYPE"]) : "";

            // Special check for multipart, because the header could be multipart/form-data
            // followed by boundary
            $multipartType = "multipart/form-data";
            if (strpos($contentType, $multipartType) === 0) {
                $contentType = $multipartType;
            }

            // Firefox puts a charset on the end of the content type line
            $parts = explode(";", $contentType);
            $contentType = $parts[0];

            switch ($contentType) {
                case "application/octet-stream":
                case "image/jpeg":
                case "image/jpg":
                case "image/gif":
                case "image/png":
                    $request = new BinaryRequest();
                    break;
                case "application/json":
                    $request = new JsonRequest();
                    break;
                case "text/xml":
                case "application/xml":
                    $request = new XmlRequest();
                    break;
                case "multipart/form-data":
                    $request = new MultiPartFormDataRequest();
                    break;
                default:
                    $request = new WebRequest();
                    break;
            }
        }

        $request->phpContext = $phpContext;

        return $request;
    }
987631
public function doSpecific(Context $context)
    {
        if(!isset($this->attributes['name'])) {
            //name is a required attribute for fig:attr.
            throw new RequiredAttributeException($this->name, $this->xmlLineNumber, 'name');
        }
        //flag attribute
        // Usage: <tag><fig:attr name="ng-app" flag="true" />  will render as flag <tag ng-app> at tag level, without a value.
        if(isset($this->attributes['flag']) && $this->evaluate($context, $this->attributes['flag'])) {
            $context->setParentRuntimeAttribute($this->attributes['name'], new Flag());
        } else {
            if ($this->hasAttribute('value')) {
                $value = $this->evaluate($context, $this->attributes['value']);
                if (is_string($value)) {
                    $value = htmlspecialchars($value);
                }
                $context->setParentRuntimeAttribute($this->attributes['name'],  $value);
            } else {
                $value = '';
                /**
                 * @var ViewElement
                 */
                $child = null;
                foreach ($this->children as $child) {
                    $renderChild = $child->render($context);
                    if ($renderChild === false) {
                        throw new \Exception();
                    }
                    $value .= $renderChild;
                }
                //An XML attribute should not span accross several lines.
                $value = trim(preg_replace("#[\n\r\t]+#", ' ', $value));
                $context->setParentRuntimeAttribute($this->attributes['name'], $value);
            }
        }
        // No more rendering of the inner contents. Job is done, move to next sibling by
        // returning (non-null) empty string
        return '';
    }
224045
public function render($context)
    {
        $values = array();

        foreach ($this->vars as $var) {
            $actualRow = $this->getCell()->getActualRow();
            if (is_object($actualRow)) {
                $actualRow = $actualRow->getArrayCopy();
            }
            $values[] = $actualRow[$var];
        }

        $value = vsprintf($this->template, $values);

        if ($this->place == self::RESET_CONTEXT) {
            return $value;
        } else {
            return ($this->place == self::PRE_CONTEXT) ? $value . $context :  $context . $value;
        }
    }
373419
public function render($context)
    {
        if (count($this->class) > 0 && is_array($this->class)) {
            foreach ($this->class as $class) {
                $this->getCell()->addClass($class);
            }
        }
        return $context;
    }
1030527
public static function parse($text, $context = null)
    {
        if (!static::$_enabled || strpos($text, '{') === false) {
            return $text;
        }

        if ($context === null) {
            $context = static::_getDefaultContext();
        }

        static::cache('context', $context);
        $pattern = static::_regex();

        return preg_replace_callback("/{$pattern}/s", 'static::_doShortcode', $text);
    }
1235748
protected function before(Context $context)
    {
        // set context forwarder
        $context->forwarder = $context->forwarder ?: [$this, 'forward'];

        return parent::before($context);
    }
75654
private function nestContext(&$context)
    {
        foreach ($context as $key => $value) {
            $dot = strpos($key, '.');
            if ($dot && $dot !== strlen($key) - 1) {
                $currentContext = &$context;
                foreach (explode('.', $key) as $k) {
                    if (!isset($currentContext[$k])) {
                        $currentContext[$k] = [];
                    }
                    $currentContext = &$currentContext[$k];
                }
                $currentContext = $value;
                unset($context[$key]);
            }
        }

        return $context;
    }
1121900
public function formatPage(FormatContext $formatContext): string
    {
        $this->arrayLoader->setTemplate(
            $formatContext->templateId(),
            $this->massageTemplate($formatContext)
        );

        $data = $formatContext->data()->export();

        return $this->twig->render($formatContext->templateId(), $data);
    }