-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: test use ADR controller class FQCN as route name
- Loading branch information
Showing
16 changed files
with
78 additions
and
29 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
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
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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Twig\Extension; | ||
|
||
use Symfony\Component\Routing\RouterInterface; | ||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFunction; | ||
|
||
use function Symfony\Component\String\u; | ||
|
||
/** | ||
* Routing related stuff. | ||
*/ | ||
final class RoutingExtension extends AbstractExtension | ||
{ | ||
/** | ||
* @var array<int, string>|null | ||
*/ | ||
private ?array $controllers = null; | ||
|
||
public function __construct( | ||
private readonly RouterInterface $router, | ||
) { | ||
} | ||
|
||
public function getFunctions(): array | ||
{ | ||
return [ | ||
new TwigFunction('ctrl', $this->getControllerFqcn(...)), | ||
]; | ||
} | ||
|
||
public function getControllerFqcn(string $ctrlShortname): string | ||
{ | ||
if ($this->controllers === null) { | ||
$this->controllers = array_map( | ||
static fn ($value) => u($value)->trimSuffix('::__invoke')->toString(), | ||
array_keys($this->router->getRouteCollection()->getAliases()) | ||
); | ||
} | ||
|
||
foreach ($this->controllers as $controller) { | ||
if (u($controller)->endsWith($ctrlShortname)) { | ||
return $controller; | ||
} | ||
} | ||
|
||
throw new \InvalidArgumentException('No controller found for the "'.$ctrlShortname.'" shortname.'); | ||
} | ||
} |
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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