From PHP
The same operations, as a library.
Everything the command line does is also a PHP library, barnark.
Each factory in Rmb32\Barnark\Api\Factory gives you one part of it. This script was run in a new barn:
<?php
require __DIR__ . '/vendor/autoload.php';
use Rmb32\Barnark\Api\Factory\ProjectFactory;
use Rmb32\Barnark\Api\Factory\TemplateProfileRegistryFactory;
$registry = new TemplateProfileRegistryFactory()->create();
echo implode(', ', $registry->names()), "\n";
$template = $registry->get('Domain Driven Design');
echo $template->root()->nodes[0]->name, "\n";
foreach ($template->tags() as $tag) {
echo $tag->name, "\n";
}
$project = new ProjectFactory()->open(__DIR__);
$project->createFolder('src', '', 'Library', 'Pricing');
mkdir(__DIR__ . '/src/Stray');
foreach ($project->check(__DIR__ . '/src', 'Pricing', $project->slotsFor('src')) as $violation) {
echo $violation->rule, ': ', $violation->message, "\n";
}
$ php example.php
Domain Driven Design, Feature Based Architecture, Model View Controller, Library, Package App
Context
Application
Domain
Infrastructure
Transport
template.unexpected: This folder is not part of 'Pricing'.
TemplateProfileRegistryFactorygives the shipped templates:names()lists them andget()returns one.- A template has a
description(), aroot()whosenodesare the folders every clone has, each with itsmemberTypes, and itstags(). ProjectFactory::open()opens the project of a barn started withbarnark init.createFolder()clones a template into it and makes the folder.check()compares a folder with a template and returns aViolationfor each folder that is missing or not part of it, with arule, amessageand apath.
The calls shown are the ones this page was run with. The library needs PHP 8.5 or later.