LightnCandy\Exporter::runtime PHP Method

runtime() public static method

Export required standalone Runtime methods
public static runtime ( array\arraystring | integer> $context ) : string
$context array\arraystring | integer>
return string
    public static function runtime($context)
    {
        $class = new \ReflectionClass($context['runtime']);
        $methods = array();
        $ret = '';
        foreach ($class->getMethods() as $method) {
            $C = $method->getDeclaringClass();
            $fname = $C->getFileName();
            $lines = file_get_contents($fname);
            $file = new \SplFileObject($fname);
            $name = $method->getName();
            $file->seek($method->getStartLine() - 2);
            $spos = $file->ftell();
            $file->seek($method->getEndLine() - 2);
            $epos = $file->ftell();
            $methods[$name] = static::scanDependency($context, preg_replace('/public static function (.+)\\(/', "function {$context['funcprefix']}\$1(", substr($lines, $spos, $epos - $spos)));
        }
        unset($file);
        $exports = array_keys($context['usedCount']['runtime']);
        while (true) {
            if (array_sum(array_map(function ($name) use(&$exports, $methods) {
                $n = 0;
                foreach ($methods[$name][1] as $child => $count) {
                    if (!in_array($child, $exports)) {
                        $exports[] = $child;
                        $n++;
                    }
                }
                return $n;
            }, $exports)) == 0) {
                break;
            }
        }
        foreach ($exports as $export) {
            $ret .= $methods[$export][0] . " }\n";
        }
        return $ret;
    }

Usage Example

Beispiel #1
0
 /**
  * Compose LightnCandy render codes for include()
  *
  * @param array<string,array|string|integer> $context Current context
  * @param string $code generated PHP code
  *
  * @return string Composed PHP code
  */
 public static function composePHPRender($context, $code)
 {
     $flagJStrue = Expression::boolString($context['flags']['jstrue']);
     $flagJSObj = Expression::boolString($context['flags']['jsobj']);
     $flagSPVar = Expression::boolString($context['flags']['spvar']);
     $flagProp = Expression::boolString($context['flags']['prop']);
     $flagMethod = Expression::boolString($context['flags']['method']);
     $flagLambda = Expression::boolString($context['flags']['lambda']);
     $flagMustlok = Expression::boolString($context['flags']['mustlok']);
     $flagMustlam = Expression::boolString($context['flags']['mustlam']);
     $flagEcho = Expression::boolString($context['flags']['echo']);
     $flagPartNC = Expression::boolString($context['flags']['partnc']);
     $flagKnownHlp = Expression::boolString($context['flags']['knohlp']);
     $libstr = Exporter::runtime($context);
     $constants = Exporter::constants($context);
     $helpers = Exporter::helpers($context);
     $bhelpers = Exporter::helpers($context, 'blockhelpers');
     $hbhelpers = Exporter::helpers($context, 'hbhelpers');
     $partials = implode(",\n", $context['partialCode']);
     $debug = Runtime::DEBUG_ERROR_LOG;
     $phpstart = $context['flags']['bare'] ? '' : "<?php use {$context['runtime']} as LR;\n";
     $phpend = $context['flags']['bare'] ? ';' : "\n?>";
     // Return generated PHP code string.
     return "{$phpstart}return function (\$in, \$options = null) {\n    \$cx = array(\n        'flags' => array(\n            'jstrue' => {$flagJStrue},\n            'jsobj' => {$flagJSObj},\n            'spvar' => {$flagSPVar},\n            'prop' => {$flagProp},\n            'method' => {$flagMethod},\n            'lambda' => {$flagLambda},\n            'mustlok' => {$flagMustlok},\n            'mustlam' => {$flagMustlam},\n            'echo' => {$flagEcho},\n            'partnc' => {$flagPartNC},\n            'knohlp' => {$flagKnownHlp},\n            'debug' => isset(\$options['debug']) ? \$options['debug'] : {$debug},\n        ),\n        'constants' => {$constants},\n        'helpers' => {$helpers},\n        'blockhelpers' => {$bhelpers},\n        'hbhelpers' => isset(\$options['helpers']) ? array_merge({$hbhelpers}, \$options['helpers']) : {$hbhelpers},\n        'partials' => array({$partials}),\n        'scopes' => array(),\n        'sp_vars' => isset(\$options['data']) ? array_merge(array('root' => \$in), \$options['data']) : array('root' => \$in),\n        'blparam' => array(),\n        'runtime' => '{$context['runtime']}',\n{$libstr}\n    );\n    {$context['renderex']}\n    {$context['ops']['op_start']}'{$code}'{$context['ops']['op_end']}\n}{$phpend}";
 }
All Usage Examples Of LightnCandy\Exporter::runtime