PHP code example of apility / plugins

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

    

apility / plugins example snippets



use Apility\Plugins\Plugin;

class MyPlugin extends Plugin
{
    public function register()
    {
        // Here you can perform any registration that
        // you would normally do in a service provider.
    }
}

use Apility\Plugins\Facades\Plugin;

Plugin::register(MyPlugin::class);

use Apility\Plugins\Facades\Plugin;
use Apility\Plugins\Plugin as BasePlugin;

interface MyFeature
{
    public function doSomething();
}

class MyPlugin extends BasePlugin implements MyFeature
{
    public function doSomething()
    {
        return 'Hello world!';
    }
}

$plugins = Plugin::all(MyFeature::class);

foreach ($plugins as $plugin) {
    /** @var MyFeature $plugin */
    echo $plugin->doSomething();
}

use Apility\Plugins\Facades\Plugin;

// Get the number of registered plugins
$pluginCount = Plugin::count();

// Get the number of registered plugins by type
$pluginCount = Plugin::count(MyPlugin::class);

// Check if a plugin is registered
$pluginRegistered = Plugin::has(MyPlugin::class);

// Get all plugins
$plugins = Plugin::all();

// Get all plugins by type
$plugins = Plugin::all(MyPlugin::class);

// Get the first registered plugin
$plugin = Plugin::first();

// Get a plugin by type
$plugin = Plugin::first(MyPlugin::class);
bash
php artisan make:plugin MyPlugin
bash
php artisan make:plugin MyPlugin --policy