Download the PHP package qoliber/tsuku without Composer

On this page you can find all versions of the php package qoliber/tsuku. 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 tsuku

Tsuku (つく)

A lightweight PHP templating library for transforming data into ANY text format

Tsuku is a powerful template processing library built with a clean Lexer → Parser → Compiler architecture. Transform your data into CSV, XML, JSON, XSD, or any text format you need using simple, intuitive templates.

Perfect for e-commerce exports, API responses, configuration files, and data transformations.

📖 Documentation: tsukuru.dev

Features

Performance

Tsuku 1.4.0, PHP 8.3 run with php -n (no Xdebug, no OPcache), Intel Core Ultra 7 265K, Linux; median of 9 runs of php -n benchmarks/run-all.php:

Benchmark What it renders Per render Throughput
Simple CSV with 100 products 0.16 ms ~6,400 renders/sec
Complex 10 categories × 20 products: nested loops, conditions, @match, functions 0.56 ms ~1,800 renders/sec
Variables 1,000 {variables} 1.3 ms ~760 renders/sec
CSV export 1,000 products with @csv, @number, @match 2.9 ms ~350 exports/sec (~350,000 products/sec)

Tsuku parses the template on every process() call and keeps no compiled cache: it is built for one render with a large output (exports, feeds, documents), not for thousands of small renders per second. For feeds too large to hold in memory use processToStream().

Run the benchmarks yourself (your hardware will differ):

Use -n, or at least switch Xdebug off: with Xdebug loaded (xdebug.mode=develop) the same benchmarks ran about 5x slower on the machine above. See tsukuru.dev/guide/performance.

Requirements

Installation

Quick Start

Simple Variables

Loops with @for

Conditionals with @if and @else

Smart Object/Array Access

Custom Functions

Streaming Large Datasets

For large catalogs (10k+ rows) where holding the whole rendered output in memory is impractical, use processToStream. It renders the template incrementally — header once, each row in turn, footer once — and writes each piece through a callback as soon as it's ready.

Constraints:

Real-World Examples

CSV Export with Escaping

@csv() quotes only the values that need it. @number(value, 2) alone would print 1,299.50 - the thousands separator would split the price into two columns - so CSV templates pass the separators: @number(value, 2, ".", "").

XML Product Catalog

Tsuku escapes nothing on its own: use @xml(), @html(), @json() or @csv() for values that may contain special characters.

JSON with Commas Between Items

JSON allows no comma after the last element, so put the separator in front of every element but the first. In a list the loop key is 0 only for the first element (pass array_values($items) if the keys are different):

@json() prints a complete, quoted JSON string. More patterns: tsukuru.dev/examples/json-apis.

YAML Configuration

HTML Product List with XSS Protection

Template Syntax

Variables

Use {variableName} or {object.property} for dot notation:

Smart Object/Array Access: each segment of a path is read from an array by key; from an object Tsuku uses the first of these that exists: getX(), isX(), x(), then the public property x.

Details: tsukuru.dev/guide/variables.

For Loops

With key/value (value first, then key):

Conditionals

If/Else:

Unless:

Match (Pattern Matching):

Match with multiple values:

Else-if:

Conditions (in @if, @unless, @elseif and @?{...}):

Operator Meaning
== != > < >= <= PHP loose comparison (numeric strings compare as numbers)
in, not in list on the right: membership, comparing as strings ("7231" in ids matches 7231); string on the right: case-sensitive substring; anything else: false
not, ! negation
and, && both (short-circuit)
or, \|\| either (short-circuit)
( ... ) grouping

Precedence from lowest to highest: or < and < not < comparisons, so not a == b means not (a == b). Operands are string and number literals, variable paths, function calls and parenthesised expressions; a condition may span several lines. and, or, not and in are keywords only as whole words, so product.order, inventory or notes are ordinary variables. true, false and null are not literals (they are looked up as variables, as in earlier versions): write @if(flag) / @if(not flag).

Malformed conditions (=, x - 1, a < b < c, a dangling and, an unknown function, ...) throw a ParseException (or FunctionNotFoundException) naming the line and column instead of rendering something wrong.

Built-in Functions

String functions:

Number functions:

Templates have no arithmetic: @number(qty * price, 2) prints 0.00 and a condition such as index < length(items) - 1 throws a ParseException. Compute derived values (line totals, margins) in PHP before rendering, or register a function.

Array functions:

Escaping functions:

Date/Utility functions:

Membership functions:

Custom Functions

Register your own:

Custom Directives

Directives wrap a block of the template. The handler receives the rendered body first, then the arguments (resolved like function arguments), and returns the output that replaces the block:

A directive can be written @name(arguments) ... @end or, without arguments, @name ... @end. Registered names take precedence over functions of the same name; built-in names (if, for, ...) cannot be registered. Errors thrown by a handler follow the strictness mode, like function errors.

Whitespace Control

Templates can be indented freely; the rules decide which whitespace around directives is output:

  1. A line holding only directives (and spaces/tabs) produces no output at all - not its indentation, not its line break.
  2. Indentation before @else, @elseif, @case, @default and @end at the start of a line is dropped.
  3. A directive other than @end at the end of a content line takes that line break with it.
  4. An @end that follows content on its line keeps the line break after it.
  5. In an inline block (content before the opening directive on its line), whitespace containing a line break at the start of each branch is dropped - and at the end of each branch too when content follows the block's @end on its line. Single-line branches (@else out) stay exactly as written.

renders one row per product (WID-001,Available). \ line continuations still join lines first; \r\n line breaks are handled like \n. Full rules with examples: tsukuru.dev/guide/whitespace-control.

Escaping

@@ prints a literal @ (user@@example.com, @@media (max-width: 600px)). Braces need no escaping: {...} is a variable only when it contains a plain path, so JSON, CSS and Magento directives such as {{widget ...}} or {{media url="..."}} pass through unchanged. ({{name}} is { + the value of name + }; to print a literal {name} use @concat("{", "name}").)

Deep Nesting

Nest directives as deep as you need:

Architecture & Design

Tsuku uses a clean three-stage compiler pipeline inspired by traditional programming language design:

The Pipeline

1. Lexer (Lexical Analyzer)

What it means: "Lexer" comes from "lexical analysis" - breaking text into meaningful chunks

Location: src/Lexer/Lexer.php

The Lexer reads the raw template string character by character and breaks it into tokens (meaningful units):

Why? Makes parsing easier by converting a string into structured chunks.

2. Parser (Syntax Analyzer)

What it means: Builds a tree structure showing how pieces relate to each other

Location: src/Ast/Parser.php

The Parser takes tokens and builds an AST (Abstract Syntax Tree) - a tree structure representing the template's logical structure:

Why? The tree structure makes it easy to handle nesting and execute directives in the correct order.

3. Compiler (Code Generator)

What it means: Walks the tree and generates the final output

Location: src/Compiler/Compiler.php

The Compiler walks the AST tree using the Visitor Pattern and generates the output string:

Why? Clean separation: data lookup, conditionals, loops all handled in one place.

Key Concepts Explained

AST (Abstract Syntax Tree)

Node

Token

Visitor Pattern

Benefits of This Architecture

✅ Predictable whitespace - layout is decided once, while lexing; rendering never re-scans text ✅ Proper nesting validation - Parser builds correct tree or throws error ✅ Clean separation of concerns - Each stage has one job ✅ Easy to extend - Add new node types without breaking existing code ✅ Fast execution - Single pass through the tree ✅ Type safety - PHP 8.1+ types ensure correctness

Class Naming Conventions

Tsuku follows industry-standard naming for compiler components:

Class Name Purpose Location
Lexer Lexical analyzer - breaks text into tokens src/Lexer/
Token One meaningful unit (like a word) src/Lexer/Token.php
TokenType Enum of all token types src/Lexer/TokenType.php
Parser Syntax analyzer - builds AST from tokens src/Ast/Parser.php
*Node AST tree nodes (TextNode, ForNode, etc.) src/Ast/
NodeVisitor Interface for visiting AST nodes src/Ast/NodeVisitor.php
Compiler Code generator - walks AST to create output src/Compiler/Compiler.php
Tsuku Main API entry point src/Tsuku.php

Naming Philosophy:

How It All Works Together

This architecture is the same used by:

Further Reading:

Development

License

MIT License - see LICENSE file for details

Credits

Created by qoliber - Like a hummingbird (koliber), swift and precise in data transformation.

Tsuku (つく) means "to create" or "to make" in Japanese, reflecting the library's purpose of creating text output from data.


All versions of tsuku with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
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 qoliber/tsuku contains the following files

Loading the files please wait ...