mirror of
https://github.com/ad-aures/castopod.git
synced 2026-04-13 11:37:46 +02:00
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:
parent
5083cd2fda
commit
a95de8bab0
106 changed files with 1482 additions and 2139 deletions
|
|
@ -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';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue