Skip to content
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

Stimulus: move deprecations from DTOs to filters/functions #186

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Dto/StimulusActionsDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function addAction($dataOrControllerName, string $actionName = null, stri
if (\is_string($dataOrControllerName)) {
$data = [$dataOrControllerName => null === $eventName ? [[$actionName]] : [[$eventName => $actionName]]];
} else {
trigger_deprecation('symfony/webpack-encore-bundle', 'v1.15.0', 'Passing an array as first argument of stimulus_action() is deprecated.');
if ($actionName || $eventName || $parameters) {
throw new \InvalidArgumentException('You cannot pass a string to the second or third argument nor an array to the fourth argument while passing an array to the first argument of stimulus_action(): check the documentation.');
}
Expand Down
1 change: 0 additions & 1 deletion src/Dto/StimulusControllersDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public function addController($dataOrControllerName, array $controllerValues = [
if (\is_string($dataOrControllerName)) {
$data = [$dataOrControllerName => $controllerValues];
} else {
trigger_deprecation('symfony/webpack-encore-bundle', 'v1.15.0', 'Passing an array as first argument of stimulus_controller() is deprecated.');
if ($controllerValues) {
throw new \InvalidArgumentException('You cannot pass an array to the first and second argument of stimulus_controller(): check the documentation.');
}
Expand Down
1 change: 0 additions & 1 deletion src/Dto/StimulusTargetsDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function addTarget($dataOrControllerName, string $targetNames = null): vo
if (\is_string($dataOrControllerName)) {
$data = [$dataOrControllerName => $targetNames];
} else {
trigger_deprecation('symfony/webpack-encore-bundle', 'v1.15.0', 'Passing an array as first argument of stimulus_target() is deprecated.');
if ($targetNames) {
throw new \InvalidArgumentException('You cannot pass a string to the second argument while passing an array to the first argument of stimulus_target(): check the documentation.');
}
Expand Down
24 changes: 24 additions & 0 deletions src/Twig/StimulusTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public function getFilters(): array
*/
public function renderStimulusController(Environment $env, $dataOrControllerName, array $controllerValues = []): StimulusControllersDto
{
if (!\is_string($dataOrControllerName)) {
trigger_deprecation('symfony/webpack-encore-bundle', 'v1.15.0', 'Passing an array as first argument of stimulus_controller() is deprecated.');
}

$dto = new StimulusControllersDto($env);
$dto->addController($dataOrControllerName, $controllerValues);

Expand All @@ -65,6 +69,10 @@ public function renderStimulusController(Environment $env, $dataOrControllerName
*/
public function appendStimulusController(StimulusControllersDto $dto, $dataOrControllerName, array $controllerValues = []): StimulusControllersDto
{
if (!\is_string($dataOrControllerName)) {
trigger_deprecation('symfony/webpack-encore-bundle', 'v1.15.0', 'Passing an array as first argument of stimulus_controller() is deprecated.');
}

$dto->addController($dataOrControllerName, $controllerValues);

return $dto;
Expand All @@ -83,6 +91,10 @@ public function appendStimulusController(StimulusControllersDto $dto, $dataOrCon
*/
public function renderStimulusAction(Environment $env, $dataOrControllerName, string $actionName = null, string $eventName = null, array $parameters = []): StimulusActionsDto
{
if (!\is_string($dataOrControllerName)) {
trigger_deprecation('symfony/webpack-encore-bundle', 'v1.15.0', 'Passing an array as first argument of stimulus_action() is deprecated.');
}

$dto = new StimulusActionsDto($env);
$dto->addAction($dataOrControllerName, $actionName, $eventName, $parameters);

Expand All @@ -102,6 +114,10 @@ public function renderStimulusAction(Environment $env, $dataOrControllerName, st
*/
public function appendStimulusAction(StimulusActionsDto $dto, $dataOrControllerName, string $actionName = null, string $eventName = null, array $parameters = []): StimulusActionsDto
{
if (!\is_string($dataOrControllerName)) {
trigger_deprecation('symfony/webpack-encore-bundle', 'v1.15.0', 'Passing an array as first argument of stimulus_action() is deprecated.');
}

$dto->addAction($dataOrControllerName, $actionName, $eventName, $parameters);

return $dto;
Expand All @@ -118,6 +134,10 @@ public function appendStimulusAction(StimulusActionsDto $dto, $dataOrControllerN
*/
public function renderStimulusTarget(Environment $env, $dataOrControllerName, string $targetNames = null): StimulusTargetsDto
{
if (!\is_string($dataOrControllerName)) {
trigger_deprecation('symfony/webpack-encore-bundle', 'v1.15.0', 'Passing an array as first argument of stimulus_target() is deprecated.');
}

$dto = new StimulusTargetsDto($env);
$dto->addTarget($dataOrControllerName, $targetNames);

Expand All @@ -135,6 +155,10 @@ public function renderStimulusTarget(Environment $env, $dataOrControllerName, st
*/
public function appendStimulusTarget(StimulusTargetsDto $dto, $dataOrControllerName, string $targetNames = null): StimulusTargetsDto
{
if (!\is_string($dataOrControllerName)) {
trigger_deprecation('symfony/webpack-encore-bundle', 'v1.15.0', 'Passing an array as first argument of stimulus_target() is deprecated.');
}

$dto->addTarget($dataOrControllerName, $targetNames);

return $dto;
Expand Down