Comments (2)
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.
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)
- I do not know what is action and filter in Wordpress HOT 9
- Class 'TorMorten\Eventy\Exception' not found HOT 1
- Usage without Laravel HOT 3
- this package not work in laravel 5.7 HOT 1
- How to remove a Anonymous callable action HOT 3
- Too few arguments error HOT 4
- Does this support queue HOT 2
- Package jeremeamia/superclosure is abandoned. HOT 3
- Difference between Actions & Filters in Examples HOT 2
- Laravel 8 support HOT 1
- Accepting array callables HOT 6
- Alternative to use outside laravel HOT 4
- There is an error HOT 1
- Laravel 10 issue HOT 3
- Target class does not exist. HOT 2
- At least 30% speed improvement HOT 2
- Decrease the 5.5 requirement to 5.3 HOT 3
- Release 0.5.2 to Packagist HOT 2
- use Eventy in other system, other than Lavarel HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eventy.