Search by

adachsoft / content-articles

Arkadiusz Adach

Framework-independent domain model for immutable articles and Content Blocks documents.

Package info

gitlab.com/a.adach/content-articles

Issues

pkg:composer/adachsoft/content-articles

Statistics

Installs: 14

Dependents: 1

Suggesters: 0

Stars: 0

v0.2.0 2026-12-02 15:31 UTC

This package is auto-updated.

Last update: 2026-12-02 14:31:32 UTC


README

adachsoft/content-articles is a framework-independent domain module for articles. It provides immutable article metadata, lifecycle transitions, revision tracking, typed collections, Content Blocks body validation, a JSON file repository, and an application service. It does not require a web framework or a Symfony bundle.

Domain model

An Article has a stable ID, translation-group ID, locale, slug, status, revision, title, lead, body, one or more authors, AI disclosure, related entity references, optional SEO metadata, and timestamps. Mutating operations return a new article instance. Content and SEO changes and status transitions increment the revision; markFactChecked() updates its timestamp without changing the revision. The first publication timestamp is retained across later publication cycles. Published articles require SEO metadata.

ContentDocument wraps a Content Blocks document and checks only its top-level envelope. Full schema and referential validation is provided by ContentBlocksDocumentValidator, which delegates to adachsoft/content-blocks. The ContentDocumentValidatorInterface returns the package's AdachSoft\ContentBlocks\Validation\ValidationResult.

Domain example

use AdachSoft\ContentArticles\Article\AiDisclosure;
use AdachSoft\ContentArticles\Article\Article;
use AdachSoft\ContentArticles\Article\ArticleId;
use AdachSoft\ContentArticles\Article\ArticleLocale;
use AdachSoft\ContentArticles\Article\ArticleSlug;
use AdachSoft\ContentArticles\Article\Author;
use AdachSoft\ContentArticles\Article\AuthorTypeEnum;
use AdachSoft\ContentArticles\Article\TranslationGroupId;
use AdachSoft\ContentArticles\Body\ContentDocument;
use AdachSoft\ContentArticles\Collection\AuthorCollection;
use AdachSoft\ContentArticles\Collection\EntityRefCollection;
use DateTimeImmutable;

$now = new DateTimeImmutable('now');
$article = Article::draft(
    id: ArticleId::fromString('018f47c2-8c5a-7b12-8c3d-4e5f60718293'),
    translationGroupId: TranslationGroupId::fromString('018f47c2-8c5a-7b12-8c3d-4e5f60718294'),
    slug: new ArticleSlug('example-article'),
    locale: new ArticleLocale('en-GB'),
    title: 'Example article',
    subtitle: null,
    lead: 'A concise introduction to the article.',
    body: new ContentDocument([
        'spec' => 'content-blocks/1.0',
        'blocks' => [],
    ]),
    authors: new AuthorCollection([
        new Author('Editorial team', AuthorTypeEnum::ORGANIZATION),
    ]),
    aiDisclosure: new AiDisclosure(false, null),
    relatedEntities: new EntityRefCollection(),
    seo: null,
    now: $now,
);

$revisedArticle = $article->withContent(
    'Updated example article',
    null,
    'An updated introduction.',
    $article->body,
    new DateTimeImmutable('now'),
);

Application service and JSON persistence

ArticleService coordinates draft creation, content and SEO updates, lifecycle transitions, and fact-checking timestamps. It uses an injected ClockInterface, ContentDocumentValidatorInterface, and ArticleRepositoryInterface. JsonFileArticleRepository is the provided file-backed implementation: it stores one versioned {id}.json file per article, uses atomic replacement, checks optimistic revisions, and enforces slug uniqueness per locale. ArticleQuery supports locale, status, related-entity, and pagination filters.

use AdachSoft\ContentArticles\Application\ArticleService;
use AdachSoft\ContentArticles\Application\Dto\CreateArticleDto;
use AdachSoft\ContentArticles\Application\SystemClock;
use AdachSoft\ContentArticles\Article\AiDisclosure;
use AdachSoft\ContentArticles\Article\ArticleId;
use AdachSoft\ContentArticles\Article\ArticleLocale;
use AdachSoft\ContentArticles\Article\ArticleSlug;
use AdachSoft\ContentArticles\Article\Author;
use AdachSoft\ContentArticles\Article\AuthorTypeEnum;
use AdachSoft\ContentArticles\Article\TranslationGroupId;
use AdachSoft\ContentArticles\Body\ContentBlocksDocumentValidator;
use AdachSoft\ContentArticles\Body\ContentDocument;
use AdachSoft\ContentArticles\Collection\AuthorCollection;
use AdachSoft\ContentArticles\Collection\EntityRefCollection;
use AdachSoft\ContentArticles\Repository\JsonFileArticleRepository;

$repository = new JsonFileArticleRepository(__DIR__ . '/var/articles');
$service = new ArticleService(
    $repository,
    new ContentBlocksDocumentValidator(),
    new SystemClock(),
);

$draft = $service->createDraft(new CreateArticleDto(
    id: ArticleId::fromString('018f47c2-8c5a-7b12-8c3d-4e5f60718293'),
    translationGroupId: TranslationGroupId::fromString('018f47c2-8c5a-7b12-8c3d-4e5f60718294'),
    slug: new ArticleSlug('example-article'),
    locale: new ArticleLocale('en-GB'),
    title: 'Example article',
    subtitle: null,
    lead: 'A concise introduction to the article.',
    body: new ContentDocument([
        'spec' => 'content-blocks/1.0',
        'blocks' => [],
    ]),
    authors: new AuthorCollection([
        new Author('Editorial team', AuthorTypeEnum::ORGANIZATION),
    ]),
    aiDisclosure: new AiDisclosure(false, null),
    relatedEntities: new EntityRefCollection(),
    seo: null,
));

$storedDraft = $repository->get($draft->id);

Requirements

  • PHP 8.3 or later
  • adachsoft/collection ^3.0
  • adachsoft/content-blocks ^0.1.0

Installation

Install the package with Composer:

composer require adachsoft/content-articles

Composer's PSR-4 autoloader makes the AdachSoft\ContentArticles\ namespace available to your application.

Integration

Use ArticleService with JsonFileArticleRepository for a simple filesystem-backed application, or implement ArticleRepositoryInterface for another storage system. Supply a ContentDocumentValidatorInterface implementation to control Content Blocks validation, and a ClockInterface implementation to control application timestamps. The package has no framework-specific integration.