Giter VIP home page Giter VIP logo

Comments (2)

Blair2004 avatar Blair2004 commented on July 22, 2024

Hi, i'm also coming from WP, i've created a package with a plugin system, but... not really with this package. in fact, it could be used as hook API but, to build a plugin system here is basically what i've used :

  • FileSystem (to get all plugin config file as xml)
  • XML parser
  • Option system (i've build my own, to know which plugin should run automatically or not)

Maybe this could helps : https://github.com/Tendoo/cloud-breeze/blob/api-server/src/core/Services/Modules.php

from eventy.

tormjens avatar tormjens commented on July 22, 2024

@anubisthejackle

Laravel is already perfectly capable of acting as a plugin system itself with its auto-discovery features an all.

Eventy would act as support to the awesome that is Laravel, so you can extend your packages from other packages.

The way I have it set up in projects is that each "plugin" is its own composer package. If I want to install it to my application I simply require it via composer. Laravel's auto-discovery takes care of making sure the "plugin" is registered. Throughout the code in the plugin i make use of Eventy's actions and filters to offer abilities to extend them. If my plugin needs to extend functionality in another plugin I register my listeners in the service provider for my plugin.

For example: Plugin A has a class where it builds a query to fetch all published posts.

class PostsQueryBuilder
{
    public function query()
    {
        return Post::where('published_at', '>', now());
    }
}

Using Eventy I can offer a filter for other plugins to hook in to this:

use TorMorten\Eventy\Facades\Events as Eventy;
class PostsQueryBuilder
{
    public function query()
    {
        $query = resolve(Post::where('published_at', '>', now());
        return Eventy::filter('posts-query-builder:query', $query);
    }
}

Then, Plugin B comes along a needs to modify said query in other to only include posts with the word foo in the title.

In Plugin B's service provider (preferably in the boot method, since it will always be fired after Eventy has been made available) we'll add a listener for the event.

use TorMorten\Eventy\Facades\Events as Eventy;

class PluginBServiceProvider extends ServiceProvider 
{
    public function boot()
    {
        Eventy::addFilter('posts-query-builder:query', function($query) {
            return $query->where('title', 'like', '%foo%');
        });
    }
}

I hope this helps you on your way to building a plugin system in Laravel.

from eventy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.