Create a WordPress Plugin with Bazooka

Installation

Use the package manager composer to install BZK Core.

composer require fantassin/core

Usage in WordPress plugin

If you want to create a plugin you can easily start with :

use Fantassin\Core\WordPress\Plugin\PluginKernel;

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

class YourPlugin extends PluginKernel
{

	public function getTextDomain(): string
	{
		return 'your-plugin-name';
	}
}

$plugin = new YourPlugin( wp_get_environment_type(), WP_DEBUG );
add_action('plugins_loaded', [$plugin, 'load']);

Autoload services

To auto-register services you can add into root folder of your plugin or theme config/services.php file with this configuration :

<?php

use FantassinCoreWordPressVendor\Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return function (ContainerConfigurator $configurator) {
	$services = $configurator->services()
		->defaults()
		->autowire()       // Automatically injects dependencies in your services.
		->autoconfigure(); // Automatically registers your services as commands, event subscribers, etc.

	// Makes classes in your-folder/ available to be used as services.
	// This creates a service per class whose id is the fully-qualified class name.
	$services->load('YourNamespace\\', '../your-folder/*')
		->exclude('../your-folder/{Entity,Tests,OrOtherFolderToNotRegister}');
};