diff --git a/src/Servers/Hook.php b/src/Servers/Hook.php index 36f03e8..4a645ce 100644 --- a/src/Servers/Hook.php +++ b/src/Servers/Hook.php @@ -167,6 +167,26 @@ public function getInjections(): array return $this->injections; } + /** + * Get Dependencies + * + * @return array + */ + public function getDependencies(): array + { + if (empty($this->injections)) { + return []; + } + + $injections = array_values($this->injections); + + usort($injections, static function (array $left, array $right): int { + return $left['order'] <=> $right['order']; + }); + + return array_column($injections, 'name'); + } + /** * Inject * diff --git a/tests/Servers/Unit/HookTest.php b/tests/Servers/Unit/HookTest.php index 85e78f5..dcff538 100644 --- a/tests/Servers/Unit/HookTest.php +++ b/tests/Servers/Unit/HookTest.php @@ -73,6 +73,19 @@ public function testResourcesCanBeInjected() $this->assertEquals('time', $this->hook->getInjections()['time']['name']); } + public function testDependenciesAreReturnedInInjectionOrder() + { + $this->assertEquals([], $this->hook->getDependencies()); + + $this->hook + ->inject('user') + ->param('x', '', new Text(10)) + ->inject('time') + ->inject('locale'); + + $this->assertEquals(['user', 'time', 'locale'], $this->hook->getDependencies()); + } + public function testParamValuesCanBeSet() { $this->assertEquals([], $this->hook->getParams());