Added script for rendering templates in console.
This commit is contained in:
parent
8f532492c4
commit
720d36dd23
2 changed files with 98 additions and 1 deletions
|
@ -35,7 +35,7 @@ use RPCii\Server\HttpRpcServer;
|
||||||
class MisuzuContext {
|
class MisuzuContext {
|
||||||
public private(set) Dependencies $deps;
|
public private(set) Dependencies $deps;
|
||||||
|
|
||||||
private TplEnvironment $templating;
|
public private(set) TplEnvironment $templating;
|
||||||
|
|
||||||
public private(set) AuditLogData $auditLog;
|
public private(set) AuditLogData $auditLog;
|
||||||
public private(set) CountersData $counters;
|
public private(set) CountersData $counters;
|
||||||
|
|
97
tools/render-tpl
Executable file
97
tools/render-tpl
Executable file
|
@ -0,0 +1,97 @@
|
||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
namespace Misuzu;
|
||||||
|
|
||||||
|
use Index\Http\{HttpHeader,HttpHeaders,HttpRequest};
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../misuzu.php';
|
||||||
|
|
||||||
|
$hostName = null;
|
||||||
|
$tplArgs = [];
|
||||||
|
$pathIndex = 1;
|
||||||
|
|
||||||
|
// really bad getopt replacement that supports args with the same name
|
||||||
|
$nextIs = null;
|
||||||
|
for($i = 1; $i < $argc; ++$i) {
|
||||||
|
$arg = $argv[$i];
|
||||||
|
|
||||||
|
handleValue:
|
||||||
|
if($nextIs !== null) {
|
||||||
|
if($nextIs === 'host') {
|
||||||
|
if($hostName !== null)
|
||||||
|
die(sprintf('Failed to parse arguments: a hostname was already specified.%s', PHP_EOL));
|
||||||
|
|
||||||
|
$hostName = $arg;
|
||||||
|
$nextIs = null;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($nextIs === 'var') {
|
||||||
|
$equals = strpos($arg, '=');
|
||||||
|
if($equals === false || $equals < 1)
|
||||||
|
die(sprintf('Failed to parse arguments: variables must have names, name=value.%s', PHP_EOL));
|
||||||
|
|
||||||
|
[$name, $value] = explode('=', $arg);
|
||||||
|
$tplArgs[$name] = $value;
|
||||||
|
$nextIs = null;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
die(sprintf('Failed to parse arguments: unexpected value type encountered.%s', PHP_EOL));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($arg === '-h' || $arg === '--host') {
|
||||||
|
$nextIs = 'host';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($arg === '-v' || $arg === '--var') {
|
||||||
|
$nextIs = 'var';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(str_starts_with($arg, '--host=')) {
|
||||||
|
if($nextIs !== null)
|
||||||
|
die(sprintf('Failed to parse arguments: expected value, got flag.%s', PHP_EOL));
|
||||||
|
|
||||||
|
$nextIs = 'host';
|
||||||
|
$arg = substr($arg, 7);
|
||||||
|
goto handleValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(str_starts_with($arg, '--var=')) {
|
||||||
|
if($nextIs !== null)
|
||||||
|
die(sprintf('Failed to parse arguments: expected value, got flag.%s', PHP_EOL));
|
||||||
|
|
||||||
|
$nextIs = 'var';
|
||||||
|
$arg = substr($arg, 6);
|
||||||
|
goto handleValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pathIndex = $i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$hostName ??= 'localhost';
|
||||||
|
|
||||||
|
// this should really not be necessary
|
||||||
|
CSRF::init($msz->config->getString('csrf.secret', 'soup'), '::1');
|
||||||
|
|
||||||
|
// neither should this i think, mostly done to make sure the url handler thing is available
|
||||||
|
$msz->createRouting(new HttpRequest('::1', true, 'XX', '1.1', 'GET', '/', [], [], new HttpHeaders([
|
||||||
|
new HttpHeader('Host', $hostName),
|
||||||
|
]), null));
|
||||||
|
|
||||||
|
$msz->startTemplating();
|
||||||
|
|
||||||
|
$ctx = $msz->templating->load(implode(' ', array_slice($argv, $pathIndex)));
|
||||||
|
|
||||||
|
foreach($tplArgs as $name => $value)
|
||||||
|
$ctx->setVar($name, $value);
|
||||||
|
|
||||||
|
// things expect this to be defined which is also a bit yucky
|
||||||
|
if(!defined('MSZ_TPL_RENDER'))
|
||||||
|
define('MSZ_TPL_RENDER', microtime(true));
|
||||||
|
|
||||||
|
echo $ctx->render();
|
Loading…
Add table
Reference in a new issue