Creating an extension

Lets start create an extension, a Plugin in this case:

1. Create a extension

<?php namespace MyNamespace\BarPlugin;


use Mascame\Artificer\Plugin\AbstractPlugin;


class BarPlugin extends AbstractPlugin {

    /**
     * This will be called if the plugin is installed
     */
    public function boot()
    {
        // We will be able to do something here once the plugin is installed by the client    
    }

}

2. Adding the ServiceProvider

The ServiceProvider takes care of registering plugins & widgets under a package namespace.

You must extend ArtificerExtensionServiceProvider and indicate the $package.

📘

What is $package?

You can add multiple extensions (plugins and/or widgets) in the same repository for convenience. That's why we need to unify them under a name, in this case that name is the $package property.

<?php namespace MyNamespace\BarPlugin;

use MyNamespace\BarPlugin\BarPlugin;

class BarPluginServiceProvider extends ArtificerExtensionServiceProvider {

    protected $package = 'my-namespace/bar-plugin';

    public function register()
    {
        $this->addPlugin(BarPlugin::class);
    }

}

📘

Extends ArtificerExtensionServiceProvider

Adds addPlugin & addWidget methods and hides the methods of ServiceProvider that must not be used. That will let us focus on what matters and avoid errors.

3. Registering the ServiceProvider

Now that we created the ServiceProvider lets register it:

'providers' => [
        Collective\Html\HtmlServiceProvider::class,
        Stolz\Assets\Laravel\ServiceProvider::class,
        Mascame\Artificer\DefaultThemeServiceProvider::class,
        Mascame\Artificer\InstallServiceProvider::class,
        Mascame\Artificer\LoginPluginServiceProvider::class,
        Mascame\Artificer\ArtificerWidgetsServiceProvider::class,
        Mascame\Artificer\LogReaderPluginServiceProvider::class,
        
        MyNamespace\BarPlugin\BarPluginServiceProvider::class
    ],

We successfully created our first plugin!

To learn more about what you can do with extensions keep reading the Extending section.