- First commit of first draft
This commit is contained in:
commit
66c7b349d1
36 files changed
+820
No files matched your search
@@ -0,0 +1,44 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Picea\Compiler;
|
||||
|
||||
use Picea\Compiler;
|
||||
|
||||
abstract class Context {
|
||||
|
||||
public string $namespace = "";
|
||||
|
||||
public string $extendFrom = "";
|
||||
|
||||
public array $switchStack = [];
|
||||
|
||||
public array $iterateStack = [];
|
||||
|
||||
public array $useStack = [];
|
||||
|
||||
public array $hooks = [];
|
||||
|
||||
public Compiler $compiler;
|
||||
|
||||
public function hook(string $path, Callable $callback) : self
|
||||
{
|
||||
$this->hooks[$path] ??= [];
|
||||
$this->hooks[$path][] = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function run(string $path, ...$arguments) : self
|
||||
{
|
||||
if ( $this->hooks[$path] ?? false ) {
|
||||
while ( $callback = array_pop($this->hooks[$path]) ) {
|
||||
$callback(...$arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function renderUses() : string
|
||||
{
|
||||
return implode(",", $context->useStack ?? []);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user