# SimpleFactory

> Creates and configures tag instances from cookbook-style definitions.

[API reference](/docs/api/index.md) › [HTML Core](/docs/extensions/html-core/reference/index.md) › [Factory](/docs/extensions/html-core/reference/factory/index.md) › SimpleFactory

| final class | `UIAwesome\Html\Core\Factory\SimpleFactory` |
| --- | --- |
| Source | [`src/Factory/SimpleFactory.php`](https://github.com/ui-awesome/html-core/blob/main/src/Factory/SimpleFactory.php#L25) |

Creates and configures tag instances from cookbook-style definitions.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`configure()`](#method-configure) static | Applies configuration values to a tag instance. | `SimpleFactory` |
| [`create()`](#method-create) static | Creates a non-abstract tag instance by class name. | `SimpleFactory` |

## Method details

### configure() <span id="method-configure"></span>

```php
public static function configure(UIAwesome\Html\Core\Base\BaseTag $tag, array $defaults): UIAwesome\Html\Core\Base\BaseTag
```

Applies configuration values to a tag instance.

Keys resolve to methods first, then to properties, and must name a public instance member. A method must return
an instance of the tag class, such as the clone returned by an immutable setter. A numeric key, or a key matching
no method or property, aborts the configuration with [`ConfigException`](/docs/extensions/html-core/reference/exception/configexception/index.md).

Property writes rejected at runtime, such as `readonly`, asymmetric visibility, or type mismatches, surface as
[`ConfigException`](/docs/extensions/html-core/reference/exception/configexception/index.md) with the original `Error` attached as the previous exception.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tag` | [`UIAwesome\Html\Core\Base\BaseTag`](/docs/extensions/html-core/reference/base/basetag/index.md) | Tag instance to configure. |
| `$defaults` | `array` | Associative array of method names and arguments. |

**Returns**

[`UIAwesome\Html\Core\Base\BaseTag`](/docs/extensions/html-core/reference/base/basetag/index.md): Configured tag instance.

**Throws**

- [`UIAwesome\Html\Core\Exception\ConfigException`](/docs/extensions/html-core/reference/exception/configexception/index.md): if a key is numeric, matches no method or property, resolves to a method that is not a public instance method or does not return an instance of the tag class, resolves to a property that is not a public instance property, or resolves to a public property that rejects the write.

### create() <span id="method-create"></span>

```php
public static function create(string $class): UIAwesome\Html\Core\Base\BaseTag
```

Creates a non-abstract tag instance by class name.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$class` | `string` | Tag class name. |

**Returns**

[`UIAwesome\Html\Core\Base\BaseTag`](/docs/extensions/html-core/reference/base/basetag/index.md): Instantiated tag object.

**Throws**

- [`LogicException`](https://www.php.net/manual/en/class.logicexception.php): if the class is abstract and cannot be instantiated.
- [`ReflectionException`](https://www.php.net/manual/en/class.reflectionexception.php)