Examples

Real-world code samples for WPZylos Config.

Application Config

// config/app.php
return [
    'name' => 'My Plugin',
    'slug' => 'my-plugin',
    'version' => '1.0.0',
    'text_domain' => 'my-plugin',

    'providers' => [
        App\Providers\AppServiceProvider::class,
        App\Providers\RouteServiceProvider::class,
        App\Providers\EventServiceProvider::class,
    ],

    'aliases' => [
        'Config' => WPZylos\Framework\Config\ConfigRepository::class,
        'Route' => WPZylos\Framework\Routing\Route::class,
    ],
];

Database Config

// config/database.php
return [
    'prefix' => 'myplugin_',

    'tables' => [
        'products',
        'orders',
        'order_items',
        'customers',
    ],

    'query_log' => WPZylos\Framework\Config\EnvLoader::env('DB_QUERY_LOG', false),
];

Logging Config

// config/logging.php
return [
    'default' => 'file',

    'channels' => [
        'file' => [
            'driver' => 'file',
            'path' => 'logs/plugin.log',
            'level' => 'debug',
        ],

        'error_log' => [
            'driver' => 'error_log',
            'level' => 'warning',
        ],
    ],
];

Using Config in Services

class PluginService
{
    public function __construct(
        private ConfigRepository $config
    ) {}

    public function getVersion(): string
    {
        return $this->config->get('app.version');
    }

    public function isDebugMode(): bool
    {
        return $this->config->get('app.debug', false);
    }

    public function getApiConfig(): array
    {
        return $this->config->get('api', [
            'timeout' => 30,
            'retry' => 3,
        ]);
    }
}

Dynamic Configuration

// Set runtime config
$config->set('api.timeout', 60);

// Check if exists
if ($config->has('api.key')) {
    // Use API key
}

// Get all config for a file
$appConfig = $config->get('app');