OpcuaManager API
Every method on PhpOpcua\\SymfonyOpcua\\OpcuaManager — connection management, runtime logger override, the magic __call proxy.
Reference for PhpOpcua\SymfonyOpcua\OpcuaManager. Most
methods autowire via the manager service (opcua).
Construction
public function __construct(
array $config,
?LoggerInterface $defaultLogger = null,
?CacheInterface $defaultCache = null,
?EventDispatcherInterface $defaultEventDispatcher = null,
?\Closure $loggerResolver = null,
);
Wired by the bundle's loadExtension() — you rarely construct
this yourself outside of tests.
| Parameter | Type | Purpose |
|---|---|---|
$config |
array |
The merged YAML config tree |
$defaultLogger |
?LoggerInterface |
The default PSR-3 logger |
$defaultCache |
?CacheInterface |
The PSR-16-wrapped cache pool |
$defaultEventDispatcher |
?EventDispatcherInterface |
Symfony's EventDispatcher (PSR-14) |
$loggerResolver |
?\Closure(string): ?LoggerInterface |
Maps log_channel strings to Monolog services |
Connection management
connect()
public function connect(?string $name = null): OpcUaClientInterface
Returns a connected client for the named connection. In managed mode, opens the daemon session if not yet opened.
$name defaults to the value of getDefaultConnection() — which
reads $this->config['default'] and falls back to 'default'.
The $config array is the merged
php_opcua_symfony_opcua.* config tree injected by the bundle;
there is no Laravel-style config(...) helper involved.
Throws \InvalidArgumentException if the name isn't in
connections.*.
connection()
public function connection(?string $name = null): OpcUaClientInterface
Returns a client for the named connection.
- Managed mode: the returned
ManagedClientis configured but not yet connected — IPC handshake happens lazily on the first request. - Direct mode:
connection()callsClientBuilder::connect()during the call. The returnedClientis already connected at the OPC UA level (the TCP handshake and OpenSecureChannel / CreateSession / ActivateSession round-trips have run).
The only meaningful difference between connection() and
connect() is that connect() forces an immediate
ManagedClient::connect($endpoint) if the cached managed client
reports isConnected() === false.
connectTo()
public function connectTo(
string $endpointUrl,
array $config = [],
?string $as = null,
): OpcUaClientInterface
Opens an ad-hoc connection from a config array. $as
caches under that key — calls with the same $as return the
same client.
Config keys: same as a YAML connections.* entry.
disconnect()
public function disconnect(?string $name = null): void
Closes the named connection. $name defaults to the value of
getDefaultConnection(). The method accepts only a string
(or null); passing a client instance will TypeError on PHP 8.2+.
To close every cached connection, call disconnectAll().
disconnectAll()
public function disconnectAll(): void
Closes every cached connection.
isSessionManagerRunning()
public function isSessionManagerRunning(): bool
Checks the configured daemon endpoint passively: for a Unix
socket it does file_exists($path); for a TCP endpoint it
returns true without actually connecting. This is not an
active ping — the daemon process could have crashed and the
socket file still exists for a short window before the OS cleans
it up.
getDefaultConnection()
public function getDefaultConnection(): string
Returns the default connection name.
Logger surface (v4.3+)
setLogger()
public function setLogger(LoggerInterface $logger): self
Sets a runtime logger that overrides any per-connection
log_channel / logger config. Propagated to existing
connections via method_exists($client, 'setLogger').
Returns $this for chaining.
getLogger()
public function getLogger(): ?LoggerInterface
Returns the runtime logger override, or null if none.
useConsoleLogger()
public function useConsoleLogger(
OutputInterface $output,
array $verbosityMap = [],
array $formatLevelMap = [],
?string $dateFormat = 'Y-m-d H:i:s.v',
): self
Attaches a Symfony ConsoleLogger (respecting -v / -vv /
-vvv). By default wraps in TimestampedLogger. Pass
dateFormat: null to disable the wrap.
Returns $this for chaining.
Magic __call
OpcuaManager::__call($method, $args) forwards to the default
connection's client. So:
$opcua->read('ns=2;s=Speed');
// is internally:
$opcua->connection()->read('ns=2;s=Speed');
That's how Opcua::read() works without the manager defining
read() explicitly.
This works for any method on OpcUaClientInterface — write,
browse, call, createSubscription, historyReadRaw, etc.
Subclassing
For runtime customisation:
final class CustomOpcuaManager extends OpcuaManager
{
public function connect(?string $name = null): OpcUaClientInterface
{
$client = parent::connect($name);
// Custom logging / metrics / etc.
return $client;
}
}
Register the subclass via service decoration — see Configuration · Parameters and overrides.
Where to read next
- Bundle services — all the services the bundle registers.
- Console commands — CLI surface.
- Exceptions — what can be thrown.