Serialize the context.

@param  \Nuwave\Lighthouse\Support\Contracts\GraphQLContext  $context
@return string
17640
public function serialize(GraphQLContext $context): string
    {
        $request = $context->request();

        return serialize([
            'request' => [
                'query' => $request->query->all(),
                'request' => $request->request->all(),
                'attributes' => $request->attributes->all(),
                'cookies' => [],
                'files' => [],
                'server' => Arr::except($request->server->all(), ['HTTP_AUTHORIZATION']),
                'content' => $request->getContent(),
            ],
            'user' => serialize($context->user()),
        ]);
    }
1317711
protected function dumpContext($context)
    {
        $export = '';
        foreach ($context as $key => $value) {
            $export .= "{$key}: ";
            $export .= preg_replace(array(
                '/=>\s+([a-zA-Z])/im',
                '/array\(\s+\)/im',
                '/^  |\G  /m',
            ), array(
                '=> $1',
                'array()',
                '    ',
            ), str_replace('array (', 'array(', var_export($value, true)));
            $export .= PHP_EOL;
        }

        return str_replace(array('\\\\', '\\\''), array('\\', '\''), rtrim($export));
    }
1078319
protected function workOnInstance(Context $context)
    {
        $context = $context->setSerializeNull($this->setSerializeNull);

        // group override?
        if (true === $this->overrideHeaderAllowed &&
            $this->requestStack instanceof RequestStack &&
            $this->requestStack->getCurrentRequest() instanceof Request
        ) {
            $headerValue = $this->requestStack->getCurrentRequest()->headers->get($this->overrideHeaderName);
            if (!is_null($headerValue)) {
                $this->groups = array_map('trim', explode(',', $headerValue));
            }
        }

        $serializerGroups = [GroupsExclusionStrategy::DEFAULT_GROUP];
        if (is_array($this->groups) && !empty($this->groups)) {
            $serializerGroups = array_merge($serializerGroups, $this->groups);
        }

        foreach ($this->exclusionStrategies as $strategy) {
            $context->addExclusionStrategy($strategy);
        }

        return $context->setGroups($serializerGroups);
    }
416160
public function context($context = NULL)
	{
		if ( ! func_num_args())
		{
			return $this->_context;
		}
		$this->_context = $context;
		return $this;
	}
919529
public function buffer(Context $context): Promise
    {
        return $context->task(function (Context $context) {
            $buffer = '';
            
            try {
                while (null !== ($chunk = yield $this->read($context, 0xFFFF))) {
                    $buffer .= $chunk;
                }
            } finally {
                $this->close();
            }
            
            return $buffer;
        });
    }
821526
public function saveContext($context)
    {

        $time = time();
        $now = date("{$this->dateFormat} {$this->timeFormat}", $time);
        $settingsValue = serialize($context->getSettings());
        $id = $context->getRecordId();
        $consumer_pk = $context->getConsumer()->getRecordId();
        if (empty($id)) {
            $sql = "INSERT INTO {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' (consumer_pk, lti_context_id, ' .
                   'type, settings, created, updated) ' .
                   'VALUES (:cid, :ctx, :type, :settings, :created, :updated)';
            $query = $this->db->prepare($sql);
            $query->bindValue('cid', $consumer_pk, PDO::PARAM_INT);
            $query->bindValue('ctx', $context->ltiContextId, PDO::PARAM_STR);
            $query->bindValue('type', $context->type, PDO::PARAM_STR);
            $query->bindValue('settings', $settingsValue, PDO::PARAM_STR);
            $query->bindValue('created', $now, PDO::PARAM_STR);
            $query->bindValue('updated', $now, PDO::PARAM_STR);
        } else {
            $sql = "UPDATE {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' SET ' .
                   'lti_context_id = :ctx, type = :type, settings = :settings, '.
                   'updated = :updated ' .
                   'WHERE (consumer_pk = :cid) AND (context_pk = :ctxid)';
            $query = $this->db->prepare($sql);
            $query->bindValue('ctx', $context->ltiContextId, PDO::PARAM_STR);
            $query->bindValue('type', $context->type, PDO::PARAM_STR);
            $query->bindValue('settings', $settingsValue, PDO::PARAM_STR);
            $query->bindValue('updated', $now, PDO::PARAM_STR);
            $query->bindValue('cid', $consumer_pk, PDO::PARAM_INT);
            $query->bindValue('ctxid', $id, PDO::PARAM_INT);
        }
        $ok = $query->execute();
        if ($ok) {
            if (empty($id)) {
                $context->setRecordId(intval($this->db->lastInsertId()));
                $context->created = $time;
            }
            $context->updated = $time;
        }

        return $ok;

    }
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;
        }
    }
402939
public function assemble(ContextInterface $context)
    {
        $class = $context->getClass();
        $property = $context->getProperty();
        try {
            $methodName = Normalizer::generatePropertyMethod('with', $property->getName());
            $class->removeMethod($methodName);
            $lines = [
                sprintf('$new = clone $this;'),
                sprintf('$new->%1$s = $%1$s;', $property->getName()),
                '',
                sprintf('return $new;'),
            ];
            $parameterOptions = ['name' => $property->getName()];
            if ($this->options->useTypeHints()) {
                $parameterOptions['type'] = $property->getType();
            }
            $class->addMethodFromGenerator(
                MethodGenerator::fromArray(
                    [
                        'name' => $methodName,
                        'parameters' => [$parameterOptions],
                        'visibility' => MethodGenerator::VISIBILITY_PUBLIC,
                        'body' => implode($class::LINE_FEED, $lines),
                        'docblock' => DocBlockGeneratorFactory::fromArray([
                            'tags' => [
                                [
                                    'name' => 'param',
                                    'description' => sprintf('%s $%s', $property->getType(), $property->getName()),
                                ],
                                [
                                    'name' => 'return',
                                    'description' => $class->getName(),
                                ],
                            ],
                        ]),
                    ]
                )
            );
        } catch (\Exception $e) {
            throw AssemblerException::fromException($e);
        }
    }
1017104
public static function toDeserializationContext(array $context): DeserializationContext
    {
        $ctx = new DeserializationContext();

        if (isset($context['object_to_populate'])) {
            $ctx->setAttribute('target', $context['object_to_populate']);
        }

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

        return $ctx;
    }
519820
public function getContextLabel($context = 'default') {
    if ($context === self::CONTEXT_DEFAULT) {
      return parent::getContextLabel($context);
    }
    
    return parent::getContextLabel($context);
  }
256953
public function createVariantForContext($context): NodeInterface
    {
        $autoCreatedChildNodes = [];
        $nodeType = $this->getNodeType();
        foreach ($nodeType->getAutoCreatedChildNodes() as $childNodeName => $childNodeConfiguration) {
            $childNode = $this->getNode($childNodeName);
            if ($childNode !== null) {
                $autoCreatedChildNodes[$childNodeName] = $childNode;
            }
        }

        $nodeData = new NodeData($this->nodeData->getPath(), $context->getWorkspace(), $this->nodeData->getIdentifier(), $context->getTargetDimensionValues());
        $nodeData->similarize($this->nodeData);

        if ($this->context !== $context) {
            $node = $this->nodeFactory->createFromNodeData($nodeData, $context);
        } else {
            $this->setNodeData($nodeData);
            $node = $this;
        }

        $this->context->getFirstLevelNodeCache()->flush();
        $this->emitNodeAdded($node);

        /**
         * @var $autoCreatedChildNode NodeInterface
         */
        foreach ($autoCreatedChildNodes as $autoCreatedChildNode) {
            $existingChildNode = $node->getNode($autoCreatedChildNode->getName());
            if ($existingChildNode === null || !$existingChildNode->dimensionsAreMatchingTargetDimensionValues()) {
                // only if needed, see https://github.com/neos/neos-development-collection/issues/782
                $autoCreatedChildNode->createVariantForContext($context);
            }
        }

        return $node;
    }
920660
public function render($context)
    {
        if (count($this->attr) > 0) {
            foreach ($this->attr as $name => $value) {
                $this->getCell()->addVarAttr($name, $value);
            }
        }
        return $context;
    }
468535
public function renderContext($contextUid)
    {
        $endpoint = vsprintf('contexts/%s/render', $contextUid);
        $requestData = $this->getDefaultRequestData('form_params', []);

        return $this->sendRequest($endpoint, $requestData, self::HTTP_METHOD_POST);
    }
580327
private function convertContext(Context $context, $direction)
    {
        if (self::SERIALIZATION === $direction) {
            $jmsContext = $this->serializationContextFactory
                ? $this->serializationContextFactory->createSerializationContext()
                : SerializationContext::create();
        } else {
            $jmsContext = $this->deserializationContextFactory
                ? $this->deserializationContextFactory->createDeserializationContext()
                : DeserializationContext::create();
            $maxDepth = $context->getMaxDepth(false);
            if (null !== $maxDepth) {
                for ($i = 0; $i < $maxDepth; ++$i) {
                    $jmsContext->increaseDepth();
                }
            }
        }

        foreach ($context->getAttributes() as $key => $value) {
            $jmsContext->setAttribute($key, $value);
        }

        if (null !== $context->getVersion()) {
            $jmsContext->setVersion($context->getVersion());
        }
        if (null !== $context->getGroups()) {
            $jmsContext->setGroups($context->getGroups());
        }
        if (null !== $context->getMaxDepth(false) || null !== $context->isMaxDepthEnabled()) {
            $jmsContext->enableMaxDepthChecks();
        }
        if (null !== $context->getSerializeNull()) {
            $jmsContext->setSerializeNull($context->getSerializeNull());
        }

        foreach ($context->getExclusionStrategies() as $strategy) {
            $jmsContext->addExclusionStrategy($strategy);
        }

        return $jmsContext;
    }
1296868
protected function initContext($context)
    {
        foreach ($context as $key => &$value) {
            switch (gettype($value)) {
                case 'string':
                case 'integer':
                case 'double':
                    // These types require no conversion
                    break;
                case 'array':
                case 'boolean':
                    $value = json_encode($value);
                    break;
                case 'object':
                    if (method_exists($value, '__toString')) {
                        $value = (string)$value;
                    } else {
                        $value = '[object (' . get_class($value) . ')]';
                    }
                    break;
                case 'NULL':
                    $value = 'NULL';
                    break;
                default:
                    $value = '[' . gettype($value) . ']';
                    break;
            }
        }

        return $context;
    }
1038529
public static JsonObject serialize(IOContext<?> context) {
    return serialize(context.uri(), context.instance().component().network());
  }
1307923
public function getContext(ViewContextInterface $context = null)
    {
        $context = new ViewContextTemplate(parent::getContext());
        $context->setLayout($this->getLayout());

        return $context;
    }