LightnCandy option: FLAG_STANDALONEPHP

Generate stand-alone PHP codes which can be execute without LightnCandy\Runtime class. The compiled PHP code will contain scoped Runtime functions and the file size will be bigger. And, the performance will faster 5 ~10%.

Sample Codes

Default, require LightnCandy\Runtime.

Used option: FLAG_JSTRUE

Data:
NULL
Template:
{{{foo}}}
Result:
use \LightnCandy\Runtime as LR;return function ($in = null, $options = null) {
    $helpers = array();
    $partials = array();
    $cx = array(
        'flags' => array(
            'jstrue' => true,
            'jsobj' => false,
            'jslen' => false,
            'spvar' => false,
            'prop' => false,
            'method' => false,
            'lambda' => false,
            'mustlok' => false,
            'mustlam' => false,
            'mustsec' => false,
            'echo' => false,
            'partnc' => false,
            'knohlp' => false,
            'debug' => isset($options['debug']) ? $options['debug'] : 1,
        ),
        'constants' => array(),
        'helpers' => isset($options['helpers']) ? array_merge($helpers, $options['helpers']) : $helpers,
        'partials' => isset($options['partials']) ? array_merge($partials, $options['partials']) : $partials,
        'scopes' => array(),
        'sp_vars' => isset($options['data']) ? array_merge(array('root' => $in), $options['data']) : array('root' => $in),
        'blparam' => array(),
        'partialid' => 0,
        'runtime' => '\LightnCandy\Runtime',
    );
    
    $inary=is_array($in);
    return ''.LR::raw($cx, (($inary && isset($in['foo'])) ? $in['foo'] : null)).'';
};
Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{{foo}}}";

$php = LightnCandy::compile($template, array(
  "flags" => LightnCandy::FLAG_JSTRUE
));

echo $php

Stand alone, include used LightnCandy\Runtime functions.

Used option: FLAG_STANDALONEPHP FLAG_JSTRUE

Data:
NULL
Template:
{{{foo}}}
Result:
 function lcr62387a1b40e85raw($cx, $v, $ex = 0)
 {
  if ($ex) {
   return $v;
  }

  if ($v === true) {
   if ($cx['flags']['jstrue']) {
    return 'true';
   }
  }

  if (($v === false)) {
   if ($cx['flags']['jstrue']) {
    return 'false';
   }
  }

  if (is_array($v)) {
   if ($cx['flags']['jsobj']) {
    if (count(array_diff_key($v, array_keys(array_keys($v)))) > 0) {
     return '[object Object]';
    } else {
     $ret = array();
     foreach ($v as $k => $vv) {
      $ret[] = lcr62387a1b40e85raw($cx, $vv);
     }
     return join(',', $ret);
    }
   } else {
    return 'Array';
   }
  }

  return "$v";
 }

return function ($in = null, $options = null) {
    $helpers = array();
    $partials = array();
    $cx = array(
        'flags' => array(
            'jstrue' => true,
            'jsobj' => false,
            'jslen' => false,
            'spvar' => false,
            'prop' => false,
            'method' => false,
            'lambda' => false,
            'mustlok' => false,
            'mustlam' => false,
            'mustsec' => false,
            'echo' => false,
            'partnc' => false,
            'knohlp' => false,
            'debug' => isset($options['debug']) ? $options['debug'] : 1,
        ),
        'constants' =>  array(
            'DEBUG_ERROR_LOG' => 1,
            'DEBUG_ERROR_EXCEPTION' => 2,
            'DEBUG_TAGS' => 4,
            'DEBUG_TAGS_ANSI' => 12,
            'DEBUG_TAGS_HTML' => 20,
        ),
        'helpers' => isset($options['helpers']) ? array_merge($helpers, $options['helpers']) : $helpers,
        'partials' => isset($options['partials']) ? array_merge($partials, $options['partials']) : $partials,
        'scopes' => array(),
        'sp_vars' => isset($options['data']) ? array_merge(array('root' => $in), $options['data']) : array('root' => $in),
        'blparam' => array(),
        'partialid' => 0,
        'runtime' => '\LightnCandy\Runtime',
    );
    
    $inary=is_array($in);
    return ''.lcr62387a1b40e85raw($cx, (($inary && isset($in['foo'])) ? $in['foo'] : null)).'';
};
Source Code
require('./vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = "{{{foo}}}";

$php = LightnCandy::compile($template, array(
  "flags" => LightnCandy::FLAG_STANDALONEPHP | LightnCandy::FLAG_JSTRUE
));

echo $php