Skip to content

Instantly share code, notes, and snippets.

@knksmith57
Created July 15, 2016 15:44
Show Gist options
  • Save knksmith57/1d3e07914fd6085ba286718b5f6c820b to your computer and use it in GitHub Desktop.
Save knksmith57/1d3e07914fd6085ba286718b5f6c820b to your computer and use it in GitHub Desktop.
{
"name": "knksmith57/lnc-identity-call-stack-error",
"description": "example setup for reproducing LnC #235",
"authors": [
{
"name": "Kyle Smith",
"email": "knksmith57@gmail.com"
}
],
"require": {
"zordius/lightncandy": "v0.89"
}
}
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "920b6a4b9ea52bba83e42ff4d2a07739",
"content-hash": "3d8a57e817766d5aa06e8486b084d658",
"packages": [
{
"name": "zordius/lightncandy",
"version": "v0.89",
"source": {
"type": "git",
"url": "https://github.com/zordius/lightncandy.git",
"reference": "af1f9adec7bc684409cd2b01cbca02967edc14b4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zordius/lightncandy/zipball/af1f9adec7bc684409cd2b01cbca02967edc14b4",
"reference": "af1f9adec7bc684409cd2b01cbca02967edc14b4",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "4.0.17"
},
"type": "library",
"autoload": {
"psr-4": {
"LightnCandy\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Zordius Chen",
"email": "zordius@yahoo-inc.com"
}
],
"description": "An extremely fast PHP implementation of handlebars ( http://handlebarsjs.com/ ) and mustache ( http://mustache.github.io/ ).",
"homepage": "https://github.com/zordius/lightncandy",
"keywords": [
"handlebars",
"logicless",
"mustache",
"php",
"template"
],
"time": "2015-12-05 13:08:25"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}
#!/usr/bin/env php
<?php
error_reporting(E_ALL);
require_once('vendor/autoload.php');
use LightnCandy\LightnCandy;
$template = '{{>(identity @root.foo.bar.baz)}}';
$phpStr = LightnCandy::compile($template, [
'flags' => 0
| LightnCandy::FLAG_RENDER_DEBUG
| LightnCandy::FLAG_BESTPERFORMANCE
| LightnCandy::FLAG_ERROR_EXCEPTION
| LightnCandy::FLAG_RUNTIMEPARTIAL
| LightnCandy::FLAG_SPACECTL
| LightnCandy::FLAG_SPVARS
| LightnCandy::FLAG_HANDLEBARS,
'helpers' => [
'identity' => '\HandlebarsHelpers::identity'
],
'partials' => [
'myPartial' => 'hello, world'
]
]);
$output = eval('?>' . $phpStr);
echo $output([
'foo' => [
'bar' => [
'baz' => 'myPartial'
]
]
]);
class HandlebarsHelpers
{
public static function identity ($args) {
$argc = count($args);
if ($argc !== 1) {
throw new \RuntimeException('identity helper requires exactly one positional argument');
}
return $args[0];
}
}
@knksmith57
Copy link
Author

❯ git clone https://gist.github.com/1d3e07914fd6085ba286718b5f6c820b lnc-dynamic-partial-test && cd $_
Cloning into 'lnc-dynamic-partial-test'...
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (5/5), done.
Checking connectivity... done.

❯ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
  - Installing zordius/lightncandy (v0.89)
    Loading from cache

Generating autoload files

❯ php main.php
hello, world

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment