Oihana PHP System

UserAgentInfo extends Intangible uses UserAgentInfoTrait

Structured view of an HTTP request `User-Agent` header.

Lightweight DTO populated by the parsing helpers in oihana/php-http (e.g. oihana\http\helpers\parseUserAgent()). The User-Agent header carries free-form vendor strings that are hard to consume programmatically — this DTO normalises the most useful fields (browser, OS, device class, bot flag) while keeping the original string under UserAgentInfo::$raw for audit and forensics.

Intentionally extends Schema.org Intangible rather than Thing: a User-Agent is not a persistable entity — it is a transient attribute of a request that may be embedded in a Session or an AuditAction.

Example

use xyz\oihana\schema\http\UserAgentInfo;
use xyz\oihana\schema\constants\http\DeviceType;

$info = new UserAgentInfo
([
    UserAgentInfo::BROWSER         => 'Chrome'  ,
    UserAgentInfo::BROWSER_VERSION => '126.0'   ,
    UserAgentInfo::OS              => 'macOS'   ,
    UserAgentInfo::OS_VERSION      => '14.5'    ,
    UserAgentInfo::DEVICE_TYPE     => DeviceType::DESKTOP ,
    UserAgentInfo::IS_BOT          => false     ,
    UserAgentInfo::RAW             => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_5) AppleWebKit/...' ,
]) ;
Tags
see
https://schema.org/Intangible
category

HTTP

author

Marc Alcaraz (ekameleon)

Table of Contents

Constants

BROWSER  : string = 'browser'
The browser product name (e.g. `'Chrome'`, `'Firefox'`, `'Safari'`, `'Edge'`). `null` when no browser could be identified.
BROWSER_VERSION  : string = 'browserVersion'
The browser product version as a free-form string (e.g. `'126.0.6478.127'`). `null` when not extracted.
CONTEXT  : string = \xyz\oihana\schema\constants\Oihana::SCHEMA
The @context of the json-ld representation of the thing.
DEVICE_TYPE  : string = 'deviceType'
The coarse-grained device classification — one of the `xyz\oihana\schema\constants\http\DeviceType` constants.
IS_BOT  : string = 'isBot'
Whether the User-Agent was identified as belonging to a bot, crawler or other automated agent.
JSON_PRIORITY_KEYS  : array<string|int, mixed> = [\org\schema\constants\Schema::AT_TYPE, \org\sc...
Defines the priority order of keys when serializing the object to JSON-LD.
OS  : string = 'os'
The operating system name (e.g. `'Windows'`, `'macOS'`, `'Linux'`, `'Android'`, `'iOS'`). `null` when no OS could be identified.
OS_VERSION  : string = 'osVersion'
The operating system version as a free-form string (e.g. `'10'`, `'14.5'`). `null` when not extracted.
RAW  : string = 'raw'
The original `User-Agent` request header value, preserved verbatim for audit and forensics.

Properties

$_from  : string|null
The metadata to indicates the edge 'from' identifier.
$_id  : null|string
The metadata identifier of the item.
$_key  : null|string
The metadata unique key identifier of the thing.
$_rev  : null|string
The metadata revision value of the thing.
$_to  : string|null
The metadata to indicates the edge 'to' identifier.
$active  : bool|null
The visibility flag.
$additionalType  : array<string|int, mixed>|string|null|object
An additionalType for the item.
$alternateName  : string|object|array<string|int, mixed>|null
An alias for the item.
$browser  : string|null
The browser product name (e.g. `'Chrome'`, `'Firefox'`, `'Safari'`, `'Edge'`). `null` when no browser could be identified from the `User-Agent` string.
$browserVersion  : string|null
The browser product version as a free-form string (e.g. `'126.0.6478.127'`). `null` when not extracted.
$created  : null|string
Date of creation of the resource.
$description  : string|object|array<string|int, mixed>|null
A short description of the item.
$deviceType  : string|null
The coarse-grained device classification.
$disambiguatingDescription  : string|null
A sub property of description. A short description of the item used to disambiguate from other, similar items. Information from other properties (in particular, name) may be necessary for the description to be useful for disambiguation.
$hasPart  : string|Thing|array<string|int, Thing>|null
Indicates an item that this part of this item.
$id  : null|int|string
The unique identifier of the item.
$identifier  : string|null
The identifier of the item.
$image  : string|ImageObject|array<string|int, ImageObject|string>|null
The image reference of this resource.
$isBot  : bool|null
Whether the User-Agent was identified as belonging to a bot, crawler or other automated agent.
$isPartOf  : string|Thing|array<string|int, Thing>|null
Indicates an item that this item is part of.
$license  : string|object|null
A legal document giving official permission to do something with the resource.
$mainEntityOfPage  : string|null
Indicates a page (or other CreativeWork) for which this thing is the main entity being described.
$modified  : null|string
Date on which the resource was changed.
$name  : int|string|null
The name of the item.
$os  : string|null
The operating system name (e.g. `'Windows'`, `'macOS'`, `'Linux'`, `'Android'`, `'iOS'`). `null` when no OS could be identified.
$osVersion  : string|null
The operating system version as a free-form string (e.g. `'10'`, `'14.5'`). `null` when not extracted.
$owner  : null|string|Thing
The owner of this Thing.
$potentialAction  : array<string|int, mixed>|Action|null
Indicates a potential Action, which describes an idealized action in which this thing would play an 'object' role.
$publisher  : string|array<string|int, string|Person|Organization>|Person|Organization|null
The publisher of the resource.
$raw  : string|null
The original `User-Agent` request header value, preserved verbatim for audit and forensics.
$sameAs  : string|array<string|int, mixed>|null
URL of a reference Web page that unambiguously indicates the item's identity.
$subjectOf  : null|string|array<string|int, mixed>|CreativeWork|Event
A CreativeWork or Event about this Thing.
$url  : int|string|null
URL of the item.
$atContext  : string|null
The JSON-LD `@context` value.
$atType  : string|null
The JSON-LD `@type` value.
$DEFAULT_JSON_SERIALIZE_OPTIONS  : array<string|int, mixed>
The default static jsonSerialize options (class-level configuration).
$schemaTypeCache  : array<string, string>
Internal cache for resolved schema types.

Methods

__construct()  : mixed
Constructor to hydrate public properties from an array or stdClass.
getJsonSerializeOptions()  : array<string|int, mixed>
Returns the default JSON serialization options.
getSchemaType()  : string
Returns the fully qualified URI of the schema type.
jsonSerialize()  : array<string|int, mixed>
Serializes the current object into a JSON-LD array.
withAtContext()  : $this
Sets the internal JSON-LD `@context` attribute.
withAtType()  : $this
Sets the internal JSON-LD `@type` attribute.
withJSONLDMeta()  : $this
Initializes both JSON-LD metadata: `@type` and `@context`.

Constants

BROWSER

The browser product name (e.g. `'Chrome'`, `'Firefox'`, `'Safari'`, `'Edge'`). `null` when no browser could be identified.

public string BROWSER = 'browser'

BROWSER_VERSION

The browser product version as a free-form string (e.g. `'126.0.6478.127'`). `null` when not extracted.

public string BROWSER_VERSION = 'browserVersion'

CONTEXT

The @context of the json-ld representation of the thing.

public string CONTEXT = \xyz\oihana\schema\constants\Oihana::SCHEMA

DEVICE_TYPE

The coarse-grained device classification — one of the `xyz\oihana\schema\constants\http\DeviceType` constants.

public string DEVICE_TYPE = 'deviceType'

IS_BOT

Whether the User-Agent was identified as belonging to a bot, crawler or other automated agent.

public string IS_BOT = 'isBot'

JSON_PRIORITY_KEYS

Defines the priority order of keys when serializing the object to JSON-LD.

public array<string|int, mixed> JSON_PRIORITY_KEYS = [\org\schema\constants\Schema::AT_TYPE, \org\schema\constants\Schema::AT_CONTEXT, \org\schema\constants\Schema::_KEY, \org\schema\constants\Schema::_FROM, \org\schema\constants\Schema::_TO, \org\schema\constants\Schema::ID, \org\schema\constants\Schema::NAME, \org\schema\constants\Schema::URL, \org\schema\constants\Schema::CREATED, \org\schema\constants\Schema::MODIFIED]

Keys listed here will always appear first in the serialized array, in the order specified. All remaining public properties will be sorted alphabetically after these priority keys.

This ensures that important JSON-LD metadata and system fields (like @type, @context, _key, id, url, created, modified, etc.) appear at the top of the output for consistency and readability.

Usage:

$orderedKeys = self::JSON_PRIORITY_KEYS;

Notes:

  • Can be overridden in a subclass by redefining the constant.
  • Late static binding (static::JSON_PRIORITY_KEYS) allows child classes to modify the serialization order.

List of JSON-LD keys in priority order.

OS

The operating system name (e.g. `'Windows'`, `'macOS'`, `'Linux'`, `'Android'`, `'iOS'`). `null` when no OS could be identified.

public string OS = 'os'

OS_VERSION

The operating system version as a free-form string (e.g. `'10'`, `'14.5'`). `null` when not extracted.

public string OS_VERSION = 'osVersion'

RAW

The original `User-Agent` request header value, preserved verbatim for audit and forensics.

public string RAW = 'raw'

Properties

$_from

The metadata to indicates the edge 'from' identifier.

public string|null $_from

$_id

The metadata identifier of the item.

public null|string $_id

$_key

The metadata unique key identifier of the thing.

public null|string $_key

$_rev

The metadata revision value of the thing.

public null|string $_rev

$_to

The metadata to indicates the edge 'to' identifier.

public string|null $_to

$active

The visibility flag.

public bool|null $active

$additionalType

An additionalType for the item.

public array<string|int, mixed>|string|null|object $additionalType

$alternateName

An alias for the item.

public string|object|array<string|int, mixed>|null $alternateName

$browser

The browser product name (e.g. `'Chrome'`, `'Firefox'`, `'Safari'`, `'Edge'`). `null` when no browser could be identified from the `User-Agent` string.

public string|null $browser

$browserVersion

The browser product version as a free-form string (e.g. `'126.0.6478.127'`). `null` when not extracted.

public string|null $browserVersion

$created

Date of creation of the resource.

public null|string $created

$description

A short description of the item.

public string|object|array<string|int, mixed>|null $description

$deviceType

The coarse-grained device classification.

public string|null $deviceType

Expected values are xyz\oihana\schema\constants\http\DeviceType constants (desktop, mobile, tablet, bot, unknown). Stored as a string for forward-compatibility with future device classes a parser may introduce.

$disambiguatingDescription

A sub property of description. A short description of the item used to disambiguate from other, similar items. Information from other properties (in particular, name) may be necessary for the description to be useful for disambiguation.

public string|null $disambiguatingDescription

$hasPart

Indicates an item that this part of this item.

public string|Thing|array<string|int, Thing>|null $hasPart

$id

The unique identifier of the item.

public null|int|string $id

$identifier

The identifier of the item.

public string|null $identifier

$isBot

Whether the User-Agent was identified as belonging to a bot, crawler or other automated agent.

public bool|null $isBot

$isPartOf

Indicates an item that this item is part of.

public string|Thing|array<string|int, Thing>|null $isPartOf

$license

A legal document giving official permission to do something with the resource.

public string|object|null $license

$mainEntityOfPage

Indicates a page (or other CreativeWork) for which this thing is the main entity being described.

public string|null $mainEntityOfPage

$modified

Date on which the resource was changed.

public null|string $modified

$name

The name of the item.

public int|string|null $name

$os

The operating system name (e.g. `'Windows'`, `'macOS'`, `'Linux'`, `'Android'`, `'iOS'`). `null` when no OS could be identified.

public string|null $os

$osVersion

The operating system version as a free-form string (e.g. `'10'`, `'14.5'`). `null` when not extracted.

public string|null $osVersion

$owner

The owner of this Thing.

public null|string|Thing $owner

Represents any entity (person, organization, system, or other object) that can be considered the possessor of this Thing.

$potentialAction

Indicates a potential Action, which describes an idealized action in which this thing would play an 'object' role.

public array<string|int, mixed>|Action|null $potentialAction

$raw

The original `User-Agent` request header value, preserved verbatim for audit and forensics.

public string|null $raw

$sameAs

URL of a reference Web page that unambiguously indicates the item's identity.

public string|array<string|int, mixed>|null $sameAs

E.g. the URL of the item's Wikipedia page, Wikidata entry, or official website.

$subjectOf

A CreativeWork or Event about this Thing.

public null|string|array<string|int, mixed>|CreativeWork|Event $subjectOf

$url

URL of the item.

public int|string|null $url

$atContext

The JSON-LD `@context` value.

protected string|null $atContext = null

Default is https://schema.org.

$atType

The JSON-LD `@type` value.

protected string|null $atType = null

This can be manually set or automatically inferred from the class name.

$DEFAULT_JSON_SERIALIZE_OPTIONS

The default static jsonSerialize options (class-level configuration).

protected static array<string|int, mixed> $DEFAULT_JSON_SERIALIZE_OPTIONS = []

$schemaTypeCache

Internal cache for resolved schema types.

private static array<string, string> $schemaTypeCache = []

Methods

__construct()

Constructor to hydrate public properties from an array or stdClass.

public __construct([array<string|int, mixed>|object|null $init = null ]) : mixed

This allows objects to be quickly populated with associative data without manually setting each property.

Parameters
$init : array<string|int, mixed>|object|null = null

A data array or object used to initialize the instance. Keys must match public property names.

Tags
throws
ReflectionException
example
use org\schema\Person;
use org\schema\constants\Prop;

$person = new Person
([
    Prop::NAME => 'Jane Doe',
    Prop::URL  => 'https://example.com/janedoe'
]);

echo $person->name; // Outputs: Jane Doe

getJsonSerializeOptions()

Returns the default JSON serialization options.

public getJsonSerializeOptions() : array<string|int, mixed>

This method determines how the jsonSerialize() output is reduced or compressed, etc. It can be overridden in child classes to customize serialization behavior.

Return values
array<string|int, mixed>

Returns the reduction/compression options for JSON serialization.

getSchemaType()

Returns the fully qualified URI of the schema type.

public static getSchemaType() : string

This method combines the class's CONTEXT constant with its short name to produce a globally unique identifier for the entity type.

  • It uses Late Static Binding to ensure the correct context is retrieved even when called from an inherited class (e.g., Corporation vs. Affiliate).
  • Performance Optimization: Results are stored in a static cache ($schemaTypeCache) to avoid redundant Reflection calls during the same execution lifecycle.
Return values
string

The absolute URI of the type (e.g., "https://schema.org/Thing"). ** @example

echo Thing::getSchemaType();      // https://schema.org/Thing
echo Affiliate::getSchemaType();  // https://schema.oihana.xyz/Pagination

jsonSerialize()

Serializes the current object into a JSON-LD array.

public jsonSerialize() : array<string|int, mixed>

Includes public properties, the JSON-LD @context and @type. Null values are automatically removed.

Tags
throws
ReflectionException

If reflection fails when accessing properties.

example
use org\schema\Person;
use org\schema\constants\Prop;

$person = new Person
([
    Prop::NAME => 'John Smith',
    Prop::ID   => 'jsmith-001'
]);

echo json_encode($person, JSON_PRETTY_PRINT);

Output:

{
   "@type": "Person",
   "@context": "https://schema.org",
   "id": "jsmith-001",
   "name": "John Smith"
}
Return values
array<string|int, mixed>

JSON-LD representation of the object.

withAtContext()

Sets the internal JSON-LD `@context` attribute.

public withAtContext(string $context) : $this

Useful if you need a custom JSON-LD context.

Parameters
$context : string

Optional JSON-LD context.

Return values
$this

withAtType()

Sets the internal JSON-LD `@type` attribute.

public withAtType(string $type) : $this

Allows overriding the default type inferred from the class.

Parameters
$type : string

Optional JSON-LD type

Return values
$this

withJSONLDMeta()

Initializes both JSON-LD metadata: `@type` and `@context`.

public withJSONLDMeta([string|null $atType = null ][, string|null $atContext = null ]) : $this

Can be called from constructor or later to override default values.

Parameters
$atType : string|null = null

Optional JSON-LD type

$atContext : string|null = null

Optional JSON-LD context

Return values
$this
On this page

Search results