Skip to content

Commit

Permalink
thusfar
Browse files Browse the repository at this point in the history
  • Loading branch information
bobmagicii committed Sep 13, 2023
1 parent b0879bb commit d8c860e
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 2 deletions.
171 changes: 171 additions & 0 deletions src/Nether/Surface/Element.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<?php

namespace Nether\Surface;

use Nether\Common;

use Stringable;

#[Common\Meta\Date('2023-09-12')]
class Element
extends Common\Prototype
implements Stringable {

public string
$UUID;

public string
$Area;

public Common\Datastore
$Data;

public Engine
$Surface;

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////

public function
__Construct(Engine $Surface) {
parent::__Construct();

$this->UUID = Common\UUID::V7();
$this->Data = new Common\Datastore;
$this->Surface = $Surface;

return;
}

public function
__ToString():
string {

return $this->Render();
}

////////////////////////////////////////////////////////////////
// LOCAL: Element Events ///////////////////////////////////////

#[Common\Meta\Info('Runs when a render begins prior to the generation.')]
protected function
OnRender():
static {

return $this;
}

#[Common\Meta\Info('Runs after a render to filter the output.')]
protected function
OnRenderPost(string $Output):
string {

return $Output;
}

////////////////////////////////////////////////////////////////
// LOCAL: Misc Info API ////////////////////////////////////////

public function
GetID():
string {

$Output = sprintf(
'el-%s',
preg_replace('#[^a-z0-9]#', '', $this->UUID)
);

return $Output;
}

public function
GetSelectorID():
string {

return "#{$this->GetID()}";
}

public function
GetUUID():
string {

return $this->UUID;
}

public function
GetArea():
string {

if(!isset($this->Area))
throw new Common\Error\RequiredDataMissing('Area', 'string');

return static::ExpandAreaPath($this->Area);
}

public function
GetData():
Common\Datastore {

$this->Data['Element'] = $this;

return $this->Data;
}

////////////////////////////////////////////////////////////////
// LOCAL: Data Management //////////////////////////////////////

public function
Get(string $Key):
mixed {

return $this->Data->Get($Key);
}

public function
Set(string $Key, mixed $Val):
static {

$this->Data[$Key] = $Val;

return $this;
}

////////////////////////////////////////////////////////////////
// LOCAL: Rendering API ////////////////////////////////////////

public function
Render():
string {

return (
$this
->OnRender()
->OnRenderPost($this->Surface->GetArea(
$this->GetArea(),
$this->GetData()
))
);
}

public function
Print():
static {

echo $this->Render();
return $this;
}

////////////////////////////////////////////////////////////////
// Utility Methods /////////////////////////////////////////////

static public function
ExpandAreaPath(string $Area):
string {

if(str_starts_with($Area, '~/'))
$Area = preg_replace('#^~/#', 'elements/slider/', $Area);

return $Area;
}

};
4 changes: 2 additions & 2 deletions src/Nether/Surface/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public function
////////////////////////////////////////////////////////////////

public function
Wrap(string $Area, array $Scope=[], ?string $Masq=NULL, ?string $Wrapper=NULL):
Wrap(string $Area, iterable $Scope=[], ?string $Masq=NULL, ?string $Wrapper=NULL):
static {

$Scope['Area'] = $Area;
Expand Down Expand Up @@ -232,7 +232,7 @@ public function
}

public function
GetArea(string $Area, array $Scope=[], ?string $Masquerade=NULL):
GetArea(string $Area, iterable $Scope=[], ?string $Masquerade=NULL):
string {

ob_start();
Expand Down

0 comments on commit d8c860e

Please sign in to comment.