Skip to content

Commit

Permalink
feat: autoload files
Browse files Browse the repository at this point in the history
  • Loading branch information
jevantang committed Nov 21, 2022
1 parent f7b9e3c commit b6c9bd9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Commands/stubs/plugin.json.stub
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"providers": [
"$PLUGIN_NAMESPACE$\\$STUDLY_NAME$\\Providers\\$STUDLY_NAME$ServiceProvider"
],
"autoloadFiles": [],
"aliases": {}
}
13 changes: 13 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,19 @@ public function allDeactivate(): array
return array_diff($this->all(), $this->allActivate());
}

public function registerFiles()
{
$path = $this->getPluginPath();

$files = Json::make($this->getPluginJsonPath())->get('autoloadFiles', []);
foreach ($files as $file) {
$filepath = "$path/$file";
if (file_exists($filepath)) {
include_once $filepath;
}
}
}

public function registerProviders()
{
$providers = Json::make($this->getPluginJsonPath())->get('providers', []);
Expand Down
1 change: 1 addition & 0 deletions src/Providers/PluginServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ protected function autoload()
$plugin = new Plugin($pluginName);

if ($plugin->isAvailablePlugin() && $plugin->isActivate()) {
$plugin->registerFiles();
$plugin->registerProviders();
$plugin->registerAliases();
}
Expand Down

0 comments on commit b6c9bd9

Please sign in to comment.