Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/Servers/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
13 changes: 13 additions & 0 deletions tests/Servers/Unit/HookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down