Skip to content

Commit e4f3b38

Browse files
smnandrekbond
authored andcommitted
[LiveComponent] Add docblocks on attributes
1 parent 7a54335 commit e4f3b38

File tree

7 files changed

+121
-82
lines changed

7 files changed

+121
-82
lines changed

src/LiveComponent/src/Attribute/AsLiveComponent.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,26 @@
1414
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
1515

1616
/**
17+
* An attribute to register a LiveComponent.
18+
*
19+
* @see https://symfony.com/bundles/ux-live-component
20+
*
1721
* @author Kevin Bond <[email protected]>
1822
*
1923
* @experimental
2024
*/
2125
#[\Attribute(\Attribute::TARGET_CLASS)]
2226
final class AsLiveComponent extends AsTwigComponent
2327
{
28+
/**
29+
* @param string|null $name The component name (ie: TodoList)
30+
* @param string|null $template The template path of the component (ie: components/TodoList.html.twig).
31+
* @param string|null $defaultAction The default action to call when the component is mounted (ie: __invoke)
32+
* @param bool $exposePublicProps Whether to expose every public property as a Twig variable
33+
* @param string $attributesVar The name of the special "attributes" variable in the template
34+
* @param bool $csrf Whether to enable CSRF protection (default: true)
35+
* @param string $route The route used to render the component & handle actions (default: ux_live_component)
36+
*/
2437
public function __construct(
2538
string $name = null,
2639
string $template = null,

src/LiveComponent/src/Attribute/LiveAction.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
namespace Symfony\UX\LiveComponent\Attribute;
1313

1414
/**
15+
* An attribute to register a LiveAction method.
16+
*
17+
* @see https://symfony.com/bundles/ux-live-component/current/index.html#actions
18+
*
1519
* @experimental
1620
*/
1721
#[\Attribute(\Attribute::TARGET_METHOD)]

src/LiveComponent/src/Attribute/LiveArg.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,23 @@
1212
namespace Symfony\UX\LiveComponent\Attribute;
1313

1414
/**
15+
* An attribute to configure a LiveArg (custom argument passed to a LiveAction).
16+
*
17+
* @see https://symfony.com/bundles/ux-live-component/current/index.html#actions-arguments
18+
*
1519
* @author Tomas Norkūnas <[email protected]>
1620
*
1721
* @experimental
1822
*/
1923
#[\Attribute(\Attribute::TARGET_PARAMETER)]
2024
final class LiveArg
2125
{
22-
public function __construct(public ?string $name = null)
23-
{
26+
public function __construct(
27+
/**
28+
* @param string|null $name The name of the argument received by the LiveAction
29+
*/
30+
public ?string $name = null,
31+
) {
2432
}
2533

2634
/**

src/LiveComponent/src/Attribute/LiveListener.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,21 @@
1212
namespace Symfony\UX\LiveComponent\Attribute;
1313

1414
/**
15+
* An Attribute to register a LiveListener method.
16+
*
17+
* When any component emits the event, an Ajax call will be made to call this
18+
* method and re-render the component.
19+
*
20+
* @see https://symfony.com/bundles/ux-live-component/current/index.html#listeners
21+
*
1522
* @experimental
1623
*/
1724
#[\Attribute(\Attribute::TARGET_METHOD)]
1825
class LiveListener extends LiveAction
1926
{
27+
/**
28+
* @param string $eventName The name of the event to listen to (e.g. "itemUpdated")
29+
*/
2030
public function __construct(private string $eventName)
2131
{
2232
}

src/LiveComponent/src/Attribute/LiveProp.php

Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
namespace Symfony\UX\LiveComponent\Attribute;
1313

1414
/**
15+
* An attribute to mark a property as a "LiveProp".
16+
*
17+
* @see https://symfony.com/bundles/ux-live-component/current/index.html#liveprops-stateful-component-properties
18+
*
1519
* @experimental
1620
*/
1721
#[\Attribute(\Attribute::TARGET_PROPERTY)]
@@ -23,87 +27,83 @@ final class LiveProp
2327
*/
2428
public const IDENTITY = '@identity';
2529

26-
/** @var bool|string[] */
27-
private bool|array $writable;
28-
29-
private ?string $hydrateWith;
30-
31-
private ?string $dehydrateWith;
32-
33-
private bool $useSerializerForHydration;
34-
35-
private array $serializationContext;
36-
37-
/**
38-
* The "frontend" field name that should be used for this property.
39-
*
40-
* This can be used, for example, to have a property called "foo", which actually
41-
* maps to a frontend data model called "bar".
42-
*
43-
* If you pass a string that ends in () - like "getFieldName()" - that
44-
* method on the component will be called to determine this.
45-
*/
46-
private ?string $fieldName;
47-
48-
private ?string $format;
49-
50-
private bool $acceptUpdatesFromParent;
51-
52-
/**
53-
* @var string|string[]|null
54-
*
55-
* A hook that will be called after the property is updated.
56-
* Set it to a method name on the Live Component that should be called.
57-
* The old value of the property will be passed as an argument to it.
58-
*/
59-
private null|string|array $onUpdated;
60-
61-
/**
62-
* Tells if this property should be bound to the URL.
63-
*/
64-
private bool $url;
65-
66-
/**
67-
* @param bool|array $writable If true, this property can be changed by the frontend.
68-
* Or set to an array of paths within this object/array
69-
* that are writable.
70-
* @param bool $useSerializerForHydration If true, the serializer will be used to
71-
* dehydrate then hydrate this property.
72-
* Incompatible with hydrateWith and dehydrateWith.
73-
* @param string|null $format The format to be used if the value is a DateTime of some sort.
74-
* For example: 'Y-m-d H:i:s'. If this property is writable, set this
75-
* to the format that your frontend field will use/set.
76-
* @param bool $updateFromParent if true, while a parent component is re-rendering,
77-
* if the parent passes in this prop and it changed
78-
* from the value used when originally rendering
79-
* this child, the value in the child will be updated
80-
* to match the new value and the child will be re-rendered
81-
* @param bool $url if true, this property will be synchronized with a query parameter
82-
* in the URL
83-
*/
8430
public function __construct(
85-
bool|array $writable = false,
86-
string $hydrateWith = null,
87-
string $dehydrateWith = null,
88-
bool $useSerializerForHydration = false,
89-
array $serializationContext = [],
90-
string $fieldName = null,
91-
string $format = null,
92-
bool $updateFromParent = false,
93-
string|array $onUpdated = null,
94-
bool $url = false,
31+
/**
32+
* If true, this property can be changed by the frontend.
33+
*
34+
* Or set to an array of paths within this object/array
35+
* that are writable.
36+
*
37+
* @var bool|string[]
38+
*/
39+
private bool|array $writable = false,
40+
41+
/**
42+
* Method to call to hydrate this property.
43+
*/
44+
private ?string $hydrateWith = null,
45+
46+
/**
47+
* Method to call to dehydrate this property.
48+
*/
49+
private ?string $dehydrateWith = null,
50+
51+
/**
52+
* If true, the serializer will be used to dehydrate then hydrate
53+
* this property.
54+
*
55+
* Incompatible with hydrateWith and dehydrateWith.
56+
*/
57+
private bool $useSerializerForHydration = false,
58+
59+
/**
60+
* @var array<string, mixed>
61+
*/
62+
private array $serializationContext = [],
63+
64+
/**
65+
* The "frontend" field name that should be used for this property.
66+
*
67+
* This can be used, for example, to have a property called "foo", which
68+
* actually maps to a frontend data model called "bar".
69+
*
70+
* If you pass a string that ends in () - like "getFieldName()" - that
71+
* method on the component will be called to determine this.
72+
*/
73+
private ?string $fieldName = null,
74+
75+
/**
76+
* The format to be used if the value is a DateTime of some sort.
77+
*
78+
* For example: 'Y-m-d H:i:s'. If this property is writable, set this
79+
* to the format that your frontend field will use/set.
80+
*/
81+
private ?string $format = null,
82+
83+
/**
84+
* If true, while a parent component is re-rendering, if the parent
85+
* passes in this prop and it changed from the value used when
86+
* originally rendering this child, the value in the child will be
87+
* updated to match the new value and the child will be re-rendered.
88+
*/
89+
private bool $updateFromParent = false,
90+
91+
/**
92+
* A hook that will be called after the property is updated.
93+
*
94+
* Set it to a method name on the Live Component that should be called.
95+
* The old value of the property will be passed as an argument to it.
96+
*
97+
* @var string|string[]|null
98+
*/
99+
private null|string|array $onUpdated = null,
100+
101+
/**
102+
* If true, this property will be synchronized with a query parameter
103+
* in the URL.
104+
*/
105+
private bool $url = false,
95106
) {
96-
$this->writable = $writable;
97-
$this->hydrateWith = $hydrateWith;
98-
$this->dehydrateWith = $dehydrateWith;
99-
$this->useSerializerForHydration = $useSerializerForHydration;
100-
$this->serializationContext = $serializationContext;
101-
$this->fieldName = $fieldName;
102-
$this->format = $format;
103-
$this->acceptUpdatesFromParent = $updateFromParent;
104-
$this->onUpdated = $onUpdated;
105-
$this->url = $url;
106-
107107
if ($this->useSerializerForHydration && ($this->hydrateWith || $this->dehydrateWith)) {
108108
throw new \InvalidArgumentException('Cannot use useSerializerForHydration with hydrateWith or dehydrateWith.');
109109
}
@@ -190,7 +190,7 @@ public function format(): ?string
190190

191191
public function acceptUpdatesFromParent(): bool
192192
{
193-
return $this->acceptUpdatesFromParent;
193+
return $this->updateFromParent;
194194
}
195195

196196
public function onUpdated(): null|string|array

src/LiveComponent/src/Attribute/PostHydrate.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\UX\LiveComponent\Attribute;
1313

1414
/**
15+
* An attribute to register a PostHydrate hook.
16+
*
1517
* @experimental
1618
*/
1719
#[\Attribute(\Attribute::TARGET_METHOD)]

src/LiveComponent/src/Attribute/PreDehydrate.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\UX\LiveComponent\Attribute;
1313

1414
/**
15+
* An attribute to register a PreDehydrate hook.
16+
*
1517
* @experimental
1618
*/
1719
#[\Attribute(\Attribute::TARGET_METHOD)]

0 commit comments

Comments
 (0)