You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* #11 use nelmio/alice for data-faking
* #11 cs-fixer
* #11 implemented generators for providing template data
* Update docs/ComponentConfiguration.md
Co-authored-by: Benjamin Schultz <[email protected]>
* Update tests/Unit/Component/ComponentItemFactoryTest.php
Co-authored-by: Benjamin Schultz <[email protected]>
* Breakpoint configuration (#18)
* add breakpoint config
* add disclaimer
- added forgotten documentation for breakpoints
* Fix typo
* Optimize function calls
[EA] '$item->$method()' would make more sense here (it's also faster).
* Fix route prefix
Regarding best practices, the bundle routes must be prefixed with the bundle alias.
* Cleanup and optimize code
Add strict types and return types where it was missing.
* merge update
* add class usages
* #11 code review changes
- added cs-fixer rule for strict types
* #11 code review changes
---------
Co-authored-by: Benjamin Schultz <[email protected]>
You must provide the types of your template parameters in the configuration.
89
+
As twig templates are not aware of types, there is no other possibility at the moment.
90
+
As this bundle makes use of [Nelmio/Alice](https://github.com/nelmio/alice) and [FakerPhp](https://fakerphp.github.io), all you need to do is
91
+
define the types of your parameters in the component configuration.
92
+
The bundle will take care of creating a set of parameters for every component.
93
+
94
+
E.g. when your template optionally requires a User object, you can say the template needs a parameter named user that is of type App\Entity\User:
95
+
```twig
96
+
{#TWIG_DOC
97
+
title: Fancy Button
98
+
description: This is a really fancy button
99
+
category: Buttons
100
+
tags:
101
+
- button
102
+
parameters:
103
+
type: String
104
+
text: String
105
+
user: App\Entity\User
106
+
#TWIG_DOC}
107
+
108
+
{% if user %}
109
+
Hello {{ user.name }}
110
+
{% endif %}
111
+
<button class="btn btn-{{ type }}">{{ text }}</button>
112
+
```
113
+
114
+
As we do not provide an explicit variation, the bundle creates a default variation for this component.
115
+
This default variation will contain a fixture for the user object, as well as random values for other parameters.
116
+
If the property "name" of the user object is writable, the bundle will also create a random text-value for the name.
117
+
118
+
So, what to do if you want an example of both possibilities (user as object and as NULL)? Answer: provide variations for both cases:
119
+
```twig
120
+
{#TWIG_DOC
121
+
title: Fancy Button
122
+
description: This is a really fancy button
123
+
category: Buttons
124
+
tags:
125
+
- button
126
+
parameters:
127
+
user: App\Entity\User
128
+
type: String
129
+
text: String
130
+
variations:
131
+
logged-in:
132
+
user:
133
+
name: superadmin
134
+
type: primary
135
+
anonymous:
136
+
user: null
137
+
text: Button Text
138
+
#TWIG_DOC}
139
+
140
+
{% if user %}
141
+
Hello {{ user.name }}
142
+
{% endif %}
143
+
<button class="btn btn-{{ type }}">{{ text }}</button>
144
+
```
145
+
146
+
For all parameters that are missing from the variations configuration, the bundle will create random-values with FakerPHP.
147
+
It is possible to mix explicitly defined parameter-values and randomly created ones.
148
+
149
+
### Custom Data Provider
150
+
151
+
This bundle comes with 3 default data providers to create fake data for your components:
152
+
153
+
- FixtureGenerator
154
+
- creates fixtures for classes with nelmio/alice and fakerphp/faker
155
+
- ScalarGenerator
156
+
- creates scalar values for string/bool/number parameters in your components with fakerphp
157
+
- NullGenerator
158
+
- creates null values for any unknown type
159
+
160
+
You can easily add your own data generator by creating an implementation of `Qossmic\TwigDocBundle\Component\Data\GeneratorInterface`
161
+
and tagging it with `twig_doc.data_generator`. The higher the priority, the earlier the generator will be used.
162
+
This works by using the ["tagged_iterator" functionality](https://symfony.com/doc/current/service_container/tags.html#tagged-services-with-priority) of Symfony.
thrownewInvalidComponentConfigurationException(ConstraintViolationList::createFromMessage(sprintf('A component variation must contain an array of parameters. Variation Name: %s', $variationName)));
0 commit comments