PHP Luminova: Interfaces and Class Contracts
Luminova’s interface contracts and the method signatures required by implementing classes.
Interfaces define what a class must provide so framework components can use it interchangeably with other implementations. Framework interfaces share the Luminova\Interface namespace.
Interface Implementation
A concrete class must implement the methods declared by the interface and any parent interfaces, unless a base class already supplies them. Keep method visibility, static declarations, and parameter and return types compatible with the contract. Marker interfaces have no methods. Implement them when a feature checks for that type.
use Luminova\Interface\InvokableInterface;
class JoinWords implements InvokableInterface
{
public function __invoke(mixed ...$arguments): mixed
{
return implode(' ', $arguments);
}
}ExceptionInterface
Namespace: Luminova\Interface\ExceptionInterface
This interface acts as a foundational contract for custom exception classes, standardizing exception handling and error logging throughout the application. It covers error code checks, sanitized messages, backtraces, logging through the configured pipeline, and handling an exception through the framework error pipeline instead of throwing it.
See Exception handling.
ErrorControllerInterface
Namespace: Luminova\Interface\ErrorControllerInterface
This interface specifies the type of controller class used in the router for managing errors. Implement it on the application error controller to provide public static function onTrigger(int $status, Segments $segments): int. The method accepts the HTTP status and request URI segments and returns STATUS_SUCCESS or STATUS_SILENCE.
See HTTP controller error handling.
CookieInterface
Namespace: Luminova\Interface\CookieInterface
Interface for managing a single HTTP client-side cookie, providing methods to create it from a Set-Cookie header or an array, read its value and options, update them, and convert the cookie to a header string or array.
See Cookie.
CookieJarInterface
Namespace: Luminova\Interface\CookieJarInterface
This interface defines the contract for the implementing HTTP cookie file jar. It covers creating a jar, setting and retrieving cookies by name or domain, parsing cookies from Set-Cookie headers or $_COOKIE, saving changes with commit(), and exporting cookies in Netscape format.
See Cookie File Jar.
DatabaseDriverInterface
Namespace: Luminova\Interface\DatabaseDriverInterface
This interface defines methods for establishing and managing database connections, preparing and executing SQL statements, managing transactions and database locks, binding parameters, and fetching query results. It serves as a contract for implementing various database drivers.
See Database driver connections.
DriverConnectionInterface
Namespace: Luminova\Interface\DriverConnectionInterface
This interface specifies the type of connection wrapper returned by a database driver's getConn() method. The wrapper exposes the underlying PDO or mysqli object through getConn(), and provides close(), isConnected(), isPdo() and isMysqli(), allowing interchangeable implementations while adhering to a common contract.
See Native PDO and MySQLi connection wrapper.
EncryptionInterface
Namespace: Luminova\Interface\EncryptionInterface
Interface for encryption and decryption drivers, defining methods for encrypting data with various cryptographic algorithms and keys, as well as decrypting encrypted data. It also supports associated authentication data (AEAD) and nonce management.
See Encryption drivers.
ClientInterface
Namespace: Luminova\Interface\ClientInterface
This interface defines methods for HTTP client drivers (e.g., Novio and the Guzzle adapter), enabling the sending of synchronous and asynchronous network requests and manipulation of responses. It extends the PSR-18 Psr\Http\Client\ClientInterface.
RequestInterface
Namespace: Luminova\Interface\RequestInterface
This interface defines the contract for handling HTTP request data within the Luminova framework. Implementations of this interface are responsible for encapsulating the details of incoming HTTP requests, such as request methods, headers, query parameters, payloads, uploaded files, cookies, and client information. It extends the PSR-7 Psr\Http\Message\RequestInterface.
See Incoming Request.
ResponseInterface
Namespace: Luminova\Interface\ResponseInterface
Defines the contract for handling HTTP client responses in Luminova. The framework response adds conveniences such as getContents() and toString() and extends the PSR-7 Psr\Http\Message\ResponseInterface.
See HTTP client response object.
ContentResponseInterface
Namespace: Luminova\Interface\ContentResponseInterface
The interface defines the methods for building and sending the application's HTTP response. This interface handles the final output that will be sent back to the client, such as HTML, JSON, XML and TEXT, along with status codes, headers, compression, minification, file downloads, streaming and redirects.
See Application response handling.
PromiseInterface
Namespace: Luminova\Interface\PromiseInterface
The contract for promise-based implementations in Luminova, including the Luminova\Promise\Promise class. It defines methods for chaining handlers (then, catch, finally), resolving, rejecting and cancelling a promise, and waiting for its result.
See Promise resolver.
AwaitableInterface
Namespace: Luminova\Interface\AwaitableInterface
This interface defines the contract for asynchronous tasks, such as FiberFuture and ProcessFuture, that can be started, polled and awaited. It provides state checks (isPending(), isRunning(), isCompleted(), isFailed(), and others), tick() for non-blocking polling, value() for reading the result, and await() for waiting until the task completes.
See Async and await.
MailerInterface
Namespace: Luminova\Interface\MailerInterface
This interface outlines methods for composing and sending emails, managing attachments, specifying recipient and sender addresses, and configuring email delivery options.
See Mail delivery.
SessionInterface
Namespace: Luminova\Interface\SessionInterface
This interface defines the contract for the application session class. It covers starting and closing a session, reading and writing session items, login state and metadata, login attempt tracking, IP locking, and user role guards.
See Session handling.
SessionManagerInterface
Namespace: Luminova\Interface\SessionManagerInterface
This interface offers methods for managing backend session storage drivers (Luminova\Sessions\Managers\SessionManager and Luminova\Sessions\Managers\CookieManager), including starting a session, storing and retrieving session items, regenerating the session identifier, and closing or clearing session data.
See Session manager configuration.
InputValidationInterface
Namespace: Luminova\Interface\InputValidationInterface
Interface for validating user-submitted input data against predefined rules. It provides methods for defining validation rules and custom messages, applying them to a request or array body, and retrieving validation errors, thereby ensuring data integrity and enforcing validation constraints in applications.
See Input validation.
AuthenticatorInterface
Namespace: Luminova\Interface\AuthenticatorInterface
This interface defines the contract for implementing Time-Based One-Time Password (TOTP) generation and validation. It serves as the foundation for managing secrets, generating QR codes, and validating TOTP codes, leveraging tools like Google Authenticator or similar implementations.
See TOTP authentication.
AIAgentInterface
Namespace: Luminova\Interface\AIAgentInterface
This interface defines the contract for AI agents. The supported implementations are Luminova\AI\Agents\OpenAI, Luminova\AI\Agents\Anthropic and Luminova\AI\Agents\Ollama. It covers chat and text generation, image generation and vision, embeddings, speech and audio transcription, model listing, web search, and fine-tuning. When extending AbstractAiAgent, provide the required chat and vision implementations. Some optional base methods return an empty array or false. Check the contract for each method and the provider’s supported features.
See Base AI Agent.
ArrayableInterface
Namespace: Luminova\Interface\ArrayableInterface
Contract for objects that expose an explicit array representation. It extends JsonSerializable and requires toArray(), __toArray() and jsonSerialize(). Call toArray() or __toArray() for array conversion. PHP calls jsonSerialize() when it encodes the object with json_encode().
InvokableInterface
Namespace: Luminova\Interface\InvokableInterface
Defines a contract for classes that can be called as functions. Implementations must provide the magic __invoke(mixed ...$arguments): mixed method.
QueueableInterface
Namespace: Luminova\Interface\QueueableInterface
Contract for tasks that can be queued and executed in the background. It extends InvokableInterface and adds deleteOnCompletion(), which determines whether the task is removed after it completes successfully.
See Database task queue.
TaskWorkerInterface
Namespace: Luminova\Interface\TaskWorkerInterface
Implement this interface on a database task handler that needs the worker’s terminal input. When an Input instance is available, the queue calls the setter before invoking the task and uses the returned handler instance. Store the input where your handler can read its arguments and options.
public function setCommandInput(Input $input): self;| Parameter | Type | Description |
|---|---|---|
$input | Luminova\Command\Input | Command input supplied by the queue worker. |
Return:
self - Returns the handler instance to use for execution.
See Database task queue base class.
PrototypeableInterface
Namespace: Luminova\Interface\PrototypeableInterface
A marker interface for classes that support prototypal behavior, allowing properties and methods to be added at runtime. Use it together with the Luminova\Components\Object\Prototypeable trait.
use Luminova\Components\Object\Prototypeable;
use Luminova\Interface\PrototypeableInterface;
class User implements PrototypeableInterface
{
use Prototypeable;
}
$user = new User();
$user->prototype('nickname', 'Johnny');
$user->prototype('sayHello', fn() => "Hello from {$this->nickname}");
echo $user->nickname; // "Johnny"
echo $user->sayHello(); // "Hello from Johnny"RoutableInterface
Namespace: Luminova\Interface\RoutableInterface
Marker interface for custom classes that receive routed calls. The framework’s HTTP and CLI AbstractController classes already implement it. A standalone routable class can declare the marker while meeting the same route and handler requirements.
See Routing overview.
RouterInterface
Namespace: Luminova\Interface\RouterInterface
Implement this contract to supply a custom application router. It covers application binding, controller namespaces, routing contexts, dispatch, HTTP and CLI route registration, error handling, and URI inspection. The application kernel’s getRoutingSystem() method must return a RouterInterface.
See Routing overview.
LazyObjectInterface
Namespace: Luminova\Interface\LazyObjectInterface
This marker interface lets a property accept both a compatible lazy proxy and the target object. Create the lazy instance with LazyObject::newObject().
Implementation
To use the LazyObjectInterface, implement it in your class:
// /app/Utils/Foo.php
namespace App\Utils;
use Luminova\Interface\LazyObjectInterface;
class Foo implements LazyObjectInterface
{
// Foo class methods
}Usage Example
Below is an example demonstrating how to use the LazyObjectInterface with the Luminova\Components\Object\LazyObject utility for initializing a lazy-loaded instance:
use Luminova\Interface\LazyObjectInterface;
use Luminova\Components\Object\LazyObject;
use App\Utils\Foo;
class SomeClass
{
/**
* Lazy-loaded instance of Foo.
*
*/
private ?LazyObjectInterface $foo = null;
public function __construct()
{
// Initialize the lazy-loaded instance of Foo.
$this->foo = LazyObject::newObject(Foo::class);
}
}See Lazy Object.