Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Symfony 5.1] Add LogoutSuccessHandlerToLogoutEventSubscriberRector
- Loading branch information
1 parent
b4d3b7c
commit ae52376
Showing
13 changed files
with
582 additions
and
56 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
14 changes: 14 additions & 0 deletions
14
rules/symfony-code-quality/src/Contract/EventReferenceToMethodNameInterface.php
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\SymfonyCodeQuality\Contract; | ||
|
||
use PhpParser\Node\Expr\ClassConstFetch; | ||
|
||
interface EventReferenceToMethodNameInterface | ||
{ | ||
public function getClassConstFetch(): ClassConstFetch; | ||
|
||
public function getMethodName(): string; | ||
} |
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
48 changes: 48 additions & 0 deletions
48
rules/symfony-code-quality/src/ValueObject/EventReferenceToMethodNameWithPriority.php
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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\SymfonyCodeQuality\ValueObject; | ||
|
||
use PhpParser\Node\Expr\ClassConstFetch; | ||
use Rector\SymfonyCodeQuality\Contract\EventReferenceToMethodNameInterface; | ||
|
||
final class EventReferenceToMethodNameWithPriority implements EventReferenceToMethodNameInterface | ||
{ | ||
/** | ||
* @var ClassConstFetch | ||
*/ | ||
private $classConstFetch; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $methodName; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $priority; | ||
|
||
public function __construct(ClassConstFetch $classConstFetch, string $methodName, int $priority) | ||
{ | ||
$this->classConstFetch = $classConstFetch; | ||
$this->methodName = $methodName; | ||
$this->priority = $priority; | ||
} | ||
|
||
public function getClassConstFetch(): ClassConstFetch | ||
{ | ||
return $this->classConstFetch; | ||
} | ||
|
||
public function getMethodName(): string | ||
{ | ||
return $this->methodName; | ||
} | ||
|
||
public function getPriority(): int | ||
{ | ||
return $this->priority; | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
rules/symfony5/src/NodeFactory/BareLogoutClassMethodFactory.php
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,81 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Symfony5\NodeFactory; | ||
|
||
use PhpParser\Node\Expr\Variable; | ||
use PhpParser\Node\Identifier; | ||
use PhpParser\Node\Name\FullyQualified; | ||
use PhpParser\Node\Param; | ||
use PhpParser\Node\Stmt\ClassMethod; | ||
use Rector\Core\Php\PhpVersionProvider; | ||
use Rector\Core\PhpParser\Node\NodeFactory; | ||
use Rector\Core\ValueObject\PhpVersionFeature; | ||
use Rector\NetteKdyby\NodeManipulator\ListeningClassMethodArgumentManipulator; | ||
use Rector\NodeNameResolver\NodeNameResolver; | ||
use Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser; | ||
|
||
final class BareLogoutClassMethodFactory | ||
{ | ||
/** | ||
* @var NodeFactory | ||
*/ | ||
private $nodeFactory; | ||
|
||
/** | ||
* @var PhpVersionProvider | ||
*/ | ||
private $phpVersionProvider; | ||
|
||
/** | ||
* @var ListeningClassMethodArgumentManipulator | ||
*/ | ||
private $listeningClassMethodArgumentManipulator; | ||
|
||
/** | ||
* @var NodeNameResolver | ||
*/ | ||
private $nodeNameResolver; | ||
|
||
/** | ||
* @var SimpleCallableNodeTraverser | ||
*/ | ||
private $simpleCallableNodeTraverser; | ||
|
||
public function __construct( | ||
NodeFactory $nodeFactory, | ||
PhpVersionProvider $phpVersionProvider, | ||
ListeningClassMethodArgumentManipulator $listeningClassMethodArgumentManipulator, | ||
NodeNameResolver $nodeNameResolver, | ||
SimpleCallableNodeTraverser $simpleCallableNodeTraverser | ||
) { | ||
$this->nodeFactory = $nodeFactory; | ||
$this->phpVersionProvider = $phpVersionProvider; | ||
$this->listeningClassMethodArgumentManipulator = $listeningClassMethodArgumentManipulator; | ||
$this->nodeNameResolver = $nodeNameResolver; | ||
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser; | ||
} | ||
|
||
public function create(): ClassMethod | ||
{ | ||
$classMethod = $this->nodeFactory->createPublicMethod('onLogout'); | ||
|
||
$variable = new Variable('logoutEvent'); | ||
$classMethod->params[] = $this->createLogoutEventParam($variable); | ||
|
||
if ($this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::VOID_TYPE)) { | ||
$classMethod->returnType = new Identifier('void'); | ||
} | ||
|
||
return $classMethod; | ||
} | ||
|
||
private function createLogoutEventParam(Variable $variable): Param | ||
{ | ||
$param = new Param($variable); | ||
$param->type = new FullyQualified('Symfony\Component\Security\Http\Event\LogoutEvent'); | ||
|
||
return $param; | ||
} | ||
} |
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
Oops, something went wrong.