Skip to content

Latest commit

 

History

History
541 lines (401 loc) · 15.7 KB

File metadata and controls

541 lines (401 loc) · 15.7 KB
eyebrow Docs · Reference
lede Every method on the Opcua facade. Manager methods (connection management) plus the full OpcUaClientInterface surface proxied to the default connection.
see_also
href meta
./opcua-manager-api.md
5 min
href meta
./exceptions.md
4 min
href meta
../using-the-client/facade-vs-injection.md
5 min
prev
label href
Filament
../integrations/filament.md
next
label href
OpcuaManager API
./opcua-manager-api.md

Facade methods

The Opcua facade resolves to the OpcuaManager singleton (the container alias 'opcua' points to OpcuaManager::class — see OpcuaManager API).

Two groups of methods are accessible through the facade:

  1. Manager methods — connection lifecycle, defined directly on OpcuaManager.
  2. Client methods — every method on PhpOpcua\Client\OpcUaClientInterface, proxied to the default connection via OpcuaManager::__call().

The authoritative @method list lives in src/Facades/Opcua.php (the IDE-readable docblock).

Connection management (manager methods)

Returns the client for a named connection, creating and caching it on first use.

Signature

Opcua::connection(?string $name = null): OpcUaClientInterface
Parameter Type Description
$name ?string Connection name; defaults to config('opcua.default')

Throws \InvalidArgumentException if the connection is not defined in config/opcua.php.

Like connection(), but for managed-mode clients it also forces an explicit connect() to the configured endpoint (managed clients are created in a disconnected state).

Signature

Opcua::connect(?string $name = null): OpcUaClientInterface

Opens a client for an arbitrary endpoint not defined in the config file. The endpoint URL is the first positional argument, not a key inside the config array.

Signature

Opcua::connectTo(string $endpointUrl, array $config = [], ?string $as = null): OpcUaClientInterface
Parameter Type Description
$endpointUrl string OPC UA endpoint URL (e.g. opc.tcp://host:4840)
$config array Optional connection config — same keys as a connections.* entry
$as ?string Optional name to store the connection under (default: ad-hoc:<endpointUrl>)

Returns the connected client. The instance is also tracked internally, so it gets closed by disconnectAll() and can be reached again by calling Opcua::connection($as).

Closes a connection by name and removes it from the manager's cache.

Signature

Opcua::disconnect(?string $name = null): void
Parameter Type Description
$name ?string Connection name; defaults to the default

There is no overload that accepts a client instance — pass the name (or the $as name used at connectTo() time). In managed mode this triggers a close IPC frame against the daemon, releasing the daemon-side session (so the next call rebuilds it).

Closes every cached connection.

Signature

Opcua::disconnectAll(): void

The manager does not register a register_shutdown_function() hook — call this explicitly (typically in a queue worker's afterTerminate callback, or in an Octane RequestTerminated listener) if you need deterministic cleanup.

Checks whether the session manager daemon's socket file exists.

Signature

Opcua::isSessionManagerRunning(): bool

For Unix-domain endpoints this is a file_exists($socketPath) check — not a live ping round-trip. For TCP endpoints (Windows) the method always returns true and the first IPC call surfaces the real status via a DaemonException.

Returns the default connection name (the value of config('opcua.default')).

Signature

Opcua::getDefaultConnection(): string

Client methods (proxied to the default connection)

The methods below live on OpcUaClientInterface and are forwarded to the default connection by OpcuaManager::__call(). To target a non-default connection use Opcua::connection('other')->read(...).

Read

Reads a single attribute of a single node.

Signature

Opcua::read(NodeId|string $nodeId, int $attributeId = 13, bool $refresh = false): DataValue

Default $attributeId is 13 (Value). Pass other AttributeId::* constants for DisplayName, DataType, etc. $refresh bypasses the read-metadata cache when true.

Use $dv->getValue() to read the value — the DataValue class exposes the value via that accessor (the underlying Variant is private).

Reads multiple attributes / nodes. Call without arguments to get back a fluent ReadMultiBuilder; with ?array $readItems it runs immediately and returns an array of DataValue.

Signature

Opcua::readMulti(?array $readItems = null): array|ReadMultiBuilder
$values = Opcua::readMulti()
    ->node('ns=2;s=Speed')
    ->node('ns=2;s=Temp')->attribute(AttributeId::Value)
    ->execute();

The builder's execute() always returns an array of DataValue, keyed positionally.

Write

Writes the Value attribute of a node. Returns the OPC UA status code as int — check it with StatusCode::isGood($code).

Signature

Opcua::write(NodeId|string $nodeId, mixed $value, ?BuiltinType $type = null): int

When $type is null and auto_detect_write_type is enabled, the client reads the node's DataType attribute to derive the BuiltinType automatically (see Operations · Writing).

Multi-write with optional builder. Returns int[] of status codes when called with an array; returns a WriteMultiBuilder when called with null.

Signature

Opcua::writeMulti(?array $writeItems = null): array|WriteMultiBuilder

Builder usage:

Opcua::writeMulti()
    ->node('ns=2;s=Setpoint')->value(75.0)
    ->node('ns=2;s=Enabled')->typed(true, BuiltinType::Boolean)
    ->execute();

value() takes one argument (auto-detect type). typed() takes (value, BuiltinType). node() is mandatory before each value() / typed().

Browse

Returns the immediate children of a node.

Signature

Opcua::browse(
    NodeId|string $nodeId,
    BrowseDirection $direction = BrowseDirection::Forward,
    ?NodeId $referenceTypeId = null,
    bool $includeSubtypes = true,
    array $nodeClasses = [],
    bool $useCache = true,
): array

Returns ReferenceDescription[]. See Operations · Browsing.

Walks the subtree under a node. $maxDepth is the third positional parameter — use the named argument (maxDepth:) if you don't need to set $direction.

Signature

Opcua::browseRecursive(
    NodeId|string $nodeId,
    BrowseDirection $direction = BrowseDirection::Forward,
    ?int $maxDepth = null,
    ?NodeId $referenceTypeId = null,
    bool $includeSubtypes = true,
    array $nodeClasses = [],
): array

Returns BrowseNode[].

Multi-path translation. Returns BrowsePathResult[] when called with an array, or a BrowsePathsBuilder when called with null.

Signature

Opcua::translateBrowsePaths(?array $browsePaths = null): array|BrowsePathsBuilder

Resolves a browse-path string to a NodeId.

Signature

Opcua::resolveNodeId(string $path, NodeId|string|null $startingNodeId = null, bool $useCache = true): NodeId

Method calls

Invokes an OPC UA method. Returns a CallResult object, not a [status, outputs] tuple.

Signature

Opcua::call(NodeId|string $objectId, NodeId|string $methodId, array $inputArguments = []): CallResult

Use $result->statusCode and $result->outputArguments to read the fields.

Subscriptions

Creates an OPC UA subscription on the server.

Signature

Opcua::createSubscription(
    float $publishingInterval = 500.0,
    int $lifetimeCount = 2400,
    int $maxKeepAliveCount = 10,
    int $maxNotificationsPerPublish = 0,
    bool $publishingEnabled = true,
    int $priority = 0,
): SubscriptionResult

Returns a SubscriptionResult carrying the server-assigned $subscriptionId. Pass that ID to createMonitoredItems() / createEventMonitoredItem() to attach items.

Creates monitored items on a subscription. Pass null to get the builder, or array to run immediately.

Signature

Opcua::createMonitoredItems(int $subscriptionId, ?array $items = null): array|MonitoredItemsBuilder

Creates a single event-shaped monitored item.

Signature

Opcua::createEventMonitoredItem(
    int $subscriptionId,
    NodeId|string $nodeId,
    array $selectFields = ['EventId', 'EventType', 'SourceName', 'Time', 'Message', 'Severity'],
    int $clientHandle = 1,
): MonitoredItemResult

Deletes a subscription on the server.

Signature

Opcua::deleteSubscription(int $subscriptionId): int

Drives the publish loop. Notifications flow out through PSR-14 events (DataChangeReceived, EventNotificationReceived, alarm events) — see Events · Overview.

Signature

Opcua::publish(array $acknowledgements = []): PublishResult

History

Reads a contiguous range of historical values.

Signature

Opcua::historyReadRaw(
    NodeId|string $nodeId,
    ?\DateTimeImmutable $startTime = null,
    ?\DateTimeImmutable $endTime = null,
    int $numValuesPerNode = 0,
    bool $returnBounds = false,
): array

Returns DataValue[].

Reads server-aggregated historical values (averages, min/max, …).

Signature

Opcua::historyReadProcessed(
    NodeId|string $nodeId,
    \DateTimeImmutable $startTime,
    \DateTimeImmutable $endTime,
    float $processingInterval,
    NodeId $aggregateType,
): array

Reads historical values at a discrete set of timestamps.

Signature

Opcua::historyReadAtTime(NodeId|string $nodeId, array $timestamps): array

Discovery

Returns the server's published endpoint descriptions.

Signature

Opcua::getEndpoints(string $endpointUrl, bool $useCache = true): array

Returns EndpointDescription[] — one per (security policy, security mode) the server advertises.

Triggers discovery of server-defined complex DataTypes and seeds the extension-object repository.

Signature

Opcua::discoverDataTypes(?int $namespaceIndex = null, bool $useCache = true): int

Returns the number of types discovered.

Trust store

Persists a server certificate (DER bytes) into the trust store.

Signature

Opcua::trustCertificate(string $certDer): void

Removes a trusted certificate by SHA-1 fingerprint.

Signature

Opcua::untrustCertificate(string $fingerprint): void

Note: trust-store fingerprints are SHA-1, not SHA-256 — see Security · Trust store.

Other accessors

Method Returns Notes
reconnect(): void Tears down and rebuilds the session
isConnected(): bool bool
getConnectionState(): ConnectionState enum
getLogger(): LoggerInterface PSR-3 logger
getEventDispatcher(): EventDispatcherInterface PSR-14 dispatcher
getCache(): ?CacheInterface PSR-16 cache (nullable)
invalidateCache(NodeId|string $nodeId): void
flushCache(): void
getTimeout(): float
getAutoRetry(): int

See src/Facades/Opcua.php for the complete @method list.

Testing helpers (inherited from Illuminate\Support\Facades\Facade)

These are not package methods — they come from the base Laravel Facade class and are available on every facade.

  • Opcua::partialMock(): Mockery\MockInterface — Mockery partial mock
  • Opcua::spy(): Mockery\MockInterface — Mockery spy
  • Opcua::shouldReceive(...), Opcua::swap(...) — standard Mockery / Facade entry points

There is no Opcua::fake() method shipped by either Laravel's Facade base class or this package. Use Mocking the facade for the supported patterns.

Implementation notes

OpcuaServiceProvider::register() registers the manager as

$this->app->singleton(OpcuaManager::class, function ($app) { ... });
$this->app->alias(OpcuaManager::class, 'opcua');

so the primary binding is on OpcuaManager::class and 'opcua' is an alias to it. The facade resolves 'opcua' via getFacadeAccessor() — both reach the same singleton.

Method calls dispatch through OpcuaManager::__call(), which forwards to $this->connection()->$method(...$parameters) — the default connection's client.

Where to read next