Giter Site home page Giter Site logo

php-handlebars's Introduction

php-handlebars

GitHub Build Status Coverage Status License

PHP bindings for handlebars.c.

Installation

Nix / NixOS

nix-env -i -f https://github.com/jbboehr/php-handlebars/archive/v0.9.1.tar.gz

with a custom version of PHP:

nix-env -i -f https://github.com/jbboehr/php-handlebars/archive/v0.9.1.tar.gz \
    --arg php '(import <nixpkgs> {}).php73'

or, in a .nix file:

(import <nixpkgs> {}).callPackage (import (fetchTarball {
  url = https://github.com/jbboehr/php-handlebars/archive/v0.9.0.tar.gz;
  sha256 = "1dgq05b11hg6llfjl8zwxzvixf2g7vn4np4ihcl589jmxdal9np4";
})) {}

RPM repository

The extension is available in Remi's repository:

Fedora (change 24 to match your Fedora version)

dnf install https://rpms.remirepo.net/fedora/remi-release-24.rpm
dnf install --enablerepo=remi php-pecl-handlebars

RHEL/CentOS (for default PHP in base repository)

yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install php-pecl-handlebars

Source

Install handlebars.c

Linux / OSX

Prerequisite packages are:

  • PHP development headers and tools
  • gcc >= 4.4 | clang >= 3.x | vc >= 11
  • GNU make >= 3.81
  • automake
  • autoconf
  • handlebars.c and all of its dependencies (talloc, json-c, libyaml)
  • (optional) php-psr

You will need the PHP development headers. If PHP was manually installed, these should be available by default. Otherwise, you will need to fetch them from a repository.

git clone https://github.com/jbboehr/php-handlebars.git
cd php-handlebars
phpize
./configure
make
make test
sudo make install

If you have specific PHP versions running:

git clone https://github.com/jbboehr/php-handlebars.git
cd php-handlebars
/usr/local/bin/phpize
./configure --with-php-config=/usr/local/bin/php-config
make
make test
sudo make install

Add the extension to your php.ini:

echo extension=handlebars.so | tee -a /path/to/your/php.ini

Finally, restart the web server.

Usage

$vm = new Handlebars\VM();

echo $vm->render('{{foo}}', array('foo' => 'bar'));

echo $vm->renderFile('/path/to/foo.hbs', array('foo' => 'bar'));

See the examples folder for more examples.

License

This project is licensed under the Simplified BSD License (BSD-2-Clause).

php-handlebars's People

Contributors

jbboehr avatar remicollet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

remicollet

php-handlebars's Issues

[0.9.0] failed test on 32-bit

1 failed test, only on 32-bit

TEST 1256/1258 [tests/vm/renderFromBinaryString.phpt]
========DIFF========
005+ 
005- string(%d) "bar"
006+ Fatal error: Uncaught Handlebars\InvalidBinaryStringException: Failed to validate precompiled template: template data segment was 1136 bytes, expected 57621504 in /builddir/bu
ild/BUILD/php-pecl-handlebars-0.9.0/NTS/tests/vm/renderFromBinaryString.php:40
007+ Stack trace:
008+ #0 /builddir/build/BUILD/php-pecl-handlebars-0.9.0/NTS/tests/vm/renderFromBinaryString.php(40): Handlebars\VM->renderFromBinaryString('\f\xCD\x088\xE0\xE9\xBF\x16\xBC\x02\x00\
x00\x00\x00\x00...', Array)
009+ #1 {main}
010+   thrown in /builddir/build/BUILD/php-pecl-handlebars-0.9.0/NTS/tests/vm/renderFromBinaryString.php on line 40
========DONE========
FAIL Handlebars\VM::renderFromBinaryString() [tests/vm/renderFromBinaryString.phpt] 

[0.9.1] test failure with library 0.7.1

With library 0.7.0, everything is ok

With library 0.7.1

TEST 1256/1258 [tests/vm/renderFromBinaryString.phpt]
========DIFF========
002+ bool(false)
002- bool(true)
========DONE========
FAIL Handlebars\VM::renderFromBinaryString() [tests/vm/renderFromBinaryString.phpt] 

[1.0.0] test failures

Despite changelog claims "- PHP 8.1 and 8.2 compat", lot of test are failing with 8.1 / 8.2 (AST doesn't seems covered by CI)

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
helpers - knownHelpers - Known helper should render helper [tests/handlebars/export/helpers/050.phpt]
helpers - knownHelpers - Unknown helper in knownHelpers only mode should be passed as undefined [tests/handlebars/export/helpers/051.phpt]
helpers - knownHelpers - Field lookup works in knownHelpers only mode [tests/handlebars/export/helpers/053.phpt]
helpers - knownHelpers - Conditional blocks work in knownHelpers only mode [tests/handlebars/export/helpers/054.phpt]
helpers - knownHelpers - Invert blocks work in knownHelpers only mode [tests/handlebars/export/helpers/055.phpt]
helpers - knownHelpers - Functions are bound to the context in knownHelpers only mode [tests/handlebars/export/helpers/056.phpt]
helpers - name field - should include in known helper calls [tests/handlebars/export/helpers/064.phpt]
string params mode - information about the types is passed along [tests/handlebars/export/string-params/004.phpt]
track ids - builtin helpers - #each - should handle block params [tests/handlebars/export/track-ids/012.phpt]
partials - standalone partials - prevent nested indented partials [tests/handlebars/export/partials/054.phpt]
string params mode - hash parameters get type information [tests/handlebars/export/string-params/005.phpt]
string params mode - when inside a block in String mode, .. passes the appropriate context in the options hash to a block helper [tests/handlebars/export/string-params/006.phpt]
track ids - builtin helpers - #with - should track contextPath [tests/handlebars/export/track-ids/013.phpt]
string params mode - with nested block ambiguous [tests/handlebars/export/string-params/007.phpt]
string params mode - should handle DATA [tests/handlebars/export/string-params/008.phpt]
track ids - builtin helpers - #with - should handle nesting [tests/handlebars/export/track-ids/014.phpt]
track ids - builtin helpers - #blockHelperMissing - should track contextPath for arrays [tests/handlebars/export/track-ids/015.phpt]
track ids - builtin helpers - #blockHelperMissing - should track contextPath for keys [tests/handlebars/export/track-ids/016.phpt]
strict - strict mode - should error on missing property lookup in known helpers mode [tests/handlebars/export/strict/005.phpt]
track ids - builtin helpers - #blockHelperMissing - should handle nesting [tests/handlebars/export/track-ids/017.phpt]
subexpressions - in string params mode, [tests/handlebars/export/subexpressions/015.phpt]
partials - partials with no context [tests/handlebars/export/partials/007.phpt]
track ids - should include argument ids [tests/handlebars/export/track-ids/002.phpt]
subexpressions - as hashes in string params mode [tests/handlebars/export/subexpressions/016.phpt]
track ids - should include hash ids [tests/handlebars/export/track-ids/003.phpt]
track ids - should note ../ and ./ references [tests/handlebars/export/track-ids/004.phpt]
partials - partials with no context - 01 [tests/handlebars/export/partials/008.phpt]
track ids - should note @data references [tests/handlebars/export/track-ids/005.phpt]
string params mode - arguments to helpers can be retrieved from options hash in string form [tests/handlebars/export/string-params/001.phpt]
track ids - should return null for constants [tests/handlebars/export/track-ids/006.phpt]
track ids - should return true for subexpressions [tests/handlebars/export/track-ids/007.phpt]
string params mode - when using block form, arguments to helpers can be retrieved from options hash in string form [tests/handlebars/export/string-params/002.phpt]
string params mode - when inside a block in String mode, .. passes the appropriate context in the options hash [tests/handlebars/export/string-params/003.phpt]
track ids - should use block param paths [tests/handlebars/export/track-ids/008.phpt]
track ids - builtin helpers - #each - should track contextPath for arrays [tests/handlebars/export/track-ids/009.phpt]
track ids - builtin helpers - #each - should track contextPath for keys [tests/handlebars/export/track-ids/010.phpt]
track ids - builtin helpers - #each - should handle nesting [tests/handlebars/export/track-ids/011.phpt]
=====================================================================

Build failure with GCC 11

Which is the default compiler on the upcoming Fedora 34

/builddir/build/BUILD/php-pecl-grpc-1.35.0/NTS/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc: In member function 'void absl::lts_2020_09_23::synchronization_internal::GraphCycles::RemoveNode(void*)':
/builddir/build/BUILD/php-pecl-grpc-1.35.0/NTS/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc:451:26: error: 'numeric_limits' is not a member of 'std'
  451 |   if (x->version == std::numeric_limits<uint32_t>::max()) {
      |                          ^~~~~~~~~~~~~~
/builddir/build/BUILD/php-pecl-grpc-1.35.0/NTS/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc:451:49: error: expected primary-expression before '>' token
  451 |   if (x->version == std::numeric_limits<uint32_t>::max()) {
      |                                                 ^
/builddir/build/BUILD/php-pecl-grpc-1.35.0/NTS/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc:451:52: error: '::max' has not been declared; did you mean 'std::max'?
  451 |   if (x->version == std::numeric_limits<uint32_t>::max()) {
      |                                                    ^~~
      |                                                    std::max
In file included from /usr/include/c++/11/algorithm:62,
                 from /builddir/build/BUILD/php-pecl-grpc-1.35.0/NTS/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc:38:
/usr/include/c++/11/bits/stl_algo.h:3467:5: note: 'std::max' declared here
 3467 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~

Segfault using lookup helper with empty parameter

The exact code was something along the lines:

{{#with (lookup a b.c)}}{{d}}{{/with}}
==1519== Invalid read of size 8
==1519==    at 0x132F0DEC: ??? (in /usr/lib/php/20151012/handlebars.so)
==1519==    by 0x13512FE4: handlebars_builtin_lookup (in /usr/lib/x86_64-linux-gnu/libhandlebars.so.5.0.0)
==1519==    by 0x1351DF67: ??? (in /usr/lib/x86_64-linux-gnu/libhandlebars.so.5.0.0)
==1519==    by 0x1351E54C: handlebars_vm_execute_program_ex (in /usr/lib/x86_64-linux-gnu/libhandlebars.so.5.0.0)
==1519==    by 0x1351BCCA: handlebars_vm_execute (in /usr/lib/x86_64-linux-gnu/libhandlebars.so.5.0.0)
==1519==    by 0x132F0325: zim_HandlebarsVM_renderFile (in /usr/lib/php/20151012/handlebars.so)
==1519==    by 0x3E34B5: ??? (in /usr/sbin/php-fpm7.0)
==1519==    by 0x39E11A: execute_ex (in /usr/sbin/php-fpm7.0)
==1519==    by 0x34EEA2: zend_call_function (in /usr/sbin/php-fpm7.0)
==1519==    by 0x34F278: call_user_function_ex (in /usr/sbin/php-fpm7.0)
==1519==    by 0x387538: zim_Closure___invoke (in /usr/sbin/php-fpm7.0)
==1519==    by 0x34EDFE: zend_call_function (in /usr/sbin/php-fpm7.0)
==1519==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==1519== 
==1519== 
==1519== Process terminating with default action of signal 11 (SIGSEGV)
==1519==  Access not within mapped region at address 0x0
==1519==    at 0x132F0DEC: ??? (in /usr/lib/php/20151012/handlebars.so)
==1519==    by 0x13512FE4: handlebars_builtin_lookup (in /usr/lib/x86_64-linux-gnu/libhandlebars.so.5.0.0)
==1519==    by 0x1351DF67: ??? (in /usr/lib/x86_64-linux-gnu/libhandlebars.so.5.0.0)
==1519==    by 0x1351E54C: handlebars_vm_execute_program_ex (in /usr/lib/x86_64-linux-gnu/libhandlebars.so.5.0.0)
==1519==    by 0x1351BCCA: handlebars_vm_execute (in /usr/lib/x86_64-linux-gnu/libhandlebars.so.5.0.0)
==1519==    by 0x132F0325: zim_HandlebarsVM_renderFile (in /usr/lib/php/20151012/handlebars.so)
==1519==    by 0x3E34B5: ??? (in /usr/sbin/php-fpm7.0)
==1519==    by 0x39E11A: execute_ex (in /usr/sbin/php-fpm7.0)
==1519==    by 0x34EEA2: zend_call_function (in /usr/sbin/php-fpm7.0)
==1519==    by 0x34F278: call_user_function_ex (in /usr/sbin/php-fpm7.0)
==1519==    by 0x387538: zim_Closure___invoke (in /usr/sbin/php-fpm7.0)
==1519==    by 0x34EDFE: zend_call_function (in /usr/sbin/php-fpm7.0)
==1519==  If you believe this happened as a result of a stack
==1519==  overflow in your program's main thread (unlikely but
==1519==  possible), you can try to increase the size of the
==1519==  main thread stack using the --main-stacksize= flag.
==1519==  The main thread stack size used in this run was 8388608.
==1519== 
==1519== HEAP SUMMARY:
==1519==     in use at exit: 4,790,761 bytes in 34,333 blocks
==1519==   total heap usage: 50,787 allocs, 16,454 frees, 13,688,943 bytes allocated
==1519== 
==1519== LEAK SUMMARY:
==1519==    definitely lost: 2,336 bytes in 17 blocks
==1519==    indirectly lost: 4,657 bytes in 35 blocks
==1519==      possibly lost: 3,651,485 bytes in 26,932 blocks
==1519==    still reachable: 1,132,283 bytes in 7,349 blocks
==1519==         suppressed: 0 bytes in 0 blocks
==1519== Rerun with --leak-check=full to see details of leaked memory
==1519== 
==1519== For counts of detected and suppressed errors, rerun with: -v
==1519== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
==1519== could not unlink /tmp/vgdb-pipe-from-vgdb-to-1519-by-???-on-???
==1519== could not unlink /tmp/vgdb-pipe-to-vgdb-from-1519-by-???-on-???
==1519== could not unlink /tmp/vgdb-pipe-shared-mem-vgdb-1519-by-???-on-???

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.