2017 © Pedro Peláez
 

library plitz

Pure PHP port of Blitz

image

mcuelenaere/plitz

Pure PHP port of Blitz

  • Friday, May 20, 2016
  • by mcuelenaere
  • Repository
  • 2 Watchers
  • 2 Stars
  • 1,250 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

Plitz

travis ci coveralls github tag packagist downloads, (*1)

Plitz is a pure PHP port of the Blitz PHP template extension., (*2)

Installation

Install with composer:, (*3)

  composer require mcuelenaere/plitz

Usage

There are 2 ways to use the functionality provided by Plitz:, (*4)

Blitz compatibility layer

$template = <<<EOF
  Hello {{ audience }}!
EOF
;

$assignments = [
  'audience' => 'world'
];

// construct Blitz object
$blitz = new Plitz\Bindings\Blitz\Blitz();

// load template
$blitz->load($template);

// render template to stdout
$blitz->display($assignments);

Direct access to Plitz classes

$template = <<<EOF
  Hello {{ audience }}!
EOF
;

$assignments = [
  'audience' => 'world'
];

// wrap template in a simple data:// stream
$inputStream = fopen("data://text/plain;base64," . base64_encode($template), "r");
// write compiled template to a memory buffer
$outputStream = fopen("php://memory", "r+");

try {
  // setup the required infrastructure
  $lexer = new Plitz\Lexer\Lexer($inputStream, "no template filename available");
  $compiler = new Plitz\Compilers\PhpCompiler($outputStream); // or perhaps you want the Plitz\Compilers\JsCompiler ?
  $parser = new Plitz\Parser\Parser($lexer->lex(), $compiler);

  // lex and parse from the input stream and compile to the output stream
  $parser->parse();

  // retrieve the compiled code from the memory stream
  fseek($outputStream, 0, SEEK_SET);
  $compiledCode = stream_get_contents($outputStream);
} catch (Plitz\Lexer\LexException $ex) {
  printf("We got an exception from the lexer: %s (%s: line %d, pos %d)", $ex->getMessage(), $ex->getTemplateName(), $ex->getTemplateLine(), $ex->getTemplateColumn());
  exit(1);
} catch (Plitz\Parser\ParseException $ex) {
  printf("We got an exception from the parser: %s (%s: line %d, pos %d)", $ex->getMessage(), $ex->getTemplateName(), $ex->getTemplateLine(), $ex->getTemplateColumn());
  exit(1);
} finally {
  // cleanup when we're done
  fclose($inputStream);
  fclose($outputStream);
}

// create a function from the compiled code
$templateFunction = create_function('$context', 'ob_start(); ?>' . $compiledCode . '<?php return ob_get_clean();');

// and last but not least: actually run it!
echo $templateFunction($assignments);

Design

Plitz consists of 4 components: * the lexer: tokenizes the input stream into a stream of Plitz\Lexer\Tokens * the parser: parses a Plitz\Lexer\TokenStream and informs a Plitz\Parser\Visitor of the parsed blocks * the compiler: implements the Plitz\Parser\Visitor class and writes code to an output stream * the Blitz compatibility layer: wraps all the parts above up in a single class while trying to maintain source-compatibility with Blitz, (*5)

The Versions

20/05 2016

dev-feature-loop-objects

dev-feature-loop-objects

Pure PHP port of Blitz

  Sources   Download

LGPL-2.1+

The Requires

  • php >=5.5

 

The Development Requires

06/03 2016

dev-feature-scoped-includes

dev-feature-scoped-includes

Pure PHP port of Blitz

  Sources   Download

LGPL-2.1+

The Requires

  • php >=5.5

 

The Development Requires

06/03 2016

dev-master

9999999-dev

Pure PHP port of Blitz

  Sources   Download

LGPL-2.1+

The Requires

  • php >=5.5

 

The Development Requires

06/03 2016

0.0.4

0.0.4.0

Pure PHP port of Blitz

  Sources   Download

LGPL-2.1+

The Requires

  • php >=5.5

 

The Development Requires

16/08 2015

0.0.3

0.0.3.0

Pure PHP port of Blitz

  Sources   Download

LGPL-2.1+

The Requires

  • php >=5.5

 

The Development Requires

09/07 2015

dev-blitz-tests

dev-blitz-tests

Pure PHP port of Blitz

  Sources   Download

LGPL-2.1+

The Requires

  • php >=5.5

 

The Development Requires

28/06 2015

dev-js-check-each-sub-expression-when-dereferencing

dev-js-check-each-sub-expression-when-dereferencing

Pure PHP port of Blitz

  Sources   Download

LGPL-2.1+

The Requires

  • php >=5.5

 

The Development Requires

17/02 2015

0.0.2

0.0.2.0

Pure PHP port of Blitz

  Sources   Download

LGPL-2.1+

The Requires

  • php >=5.5

 

The Development Requires

08/02 2015

0.0.1

0.0.1.0

Pure PHP port of Blitz

  Sources   Download

LGPL-2.1+

The Requires

  • php >=5.5

 

The Development Requires