- Work on Language Handler and extension.
- Added an URL extension which allows routes and URLs. - Fixed some bug within ClassTemplate
This commit is contained in:
1 parent
a64989af9f
commit
ddc3ae704a
10 files changed
+267
-82
No files matched your search
+53
-18
@@ -27,13 +27,13 @@ class Picea implements LanguageRegistration
|
||||
public bool $debug;
|
||||
|
||||
public function __construct(
|
||||
?Closure $responseHtml = null,
|
||||
?Compiler\Context $context = null,
|
||||
?Caching\Cache $cache = null,
|
||||
?Compiler $compiler = null,
|
||||
?LanguageRegistration $languageRegistration = null,
|
||||
?FileFetcher $fileFetcher = null,
|
||||
?string $builderTemplatePath = null,
|
||||
? Closure $responseHtml = null,
|
||||
? Compiler\Context $context = null,
|
||||
? Caching\Cache $cache = null,
|
||||
? Compiler $compiler = null,
|
||||
? LanguageRegistration $languageRegistration = null,
|
||||
? FileFetcher $fileFetcher = null,
|
||||
? string $builderTemplatePath = null,
|
||||
bool $debug = false
|
||||
){
|
||||
$this->response = $responseHtml;
|
||||
@@ -44,6 +44,9 @@ class Picea implements LanguageRegistration
|
||||
$this->compiler = $compiler ?? $this->instanciateCompiler();
|
||||
$this->fileFetcher = $fileFetcher ?? $this->instanciateFileFetcher();
|
||||
$this->debug = $debug;
|
||||
|
||||
#$this->context->exportFunctions();
|
||||
$this->renderContext($this->context);
|
||||
}
|
||||
|
||||
public function renderHtml(string $viewPath, array $variables = [], ?object $proxy = null) : string
|
||||
@@ -55,21 +58,31 @@ class Picea implements LanguageRegistration
|
||||
return $object();
|
||||
}
|
||||
|
||||
public function outputHtml(string $viewPath, array $variables) : ResponseInterface
|
||||
public function renderContext(Compiler\Context $context) : object
|
||||
{
|
||||
if ( $this->response ?? false ) {
|
||||
if ( false === $content = $this->cache->handle($viewPath) ) {
|
||||
|
||||
}
|
||||
|
||||
$source = $this->compileSource($source ?? "test");
|
||||
$response = $this->response;
|
||||
return $response("abc");
|
||||
if ( null === $object = $this->contextFromCache($context) ) {
|
||||
throw new \RuntimeException("An error occured while trying to save a compiled template.");
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException("No \Psr\Http\Message\ResponseInterface closure provided. Please provide one using the constructor or assigning it to the class variable `responseHtml`.");
|
||||
return $object;
|
||||
}
|
||||
|
||||
|
||||
#public function outputHtml(string $viewPath, array $variables) : ResponseInterface
|
||||
#{
|
||||
# if ( $this->response ?? false ) {
|
||||
# if ( false === $content = $this->cache->handle($viewPath) ) {
|
||||
#
|
||||
# }
|
||||
|
||||
# $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 assigning it to the class variable `responseHtml`.");
|
||||
#}
|
||||
|
||||
public function compileSource(string $source) : array
|
||||
{
|
||||
$this->compiler->loadSourceCode($source);
|
||||
@@ -94,7 +107,7 @@ class Picea implements LanguageRegistration
|
||||
$context = clone $this->context;
|
||||
$context->viewPath = $viewPath;
|
||||
$context->source = $this->compiler->compile($context);
|
||||
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
@@ -129,6 +142,16 @@ class Picea implements LanguageRegistration
|
||||
return $this->cache->load($viewPath, $this, $variables, $proxy);
|
||||
}
|
||||
|
||||
public function contextFromCache(Compiler\Context $context) : ?object
|
||||
{
|
||||
if ( $this->debug || ! $this->cache->compiled( $context->cacheFilename() ) ) {
|
||||
$context = $this->compileContext($context);
|
||||
$this->cache->save($context);
|
||||
}
|
||||
|
||||
return $this->cache->load($context->cacheFilename(), $this);
|
||||
}
|
||||
|
||||
public function instanciateCompiler() : Compiler
|
||||
{
|
||||
return new Compiler($this->languageRegistration);
|
||||
@@ -182,4 +205,16 @@ class Picea implements LanguageRegistration
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
protected function compileContext(Compiler\Context $context) : Compiler\Context
|
||||
{
|
||||
$tmpFolder = sys_get_temp_dir();
|
||||
$builder = $this->instanciateBuilder();
|
||||
$compiled = $this->compileSource("");
|
||||
$context->viewPath = $context->cacheFilename();
|
||||
$builder->build($context, "");
|
||||
$context->classPath = $tmpFolder . DIRECTORY_SEPARATOR . $context->cacheFilename() . ".php";
|
||||
|
||||
return $context;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user