From 80a4ad9f71b886ee8cbfb2656b342cf95c86a4b4 Mon Sep 17 00:00:00 2001 From: Guy Carpenter Date: Fri, 14 Sep 2012 13:10:32 +1000 Subject: [PATCH] Added PHP expansion within arguments - not terribly smart, but enough to be useful. --- Foml.php | 1 + FomlElementNode.php | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Foml.php b/Foml.php index 34c297f..1caf49e 100755 --- a/Foml.php +++ b/Foml.php @@ -96,6 +96,7 @@ static function XslFoToPdf($XslFo) // specify a new user.home value in FOP_OPTS. Note that for the cache to work // you should create FOML/.fop and make it writable by the webserver user. $env['FOP_OPTS'] = "-Duser.home={$fomlDir}"; + $env['FOP_OPTS'].- " -Xmx1024m"; // give the JVM extra memory - needed on small systems for complex documents $outFile = Foml::TempName("stdout-"); $errFile = Foml::TempName("stderr-"); diff --git a/FomlElementNode.php b/FomlElementNode.php index bcda10a..36691ea 100755 --- a/FomlElementNode.php +++ b/FomlElementNode.php @@ -26,6 +26,25 @@ function __construct($Matches) $this->ParseExtra($extra); } + // replace instances of #{...} with [php] print($1);[/php] + function ExpandExpressions($Text) + { + $text = $Text; + $expansion = ''; + while (preg_match("/\#\{(.*?)\}/", $text, $matches, PREG_OFFSET_CAPTURE)) { + $matchLength = $matches[0][1]; // including length of markup + $expression = $matches[1][0]; + $expansion .= substr($text, 0, $matchLength); + $text = substr($text, $matchLength+strlen($matches[0][0])); + $expansion .= ''; + } + $expansion.=$text; + return $expansion; + } + function ParseArgs($Args) { // REVISIT - this is a piss-poor @@ -37,8 +56,10 @@ function ParseArgs($Args) // For now switch to hungry because it is harder to work around that deficiency if (preg_match("/^\((.*)\)(.*)/", $Args, $matches)) { //print "
"; print_r($matches); print "
"; - $this->args = $matches[1]; + // REVISIT - this offers only minimal support for #{} + $this->args = $this->ExpandExpressions($matches[1]); $Args = $matches[2]; + //$Args = $matches[2]; } return $Args; }