-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Set stable version to to v3.8.0 - Update README - Refactor after phpcs
- Loading branch information
Showing
11 changed files
with
200 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ctasca\MageBundle\Api; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
interface UtilCommandInterface | ||
{ | ||
/** | ||
* @param \Symfony\Component\Console\Input\InputInterface $input | ||
* @param \Symfony\Component\Console\Output\OutputInterface $output | ||
* @return void | ||
*/ | ||
public function execute(InputInterface $input, OutputInterface $output): void; | ||
} |
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,48 @@ | ||
<?php | ||
|
||
// phpcs:disable SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion.RequiredConstructorPropertyPromotion | ||
|
||
|
||
declare(strict_types=1); | ||
|
||
namespace Ctasca\MageBundle\Console\Command; | ||
|
||
use Ctasca\MageBundle\Model\Util\Encryptor; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class EncryptorCommand extends Command | ||
{ | ||
private Encryptor $encryptor; | ||
|
||
/** | ||
* @param \Ctasca\MageBundle\Model\Util\Encryptor $encryptor | ||
*/ | ||
public function __construct(Encryptor $encryptor) | ||
{ | ||
parent::__construct(); | ||
$this->encryptor = $encryptor; | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function configure(): void | ||
{ | ||
$this->setName('magebundle:util:encryptor') | ||
->setDescription('Encrypts/Decrypts a string using Magento crypt key'); | ||
|
||
parent::configure(); | ||
} | ||
|
||
/** | ||
* @param \Symfony\Component\Console\Input\InputInterface $input | ||
* @param \Symfony\Component\Console\Output\OutputInterface $output | ||
* @return void | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): void | ||
{ | ||
$this->encryptor->execute($input, $output); | ||
} | ||
} |
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
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,96 @@ | ||
<?php | ||
|
||
// phpcs:disable SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion.RequiredConstructorPropertyPromotion | ||
// phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification | ||
// phpcs:disable SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification | ||
// phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint | ||
|
||
|
||
declare(strict_types=1); | ||
|
||
namespace Ctasca\MageBundle\Model\Util; | ||
|
||
use Ctasca\MageBundle\Api\UtilCommandInterface; | ||
use Ctasca\MageBundle\Console\Question\Choice\Factory as QuestionChoiceFactory; | ||
use Ctasca\MageBundle\Console\Question\Factory as QuestionFactory; | ||
use Magento\Framework\App\Area; | ||
use Magento\Framework\App\State; | ||
use Magento\Framework\Encryption\Encryptor as MagentoEncryptor; | ||
use Symfony\Component\Console\Helper\SymfonyQuestionHelper; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class Encryptor implements UtilCommandInterface | ||
{ | ||
private State $state; | ||
private MagentoEncryptor $encryptor; | ||
private QuestionChoiceFactory $questionChoiceFactory; | ||
private SymfonyQuestionHelper $questionHelper; | ||
private QuestionFactory $questionFactory; | ||
|
||
/** | ||
* @param \Magento\Framework\App\State $state | ||
* @param \Magento\Framework\Encryption\Encryptor $encryptor | ||
* @param \Ctasca\MageBundle\Console\Question\Choice\Factory $questionChoiceFactory | ||
* @param \Symfony\Component\Console\Helper\SymfonyQuestionHelper $questionHelper | ||
* @param \Ctasca\MageBundle\Console\Question\Factory $questionFactory | ||
*/ | ||
public function __construct( | ||
State $state, | ||
MagentoEncryptor $encryptor, | ||
QuestionChoiceFactory $questionChoiceFactory, | ||
SymfonyQuestionHelper $questionHelper, | ||
QuestionFactory $questionFactory | ||
) { | ||
$this->state = $state; | ||
$this->encryptor = $encryptor; | ||
$this->questionChoiceFactory = $questionChoiceFactory; | ||
$this->questionHelper = $questionHelper; | ||
$this->questionFactory = $questionFactory; | ||
} | ||
|
||
/** | ||
* @param \Symfony\Component\Console\Input\InputInterface $input | ||
* @param \Symfony\Component\Console\Output\OutputInterface $output | ||
* @return void | ||
*/ | ||
public function execute(InputInterface $input, OutputInterface $output): void | ||
{ | ||
try { | ||
$this->state->setAreaCode(Area::AREA_ADMINHTML); | ||
$question = $this->questionChoiceFactory->create( | ||
'Choose whether you want to encrypt or decrypt', | ||
$this->getEncryptorChoices() | ||
); | ||
$question->setErrorMessage('Chosen action %s is invalid.'); | ||
$action = $this->questionHelper->ask($input, $output, $question); | ||
|
||
$question = $this->questionFactory->create(sprintf('Enter string to %s', $action)); | ||
$string = $this->questionHelper->ask($input, $output, $question); | ||
|
||
if ($action === 'encrypt') { | ||
$output->writeln( | ||
'<info>' . $this->encryptor->encrypt($string) . '</info>' | ||
); | ||
} | ||
|
||
if ($action === 'decrypt') { | ||
$output->writeln( | ||
'<info>' . $this->encryptor->decrypt($string) . '</info>' | ||
); | ||
} | ||
|
||
$output->writeln(''); | ||
} catch (\Exception $e) { | ||
$output->writeln($e->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
private function getEncryptorChoices(): array | ||
{ | ||
return ['encrypt', 'decrypt']; | ||
} | ||
} |
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