# wt-shared-libs

> Shared PHP library for the webtrees custom modules

---

![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)
![webtrees major version](https://img.shields.io/badge/webtrees-v2.2|v2.3-green)

`wt-shared-libs` is the shared PHP library behind the `modules_v4` custom modules [LinkEnhancer](../linkenhancer) and [Cronjob](../cronjob). It exists to keep two webtrees major versions (2.2 and 2.3) working side by side: version-dependent classes, methods and signatures are wrapped once here instead of duplicated in every module.

Parts and especially the loading routine are inspired by the similar package [Jefferson49/webtrees-common](https://github.com/Jefferson49/webtrees-common).

## What's inside

Everything lives under the PSR-4 root `Schwendinger\Webtrees\`. The full per-method API is documented in the repository — this page is just an overview:

| Component | Namespace | What it does |
| --- | --- | --- |
| <a href="https://codeberg.org/bschwede/wt-shared-libs/src/branch/main/src/Helpers/Functions.php" target="_blank" rel="noopener"><code>Functions.php</code></a>
 | `Helpers` | 15 version-aware static helpers — version checks, routes, private data, DataTables normalization, HTTP status codes |
| <a href="https://codeberg.org/bschwede/wt-shared-libs/src/branch/main/src/Helpers/ClassName.php" target="_blank" rel="noopener"><code>ClassName.php</code></a>
 | `Helpers` | version-safe webtrees class names — `get` / `isInstanceOf` + 2.2/2.3 constants |
| <a href="https://codeberg.org/bschwede/wt-shared-libs/src/branch/main/src/Helpers/MoreI18N.php" target="_blank" rel="noopener"><code>MoreI18N.php</code></a>
 | `Helpers` | translation — `translate` for own strings, `xlate` for strings already covered by the webtrees core |
| <a href="https://codeberg.org/bschwede/wt-shared-libs/src/branch/main/src/Services/CliBootstrap.php" target="_blank" rel="noopener"><code>CliBootstrap.php</code></a>
 | `Services` | CLI bootstrap — `boot` / `guard` + offline detection |
| <a href="https://codeberg.org/bschwede/wt-shared-libs/src/branch/main/src/Services/ModuleLog.php" target="_blank" rel="noopener"><code>ModuleLog.php</code></a>
 | `Services` | per-module singleton logger — `error` / `debug` / `trace` |
| <a href="https://codeberg.org/bschwede/wt-shared-libs/src/branch/main/src/Traits/ModuleCustomTrait.php" target="_blank" rel="noopener"><code>ModuleCustomTrait.php</code></a>
 | `Traits` | custom-module metadata — author, version, URLs, `customTranslations` |
| <a href="https://codeberg.org/bschwede/wt-shared-libs/src/branch/main/autoload.php" target="_blank" rel="noopener"><code>autoload.php</code></a>
 | – | the loader (see below) |

> Full per-method API: <a href="https://codeberg.org/bschwede/wt-shared-libs/src/branch/main/docs/reference.md" target="_blank" rel="noopener"><code>reference.md</code></a>
 in the repository.

## How the loader works

<a href="https://codeberg.org/bschwede/wt-shared-libs/src/branch/main/autoload.php" target="_blank" rel="noopener"><code>autoload.php</code></a>
 is a **skew-tolerant loader**: it compares the library version a module bundles with the version installed at the webtrees root and always lets the **latest** copy win, so a stale bundled copy can never shadow a newer site-level one. One rule for consumers — do **not** load the library from your module class's `__construct()`; it can change the autoload order. The full premises and the proof live in <a href="https://codeberg.org/bschwede/wt-shared-libs/src/branch/main/docs/reference.md" target="_blank" rel="noopener"><code>reference.md</code></a>
.

## Quick start (as a consuming module)

Add a path repository to your module's `composer.json` and register the loader in your own load routine (after your other composer libraries):

```json
"repositories": [
    { "type": "path", "url": "../wt-shared-libs", "options": { "symlink": false } }
],
"require": {
    "bschwede/wt-shared-libs": "^1.0"
},
"config": {
    "prepend-autoloader": false
}
```

## Releases

Releases are versioned by Git tag, and the tag always equals the `composer.json` `version` field (no `v` prefix). See <a href="https://codeberg.org/bschwede/wt-shared-libs/src/branch/main/CHANGELOG.md" target="_blank" rel="noopener"><code>CHANGELOG.md</code></a>
.

## Further reading

- API reference — <a href="https://codeberg.org/bschwede/wt-shared-libs/src/branch/main/docs/reference.md" target="_blank" rel="noopener"><code>reference.md</code></a>

- Contributing / adding a class — <a href="https://codeberg.org/bschwede/wt-shared-libs/src/branch/main/docs/contributing.md" target="_blank" rel="noopener"><code>contributing.md</code></a>

- Changelog — <a href="https://codeberg.org/bschwede/wt-shared-libs/src/branch/main/CHANGELOG.md" target="_blank" rel="noopener"><code>CHANGELOG.md</code></a>

- [Issues & PRs on Codeberg](https://codeberg.org/bschwede/wt-shared-libs)
