feat(components): add custom view renderer with ComponentRenderer adapted from bonfire2

- update Component class structure and remove component helper function and ComponentLoader
- update residual activitypub naming to fediverse
This commit is contained in:
Yassine Doghri 2021-08-27 10:58:22 +00:00
commit a95de8bab0
106 changed files with 1482 additions and 2139 deletions

View file

@ -6,6 +6,8 @@ namespace ViewComponents;
class Component implements ComponentInterface
{
protected string $slot = '';
/**
* @var array<string, string>
*/
@ -14,21 +16,33 @@ class Component implements ComponentInterface
];
/**
* @param array<string, mixed> $properties
* @param array<string, string> $attributes
*/
public function __construct(
protected array $properties,
array $attributes
) {
// overwrite default properties if set
foreach ($properties as $key => $value) {
$this->{$key} = $value;
public function __construct(array $attributes)
{
if ($attributes !== []) {
$this->hydrate($attributes);
}
// overwrite default attributes if set
$this->attributes = array_merge($this->attributes, $attributes);
}
/**
* @param array<string, string> $attributes
*/
public function hydrate(array $attributes): void
{
foreach ($attributes as $name => $value) {
$method = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $name)));
if (is_callable([$this, $method])) {
$this->{$method}($value);
} else {
$this->{$name} = $value;
}
}
}
public function render(): string
{
return static::class . ': RENDER METHOD NOT IMPLEMENTED';