Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add DI container support #327

Merged
merged 11 commits into from
May 3, 2022

Conversation

LordSimal
Copy link
Contributor

Fixes #324

This implementation allows the user to get access to the DI container instance via adding

public function services(ContainerInterface $container): void {
	$this->testService = $container->get(TestService::class);
}

to the desired task.

I first thought to implement the same behaviour as it is present in the controller where the services() method automatically detects the desired services via the argument types but i think it is easier to just pass the DI container instance to the task and the user can retrieve as many services as he wants from that instance.

The only thing I am not really sure if its the "correct" way is the fact how I inject the container instance into the processor (and therefore into the task) - see bellow my github code comment.

@codecov-commenter
Copy link

codecov-commenter commented May 1, 2022

Codecov Report

Merging #327 (d75f57b) into master (d46358e) will decrease coverage by 0.17%.
The diff coverage is 35.29%.

@@             Coverage Diff              @@
##             master     #327      +/-   ##
============================================
- Coverage     57.74%   57.57%   -0.18%     
- Complexity      658      665       +7     
============================================
  Files            35       36       +1     
  Lines          2123     2138      +15     
============================================
+ Hits           1226     1231       +5     
- Misses          897      907      +10     
Impacted Files Coverage Δ
src/Command/RunCommand.php 0.00% <0.00%> (ø)
src/Controller/Admin/QueueProcessesController.php 81.39% <ø> (ø)
src/Controller/Admin/QueuedJobsController.php 47.30% <ø> (ø)
src/Model/Table/QueueProcessesTable.php 81.89% <ø> (ø)
src/Model/Table/QueuedJobsTable.php 40.05% <ø> (ø)
src/Queue/ServicesTrait.php 0.00% <0.00%> (ø)
src/Queue/Processor.php 12.84% <40.00%> (+0.27%) ⬆️
src/Plugin.php 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d46358e...d75f57b. Read the comment docs.

LordSimal and others added 4 commits May 1, 2022 19:47
@dereuromark
Copy link
Owner

Sounds pretty BC safe to me now.

@LordSimal
Copy link
Contributor Author

Should I ignore that phpcs error regarding Invalid Inline Doc Block? Or what exactly is wrong there?

@dereuromark dereuromark merged commit 1630148 into dereuromark:master May 3, 2022
@dereuromark
Copy link
Owner

Can you maybe add some docs for it too?
So people know how to use it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is it possible to use the DI Container inside a task?
3 participants