Examples

Complete Plugin Bootstrap

<?php
/**
 * Plugin Name: My Plugin
 * Version: 1.0.0
 * Requires PHP: 8.1
 */

declare(strict_types=1);

defined('ABSPATH') || exit;

require_once __DIR__ . '/vendor/autoload.php';

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

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

// Activation hook (uses closure for context)
register_activation_hook(__FILE__, function () use ($context) {
    // Activation logic
});

// Bootstrap on plugins_loaded
add_action('plugins_loaded', function () use ($context) {
    $app = new Application($context);
    $app->boot();
});

Custom Service Provider

<?php

declare(strict_types=1);

namespace MyPlugin\Providers;

use WPZylos\Framework\Core\ServiceProvider;
use WPZylos\Framework\Core\Contracts\ApplicationInterface;
use MyPlugin\Services\PaymentGateway;
use MyPlugin\Services\EmailService;

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

        // Singleton (shared instance)
        $this->singleton(PaymentGateway::class, function () {
            $config = $this->app->make('config');
            return new PaymentGateway(
                $config->get('payments.api_key'),
                $config->get('payments.sandbox', false)
            );
        });

        // Factory (new instance each time)
        $this->bind(EmailService::class, function () {
            return new EmailService($this->app->context()->textDomain());
        });
    }
}

Using Paths

<?php

use WPZylos\Framework\Core\Paths;

$paths = new Paths($context->path());

// Add custom aliases
$paths->addAlias('@templates', 'resources/templates');
$paths->addAlias('@assets', 'public/assets');

// Resolve paths
$templatePath = $paths->path('@templates/email/welcome.php');
$assetUrl = $paths->url('@assets/css/style.css');

Extending PluginContext

<?php

declare(strict_types=1);

namespace MyPlugin\Core;

use WPZylos\Framework\Core\PluginContext as BaseContext;

class PluginContext extends BaseContext
{
    public function apiEndpoint(): string
    {
        return 'https://api.example.com/v1';
    }

    public function isDebug(): bool
    {
        return defined('WP_DEBUG') && WP_DEBUG;
    }
}