Skip to content

Commit

Permalink
Allow classes without hooks to create more complex plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
PipoCanaja committed Aug 10, 2024
1 parent f296464 commit 36135d8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
13 changes: 13 additions & 0 deletions app/Plugins/ExamplePlugin/ExamplePlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Plugins\ExamplePlugin;

use App\Models\Plugin;

class ExamplePlugin extends Plugin
{
public static function boot()
{
}
}

20 changes: 12 additions & 8 deletions app/Providers/PluginProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,20 @@ protected function loadLocalPlugins(PluginManager $manager): void
continue; // don't load the hooks :D
}

$class = $this->className($plugin_name, $matches[3]);
$hook_type = $this->hookType($class);
try {
$class = $this->className($plugin_name, $matches[3]);
$hook_type = $this->hookType($class);

// publish hooks in class
$hook_published = $manager->publishHook($plugin_name, $hook_type, $class);
// publish hooks in class
$hook_published = $manager->publishHook($plugin_name, $hook_type, $class);

// register view namespace
if ($hook_published && ! in_array($plugin_name, $plugin_view_location_registered)) {
$plugin_view_location_registered[] = $plugin_name; // don't register twice
$this->loadViewsFrom($matches[1], $plugin_name);
// register view namespace
if ($hook_published && ! in_array($plugin_name, $plugin_view_location_registered)) {
$plugin_view_location_registered[] = $plugin_name; // don't register twice
$this->loadViewsFrom($matches[1], $plugin_name);
}
} catch (PluginDoesNotImplementHookException $e) {
// No hook in that class, but we can still load it for code.
}
}
}
Expand Down

0 comments on commit 36135d8

Please sign in to comment.