---
# 5. Scaffolding with the Component Kickstarter
Due to the elaborate nature of PresentationObjects `PackageFactory.AtomicFusion.PresentationObjects` ships with a scaffolding tool that eases the creation of all required code patterns. This tool comes in the form of a set of Neos.Flow commands and enables you to generate code from the command line.
## `component:kickstartenum` command
This command generates a new pseudo-enum value object. A pseudo-enum is an attempt to enable enumeration types in PHP, since it doesn't have a native language construct for this (although this might change in the future: https://wiki.php.net/rfc/enum).
Enumerations (or: enums) can be used to represent discrete values. Think of the state of a traffic light which can only take one of the values red, yellow and green (simplified, of course). A good example in HTML would be the `type` attribute of a `` element, which is supposed to only take one of the values `button` or `submit`.
For more information on this pattern, have a look at this excellent article: https://stitcher.io/blog/php-enums
> **Hint:** For a full parameter list use the built-in command documentation of Neos.Flow: `./flow help component:kickstartenum`
### Example
```sh
./flow component:kickstartenum \
Vendor.Site:Headline \
HeadlineLook string \
--values=regular,hero
```
> **Hint:** Components are namespaced, defaulting to "Component". The component name "Vendor.Site:Headline" thus will be evaluated as "Vendor.Site:Component.Headline".
> Arbitrary other namespaces, including nested, are supported, like "Vendor.Site:MyNamespace.Headline" or "Vendor.Site:My.Namespace.Headline".
### What files are being created?
#### HeadlineLook.php
This is the central pseudo-enum class. It consists of:
* A set of constants that represent the enum cases
* Static factory methods that are named like the enum cases
* `getIs*` methods to identify a value both in PHP and Neos.Eel
* A static `cases` method to retrieve a list of all possible enum cases
* A `getValue` method that will return the value of the enum instance as your chosen type
* A `__toString` method for string casting
```php
|self[]
*/
private static array $instances = [];
private string $value;
private function __construct(string $value)
{
$this->value = $value;
}
public static function from(string $string): self
{
if (!isset(self::$instances[$string])) {
if ($string !== self::LOOK_REGULAR
&& $string !== self::LOOK_HERO) {
throw HeadlineLookIsInvalid::becauseItMustBeOneOfTheDefinedConstants($string);
}
self::$instances[$string] = new self($string);
}
return self::$instances[$string];
}
public static function regular(): self
{
return self::from(self::LOOK_REGULAR);
}
public static function hero(): self
{
return self::from(self::LOOK_HERO);
}
public function getIsRegular(): bool
{
return $this->value === self::LOOK_REGULAR;
}
public function getIsHero(): bool
{
return $this->value === self::LOOK_HERO;
}
/**
* @return array|self[]
*/
public static function cases(): array
{
return [
self::from(self::LOOK_REGULAR),
self::from(self::LOOK_HERO)
];
}
public function getValue(): string
{
return $this->value;
}
public function __toString(): string
{
return $this->value;
}
}
```
#### HeadlineLookIsInvalid.php
The exception in this file will be thrown, when the pseudo-enum is initialized with an invalid value (which could happen, when `::from` is called).
```php
**Hint:** It is recommended to create all required values and sub-components beforehand, so the kickstarter can find and create proper `use`-statements for them.
```sh
./flow component:kickstart Vendor.Site:Headline \
type:HeadlineType \
look:HeadlineLook \
content:string
```
> **Hint:** Components are namespaced, defaulting to "Component". The component name "Vendor.Site:Headline" thus will be evaluated as "Vendor.Site:Component.Headline".
> Arbitrary other namespaces, including nested, are supported, like "Vendor.Site:MyNamespace.Headline" or "Vendor.Site:My.Namespace.Headline".
### What files are being created?
#### Headline.fusion
The is the fusion code for the component. It consists of a full `@styleguide` configuration for [Sitegeist.Monocle](https://github.com/sitegeist/Sitegeist.Monocle) as well as a dummy renderer that displays all PresentationObject properties as a definition list (see: https://developer.mozilla.org/de/docs/Web/HTML/Element/dl).
```fusion
prototype(Vendor.Site:Component.Headline) < prototype(PackageFactory.AtomicFusion.PresentationObjects:PresentationObjectComponent) {
@presentationObjectInterface = 'Vendor\\Site\\Presentation\\Headline\\HeadlineInterface'
@styleguide {
title = 'Headline'
props {
type = 'h1'
look = 'regular'
content = 'Text'
}
}
renderer = afx`
type:
{presentationObject.type}
look:
{presentationObject.look}
content:
{presentationObject.content}
`
}
```
#### HeadlineInterface.php
This is the PHP interface of the PresentationObject. It consists of a getter for each property descriptor that was passed to `component:kickstart`.
```php
type = $type;
$this->look = $look;
$this->content = $content;
}
public function getType(): HeadlineType
{
return $this->type;
}
public function getLook(): HeadlineLook
{
return $this->look;
}
public function getContent(): string
{
return $this->content;
}
}
```
#### HeadlineFactory.php
This is an empty factory for the PresentationObject that is supposed to be used for content integration.
```php
**Hint:** It is highly recommended to decide on colocation once at the start of a project.
---