Skip to content

Commit

Permalink
minor symfony#1229 [TwigComponent][Doc] AsTwigComponent docblocks (sm…
Browse files Browse the repository at this point in the history
…nandre)

This PR was squashed before being merged into the 2.x branch.

Discussion
----------

[TwigComponent][Doc] AsTwigComponent docblocks

Add some documentation on the AsTwigComponent attribute.

Commits
-------

6c2a4a7 [TwigComponent][Doc] AsTwigComponent docblocks
  • Loading branch information
weaverryan committed Oct 26, 2023
2 parents 262db2b + 6c2a4a7 commit 52dc225
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/TwigComponent/src/Attribute/AsTwigComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,52 @@
namespace Symfony\UX\TwigComponent\Attribute;

/**
* An attribute to register a TwigComponent.
*
* @see https://symfony.com/bundles/ux-twig-component
*
* @author Kevin Bond <[email protected]>
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
class AsTwigComponent
{
public function __construct(
/**
* The component name (ie: Button).
*
* With the default configuration, the template path is resolved using
* the component's class name.
*
* App\Twig\Components\Alert -> <twig:Alert />
* App\Twig\Components\Foo\Bar -> <twig:Foo:Bar />
*
* @see https://symfony.com/bundles/ux-twig-component#naming-your-component
*/
private ?string $name = null,

/**
* The template path of the component (ie: components/Button.html.twig).
*
* With the default configuration, the template path is resolved using
* the component's name.
*
* Button -> templates/components/Button.html.twig
* Foo:Bar -> templates/components/Foo/Bar.html.twig
*
* @see https://symfony.com/bundles/ux-twig-component#component-template-path
*/
private ?string $template = null,

/**
* Whether to expose every public property as a Twig variable.
*
* @see https://symfony.com/bundles/ux-twig-component#passing-data-props-into-your-component
*/
private bool $exposePublicProps = true,

/**
* The name of the special "attributes" variable in the template.
*/
private string $attributesVar = 'attributes',
) {
}
Expand Down
2 changes: 2 additions & 0 deletions src/TwigComponent/src/Attribute/ExposeInTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* in a component template (`someProp` vs `this.someProp`). These
* properties must be "accessible" (have a getter).
*
* @see https://symfony.com/bundles/ux-twig-component#exposeintemplate-attribute
*
* @author Kevin Bond <[email protected]>
*/
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD)]
Expand Down
4 changes: 4 additions & 0 deletions src/TwigComponent/src/Attribute/PostMount.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
namespace Symfony\UX\TwigComponent\Attribute;

/**
* An attribute to register a PostMount hook.
*
* @see https://symfony.com/bundles/ux-twig-component#postmount-hook
*
* @author Kevin Bond <[email protected]>
*/
#[\Attribute(\Attribute::TARGET_METHOD)]
Expand Down
4 changes: 4 additions & 0 deletions src/TwigComponent/src/Attribute/PreMount.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
namespace Symfony\UX\TwigComponent\Attribute;

/**
* An attribute to register a PreMount hook.
*
* @see https://symfony.com/bundles/ux-twig-component#premount-hook
*
* @author Kevin Bond <[email protected]>
*/
#[\Attribute(\Attribute::TARGET_METHOD)]
Expand Down

0 comments on commit 52dc225

Please sign in to comment.