- WIP on RAW token
- WIP on caching interface - Work done on easing template rendering for the controller
This commit is contained in:
1 parent
f8e3dbd60f
commit
bcd49884fc
37 files changed
+381
-107
No files matched your search
+61
-50
@@ -2,16 +2,56 @@
|
||||
|
||||
namespace Picea;
|
||||
|
||||
class Picea
|
||||
use Closure;
|
||||
use Picea\Language\LanguageRegistration;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class Picea implements LanguageRegistration
|
||||
{
|
||||
const DEFAULT_BUILDER_TEMPLATE = "/Builder/ClassTemplate.php";
|
||||
|
||||
public Compiler\Context $context;
|
||||
|
||||
public Compiler $compiler;
|
||||
|
||||
public function __construct(?Context $context = null, ?Compiler $compiler = null)
|
||||
{
|
||||
public LanguageRegistration $languageRegistration;
|
||||
|
||||
public string $builderTemplatePath;
|
||||
|
||||
public Closure $responseHtml;
|
||||
|
||||
public Caching\Cache $cache;
|
||||
|
||||
public function __construct(
|
||||
?Closure $responseHtml = null,
|
||||
?Cache $cache = null,
|
||||
?Context $context = null,
|
||||
?Compiler $compiler = null,
|
||||
?LanguageRegistration $languageRegistration = null,
|
||||
?string $builderTemplatePath = null
|
||||
){
|
||||
$this->response = $responseHtml;
|
||||
$this->cache = $cache ?? new Caching\Memory("");
|
||||
$this->context = $context ?? new Compiler\BaseContext();
|
||||
$this->compiler = $compiler ?: $this->instanciateCompiler();
|
||||
$this->compiler = $compiler ?? $this->instanciateCompiler();
|
||||
$this->languageRegistration = $languageRegistration ?? new Language\DefaultRegistrations();
|
||||
$this->builderTemplatePath = $builderTemplatePath ?? dirname(__FILE__) . static::DEFAULT_BUILDER_TEMPLATE;
|
||||
}
|
||||
|
||||
public function outputHtml(string $viewPath, array $variables) : ResponseInterface
|
||||
{
|
||||
if ( $this->response ?? false ) {
|
||||
if ( false === $content = $this->cache->handle($viewPath) ) {
|
||||
# if ( )
|
||||
}
|
||||
|
||||
$source = $this->compileSource($source ?? "test");
|
||||
|
||||
$response = $this->response;
|
||||
return $response("abc");
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException("No \Psr\Http\Message\ResponseInterface closure provided. Please provide one using the constructor or assinging it to the class variable `responseHtml`.");
|
||||
}
|
||||
|
||||
public function compileSource(string $source) : array
|
||||
@@ -27,11 +67,11 @@ class Picea
|
||||
public function compileFile(string $filePath) : array
|
||||
{
|
||||
if (! file_exists($filePath) ) {
|
||||
throw new \InvalidArgumentException("File `$filePath` cannot be found or it is a permission problem");
|
||||
throw new \InvalidArgumentException("File `$filePath` cannot be found or there is a permission problem.");
|
||||
}
|
||||
|
||||
if ( false === $fileContent = file_get_contents($filePath) ) {
|
||||
throw new \ErrorException("Given file could not be opened `$filePath`. This could indicate a permission misconfiguration on your file or folder");
|
||||
throw new \ErrorException("Given file could not be opened `$filePath`. This could indicate a permission misconfiguration on your file or folder.");
|
||||
}
|
||||
|
||||
$this->compiler->loadSourceCode($fileContent);
|
||||
@@ -64,64 +104,35 @@ class Picea
|
||||
|
||||
}
|
||||
|
||||
public function instanciateCompiler(string $sourceCode = "") : Compiler
|
||||
public function instanciateCompiler() : Compiler
|
||||
{
|
||||
$compiler = new Compiler();
|
||||
$compiler->loadSourceCode($sourceCode);
|
||||
|
||||
$this->registerSyntax($compiler)
|
||||
->registerControlStructure($compiler)
|
||||
->registerExtension($compiler);
|
||||
|
||||
return $compiler;
|
||||
return new Compiler($this->languageRegistration);
|
||||
}
|
||||
|
||||
public function instanciateBuilder() : Builder
|
||||
{
|
||||
$builder = new Builder(dirname(__FILE__) . "/Builder/ClassTemplate.php");
|
||||
return $builder;
|
||||
return new Builder($this->builderTemplatePath);
|
||||
}
|
||||
|
||||
protected function registerSyntax(Compiler $compiler) : self
|
||||
public function registerAll(Compiler $compiler) : void
|
||||
{
|
||||
$compiler->registerSyntax( new \Picea\Syntax\PhpTagToken() );
|
||||
$compiler->registerSyntax( new \Picea\Syntax\CommentToken() );
|
||||
$compiler->registerSyntax( new \Picea\Syntax\EchoRawToken() );
|
||||
$compiler->registerSyntax( new \Picea\Syntax\EchoSafeToken() );
|
||||
|
||||
return $this;
|
||||
$this->registerSyntax($compiler);
|
||||
$this->registerControlStructure($compiler);
|
||||
$this->registerExtension($compiler);
|
||||
}
|
||||
|
||||
protected function registerControlStructure(Compiler $compiler) : self
|
||||
public function registerSyntax(Compiler $compiler) : void
|
||||
{
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\NamespaceToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\UseToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\IfToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\ElseToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\ElseIfToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\EndIfToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\ForeachToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\ForToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\OrToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\EndforeachToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\EndforToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\SwitchToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\CaseToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\DefaultToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\BreakToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\EndCaseToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\EndSwitchToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\ExtendsToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\SectionToken());
|
||||
$compiler->registerControlStructure(new \Picea\ControlStructure\EndSectionToken());
|
||||
|
||||
return $this;
|
||||
$this->languageRegistration->registerSyntax($compiler);
|
||||
}
|
||||
|
||||
protected function registerExtension(Compiler $compiler) : self
|
||||
public function registerControlStructure(Compiler $compiler) : void
|
||||
{
|
||||
$compiler->registerExtension(new \Picea\Extension\JsonExtension());
|
||||
$this->languageRegistration->registerControlStructure($compiler);
|
||||
}
|
||||
|
||||
return $this;
|
||||
public function registerExtension(Compiler $compiler) : void
|
||||
{
|
||||
$this->languageRegistration->registerExtension($compiler);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user