Download the PHP package ecourty/okf without Composer
On this page you can find all versions of the php package ecourty/okf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package okf
Short Description A PHP parser and writer for the Open Knowledge Format (OKF) — Markdown bundles with YAML frontmatter for versionable, human-readable knowledge documentation.
License MIT
Informations about the package okf
OKF for PHP
A typed PHP parser and writer for the Open Knowledge Format (OKF) — directories of Markdown files with YAML frontmatter for documenting knowledge as versionable, human- and agent-readable text.
OKF is specified by Google Cloud's
knowledge-catalogrepository — seeokf/SPEC.mdfor the full spec (currently version 0.1, draft). This library is an independent PHP implementation of that spec, not an official Google product.
Requirements
- PHP 8.3+
Installation
Quick Start
The Okf facade is the simplest way to use the library — read a bundle from disk, walk its concepts, and write it back:
Reading a Single Concept
Reading index.md and log.md
index.md and log.md are reserved filenames — the library exposes their raw Markdown body directly rather than parsing their loosely-conventional structure, so nothing is ever silently dropped:
Lazy Iteration
For large bundles, iterate concepts one at a time instead of building the whole Bundle aggregate in memory:
Modifying and Writing a Concept
All models are immutable — "modifying" a concept means constructing a new one:
Creating a New Concept
Validation
Neither reading nor writing ever validates — a concept missing type parses and writes back out without error, matching the OKF spec's permissive consumption model. Validation is a separate, explicit, opt-in step:
Linting a whole bundle:
Unknown Keys and Round-Trip Fidelity
Producer-defined frontmatter keys — and known keys whose value doesn't match the expected type (e.g. tags given as a scalar instead of a list) — are preserved rather than dropped, so a read → write cycle never silently loses data:
Error Handling
All exceptions extend OkfException (a RuntimeException) and carry structured context:
Custom Filesystem
BundleParser/BundleWriter read and write through a single FilesystemInterface seam (exists/read/write/listFiles), defaulting to LocalFilesystem. Provide your own implementation to read from a zip archive, an in-memory store, a remote object store, etc.:
Examples
See the examples/ directory for runnable scripts:
Development
License
This library is released under the MIT License.