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;
}
MethodParametersReturnsDescription
slug()stringPlugin slug (e.g., 'my-plugin')
prefix()stringPlugin prefix for options, hooks (e.g., 'myplugin_')
textDomain()stringTranslation text domain
version()stringSemantic version string
namespace()stringPlugin root namespace (e.g., 'MyPlugin')
file()stringAbsolute path to the main plugin file
path()string $relativePath = ''stringAbsolute path within the plugin directory
url()string $relativePath = ''stringFull URL within the plugin directory
hook()string $namestringPrefixed custom hook name (e.g., 'myplugin_after_save')
optionKey()string $keystringPrefixed option key (e.g., 'myplugin_version')
transientKey()string $keystringPrefixed transient key (e.g., 'myplugin_cache_data')
cronHook()string $namestringPrefixed cron hook name (e.g., 'myplugin_daily_cleanup')
tableName()string $name, string $scope = 'site'stringFull table name with WP prefix (e.g., 'wp_myplugin_orders')
metaKey()string $keystringPrefixed meta key with leading underscore (e.g., '_myplugin_order_id')
assetHandle()string $handlestringPrefixed 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;
}
MethodParametersReturnsDescription
context()ContextInterfaceGet the plugin context
container()ContainerInterfaceGet the PSR-11 DI container
register()ServiceProviderInterface $providerstaticRegister a service provider
boot()voidBoot the application and all registered providers
isBooted()boolCheck if the application has been booted
make()string $abstractmixedResolve a service from the container
bind()string $abstract, callable|string|null $concrete = nullvoidBind a service to the container
singleton()string $abstract, callable|string|null $concrete = nullvoidBind 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;
}
MethodParametersReturnsDescription
register()ApplicationInterface $appvoidRegister services during the registration phase
boot()ApplicationInterface $appvoidBootstrap 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:

AbstractResolves To
ApplicationInterface::class$this (the Application instance)
Application::class$this
'app'$this
ContextInterface::classPlugin context
'context'Plugin context
Paths::classPaths instance
'paths'Paths instance

Methods

MethodParametersReturnsDescription
context()ContextInterfaceGet the plugin context
container()ContainerInterfaceGet the underlying PSR-11 container
paths()PathsGet the paths resolver
register()ServiceProviderInterface $providerstaticRegister a service provider. If already booted, boots the provider immediately
boot()voidBoot the application (no-op if already booted)
isBooted()boolCheck if the application has been booted
make()string $abstractmixedResolve a service from the container
bind()string $abstract, callable|string|null $concrete = nullvoidBind a service to the container
singleton()string $abstract, callable|string|null $concrete = nullvoidBind a singleton service to the container
getProviders()ServiceProviderInterface[]Get all registered providers
has()string $abstractboolCheck 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

PropertyTypeVisibilityDescription
$appApplicationInterfaceprotectedThe application instance (set during register())

Methods

MethodParametersReturnsVisibilityDescription
register()ApplicationInterface $appvoidpublicStores $app reference. Override in child classes to bind services (call parent::register($app) first)
boot()ApplicationInterface $appvoidpublicCalled during boot phase. Override in child classes for boot-time setup. Default does nothing
bind()string $abstract, callable|string|null $concrete = nullvoidprotectedShortcut to bind a service via $this->app->bind()
singleton()string $abstract, callable|string|null $concrete = nullvoidprotectedShortcut to bind a singleton via $this->app->singleton()
make()string $abstractmixedprotectedShortcut to resolve a service via $this->app->make()
context()ContextInterfaceprotectedShortcut 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:

KeyTypeDescriptionExample
filestringAbsolute path to main plugin file__FILE__
slugstringPlugin slug (used in URLs, handles)'my-plugin'
prefixstringPrefix for options, hooks, DB tables'myplugin_'
textDomainstringTranslation text domain'my-plugin'
versionstringSemantic version'1.0.0'
namespacestringRoot PHP namespace'MyPlugin'

Optional config keys:

KeyTypeDescription
commitstring|nullGit commit hash for debugging

Throws InvalidArgumentException if any required key is missing.

Instance Methods

MethodParametersReturnsDescription
slug()stringPlugin slug
prefix()stringPlugin prefix
textDomain()stringText domain
version()stringPlugin version
namespace()stringRoot namespace
commit()string|nullGit commit hash (if set)
file()stringMain plugin file path
path()string $relativePath = ''stringAbsolute path within plugin directory
url()string $relativePath = ''stringFull URL within plugin directory
hook()string $namestringPrefixed hook name: prefix + name
optionKey()string $keystringPrefixed option key: prefix + key
transientKey()string $keystringPrefixed transient key: prefix + key
cronHook()string $namestringPrefixed cron hook: prefix + name
tableName()string $name, string $scope = 'site'stringFull table name: wp_prefix + plugin_prefix + name
metaKey()string $keystringPrefixed meta key: _ + prefix + key
assetHandle()string $handlestringPrefixed 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:

AliasRelative Path
appapp
configconfig
routesroutes
resourcesresources
viewsresources/views
langresources/lang
assetsresources/assets
databasedatabase
migrationsdatabase/migrations
storagestorage
logsstorage/logs
cachestorage/cache

Methods

MethodParametersReturnsDescription
alias()string $alias, string $pathstaticRegister a custom path alias. Returns $this for chaining
path()string $path = ''stringGet absolute path. Supports @alias prefix (e.g., '@views/welcome.php')
url()string $path = ''stringGet full URL. Supports @alias prefix (e.g., '@assets/css/app.css')
exists()string $pathboolCheck if a path exists on the filesystem
uploads()string $subPath = ''stringGet 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

MethodParametersReturnsDescription
get()string $key, mixed $default = nullmixedGet item from cache
put()string $key, mixed $value, int $ttl = 3600boolStore item in cache
add()string $key, mixed $value, int $ttl = 3600boolStore item only if it doesn't already exist
forget()string $keyboolRemove item from cache
has()string $keyboolCheck if item exists in cache
remember()string $key, int $ttl, callable $callbackmixedGet item or store result of callback
rememberForever()string $key, callable $callbackmixedGet item or store forever (TTL=0)
increment()string $key, int $amount = 1int|falseIncrement a numeric value
decrement()string $key, int $amount = 1int|falseDecrement a numeric value
flush()boolFlush all items in the cache group. Requires wp_cache_flush_group() support

Transient Methods (Persistent Fallback)

MethodParametersReturnsDescription
transientGet()string $key, mixed $default = nullmixedGet transient value
transientPut()string $key, mixed $value, int $ttl = 3600boolStore transient value
transientForget()string $keyboolDelete transient
transientRemember()string $key, int $ttl, callable $callbackmixedGet transient or store result of callback

Arr

Namespace: WPZylos\Framework\Core\Support

Static array helper utilities with dot-notation support.

MethodParametersReturnsDescription
get()array $array, string|int|null $key, mixed $default = nullmixedGet item using dot notation
set()array &$array, string|int|null $key, mixed $valuearraySet item using dot notation
has()array $array, string|int $keyboolCheck if item exists using dot notation
forget()array &$array, string|int|array $keysvoidRemove item(s) using dot notation
flatten()array $array, int $depth = PHP_INT_MAXarrayFlatten multidimensional array
only()array $array, array $keysarrayGet only specified keys
except()array $array, array $keysarrayGet all keys except specified ones
first()array $array, ?callable $callback = null, mixed $default = nullmixedGet the first element (optionally matching a callback)
wrap()mixed $valuearrayWrap value in an array if not already. null returns []

Str

Namespace: WPZylos\Framework\Core\Support

Static string helper utilities.

MethodParametersReturnsDescription
snake()string $valuestringConvert to snake_case
camel()string $valuestringConvert to camelCase
studly()string $valuestringConvert to StudlyCase
kebab()string $valuestringConvert to kebab-case
startsWith()string $haystack, string|array $needlesboolCheck if string starts with substring(s)
endsWith()string $haystack, string|array $needlesboolCheck if string ends with substring(s)
contains()string $haystack, string|array $needlesboolCheck if string contains substring(s)
limit()string $value, int $limit = 100, string $end = '...'stringTruncate string to given length
random()int $length = 16stringGenerate a random string
slug()string $value, string $separator = '-'stringGenerate a URL-safe slug (with transliteration)
replaceFirst()string $search, string $replace, string $subjectstringReplace first occurrence of a substring
before()string $subject, string $searchstringGet portion of string before a value
after()string $subject, string $searchstringGet portion of string after a value