1. Go to this page and download the library: Download ecourty/okf library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$rootIndex = $bundle->getIndex(); // index.md at the bundle root, or null if absent
$tablesIndex = $bundle->getIndex('tables'); // tables/index.md, or null if absent
$rootIndex?->getOkfVersion(); // the declared OKF version, if any (root index.md only)
$rootIndex?->getBody(); // raw Markdown
$log = $bundle->getLog(); // log.md at the bundle root, or null if absent
$log?->getBody();
foreach ($okf->iterateConcepts('/path/to/bundle') as $concept) {
// ...
}
use Ecourty\Okf\Model\ConceptDocument;
use Ecourty\Okf\Model\Frontmatter;
$original = $bundle->getConcept('tables/orders');
$updated = new ConceptDocument(
id: $original->getId(),
path: $original->getPath(),
frontmatter: new Frontmatter(
type: $original->getFrontmatter()->getType(),
title: $original->getFrontmatter()->getTitle(),
tags: [...$original->getFrontmatter()->getTags(), 'reviewed'],
extra: $original->getFrontmatter()->getExtra(),
),
body: $original->getBody(),
);
$okf->getWriter()->writeConcept('/path/to/bundle', $updated);
use Ecourty\Okf\Model\ConceptDocument;
use Ecourty\Okf\Model\Frontmatter;
$concept = new ConceptDocument(
id: 'metrics/daily-active-users',
path: 'metrics/daily-active-users.md',
frontmatter: new Frontmatter(
type: 'Metric',
title: 'Daily Active Users',
description: 'Count of distinct users who performed at least one action in a day.',
tags: ['growth', 'engagement'],
),
body: "# Definition\n\nCounted from the `events` table, deduplicated by `user_id` per UTC day.\n",
);
$okf->getWriter()->writeConcept('/path/to/bundle', $concept);
use Ecourty\Okf\Validator\ConceptDocumentValidator;
use Ecourty\Okf\Validator\ValidationMode;
$validator = new ConceptDocumentValidator();
// Lenient (default): only `type` is ->getViolations($concept, ValidationMode::Strict);
// Or throw directly:
$validator->validate($concept, ValidationMode::Strict); // throws InvalidDocumentException
foreach ($bundle->getConcepts() as $concept) {
$violations = $validator->getViolations($concept, ValidationMode::Lenient);
foreach ($violations as $violation) {
echo "{$concept->getId()}: {$violation}\n";
}
}
$frontmatter = $concept->getFrontmatter();
$frontmatter->getExtra(); // every key not covered by the OKF spec, as given in the source YAML
$frontmatter->toArray(); // known + extra keys, ready to round-trip back to YAML
use Ecourty\Okf\Filesystem\FilesystemInterface;
use Ecourty\Okf\Okf;
use Ecourty\Okf\Parser\BundleParser;
use Ecourty\Okf\Writer\BundleWriter;
final class MyFilesystem implements FilesystemInterface
{
// exists(), read(), write(), listFiles()
}
$filesystem = new MyFilesystem();
$okf = new Okf(
parser: new BundleParser($filesystem),
writer: new BundleWriter($filesystem),
);