{"id":49323746,"url":"https://github.com/ktav-lang/php","last_synced_at":"2026-04-26T19:00:45.268Z","repository":{"id":353849769,"uuid":"1221149841","full_name":"ktav-lang/php","owner":"ktav-lang","description":"PHP bindings for Ktav — a plain configuration format with three rules, zero indentation, and zero quoting. FFI over the reference Rust crate — no PHP extension to compile, prebuilt binaries for Linux/macOS/Windows.","archived":false,"fork":false,"pushed_at":"2026-04-25T21:12:19.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-25T22:29:10.798Z","etag":null,"topics":["bindings","composer","config","config-format","configuration","ffi","ktav","parser","php","rust"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ktav-lang.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-04-25T20:21:48.000Z","updated_at":"2026-04-25T21:12:24.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ktav-lang/php","commit_stats":null,"previous_names":["ktav-lang/php"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/ktav-lang/php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktav-lang%2Fphp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktav-lang%2Fphp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktav-lang%2Fphp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktav-lang%2Fphp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ktav-lang","download_url":"https://codeload.github.com/ktav-lang/php/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktav-lang%2Fphp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32308878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T17:23:19.671Z","status":"ssl_error","status_checked_at":"2026-04-26T17:23:19.195Z","response_time":129,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bindings","composer","config","config-format","configuration","ffi","ktav","parser","php","rust"],"created_at":"2026-04-26T19:00:41.362Z","updated_at":"2026-04-26T19:00:45.262Z","avatar_url":"https://github.com/ktav-lang.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ktav — PHP bindings\n\n**Languages:** **English** · [Русский](README.ru.md) · [简体中文](README.zh.md)\n\nPHP bindings for the [Ktav configuration format](https://github.com/ktav-lang/spec).\nThin wrapper around the reference Rust parser, loaded at runtime through\nthe **[PHP FFI extension](https://www.php.net/manual/en/book.ffi.php)** —\nno PHP extension to compile, no PECL install. Plain Composer\ndependency, the native binary is fetched on first call.\n\nRequires **PHP 7.4+** with `ext-ffi` enabled (default in CLI; web SAPIs\nneed `ffi.enable=1` in `php.ini`).\n\n## Install\n\n```bash\ncomposer require ktav-lang/ktav\n```\n\n## Quick start\n\n### Parse — read typed values straight off the array\n\n```php\nuse Ktav\\Ktav;\n\n$src = \u003c\u003c\u003cKTAV\nservice: web\nport:i 8080\nratio:f 0.75\ntls: true\ntags: [\n    prod\n    eu-west-1\n]\ndb.host: primary.internal\ndb.timeout:i 30\nKTAV;\n\n$cfg = Ktav::loads($src);\n\n$service   = $cfg['service'];        // string\n$port      = $cfg['port'];           // int\n$ratio     = $cfg['ratio'];          // float\n$tls       = $cfg['tls'];            // bool\n$tags      = $cfg['tags'];           // array\u003cstring\u003e\n$dbHost    = $cfg['db']['host'];     // string\n$dbTimeout = $cfg['db']['timeout'];  // int\n```\n\n### Build \u0026 render — construct a document in code\n\n```php\n$doc = [\n    'name'  =\u003e 'frontend',\n    'port'  =\u003e 8443,\n    'tls'   =\u003e true,\n    'ratio' =\u003e 0.95,\n    'upstreams' =\u003e [\n        ['host' =\u003e 'a.example', 'port' =\u003e 1080],\n        ['host' =\u003e 'b.example', 'port' =\u003e 1080],\n    ],\n    'notes' =\u003e null,\n];\n$text = Ktav::dumps($doc);\n```\n\nA complete runnable example lives in [`examples/basic.php`](examples/basic.php).\n\n## API\n\n| Method | Purpose |\n| --- | --- |\n| `Ktav::loads(string $src): mixed` | Parse a Ktav document. |\n| `Ktav::dumps(array $value): string` | Render an associative array as Ktav text. |\n| `Ktav::nativeVersion(): string` | Version of the loaded `ktav_cabi`. |\n\n`KtavException` is thrown on any parse / render failure; the message is\nthe UTF-8 string produced by the native parser.\n\n## Type mapping\n\n| Ktav             | PHP                                                  |\n| ---------------- | ---------------------------------------------------- |\n| `null`           | `null`                                               |\n| `true` / `false` | `bool`                                               |\n| `:i \u003cdigits\u003e`    | `int` if it fits, else `string` (PHP has no native bigint — wrap your own GMP / BCMath if you need arithmetic). |\n| `:f \u003cnumber\u003e`    | `float`                                              |\n| bare scalar      | `string`                                             |\n| `[ ... ]`        | sequential `array`                                   |\n| `{ ... }`        | associative `array` (insertion order preserved)      |\n\nTo emit an arbitrary-precision integer, wrap the digit string yourself:\n`['big' =\u003e ['$i' =\u003e '9999999999999999999']]` — same envelope used on the\nwire between PHP and the native side.\n\n## How the native library is resolved\n\nOn first call:\n\n1. **`KTAV_LIB_PATH`** env var, if set.\n2. **User cache** — `\u003cuserCache\u003e/ktav-php/v\u003cversion\u003e/\u003casset\u003e`, downloaded\n   on a previous call.\n3. **GitHub Release download** — fetched once from\n   `github.com/ktav-lang/php/releases/download/v\u003cversion\u003e/\u003casset\u003e` and\n   cached under (2). Requires network on first call after install.\n\n`\u003cuserCache\u003e` is `%LOCALAPPDATA%` on Windows, `~/Library/Caches` on\nmacOS, `$XDG_CACHE_HOME` or `~/.cache` on Linux.\n\n## Runtime support\n\n- PHP 7.4 / 8.0 / 8.1 / 8.2 / 8.3+. Tested on the LTS lines on every CI run.\n- Prebuilt binaries for: `linux/amd64`, `linux/arm64`, `darwin/amd64`,\n  `darwin/arm64`, `windows/amd64`, `windows/arm64`.\n- Linux distros must use glibc 2.17+ (zigbuild baseline). Alpine\n  (musl) support is planned.\n\n## License\n\nMIT — see [LICENSE](LICENSE).\n\n## Other Ktav implementations\n\n- [`spec`](https://github.com/ktav-lang/spec) — specification + conformance suite\n- [`rust`](https://github.com/ktav-lang/rust) — reference Rust crate (`cargo add ktav`)\n- [`csharp`](https://github.com/ktav-lang/csharp) — C# / .NET (`dotnet add package Ktav`)\n- [`golang`](https://github.com/ktav-lang/golang) — Go (`go get github.com/ktav-lang/golang`)\n- [`java`](https://github.com/ktav-lang/java) — Java / JVM (`io.github.ktav-lang:ktav` on Maven Central)\n- [`js`](https://github.com/ktav-lang/js) — JS / TS (`npm install @ktav-lang/ktav`)\n- [`python`](https://github.com/ktav-lang/python) — Python (`pip install ktav`)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktav-lang%2Fphp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fktav-lang%2Fphp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktav-lang%2Fphp/lists"}