- First commit of first draft

This commit is contained in:
mcndave committed 2019-08-21 16:11:39 -04:00
commit 66c7b349d1
36 files changed
+820

No files matched your search

+44
View File
@@ -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 ?? []);
}
}