Neuron-PHP

Invoker
in package

Command pattern invoker that processes and executes commands by name.

The Invoker class serves as the command pattern's invoker, responsible for retrieving command objects by name and executing them with provided parameters. It provides a centralized entry point for command execution while maintaining loose coupling between command requestors and command implementations.

Key responsibilities:

  • Command retrieval via Factory pattern integration
  • Parameter validation and error handling
  • Command execution coordination
  • Exception handling for missing or invalid commands
  • Integration with caching for performance optimization

The invoker uses the Factory pattern to dynamically create command instances based on string identifiers, allowing for flexible command registration and execution without tight coupling to specific command implementations.

Tags
see
Factory

Command factory for dynamic command creation

see
Cache

Command caching for performance optimization

see
ICommand

Command interface

example
// Execute a command through the invoker
$invoker = new Invoker();

// Process email command
$result = $invoker->process('email', [
    'to' => '[email protected]',
    'subject' => 'Welcome',
    'body' => 'Welcome to our application!'
]);

// Process database cleanup command
$invoker->process('cleanup-temp-data', ['days' => 7]);

// Process file processing command
$invoker->process('process-upload', [
    'filename' => 'document.pdf',
    'user_id' => 123
]);

Table of Contents

Methods

process()  : mixed

Methods

process()

public process(string $action[, array<string|int, mixed>|null $params = null ]) : mixed
Parameters
$action : string
$params : array<string|int, mixed>|null = null
Tags
throws
CommandNotFound
throws
EmptyActionParameter

        
On this page

Search results