PHP code example of bmd / wp-framework

1. Go to this page and download the library: Download bmd/wp-framework library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bmd / wp-framework example snippets







namespace Acme\Plugin;

use Bmd\WPFramework\Main;

final class App extends Main
{
	public const PACKAGE = 'acme_plugin';
}

( new App(
	[
		'config.dir' => __DIR__,
		'config.url' => plugin_dir_url( __FILE__ ),
	]
) )->mount();



namespace Acme\Plugin\Controllers;

use Bmd\WPFramework\Abstracts\Controller;

final class NoticesController extends Controller
{
	public function mountActions(): void
	{
		add_action( 'admin_notices', [ $this, 'renderNotice' ] );
	}

	public function renderNotice(): void
	{
		// Render your notice.
	}
}



namespace Acme\Plugin;

use Acme\Plugin\Controllers\NoticesController;
use Acme\Plugin\Services\ApiClient;
use Bmd\WPFramework\Main;
use Bmd\WPFramework\Services\ServiceLocator;

final class App extends Main
{
	public const PACKAGE = 'acme_plugin';

	public static function getServiceDefinitions(): array
	{
		return array_merge(
			parent::getServiceDefinitions(),
			[
				ApiClient::class => ServiceLocator::autowire(),
				NoticesController::class => ServiceLocator::autowire(),
			]
		);
	}
}

$api_client = App::locateService( ApiClient::class );

add_filter(
	'acme_plugin_config',
	static function ( array $config ): array {
		$config['config.dir'] = plugin_dir_path( __FILE__ );
		$config['config.url'] = plugin_dir_url( __FILE__ );

		return $config;
	}
);

do_action( 'acme_plugin_mount_context', $handler );

add_filter(
	'acme_plugin-frontend_script_dependencies',
	static fn ( array $dependencies ): array => array_merge( $dependencies, [ 'wp-i18n' ] )
);

add_filter(
	'acme_plugin-frontend_style_dependencies',
	static fn ( array $dependencies ): array => array_merge( $dependencies, [ 'wp-components' ] )
);



namespace Acme\Plugin\Services;

use Bmd\WPFramework\Services\FilePathResolver;
use Bmd\WPFramework\Services\UrlResolver;

final class Manifest
{
	public function __construct(
		private FilePathResolver $paths,
		private UrlResolver $urls
	) {}

	public function path(): string
	{
		return $this->paths->resolve( 'build/manifest.json' );
	}

	public function url(): string
	{
		return $this->urls->resolve( 'build/manifest.json' );
	}
}
text
build/frontend.js
build/frontend.asset.php