Skip to content

Commit

Permalink
Merge pull request #20 from Fabricio872/RCB-14-add-support-for-symfony-6
Browse files Browse the repository at this point in the history
RCB-14 Add support for Symfony 6
  • Loading branch information
Fabricio872 authored Jan 6, 2022
2 parents 8c040e5 + d7ebca6 commit 31137be
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .php-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.2
7.3
28 changes: 16 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,31 @@
}
],
"require": {
"php": "^7.2|^8.0",
"php": "^7.3|^8.0",
"doctrine/annotations": "^1.13",
"doctrine/orm": "^2.9",
"illuminate/support": "^7.30",
"symfony/config": "^4.4|^5",
"symfony/console": "^4.4|^5",
"symfony/dependency-injection": "^4.4|^5",
"symfony/http-kernel": "^4.4|^5",
"symfony/security-bundle": "^4.4|^5",
"symfony/serializer": "^4.4|^5",
"symfony/validator": "^4.4|^5"
"illuminate/support": "^8.78",
"symfony/config": "^4.4|^5|^6.0",
"symfony/console": "^4.4|^5|^6.0",
"symfony/dependency-injection": "^4.4|^5|^6.0",
"symfony/http-kernel": "^4.4|^5|^6.0",
"symfony/security-bundle": "^4.4|^5|^6.0",
"symfony/serializer": "^4.4|^5|^6.0",
"symfony/validator": "^4.4|^5|^6.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^4.4|^5",
"symfony/phpunit-bridge": "^4.4|^5|^6.0",
"symplify/easy-coding-standard": "^9.4"
},
"config": {
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true
}
},
"autoload": {
"psr-4": {
Expand All @@ -45,6 +48,7 @@
}
},
"scripts": {
"test-psr": "vendor/bin/ecs check src"
"test-psr": "vendor/bin/ecs check src",
"fix-psr": "vendor/bin/ecs check src --fix"
}
}
20 changes: 10 additions & 10 deletions src/Command/AbstractList.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
Expand Down Expand Up @@ -41,7 +41,7 @@ abstract class AbstractList extends Command
protected $currentPage = 0;
/** @var NormalizerInterface */
protected $normalizer;
/** @var UserPasswordEncoderInterface */
/** @var UserPasswordHasherInterface */
protected $passwordEncoder;
/** @var Reader */
protected $reader;
Expand All @@ -55,14 +55,14 @@ abstract class AbstractList extends Command
* @param EntityManagerInterface $em
*/
public function __construct(
string $userClassName,
int $tableLimit,
int $maxColWidth,
EntityManagerInterface $em,
NormalizerInterface $normalizer,
UserPasswordEncoderInterface $passwordEncoder,
Reader $reader,
ValidatorInterface $validator
string $userClassName,
int $tableLimit,
int $maxColWidth,
EntityManagerInterface $em,
NormalizerInterface $normalizer,
UserPasswordHasherInterface $passwordEncoder,
Reader $reader,
ValidatorInterface $validator
) {
$this->userClassName = $userClassName;
$this->tableLimit = $tableLimit;
Expand Down
8 changes: 4 additions & 4 deletions src/Command/UserRegisterCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
Expand All @@ -21,7 +21,7 @@ class UserRegisterCommand extends Command
protected static $defaultDescription = 'Register new user';
/** @var string $userClassName */
private $userClassName;
/** @var UserPasswordEncoderInterface $passwordEncoder */
/** @var UserPasswordHasherInterface $passwordEncoder */
private $passwordEncoder;
/** @var Reader $reader */
private $reader;
Expand All @@ -35,13 +35,13 @@ class UserRegisterCommand extends Command
/**
* UserRegisterCommand constructor.
* @param string $userClassName
* @param UserPasswordEncoderInterface $passwordEncoder
* @param UserPasswordHasherInterface $passwordEncoder
* @param Reader $reader
* @param EntityManagerInterface $em
*/
public function __construct(
string $userClassName,
UserPasswordEncoderInterface $passwordEncoder,
UserPasswordHasherInterface $passwordEncoder,
Reader $reader,
EntityManagerInterface $em,
ValidatorInterface $validator
Expand Down
5 changes: 3 additions & 2 deletions src/Serializer/UserEntityNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Fabricio872\RegisterCommand\Serializer;

use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

class UserEntityNormalizer implements NormalizerInterface
Expand All @@ -14,9 +13,11 @@ public function supportsNormalization($array, $format = null, array $context = [

public function normalize($objects, $format = null, array $context = [])
{
$normalized = [];
foreach ($objects as $object) {
yield $this->processProperty($object);
$normalized[] = $this->processProperty($object);
}
return $normalized;
}

private function processProperty($property)
Expand Down
2 changes: 1 addition & 1 deletion src/Services/ArrayToTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function makeTable(): Table
$table->setHeaders(array_keys($this->array[0]));

$table->setRows(array_map(function ($user) {
return iterator_to_array($this->getSerializer()->normalize($user));
return $this->getSerializer()->normalize($user);
}, $this->array));
$table->setStyle('box');

Expand Down
7 changes: 3 additions & 4 deletions src/Services/Ask.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
use Fabricio872\RegisterCommand\Annotations\RegisterCommand;
use Fabricio872\RegisterCommand\Services\Questions\QuestionAbstract;
use Fabricio872\RegisterCommand\Services\Questions\QuestionInterface;
use mysql_xdevapi\Exception;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\Validator\ValidatorInterface;
Expand All @@ -27,7 +26,7 @@ class Ask
private $input;
/** @var OutputInterface */
private $output;
/** @var UserPasswordEncoderInterface $passwordEncoder */
/** @var UserPasswordHasherInterface $passwordEncoder */
private $passwordEncoder;
/** @var string $userIdentifier */
private $userIdentifier = ' ';
Expand All @@ -40,7 +39,7 @@ public function __construct(
SymfonyStyle $io,
InputInterface $input,
OutputInterface $output,
UserPasswordEncoderInterface $passwordEncoder,
UserPasswordHasherInterface $passwordEncoder,
ValidatorInterface $validator
) {
$this->userClassName = $userClassName;
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Questions/PasswordInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class PasswordInput extends QuestionAbstract
{
public function getAnswer(): ?string
{
return is_null($password = $this->validated()) ? null : $this->passwordEncoder->encodePassword($this->user, $password);
return is_null($password = $this->validated()) ? null : $this->passwordEncoder->hashPassword($this->user, $password);
}

private function validated(): ?string
Expand Down
16 changes: 8 additions & 8 deletions src/Services/Questions/QuestionAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;

abstract class QuestionAbstract implements QuestionInterface
{
Expand All @@ -17,7 +17,7 @@ abstract class QuestionAbstract implements QuestionInterface
protected $output;
/** @var string $question */
protected $question;
/** @var UserPasswordEncoderInterface $passwordEncoder */
/** @var UserPasswordHasherInterface $passwordEncoder */
protected $passwordEncoder;
protected $user;
protected $options;
Expand All @@ -26,14 +26,14 @@ abstract class QuestionAbstract implements QuestionInterface
* QuestionAbstract constructor.
* @param SymfonyStyle $io
* @param string $question
* @param UserPasswordEncoderInterface $passwordEncoder
* @param UserPasswordHasherInterface $passwordEncoder
*/
public function __construct(
SymfonyStyle $io,
InputInterface $input,
OutputInterface $output,
string $question,
UserPasswordEncoderInterface $passwordEncoder,
SymfonyStyle $io,
InputInterface $input,
OutputInterface $output,
string $question,
UserPasswordHasherInterface $passwordEncoder,
$user,
$options
) {
Expand Down
4 changes: 2 additions & 2 deletions src/Services/Questions/QuestionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Security\Core\User\UserInterface;

interface QuestionInterface
Expand All @@ -15,7 +15,7 @@ public function __construct(
InputInterface $input,
OutputInterface $output,
string $question,
UserPasswordEncoderInterface $passwordEncoder,
UserPasswordHasherInterface $passwordEncoder,
UserInterface $user,
$options
);
Expand Down
14 changes: 7 additions & 7 deletions src/Services/UserEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ class UserEditor implements UserEditorInterface
private $ask;

public function __construct(
InputInterface $input,
OutputInterface $output,
InputInterface $input,
OutputInterface $output,
EntityManagerInterface $em,
array $userList,
NormalizerInterface $normalizer,
int $colWidth,
Ask $ask
array $userList,
NormalizerInterface $normalizer,
int $colWidth,
Ask $ask
) {
$this->input = $input;
$this->output = $output;
Expand Down Expand Up @@ -106,7 +106,7 @@ private function table()
$userArray = [];
$this->cursorEnd[0] = count($this->userList);
foreach ($this->userList as $row => $user) {
foreach (iterator_to_array($this->getSerializer()->normalize($this->normalizer->normalize($user))) as $col => $item) {
foreach ($this->getSerializer()->normalize($this->normalizer->normalize($user)) as $col => $item) {
$userArray[$row][array_keys($this->normalizer->normalize($user))[$col]] = (($this->cursor == [$row, $col]) ? "> " : " ") . $item;
}
$this->cursorEnd[1] = count($this->normalizer->normalize($user));
Expand Down

0 comments on commit 31137be

Please sign in to comment.