Services

StorageServiceInterface

v1.0.0

File storage interface for uploads, generated assets, and public URLs.

Access

$ctx->storage()?->put('reports/latest.json', $json);

How To Use It

  • Use it when the module owns generated files, exports, or uploaded assets that need a stable runtime path and URL.
  • Check existence and retrieve public URLs through the service instead of manually assuming a WordPress uploads path layout.

Methods

public function put(string $path, string $contents): string

Stores a file and returns the resolved storage path.

public function get(string $path): ?string

Reads a stored file and returns its contents or null when missing.

public function delete(string $path): bool

Deletes a stored file and reports success.

public function exists(string $path): bool

Checks whether a stored file exists.

public function url(string $path): string

Returns the public URL for a stored file.

Example

bootstrap.php
public function exportReport(SdkContext $ctx, array $report): string
{
    $path = $ctx->storage()?->put(
        'reports/latest.json',
        wp_json_encode($report, JSON_PRETTY_PRINT) ?: '{}'
    );

    return $ctx->storage()?->url($path ?? 'reports/latest.json') ?? '';
}