Download the PHP package machinateur/twig-comment-lexer without Composer

On this page you can find all versions of the php package machinateur/twig-comment-lexer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package twig-comment-lexer

machinateur/twig-comment-lexer

A custom twig lexer and extension to make comments available for parsing.

Comments like the one below are usually not available in twig for parsing. They're skipped.

This package provides a lexer extension for twig, which makes comments available for node visitors! That means we can now implement parsing of twig comments, to extract template meta-data for certain applications!

Additionally, in debug mode, this extension exposes the comment tag in the compiled twig template class, which should make deep debugging easier by providing more information than only the line number (as done by default).

The value accepted by the comment tag is a constant string only, no interpolation, no nothing. Just a raw string. Quotes are not necessary for the native comment usage.

Requirements

Installation

Use composer to install this twig extension.

Intended usage

The lexer can be installed for an environment by calling \Machinateur\Twig\Extension\CommentExtension::setLexer($twig), where $twig is the \Twig\Environment to set the lexer for. Have a look at the tests for an overview.

More out of necessity than as an actual feature, this twig extension allows for exposing comments in template code. This only works when in debug mode, for security reasons. Debug mode should not be active on production environments.

Which will become:

Apart from that, this lexer extension allows for quite creative implementations. A more interesting way this can be used, is to extract template context based on comments (at compile time):

Useful reading, regarding collecting template data:

https://matthiasnoback.nl/2013/01/symfony2-twig-collecting-data-across-templates-using-a-node-visitor/

An example on how one can expose compile-time information at runtime, is the machinateur/twig-context-tags library.

Limitations and compatibility

Since this library is quite dependent on private code structure of twig's own lexer class. So it could break easily when internals change with newer versions.

Tests

Run tests using the composer script:

License

It's MIT.


All versions of twig-comment-lexer with dependencies

PHP Build Version
Package Version
Requires twig/twig Version ^3.15
php Version >=8.1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package machinateur/twig-comment-lexer contains the following files

Loading the files please wait ....