Creating a Plugin


Introduction

Developing plugins in Pyro is a cinch and if you are already familiar with Twig it will be quite familiar!

To get started run the make:addon command:

php artisan make:addon my_project.plugin.widget

The above command will create a new addon in the /addons/{reference}. From here you can continue building up your plugin features.

Plugin Class

The make:addon command will create an empty plugin class that looks something a generic Twig extension:

<?php namespace Test\FooPlugin;

use Anomaly\Streams\Platform\Addon\Plugin\Plugin;
use Twig_Environment;
use Twig_NodeVisitorInterface;

class FooPlugin extends Plugin
{

    /**
     * Initializes the runtime environment.
     *
     * This is where you can load some file that contains filter functions for instance.
     *
     * @param Twig_Environment $environment The current Twig_Environment instance
     */
    public function initRuntime(Twig_Environment $environment)
    {
    }

    /**
     * Returns the token parser instances.
     *
     * @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances
     */
    public function getTokenParsers()
    {
        return [];
    }

    /**
     * Returns the node visitor instances.
     *
     * @return Twig_NodeVisitorInterface[] An array of Twig_NodeVisitorInterface instances
     */
    public function getNodeVisitors()
    {
        return [];
    }

    /**
     * Returns a list of filters.
     *
     * @return array An array of filters
     */
    public function getFilters()
    {
        return [];
    }

    /**
     * Returns a list of tests.
     *
     * @return array An array of tests
     */
    public function getTests()
    {
        return [];
    }

    /**
     * Returns a list of functions.
     *
     * @return array An array of functions
     */
    public function getFunctions()
    {
        return [];
    }

    /**
     * Returns a list of operators.
     *
     * @return array An array of operators
     */
    public function getOperators()
    {
        return [];
    }

    /**
     * Returns a list of global variables.
     *
     * @return array An array of global variables
     */
    public function getGlobals()
    {
        return [];
    }

}

Service Provider

You will also notice that a service provider is created as well. You can read more about using service providers in the service providers section.