Download the PHP package ktav-lang/ktav without Composer

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

ktav — PHP bindings

Packagist CI License: MIT OR Apache-2.0 Playground

Languages: English · 简体中文

Playground: convert JSON / YAML / TOML / INI ⇄ Ktav in your browser at ktav-lang.github.io.

PHP bindings for the Ktav configuration format. Thin wrapper around the reference Rust parser, loaded at runtime through the PHP FFI extension — no PHP extension to compile, no PECL install. Plain Composer dependency, the native binary is fetched on first call.

Requires PHP 7.4+ with ext-ffi enabled (default in CLI; web SAPIs need ffi.enable=1 in php.ini).

Install

Quick start

Parse — read typed values straight off the array

Build & render — construct a document in code

A complete runnable example lives in examples/basic.php.

API

Method Purpose
Ktav::loads(string $src): mixed Parse a Ktav document.
Ktav::loadsStrict(string $src): mixed Parse with strict numeric spelling checks.
Ktav::dumps(array $value): string Render an associative array as Ktav text.
Ktav::dumpsForceStrings(array $value): string Render like dumps, but coerce every leaf scalar to a String.
Ktav::emitCanonical(array $value): string Render a value as deterministic canonical form.
Ktav::format(string $src): string Normalise a document's spelling, keeping comments.
Ktav::canonicalFromSource(string $src): string Canonicalize source directly, preserving compound shape that PHP values may collapse (for example, a: {} stays a: {} while loads represents the empty Object as []). Drops comments and blank lines.
Ktav::nativeVersion(): string Version of the loaded ktav_cabi.

dumpsForceStrings flattens integers, floats, booleans and null to their textual form via the raw marker (::); objects and arrays keep their structure, since only leaves are coerced. The result parses back through loads as the same set of String scalars — useful when a downstream consumer needs string-only values.

Formatting

Ktav::format() takes Ktav source text and returns Ktav source text. It normalises structure to canonical form (§ 5.9) while keeping the trivia the canonical writer drops:

Every comment survives verbatim — Ktav has no trailing comments (§ 3.4: a comment owns a whole line), so attachment is unambiguous. Blank lines survive as a grouping hint, but a run of two or more collapses to exactly one and blank padding just inside a bracket is dropped, which makes the transform a fixed point: formatting already-formatted text changes nothing. Key order is never changed — canonical form has no sorting rule, and reordering keys would make review diffs worse.

Errors

KtavException is thrown on any parse or render failure. Beyond a human-readable getMessage(), it carries the nine structured fields of the core's error envelope:

The full set is getError(), getReason(), getErrorLine(), getLineText(), getSpan(), getPath(), getBody(), getCanonical(), getSpecSection(). Absent information is null, never a missing accessor, so a caller can read any field without checking the error class first.

getPath() is an array of exact decoded key segments, never a joined string: a key literally named a.b is one segment and cannot be confused with a two-segment path.

Two writer rejections are named apart — "UnrepresentableAt" when the writer can say which node is at fault (it fills getPath() too), and "Unrepresentable" when it cannot. The reason code is the same in both, so matching on getReason() is enough when you only need to know that a write was refused.

getErrorLine() rather than getLine(), because PHP declares Exception::getLine() final.

Type mapping

Ktav PHP
null null
true / false bool
bare integer int if it fits, else string (PHP has no native bigint — wrap your own GMP / BCMath if you need arithmetic).
bare decimal float
other scalar string
[ ... ] sequential array
{ ... } associative array (insertion order preserved)

To emit an arbitrary-precision integer, wrap the digit string yourself: ['big' => ['$i' => '9999999999999999999']] — same envelope used on the wire between PHP and the native side.

Key escaping

Since spec 0.6.4 a literal . or : inside a key segment is written with a backslash:

A literal backslash in a key is \\.

How the native library is resolved

On first call:

  1. KTAV_LIB_PATH env var, if set.
  2. User cache — <userCache>/ktav-php/v<version>/<asset>, downloaded on a previous call.
  3. GitHub Release download — fetched once from github.com/ktav-lang/php/releases/download/v<version>/<asset> and cached under (2). Requires network on first call after install.

<userCache> is %LOCALAPPDATA% on Windows, ~/Library/Caches on macOS, $XDG_CACHE_HOME or ~/.cache on Linux.

Runtime support

License

MIT OR Apache-2.0 — see LICENSE-APACHE.

Other Ktav implementations


All versions of ktav with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
ext-ffi Version *
ext-json Version *
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 ktav-lang/ktav contains the following files

Loading the files please wait ...