1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-05 10:49:36 +02:00
Daniel Neto 2024-03-05 19:22:51 -03:00
parent 7673eda07e
commit 330cdbe615
9054 changed files with 480487 additions and 41800 deletions

View file

@ -16,7 +16,7 @@ use Symfony\Component\Routing\Alias;
class AliasConfigurator
{
private $alias;
private Alias $alias;
public function __construct(Alias $alias)
{
@ -34,7 +34,7 @@ class AliasConfigurator
*
* @throws InvalidArgumentException when the message template is invalid
*/
public function deprecate(string $package, string $version, string $message): self
public function deprecate(string $package, string $version, string $message): static
{
$this->alias->setDeprecated($package, $version, $message);

View file

@ -23,12 +23,12 @@ class CollectionConfigurator
use Traits\HostTrait;
use Traits\RouteTrait;
private $parent;
private $parentConfigurator;
private $parentPrefixes;
private $host;
private RouteCollection $parent;
private ?CollectionConfigurator $parentConfigurator;
private ?array $parentPrefixes;
private string|array|null $host = null;
public function __construct(RouteCollection $parent, string $name, self $parentConfigurator = null, array $parentPrefixes = null)
public function __construct(RouteCollection $parent, string $name, ?self $parentConfigurator = null, ?array $parentPrefixes = null)
{
$this->parent = $parent;
$this->name = $name;
@ -38,14 +38,14 @@ class CollectionConfigurator
$this->parentPrefixes = $parentPrefixes;
}
/**
* @return array
*/
public function __sleep()
public function __sleep(): array
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}
/**
* @return void
*/
public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
@ -78,7 +78,7 @@ class CollectionConfigurator
*
* @return $this
*/
final public function prefix($prefix): self
final public function prefix(string|array $prefix): static
{
if (\is_array($prefix)) {
if (null === $this->parentPrefixes) {
@ -111,13 +111,16 @@ class CollectionConfigurator
*
* @return $this
*/
final public function host($host): self
final public function host(string|array $host): static
{
$this->host = $host;
return $this;
}
/**
* This method overrides the one from LocalizedRouteTrait.
*/
private function createRoute(string $path): Route
{
return (clone $this->route)->setPath($path);

View file

@ -22,7 +22,7 @@ class ImportConfigurator
use Traits\PrefixTrait;
use Traits\RouteTrait;
private $parent;
private RouteCollection $parent;
public function __construct(RouteCollection $parent, RouteCollection $route)
{
@ -30,14 +30,14 @@ class ImportConfigurator
$this->route = $route;
}
/**
* @return array
*/
public function __sleep()
public function __sleep(): array
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}
/**
* @return void
*/
public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
@ -55,7 +55,7 @@ class ImportConfigurator
*
* @return $this
*/
final public function prefix($prefix, bool $trailingSlashOnRoot = true): self
final public function prefix(string|array $prefix, bool $trailingSlashOnRoot = true): static
{
$this->addPrefix($this->route, $prefix, $trailingSlashOnRoot);
@ -67,7 +67,7 @@ class ImportConfigurator
*
* @return $this
*/
final public function namePrefix(string $namePrefix): self
final public function namePrefix(string $namePrefix): static
{
$this->route->addNamePrefix($namePrefix);
@ -81,7 +81,7 @@ class ImportConfigurator
*
* @return $this
*/
final public function host($host): self
final public function host(string|array $host): static
{
$this->addHost($this->route, $host);

View file

@ -24,7 +24,7 @@ class RouteConfigurator
protected $parentConfigurator;
public function __construct(RouteCollection $collection, RouteCollection $route, string $name = '', CollectionConfigurator $parentConfigurator = null, array $prefixes = null)
public function __construct(RouteCollection $collection, RouteCollection $route, string $name = '', ?CollectionConfigurator $parentConfigurator = null, ?array $prefixes = null)
{
$this->collection = $collection;
$this->route = $route;
@ -40,7 +40,7 @@ class RouteConfigurator
*
* @return $this
*/
final public function host($host): self
final public function host(string|array $host): static
{
$this->addHost($this->route, $host);

View file

@ -21,12 +21,12 @@ class RoutingConfigurator
{
use Traits\AddTrait;
private $loader;
private $path;
private $file;
private $env;
private PhpFileLoader $loader;
private string $path;
private string $file;
private ?string $env;
public function __construct(RouteCollection $collection, PhpFileLoader $loader, string $path, string $file, string $env = null)
public function __construct(RouteCollection $collection, PhpFileLoader $loader, string $path, string $file, ?string $env = null)
{
$this->collection = $collection;
$this->loader = $loader;
@ -38,7 +38,7 @@ class RoutingConfigurator
/**
* @param string|string[]|null $exclude Glob patterns to exclude from the import
*/
final public function import($resource, string $type = null, bool $ignoreErrors = false, $exclude = null): ImportConfigurator
final public function import(string|array $resource, ?string $type = null, bool $ignoreErrors = false, string|array|null $exclude = null): ImportConfigurator
{
$this->loader->setCurrentDir(\dirname($this->path));
@ -68,10 +68,7 @@ class RoutingConfigurator
return $this->env;
}
/**
* @return static
*/
final public function withPath(string $path): self
final public function withPath(string $path): static
{
$clone = clone $this;
$clone->path = $clone->file = $path;

View file

@ -35,7 +35,7 @@ trait AddTrait
*
* @param string|array $path the path, or the localized paths of the route
*/
public function add(string $name, $path): RouteConfigurator
public function add(string $name, string|array $path): RouteConfigurator
{
$parentConfigurator = $this instanceof CollectionConfigurator ? $this : ($this instanceof RouteConfigurator ? $this->parentConfigurator : null);
$route = $this->createLocalizedRoute($this->collection, $name, $path, $this->name, $this->prefixes);
@ -53,7 +53,7 @@ trait AddTrait
*
* @param string|array $path the path, or the localized paths of the route
*/
public function __invoke(string $name, $path): RouteConfigurator
public function __invoke(string $name, string|array $path): RouteConfigurator
{
return $this->add($name, $path);
}

View file

@ -18,7 +18,7 @@ use Symfony\Component\Routing\RouteCollection;
*/
trait HostTrait
{
final protected function addHost(RouteCollection $routes, $hosts)
final protected function addHost(RouteCollection $routes, string|array $hosts): void
{
if (!$hosts || !\is_array($hosts)) {
$routes->setHost($hosts ?: '');

View file

@ -27,7 +27,7 @@ trait LocalizedRouteTrait
*
* @param string|array $path the path, or the localized paths of the route
*/
final protected function createLocalizedRoute(RouteCollection $collection, string $name, $path, string $namePrefix = '', array $prefixes = null): RouteCollection
final protected function createLocalizedRoute(RouteCollection $collection, string $name, string|array $path, string $namePrefix = '', ?array $prefixes = null): RouteCollection
{
$paths = [];

View file

@ -21,7 +21,7 @@ use Symfony\Component\Routing\RouteCollection;
*/
trait PrefixTrait
{
final protected function addPrefix(RouteCollection $routes, $prefix, bool $trailingSlashOnRoot)
final protected function addPrefix(RouteCollection $routes, string|array $prefix, bool $trailingSlashOnRoot): void
{
if (\is_array($prefix)) {
foreach ($prefix as $locale => $localePrefix) {
@ -29,6 +29,7 @@ trait PrefixTrait
}
foreach ($routes->all() as $name => $route) {
if (null === $locale = $route->getDefault('_locale')) {
$priority = $routes->getPriority($name) ?? 0;
$routes->remove($name);
foreach ($prefix as $locale => $localePrefix) {
$localizedRoute = clone $route;
@ -36,13 +37,13 @@ trait PrefixTrait
$localizedRoute->setRequirement('_locale', preg_quote($locale));
$localizedRoute->setDefault('_canonical_route', $name);
$localizedRoute->setPath($localePrefix.(!$trailingSlashOnRoot && '/' === $route->getPath() ? '' : $route->getPath()));
$routes->add($name.'.'.$locale, $localizedRoute);
$routes->add($name.'.'.$locale, $localizedRoute, $priority);
}
} elseif (!isset($prefix[$locale])) {
throw new \InvalidArgumentException(sprintf('Route "%s" with locale "%s" is missing a corresponding prefix in its parent collection.', $name, $locale));
} else {
$route->setPath($prefix[$locale].(!$trailingSlashOnRoot && '/' === $route->getPath() ? '' : $route->getPath()));
$routes->add($name, $route);
$routes->add($name, $route, $routes->getPriority($name) ?? 0);
}
}

View file

@ -26,7 +26,7 @@ trait RouteTrait
*
* @return $this
*/
final public function defaults(array $defaults): self
final public function defaults(array $defaults): static
{
$this->route->addDefaults($defaults);
@ -38,7 +38,7 @@ trait RouteTrait
*
* @return $this
*/
final public function requirements(array $requirements): self
final public function requirements(array $requirements): static
{
$this->route->addRequirements($requirements);
@ -50,7 +50,7 @@ trait RouteTrait
*
* @return $this
*/
final public function options(array $options): self
final public function options(array $options): static
{
$this->route->addOptions($options);
@ -62,7 +62,7 @@ trait RouteTrait
*
* @return $this
*/
final public function utf8(bool $utf8 = true): self
final public function utf8(bool $utf8 = true): static
{
$this->route->addOptions(['utf8' => $utf8]);
@ -74,7 +74,7 @@ trait RouteTrait
*
* @return $this
*/
final public function condition(string $condition): self
final public function condition(string $condition): static
{
$this->route->setCondition($condition);
@ -86,7 +86,7 @@ trait RouteTrait
*
* @return $this
*/
final public function host(string $pattern): self
final public function host(string $pattern): static
{
$this->route->setHost($pattern);
@ -101,7 +101,7 @@ trait RouteTrait
*
* @return $this
*/
final public function schemes(array $schemes): self
final public function schemes(array $schemes): static
{
$this->route->setSchemes($schemes);
@ -116,7 +116,7 @@ trait RouteTrait
*
* @return $this
*/
final public function methods(array $methods): self
final public function methods(array $methods): static
{
$this->route->setMethods($methods);
@ -130,7 +130,7 @@ trait RouteTrait
*
* @return $this
*/
final public function controller($controller): self
final public function controller(callable|string|array $controller): static
{
$this->route->addDefaults(['_controller' => $controller]);
@ -142,7 +142,7 @@ trait RouteTrait
*
* @return $this
*/
final public function locale(string $locale): self
final public function locale(string $locale): static
{
$this->route->addDefaults(['_locale' => $locale]);
@ -154,7 +154,7 @@ trait RouteTrait
*
* @return $this
*/
final public function format(string $format): self
final public function format(string $format): static
{
$this->route->addDefaults(['_format' => $format]);
@ -166,7 +166,7 @@ trait RouteTrait
*
* @return $this
*/
final public function stateless(bool $stateless = true): self
final public function stateless(bool $stateless = true): static
{
$this->route->addDefaults(['_stateless' => $stateless]);