Skip to content

Commit

Permalink
Merge pull request #7953 from cakephp/ADmad-patch-1
Browse files Browse the repository at this point in the history
Update e.g. of DI for commands
  • Loading branch information
othercorey authored Nov 11, 2024
2 parents 39ef371 + 5d0813a commit f8311af
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions en/development/dependency-injection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ Command Example
::

// In src/Command/CheckUsersCommand.php
use Cake\Console\CommandFactoryInterface;

class CheckUsersCommand extends Command
{
public function __construct(public UsersService $users)
public function __construct(protected UsersService $users, ?CommandFactoryInterface $factory = null)
{
parent::__construct($factory);
}

public function execute(Arguments $args, ConsoleIo $io)
Expand All @@ -73,7 +76,8 @@ Command Example
{
$container
->add(CheckUsersCommand::class)
->addArgument(UsersService::class);
->addArgument(UsersService::class)
->addArgument(CommandFactoryInterface::class);
$container->add(UsersService::class);
}

Expand Down

0 comments on commit f8311af

Please sign in to comment.