HEX
Server: nginx
System: Linux pool195-106-36.bur.atomicsites.net 6.12.57+deb12-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.57-1~bpo12+1 (2025-11-17) x86_64
User: (0)
PHP: 8.3.32
Disabled: pcntl_fork
Upload Files
File: //usr/local/share/elastic_apm/v1.15.0/ElasticApm/Impl/TransactionContextUser.php
<?php

declare(strict_types=1);

namespace Elastic\Apm\Impl;

use Elastic\Apm\Impl\BackendComm\SerializationUtil;
use Elastic\Apm\Impl\Util\BoolUtil;
use Elastic\Apm\TransactionContextUserInterface;

/**
 * Code in this file is part of implementation internals and thus it is not covered by the backward compatibility.
 *
 * @internal
 *
 * @extends ContextPartWrapper<Transaction>
 */
final class TransactionContextUser extends ContextPartWrapper implements TransactionContextUserInterface
{
    /** @var null|int|string */
    public $id;

    /** @var ?string */
    public $email;

    /** @var ?string */
    public $username;

    public function __construct(Transaction $owner)
    {
        parent::__construct($owner);
    }

    /** @inheritDoc */
    public function setId($id): void
    {
        if ($this->beforeMutating()) {
            return;
        }

        $this->id = is_string($id) ? Tracer::limitKeywordString($id) : $id;
    }

    /** @inheritDoc */
    public function setEmail(?string $email): void
    {
        if ($this->beforeMutating()) {
            return;
        }

        $this->email = Tracer::limitNullableKeywordString($email);
    }

    /** @inheritDoc */
    public function setUsername(?string $username): void
    {
        if ($this->beforeMutating()) {
            return;
        }

        $this->username = Tracer::limitNullableKeywordString($username);
    }


    /** @inheritDoc */
    public function prepareForSerialization(): int
    {
        return BoolUtil::toInt(($this->id !== null) || ($this->email !== null) || ($this->username !== null));
    }

    /** @inheritDoc */
    public function jsonSerialize()
    {
        $result = [];

        SerializationUtil::addNameValueIfNotNull('id', $this->id, /* ref */ $result);
        SerializationUtil::addNameValueIfNotNull('email', $this->email, /* ref */ $result);
        SerializationUtil::addNameValueIfNotNull('username', $this->username, /* ref */ $result);

        return SerializationUtil::postProcessResult($result);
    }
}