-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: roxblnfk <[email protected]>
- Loading branch information
Showing
7 changed files
with
162 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace App\Command\User; | ||
|
||
use App\Entity\User; | ||
use Cycle\ORM\ORMInterface; | ||
use Cycle\ORM\Transaction; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
class CreateCommand extends Command | ||
{ | ||
private const EXIT_CODE_FAILED_TO_PERSIST = 1; | ||
|
||
private $orm; | ||
|
||
protected static $defaultName = 'user/create'; | ||
|
||
public function __construct(ORMInterface $orm) | ||
{ | ||
parent::__construct(); | ||
$this->orm = $orm; | ||
} | ||
|
||
public function configure(): void | ||
{ | ||
$this | ||
->setDescription('Creates a user') | ||
->setHelp('This command allows you to create a user') | ||
->addArgument('login', InputArgument::REQUIRED, 'Login') | ||
->addArgument('password', InputArgument::REQUIRED, 'Password'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
$login = $input->getArgument('login'); | ||
$password = $input->getArgument('password'); | ||
|
||
$user = new User(); | ||
$user->setLogin($login); | ||
$user->setPassword($password); | ||
|
||
try { | ||
$transaction = new Transaction($this->orm); | ||
$transaction->persist($user); | ||
$transaction->run(); | ||
$io->success('User created'); | ||
} catch (\Throwable $t) { | ||
$io->error($t->getMessage()); | ||
return self::EXIT_CODE_FAILED_TO_PERSIST; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters