PHP code example of estasi / plugin-manager

1. Go to this page and download the library: Download estasi/plugin-manager 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/ */

    

estasi / plugin-manager example snippets




declare(strict_types=1);

use Estasi\PluginManager\{Abstracts,Interfaces,Plugin,PluginsList};

class MyPluginManager extends Abstracts\PluginManager {

    public function getInstanceOf(): ?string
    {
        return 'MyBasicClass';
    }

    public function getPlugins(): Interfaces\PluginsList
    {
        return new PluginsList(
            new Plugin(MyFirstClass::class, ['first', 'First', /*...  aliases of class*/]),
            new Plugin('MySecondClass', ['second', 'Second', /*... aliases of class */], new MyFactoryForSecondClass()),
        );
    }
}



declare(strict_types=1);

$myPluginManager = new MyPluginManager();

// Creating a object without constructor parameters
$myFirstClass = $myPluginManager->get(MyFirstClass::class);
// or
$myFirstClass = $myPluginManager->build('first');

// With the parameters necessary (or optional) to create the object
$myFirstClass = $myPluginManager->build('First', ['foo' => 'bar', 'bar' => 'foo']);



declare(strict_types=1);

class MyFirstClass {

    public function __construct($foo, $bar = 'foo', iterable $options = null)
    {
        // your code
    }
}



declare(strict_types=1);

$myPluginManager = new MyPluginManager();

// "foo" baz" parameter will be e thing
// if you use this method all undeclared parameters will not be used when creating the object 
// and will not be