PHP code example of stracker-phil / wpdi

1. Go to this page and download the library: Download stracker-phil/wpdi 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/ */

    

stracker-phil / wpdi example snippets



/**
 * Plugin Name: My Plugin
 */

  protected function bootstrap( WPDI\Resolver $r ): void {
        $app = $r->get( My_Application::class );
        $app->run();
    }
}

My_Plugin::boot( __FILE__ );


// src/My_Application.php

class My_Application {
    public function __construct( My_Service $service, My_Logger $logger ) {
        $this->service = $service;
        $this->logger = $logger;
    }

    public function run(): void {
        add_action( 'init', array( $this, 'on_init' ) );
    }
}


// Very basic example. Read the "Configuration" doc for more options.
return array(
    Logger_Interface::class => WP_Logger:class,
    Cache_Interface::class  => Redis_Cache::class,
);