API Reference
Complete API reference for all classes and interfaces in wpzylos-core. All method signatures are documented exactly as they exist in the source code.
Interfaces
ContextInterface
Namespace: WPZylos\Framework\Core\Contracts
Plugin identity contract. Framework packages depend on this interface, not concrete implementations. Each plugin provides its own PluginContext implementing this interface — the pattern survives PHP-Scoper namespace rewriting.
interface ContextInterface
{
public function slug(): string;
public function prefix(): string;
public function textDomain(): string;
public function version(): string;
public function namespace(): string;
public function file(): string;
public function path(string $relativePath = ''): string;
public function url(string $relativePath = ''): string;
public function hook(string $name): string;
public function optionKey(string $key): string;
public function transientKey(string $key): string;
public function cronHook(string $name): string;
public function tableName(string $name, string $scope = 'site'): string;
public function metaKey(string $key): string;
public function assetHandle(string $handle): string;
}
| Method | Parameters | Returns | Description |
|---|---|---|---|
slug() | — | string | Plugin slug (e.g., 'my-plugin') |
prefix() | — | string | Plugin prefix for options, hooks (e.g., 'myplugin_') |
textDomain() | — | string | Translation text domain |
version() | — | string | Semantic version string |
namespace() | — | string | Plugin root namespace (e.g., 'MyPlugin') |
file() | — | string | Absolute path to the main plugin file |
path() | string $relativePath = '' | string | Absolute path within the plugin directory |
url() | string $relativePath = '' | string | Full URL within the plugin directory |
hook() | string $name | string | Prefixed custom hook name (e.g., 'myplugin_after_save') |
optionKey() | string $key | string | Prefixed option key (e.g., 'myplugin_version') |
transientKey() | string $key | string | Prefixed transient key (e.g., 'myplugin_cache_data') |
cronHook() | string $name | string | Prefixed cron hook name (e.g., 'myplugin_daily_cleanup') |
tableName() | string $name, string $scope = 'site' | string | Full table name with WP prefix (e.g., 'wp_myplugin_orders') |
metaKey() | string $key | string | Prefixed meta key with leading underscore (e.g., '_myplugin_order_id') |
assetHandle() | string $handle | string | Prefixed asset handle using slug (e.g., 'my-plugin-admin-js') |
ApplicationInterface
Namespace: WPZylos\Framework\Core\Contracts
The Application is the kernel of the framework. Each plugin has its own isolated Application instance with a private container.
interface ApplicationInterface
{
public function context(): ContextInterface;
public function container(): ContainerInterface;
public function register(ServiceProviderInterface $provider): static;
public function boot(): void;
public function isBooted(): bool;
public function make(string $abstract): mixed;
public function bind(string $abstract, callable|string|null $concrete = null): void;
public function singleton(string $abstract, callable|string|null $concrete = null): void;
}
| Method | Parameters | Returns | Description |
|---|---|---|---|
context() | — | ContextInterface | Get the plugin context |
container() | — | ContainerInterface | Get the PSR-11 DI container |
register() | ServiceProviderInterface $provider | static | Register a service provider |
boot() | — | void | Boot the application and all registered providers |
isBooted() | — | bool | Check if the application has been booted |
make() | string $abstract | mixed | Resolve a service from the container |
bind() | string $abstract, callable|string|null $concrete = null | void | Bind a service to the container |
singleton() | string $abstract, callable|string|null $concrete = null | void | Bind a singleton service to the container |
ServiceProviderInterface
Namespace: WPZylos\Framework\Core\Contracts
Service providers are the central place to configure and bootstrap application services.
interface ServiceProviderInterface
{
public function register(ApplicationInterface $app): void;
public function boot(ApplicationInterface $app): void;
}
| Method | Parameters | Returns | Description |
|---|---|---|---|
register() | ApplicationInterface $app | void | Register services during the registration phase |
boot() | ApplicationInterface $app | void | Bootstrap services after all providers are registered |
Classes
Application
Namespace: WPZylos\Framework\CoreImplements: ApplicationInterface
The central service container and provider coordinator. Each plugin has its own isolated Application instance.
Constructor
public function __construct(ContextInterface $context, ?ContainerInterface $container = null)
If no container is provided, the constructor auto-creates a WPZylos\Framework\Container\Container instance. Throws RuntimeException if the wpzylos-container package is not installed and no container is passed.
Auto-registered Bindings
The constructor automatically registers these bindings:
| Abstract | Resolves To |
|---|---|
ApplicationInterface::class | $this (the Application instance) |
Application::class | $this |
'app' | $this |
ContextInterface::class | Plugin context |
'context' | Plugin context |
Paths::class | Paths instance |
'paths' | Paths instance |
Methods
| Method | Parameters | Returns | Description |
|---|---|---|---|
context() | — | ContextInterface | Get the plugin context |
container() | — | ContainerInterface | Get the underlying PSR-11 container |
paths() | — | Paths | Get the paths resolver |
register() | ServiceProviderInterface $provider | static | Register a service provider. If already booted, boots the provider immediately |
boot() | — | void | Boot the application (no-op if already booted) |
isBooted() | — | bool | Check if the application has been booted |
make() | string $abstract | mixed | Resolve a service from the container |
bind() | string $abstract, callable|string|null $concrete = null | void | Bind a service to the container |
singleton() | string $abstract, callable|string|null $concrete = null | void | Bind a singleton service to the container |
getProviders() | — | ServiceProviderInterface[] | Get all registered providers |
has() | string $abstract | bool | Check if a service is bound in the container |
ServiceProvider
Namespace: WPZylos\Framework\CoreImplements: ServiceProviderInterface
Abstract base class for all service providers. Stores the $app reference on register() and provides convenient shortcut methods.
Properties
| Property | Type | Visibility | Description |
|---|---|---|---|
$app | ApplicationInterface | protected | The application instance (set during register()) |
Methods
| Method | Parameters | Returns | Visibility | Description |
|---|---|---|---|---|
register() | ApplicationInterface $app | void | public | Stores $app reference. Override in child classes to bind services (call parent::register($app) first) |
boot() | ApplicationInterface $app | void | public | Called during boot phase. Override in child classes for boot-time setup. Default does nothing |
bind() | string $abstract, callable|string|null $concrete = null | void | protected | Shortcut to bind a service via $this->app->bind() |
singleton() | string $abstract, callable|string|null $concrete = null | void | protected | Shortcut to bind a singleton via $this->app->singleton() |
make() | string $abstract | mixed | protected | Shortcut to resolve a service via $this->app->make() |
context() | — | ContextInterface | protected | Shortcut to get the plugin context via $this->app->context() |
PluginContext
Namespace: WPZylos\Framework\CoreImplements: ContextInterface
Holds all plugin identity information. The single source of truth for slug, prefix, text domain, paths, and URLs.
Note: In production plugins, this class should be copied into the plugin's own namespace to survive PHP-Scoper. The framework depends on
ContextInterface, not this concrete class.
Static Factory
public static function create(array $config): static
Required config keys:
| Key | Type | Description | Example |
|---|---|---|---|
file | string | Absolute path to main plugin file | __FILE__ |
slug | string | Plugin slug (used in URLs, handles) | 'my-plugin' |
prefix | string | Prefix for options, hooks, DB tables | 'myplugin_' |
textDomain | string | Translation text domain | 'my-plugin' |
version | string | Semantic version | '1.0.0' |
namespace | string | Root PHP namespace | 'MyPlugin' |
Optional config keys:
| Key | Type | Description |
|---|---|---|
commit | string|null | Git commit hash for debugging |
Throws InvalidArgumentException if any required key is missing.
Instance Methods
| Method | Parameters | Returns | Description |
|---|---|---|---|
slug() | — | string | Plugin slug |
prefix() | — | string | Plugin prefix |
textDomain() | — | string | Text domain |
version() | — | string | Plugin version |
namespace() | — | string | Root namespace |
commit() | — | string|null | Git commit hash (if set) |
file() | — | string | Main plugin file path |
path() | string $relativePath = '' | string | Absolute path within plugin directory |
url() | string $relativePath = '' | string | Full URL within plugin directory |
hook() | string $name | string | Prefixed hook name: prefix + name |
optionKey() | string $key | string | Prefixed option key: prefix + key |
transientKey() | string $key | string | Prefixed transient key: prefix + key |
cronHook() | string $name | string | Prefixed cron hook: prefix + name |
tableName() | string $name, string $scope = 'site' | string | Full table name: wp_prefix + plugin_prefix + name |
metaKey() | string $key | string | Prefixed meta key: _ + prefix + key |
assetHandle() | string $handle | string | Prefixed asset handle: slug + '-' + handle |
Paths
Namespace: WPZylos\Framework\Core
Path and URL resolution with named alias support. Created automatically by Application and accessible via $app->paths().
Constructor
public function __construct(ContextInterface $context)
Registers the following default aliases:
| Alias | Relative Path |
|---|---|
app | app |
config | config |
routes | routes |
resources | resources |
views | resources/views |
lang | resources/lang |
assets | resources/assets |
database | database |
migrations | database/migrations |
storage | storage |
logs | storage/logs |
cache | storage/cache |
Methods
| Method | Parameters | Returns | Description |
|---|---|---|---|
alias() | string $alias, string $path | static | Register a custom path alias. Returns $this for chaining |
path() | string $path = '' | string | Get absolute path. Supports @alias prefix (e.g., '@views/welcome.php') |
url() | string $path = '' | string | Get full URL. Supports @alias prefix (e.g., '@assets/css/app.css') |
exists() | string $path | bool | Check if a path exists on the filesystem |
uploads() | string $subPath = '' | string | Get WP uploads directory for the plugin. Creates directory if it doesn't exist |
getAliases() | — | array<string, string> | Get all registered aliases as alias => path mapping |
CacheRepository
Namespace: WPZylos\Framework\Core\Cache
Context-prefixed caching layer using WordPress object cache with transient fallback.
Constructor
public function __construct(ContextInterface $context)
Uses the plugin slug as the cache group name.
Object Cache Methods
| Method | Parameters | Returns | Description |
|---|---|---|---|
get() | string $key, mixed $default = null | mixed | Get item from cache |
put() | string $key, mixed $value, int $ttl = 3600 | bool | Store item in cache |
add() | string $key, mixed $value, int $ttl = 3600 | bool | Store item only if it doesn't already exist |
forget() | string $key | bool | Remove item from cache |
has() | string $key | bool | Check if item exists in cache |
remember() | string $key, int $ttl, callable $callback | mixed | Get item or store result of callback |
rememberForever() | string $key, callable $callback | mixed | Get item or store forever (TTL=0) |
increment() | string $key, int $amount = 1 | int|false | Increment a numeric value |
decrement() | string $key, int $amount = 1 | int|false | Decrement a numeric value |
flush() | — | bool | Flush all items in the cache group. Requires wp_cache_flush_group() support |
Transient Methods (Persistent Fallback)
| Method | Parameters | Returns | Description |
|---|---|---|---|
transientGet() | string $key, mixed $default = null | mixed | Get transient value |
transientPut() | string $key, mixed $value, int $ttl = 3600 | bool | Store transient value |
transientForget() | string $key | bool | Delete transient |
transientRemember() | string $key, int $ttl, callable $callback | mixed | Get transient or store result of callback |
Arr
Namespace: WPZylos\Framework\Core\Support
Static array helper utilities with dot-notation support.
| Method | Parameters | Returns | Description |
|---|---|---|---|
get() | array $array, string|int|null $key, mixed $default = null | mixed | Get item using dot notation |
set() | array &$array, string|int|null $key, mixed $value | array | Set item using dot notation |
has() | array $array, string|int $key | bool | Check if item exists using dot notation |
forget() | array &$array, string|int|array $keys | void | Remove item(s) using dot notation |
flatten() | array $array, int $depth = PHP_INT_MAX | array | Flatten multidimensional array |
only() | array $array, array $keys | array | Get only specified keys |
except() | array $array, array $keys | array | Get all keys except specified ones |
first() | array $array, ?callable $callback = null, mixed $default = null | mixed | Get the first element (optionally matching a callback) |
wrap() | mixed $value | array | Wrap value in an array if not already. null returns [] |
Str
Namespace: WPZylos\Framework\Core\Support
Static string helper utilities.
| Method | Parameters | Returns | Description |
|---|---|---|---|
snake() | string $value | string | Convert to snake_case |
camel() | string $value | string | Convert to camelCase |
studly() | string $value | string | Convert to StudlyCase |
kebab() | string $value | string | Convert to kebab-case |
startsWith() | string $haystack, string|array $needles | bool | Check if string starts with substring(s) |
endsWith() | string $haystack, string|array $needles | bool | Check if string ends with substring(s) |
contains() | string $haystack, string|array $needles | bool | Check if string contains substring(s) |
limit() | string $value, int $limit = 100, string $end = '...' | string | Truncate string to given length |
random() | int $length = 16 | string | Generate a random string |
slug() | string $value, string $separator = '-' | string | Generate a URL-safe slug (with transliteration) |
replaceFirst() | string $search, string $replace, string $subject | string | Replace first occurrence of a substring |
before() | string $subject, string $search | string | Get portion of string before a value |
after() | string $subject, string $search | string | Get portion of string after a value |