kynetcode/wpzylos-core

Core foundation for WPZylos framework - PluginContext, Application, ServiceProvider, and base utilities for building WordPress plugins

Maintainers

Package info

github.com/KYNetCode/wpzylos-core

Documentation

pkg:composer/kynetcode/wpzylos-core

Fund package maintenance!

Paypal

Statistics

Installs: 17

Dependents: 21

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-16 18:51 UTC

This package is auto-updated.

Last update: 2026-06-16 20:00:15 UTC


README

PHP Version License GitHub

The foundation package for WPZylos framework. Provides core interfaces, context management, and base classes for building WordPress plugins with modern architecture.

📖 Full Documentation | 🐛 Report Issues

✨ Features

  • ContextInterface — Plugin identity contract that survives PHP-Scoper
  • PluginContext — Default implementation with prefixing, paths, hooks, options, transients, cron, meta keys, and asset handles
  • Application — Plugin kernel with PSR-11 container and service provider lifecycle
  • ServiceProvider — Base class for modular service registration with convenience methods
  • Paths — Path and URL resolution with named aliases and @alias syntax
  • CacheRepository — Context-prefixed caching via WordPress object cache + transient fallback
  • UtilitiesArr (dot-notation array helpers) and Str (string manipulation) classes

📋 Requirements

Requirement Version
PHP ^8.0
WordPress 6.0+

🚀 Installation

composer require KYNetCode/wpzylos-core

📖 Quick Start

use WPZylos\Framework\Core\Application;
use WPZylos\Framework\Core\PluginContext;

// Create plugin context
$context = PluginContext::create([
    'file'       => __FILE__,
    'slug'       => 'my-plugin',
    'prefix'     => 'myplugin_',
    'textDomain' => 'my-plugin',
    'version'    => '1.0.0',
    'namespace'  => 'MyPlugin',
]);

// Create and boot application
$app = new Application($context);
$app->register(new MyServiceProvider());
$app->boot();

🏗️ Core Components

PluginContext

Holds plugin identity and configuration:

$context = PluginContext::create([
    'file'       => __FILE__,
    'slug'       => 'my-plugin',
    'prefix'     => 'myplugin_',
    'textDomain' => 'my-plugin',
    'version'    => '1.0.0',
    'namespace'  => 'MyPlugin',
]);

// Identity
$context->slug();        // 'my-plugin'
$context->prefix();      // 'myplugin_'
$context->textDomain();  // 'my-plugin'
$context->version();     // '1.0.0'
$context->namespace();   // 'MyPlugin'

// Prefixed keys
$context->optionKey('setting');          // 'myplugin_setting'
$context->hook('init');                  // 'myplugin_init'
$context->transientKey('cache');         // 'myplugin_cache'
$context->cronHook('daily_sync');        // 'myplugin_daily_sync'
$context->metaKey('order_id');           // '_myplugin_order_id'
$context->assetHandle('admin-js');       // 'my-plugin-admin-js'
$context->tableName('orders');           // 'wp_myplugin_orders'

Application

Plugin kernel that manages service providers and the DI container:

$app = new Application($context);

// Register service providers
$app->register(new DatabaseServiceProvider());
$app->register(new RoutingServiceProvider());

// Boot the application
$app->boot();

// Resolve services from the container
$service = $app->make(MyService::class);

// Check if a service is bound
$app->has(MyService::class); // true/false

ServiceProvider

Base class for modular service registration:

use WPZylos\Framework\Core\ServiceProvider;
use WPZylos\Framework\Core\Contracts\ApplicationInterface;

class MyServiceProvider extends ServiceProvider
{
    public function register(ApplicationInterface $app): void
    {
        parent::register($app);

        $this->singleton(MyService::class, function () {
            return new MyService($this->context());
        });
    }

    public function boot(ApplicationInterface $app): void
    {
        // Called after all providers are registered
        $service = $this->make(MyService::class);
    }
}

Paths

Path resolution with named aliases and @alias syntax:

$paths = $app->paths();

// Use built-in aliases
$paths->path('@views/welcome.php');     // /plugin/resources/views/welcome.php
$paths->url('@assets/css/app.css');     // https://.../resources/assets/css/app.css

// Register custom aliases (chainable)
$paths->alias('templates', 'resources/templates');

// Check existence
$paths->exists('@config/app.php');      // true/false

// Plugin uploads directory
$paths->uploads('invoices/1.pdf');      // .../wp-content/uploads/my-plugin/invoices/1.pdf

CacheRepository

Context-prefixed caching with WordPress object cache and transient fallback:

use WPZylos\Framework\Core\Cache\CacheRepository;

$cache = new CacheRepository($context);

// Object cache
$cache->put('key', 'value', 3600);
$cache->get('key');               // 'value'
$cache->forget('key');

// Remember pattern
$users = $cache->remember('active_users', 3600, function () {
    return get_users(['role' => 'subscriber']);
});

// Transient fallback (persistent across requests)
$cache->transientPut('license', $data, DAY_IN_SECONDS);
$cache->transientGet('license');
$cache->transientRemember('api_data', HOUR_IN_SECONDS, fn() => fetch_api());

📦 Related Packages

Package Description
wpzylos-container PSR-11 dependency injection
wpzylos-config Configuration management
wpzylos-hooks WordPress hook management
wpzylos-scaffold Plugin template

📖 Documentation

For comprehensive documentation, tutorials, and API reference, visit wpzylos.com.

☕ Support the Project

📄 License

MIT License. See LICENSE for details.

🤝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Made with ❤️ by KYNetCode