package and depencies

This commit is contained in:
RafficMohammed
2023-01-08 02:57:24 +05:30
parent d5332eb421
commit 1d54b8bc7f
4309 changed files with 193331 additions and 172289 deletions

View File

@@ -26,18 +26,15 @@ use Symfony\Component\Routing\RouteCollection;
*/
class CompiledUrlMatcherDumper extends MatcherDumper
{
private $expressionLanguage;
private $signalingException;
private ExpressionLanguage $expressionLanguage;
private ?\Exception $signalingException = null;
/**
* @var ExpressionFunctionProviderInterface[]
*/
private $expressionLanguageProviders = [];
private array $expressionLanguageProviders = [];
/**
* {@inheritdoc}
*/
public function dump(array $options = [])
public function dump(array $options = []): string
{
return <<<EOF
<?php
@@ -115,7 +112,7 @@ EOF;
}
$checkConditionCode = <<<EOF
static function (\$condition, \$context, \$request) { // \$checkCondition
static function (\$condition, \$context, \$request, \$params) { // \$checkCondition
switch (\$condition) {
{$this->indent(implode("\n", $conditions), 3)}
}
@@ -332,7 +329,7 @@ EOF;
if ($hasTrailingSlash = '/' !== $regex && '/' === $regex[-1]) {
$regex = substr($regex, 0, -1);
}
$hasTrailingVar = (bool) preg_match('#\{\w+\}/?$#', $route->getPath());
$hasTrailingVar = (bool) preg_match('#\{[\w\x80-\xFF]+\}/?$#', $route->getPath());
$tree->addRoute($regex, [$name, $regex, $state->vars, $route, $hasTrailingSlash, $hasTrailingVar]);
}
@@ -416,7 +413,7 @@ EOF;
/**
* Compiles a single Route to PHP code used to match it against the path info.
*/
private function compileRoute(Route $route, string $name, $vars, bool $hasTrailingSlash, bool $hasTrailingVar, array &$conditions): array
private function compileRoute(Route $route, string $name, string|array|null $vars, bool $hasTrailingSlash, bool $hasTrailingVar, array &$conditions): array
{
$defaults = $route->getDefaults();
@@ -426,8 +423,8 @@ EOF;
}
if ($condition = $route->getCondition()) {
$condition = $this->getExpressionLanguage()->compile($condition, ['context', 'request']);
$condition = $conditions[$condition] ?? $conditions[$condition] = (str_contains($condition, '$request') ? 1 : -1) * \count($conditions);
$condition = $this->getExpressionLanguage()->compile($condition, ['context', 'request', 'params']);
$condition = $conditions[$condition] ??= (str_contains($condition, '$request') ? 1 : -1) * \count($conditions);
} else {
$condition = null;
}
@@ -445,7 +442,7 @@ EOF;
private function getExpressionLanguage(): ExpressionLanguage
{
if (null === $this->expressionLanguage) {
if (!isset($this->expressionLanguage)) {
if (!class_exists(ExpressionLanguage::class)) {
throw new \LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
}
@@ -463,7 +460,7 @@ EOF;
/**
* @internal
*/
public static function export($value): string
public static function export(mixed $value): string
{
if (null === $value) {
return 'null';

View File

@@ -26,10 +26,10 @@ use Symfony\Component\Routing\RequestContext;
*/
trait CompiledUrlMatcherTrait
{
private $matchHost = false;
private $staticRoutes = [];
private $regexpList = [];
private $dynamicRoutes = [];
private bool $matchHost = false;
private array $staticRoutes = [];
private array $regexpList = [];
private array $dynamicRoutes = [];
/**
* @var callable|null
@@ -92,10 +92,6 @@ trait CompiledUrlMatcherTrait
$supportsRedirections = 'GET' === $canonicalMethod && $this instanceof RedirectableUrlMatcherInterface;
foreach ($this->staticRoutes[$trimmedPathinfo] ?? [] as [$ret, $requiredHost, $requiredMethods, $requiredSchemes, $hasTrailingSlash, , $condition]) {
if ($condition && !($this->checkCondition)($condition, $context, 0 < $condition ? $request ?? $request = $this->request ?: $this->createRequest($pathinfo) : null)) {
continue;
}
if ($requiredHost) {
if ('{' !== $requiredHost[0] ? $requiredHost !== $host : !preg_match($requiredHost, $host, $hostMatches)) {
continue;
@@ -106,6 +102,10 @@ trait CompiledUrlMatcherTrait
}
}
if ($condition && !($this->checkCondition)($condition, $context, 0 < $condition ? $request ??= $this->request ?: $this->createRequest($pathinfo) : null, $ret)) {
continue;
}
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
if ($supportsRedirections && (!$requiredMethods || isset($requiredMethods['GET']))) {
return $allow = $allowSchemes = [];
@@ -132,13 +132,8 @@ trait CompiledUrlMatcherTrait
foreach ($this->regexpList as $offset => $regex) {
while (preg_match($regex, $matchedPathinfo, $matches)) {
foreach ($this->dynamicRoutes[$m = (int) $matches['MARK']] as [$ret, $vars, $requiredMethods, $requiredSchemes, $hasTrailingSlash, $hasTrailingVar, $condition]) {
if (null !== $condition) {
if (0 === $condition) { // marks the last route in the regexp
continue 3;
}
if (!($this->checkCondition)($condition, $context, 0 < $condition ? $request ?? $request = $this->request ?: $this->createRequest($pathinfo) : null)) {
continue;
}
if (0 === $condition) { // marks the last route in the regexp
continue 3;
}
$hasTrailingVar = $trimmedPathinfo !== $pathinfo && $hasTrailingVar;
@@ -151,6 +146,16 @@ trait CompiledUrlMatcherTrait
}
}
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {
$ret[$v] = $matches[1 + $i];
}
}
if ($condition && !($this->checkCondition)($condition, $context, 0 < $condition ? $request ??= $this->request ?: $this->createRequest($pathinfo) : null, $ret)) {
continue;
}
if ('/' !== $pathinfo && !$hasTrailingVar && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
if ($supportsRedirections && (!$requiredMethods || isset($requiredMethods['GET']))) {
return $allow = $allowSchemes = [];
@@ -158,12 +163,6 @@ trait CompiledUrlMatcherTrait
continue;
}
foreach ($vars as $i => $v) {
if (isset($matches[1 + $i])) {
$ret[$v] = $matches[1 + $i];
}
}
if ($requiredSchemes && !isset($requiredSchemes[$context->getScheme()])) {
$allowSchemes += $requiredSchemes;
continue;

View File

@@ -20,17 +20,14 @@ use Symfony\Component\Routing\RouteCollection;
*/
abstract class MatcherDumper implements MatcherDumperInterface
{
private $routes;
private RouteCollection $routes;
public function __construct(RouteCollection $routes)
{
$this->routes = $routes;
}
/**
* {@inheritdoc}
*/
public function getRoutes()
public function getRoutes(): RouteCollection
{
return $this->routes;
}

View File

@@ -23,15 +23,11 @@ interface MatcherDumperInterface
/**
* Dumps a set of routes to a string representation of executable code
* that can then be used to match a request against these routes.
*
* @return string
*/
public function dump(array $options = []);
public function dump(array $options = []): string;
/**
* Gets the routes to dump.
*
* @return RouteCollection
*/
public function getRoutes();
public function getRoutes(): RouteCollection;
}

View File

@@ -23,22 +23,22 @@ use Symfony\Component\Routing\RouteCollection;
*/
class StaticPrefixCollection
{
private $prefix;
private string $prefix;
/**
* @var string[]
*/
private $staticPrefixes = [];
private array $staticPrefixes = [];
/**
* @var string[]
*/
private $prefixes = [];
private array $prefixes = [];
/**
* @var array[]|self[]
*/
private $items = [];
private array $items = [];
public function __construct(string $prefix = '/')
{
@@ -60,10 +60,8 @@ class StaticPrefixCollection
/**
* Adds a route to a group.
*
* @param array|self $route
*/
public function addRoute(string $prefix, $route)
public function addRoute(string $prefix, array|StaticPrefixCollection $route)
{
[$prefix, $staticPrefix] = $this->getCommonPrefix($prefix, $prefix);
@@ -154,7 +152,7 @@ class StaticPrefixCollection
try {
for ($i = $baseLength; $i < $end && $prefix[$i] === $anotherPrefix[$i]; ++$i) {
if ('(' === $prefix[$i]) {
$staticLength = $staticLength ?? $i;
$staticLength ??= $i;
for ($j = 1 + $i, $n = 1; $j < $end && 0 < $n; ++$j) {
if ($prefix[$j] !== $anotherPrefix[$j]) {
break 2;