Skip to content

Commit

Permalink
Added PHP expansion within arguments - not terribly smart, but enough…
Browse files Browse the repository at this point in the history
… to be useful.
  • Loading branch information
guyc committed Sep 14, 2012
1 parent c05e9bc commit 80a4ad9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions Foml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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-");
Expand Down
23 changes: 22 additions & 1 deletion FomlElementNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 .= 'php ';
$expansion .= "print({$expression});";
$expansion .= '?>';
}
$expansion.=$text;
return $expansion;
}

function ParseArgs($Args)
{
// REVISIT - this is a piss-poor
Expand All @@ -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 "<pre>"; print_r($matches); print "</pre>";
$this->args = $matches[1];
// REVISIT - this offers only minimal support for #{<phpexpression>}
$this->args = $this->ExpandExpressions($matches[1]);
$Args = $matches[2];
//$Args = $matches[2];
}
return $Args;
}
Expand Down

0 comments on commit 80a4ad9

Please sign in to comment.