From ad83d1dafac62bb28fda004f86129319a5c3e2ca Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 6 Mar 2022 01:07:59 +0100 Subject: Refactor fixes --- src/App.php | 7 ++++++- src/Controllers/EntriesController.php | 4 ++-- src/Controllers/SubmissionController.php | 2 +- src/HookManager.php | 4 ++-- src/PluginLoader.php | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/App.php b/src/App.php index 15be58b..5fc62fa 100644 --- a/src/App.php +++ b/src/App.php @@ -20,6 +20,11 @@ class App */ public function __construct() { + /**@var HookManager $hooks*/ + global $hooks; + + $hooks->doAction('init'); + $request = Request::createFromGlobals(); $response = new Response(); @@ -64,7 +69,7 @@ class App $entriesController = new EntriesController(); - $content = $entriesController->getEntries(); + $content = $entriesController->getEntries($formPath); } else { diff --git a/src/Controllers/EntriesController.php b/src/Controllers/EntriesController.php index 13aa8e0..801fe7b 100644 --- a/src/Controllers/EntriesController.php +++ b/src/Controllers/EntriesController.php @@ -6,7 +6,7 @@ use Yosymfony\Toml\Toml; class EntriesController { - public function getEntries() + public function getEntries(string $formPath): array { /**@var Utilities $utilities*/ global $utilities; @@ -65,7 +65,7 @@ class EntriesController $entriesForDay = $utilities->scandir($dayPath); foreach ($entriesForDay as $entryForDay) { - $entry = Toml::parseFile("$dayPath/$entryForDay"); + $entry = Toml::parseFile($entryForDay); if (isset($_GET['flat'])) { $entries[] = $entry; } else { diff --git a/src/Controllers/SubmissionController.php b/src/Controllers/SubmissionController.php index f2c4c80..2c3d603 100644 --- a/src/Controllers/SubmissionController.php +++ b/src/Controllers/SubmissionController.php @@ -8,7 +8,7 @@ use Yosymfony\Toml\TomlBuilder; class SubmissionController { - public function submit(Builder $builder, Validator $validator, $formPath) + public function submit(Builder $builder, Validator $validator, string $formPath): array { $fields = $builder->buildFields(); diff --git a/src/HookManager.php b/src/HookManager.php index 96ca8d3..0f252c8 100644 --- a/src/HookManager.php +++ b/src/HookManager.php @@ -9,12 +9,12 @@ class HookManager public function addAction(string $name, callable $function, int $priority = 10): void { - $this->action[$name][$priority][] = compact('name', 'function', 'priority'); + $this->actions[$name][$priority][] = compact('name', 'function', 'priority'); } public function addFilter(string $name, callable $function, int $priority = 10): void { - $this->filters[$name][$priority][] = compact('name', 'callable', 'priority'); + $this->filters[$name][$priority][] = compact('name', 'function', 'priority'); } public function doAction(string $name, mixed ...$arguments): void diff --git a/src/PluginLoader.php b/src/PluginLoader.php index c8da5fd..b2ac61d 100644 --- a/src/PluginLoader.php +++ b/src/PluginLoader.php @@ -22,7 +22,7 @@ class PluginLoader $pluginDirectories = $utilities->scandir($pluginsDirectoryPath); foreach ($pluginDirectories as $directory) { - $pluginClass = 'FlatFileForms\\Plugins\\' . $directory . '\\Plugin'; + $pluginClass = 'FlatFileForms\\Plugins\\' . basename($directory) . '\\Plugin'; $plugin = new $pluginClass(); } } -- cgit v1.2.3