-
-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert #1694 "[LiveComponent] set LiveArg value to null if empty string"
- Loading branch information
Showing
10 changed files
with
110 additions
and
286 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,49 +11,44 @@ | |
|
||
namespace Symfony\UX\LiveComponent\Attribute; | ||
|
||
use Symfony\Component\HttpKernel\Attribute\ValueResolver; | ||
use Symfony\UX\LiveComponent\ValueResolver\LiveArgValueResolver; | ||
|
||
if (class_exists(ValueResolver::class)) { | ||
/** | ||
* An attribute to configure a LiveArg (custom argument passed to a LiveAction). | ||
* | ||
* @see https://symfony.com/bundles/ux-live-component/current/index.html#actions-arguments | ||
* | ||
* @author Tomas Norkūnas <[email protected]> | ||
* @author Jannes Drijkoningen <[email protected]> | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_PARAMETER)] | ||
final class LiveArg extends ValueResolver | ||
{ | ||
public function __construct( | ||
/** | ||
* @param string|null $name The name of the argument received by the LiveAction | ||
*/ | ||
public ?string $name = null, | ||
bool $disabled = false, | ||
string $resolver = LiveArgValueResolver::class, | ||
) { | ||
parent::__construct($resolver, $disabled); | ||
} | ||
/** | ||
* An attribute to configure a LiveArg (custom argument passed to a LiveAction). | ||
* | ||
* @see https://symfony.com/bundles/ux-live-component/current/index.html#actions-arguments | ||
* | ||
* @author Tomas Norkūnas <[email protected]> | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_PARAMETER)] | ||
final class LiveArg | ||
{ | ||
public function __construct( | ||
/** | ||
* @param string|null $name The name of the argument received by the LiveAction | ||
*/ | ||
public ?string $name = null, | ||
) { | ||
} | ||
} else { | ||
|
||
/** | ||
* An attribute to configure a LiveArg (custom argument passed to a LiveAction). | ||
* | ||
* @see https://symfony.com/bundles/ux-live-component/current/index.html#actions-arguments | ||
* @internal | ||
* | ||
* @author Tomas Norkūnas <[email protected]> | ||
* @return array<string, string> | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_PARAMETER)] | ||
final class LiveArg | ||
public static function liveArgs(object $component, string $action): array | ||
{ | ||
public function __construct( | ||
/** | ||
* @param string|null $name The name of the argument received by the LiveAction | ||
*/ | ||
public ?string $name = null, | ||
) { | ||
$method = new \ReflectionMethod($component, $action); | ||
$liveArgs = []; | ||
|
||
foreach ($method->getParameters() as $parameter) { | ||
foreach ($parameter->getAttributes(self::class) as $liveArg) { | ||
/** @var LiveArg $attr */ | ||
$attr = $liveArg->newInstance(); | ||
$parameterName = $parameter->getName(); | ||
|
||
$liveArgs[$parameterName] = $attr->name ?? $parameterName; | ||
} | ||
} | ||
|
||
return $liveArgs; | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
59 changes: 0 additions & 59 deletions
59
src/LiveComponent/src/ValueResolver/LiveArgValueResolver.php
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.