-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Routing] allow setting multiple envs in #[Route]
attribute
#61358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
santysisi
wants to merge
1
commit into
symfony:7.4
Choose a base branch
from
santysisi:feature/support-multiple-envs-in-route-attribute
base: 7.4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
|
||
namespace Symfony\Component\Routing\Attribute; | ||
|
||
use Symfony\Component\Routing\Exception\LogicException; | ||
|
||
/** | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
* @author Alexander M. Turek <me@derrabus.de> | ||
|
@@ -21,6 +23,8 @@ class Route | |
private ?string $path = null; | ||
private array $localizedPaths = []; | ||
private array $methods; | ||
/** @var string[] */ | ||
private array $env; | ||
private array $schemes; | ||
/** | ||
* @var (string|DeprecatedAlias)[] | ||
|
@@ -42,7 +46,7 @@ class Route | |
* @param string|null $format The format returned by the route (i.e. "json", "xml") | ||
* @param bool|null $utf8 Whether the route accepts UTF-8 in its parameters | ||
* @param bool|null $stateless Whether the route is defined as stateless or stateful, @see https://symfony.com/doc/current/routing.html#stateless-routes | ||
* @param string|null $env The env in which the route is defined (i.e. "dev", "test", "prod") | ||
* @param string|string[]|null $env The env(s) in which the route is defined (i.e. "dev", "test", "prod", ["dev", "test"]) | ||
* @param string|DeprecatedAlias|(string|DeprecatedAlias)[] $alias The list of aliases for this route | ||
*/ | ||
public function __construct( | ||
|
@@ -60,7 +64,7 @@ public function __construct( | |
?string $format = null, | ||
?bool $utf8 = null, | ||
?bool $stateless = null, | ||
private ?string $env = null, | ||
string|array|null $env = null, | ||
string|DeprecatedAlias|array $alias = [], | ||
) { | ||
if (\is_array($path)) { | ||
|
@@ -71,6 +75,7 @@ public function __construct( | |
$this->setMethods($methods); | ||
$this->setSchemes($schemes); | ||
$this->setAliases($alias); | ||
$this->setEnvs((array) $env); | ||
|
||
if (null !== $locale) { | ||
$this->defaults['_locale'] = $locale; | ||
|
@@ -199,12 +204,37 @@ public function getPriority(): ?int | |
return $this->priority; | ||
} | ||
|
||
/** | ||
* @deprecated since Symfony 7.4, use the {@see setEnvs()} method instead | ||
*/ | ||
public function setEnv(?string $env): void | ||
{ | ||
$this->env = $env; | ||
trigger_deprecation('symfony/routing', '7.4', 'The "%s()" method is deprecated, use "setEnvs()" instead.', __METHOD__); | ||
$this->env = (array) $env; | ||
} | ||
|
||
/** | ||
* @deprecated since Symfony 7.4, use {@see getEnvs()} method instead | ||
*/ | ||
public function getEnv(): ?string | ||
{ | ||
trigger_deprecation('symfony/routing', '7.4', 'The "%s()" method is deprecated, use "getEnvs()" instead.', __METHOD__); | ||
if (!$this->env) { | ||
return null; | ||
} | ||
if (\count($this->env) > 1) { | ||
throw new LogicException(\sprintf('The "env" property has %d environments. Use "getEnvs()" to get all of them.', \count($this->env))); | ||
} | ||
|
||
return $this->env[0]; | ||
} | ||
|
||
public function setEnvs(array|string $env): void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we have setters at all? |
||
{ | ||
$this->env = (array) $env; | ||
} | ||
|
||
public function getEnvs(): array | ||
{ | ||
return $this->env; | ||
} | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.