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'.
  • TemplateProfileRegistryFactory gives the shipped templates: names() lists them and get() returns one.
  • A template has a description(), a root() whose nodes are the folders every clone has, each with its memberTypes, and its tags().
  • ProjectFactory::open() opens the project of a barn started with barnark init. createFolder() clones a template into it and makes the folder.
  • check() compares a folder with a template and returns a Violation for each folder that is missing or not part of it, with a rule, a message and a path.

The calls shown are the ones this page was run with. The library needs PHP 8.5 or later.