PHPackages                             decodelabs/archetype - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. decodelabs/archetype

ActiveLibrary[File &amp; Storage](/categories/file-storage)

decodelabs/archetype
====================

Simple named library loader

v0.4.2(7mo ago)128.6k20MITPHPPHP ^8.4CI passing

Since Nov 18Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/decodelabs/archetype)[ Packagist](https://packagist.org/packages/decodelabs/archetype)[ RSS](/packages/decodelabs-archetype/feed)WikiDiscussions develop Synced 6d ago

READMEChangelog (10)Dependencies (4)Versions (42)Used By (20)

Archetype
=========

[](#archetype)

[![PHP from Packagist](https://camo.githubusercontent.com/a1a9b17039484994320400559a06a74770ae6a41b5b5f7b91e6559cc85e40790/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6465636f64656c6162732f6172636865747970653f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/archetype)[![Latest Version](https://camo.githubusercontent.com/bdc91d584c44bdb25953f6ef7a82baa9867e4167d7506e8feba5f36a6cf5c3a4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6465636f64656c6162732f6172636865747970652e7376673f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/archetype)[![Total Downloads](https://camo.githubusercontent.com/1e28da528d5de950e3c4d910633fb11b7ddb57708ed76b9ca3725324cc99f457/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6465636f64656c6162732f6172636865747970652e7376673f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/archetype)[![GitHub Workflow Status](https://camo.githubusercontent.com/7f9bb25ba658c7dd53f87906f8b16f184bb5db00e72eae50e1d1c768899919c0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6465636f64656c6162732f6172636865747970652f696e746567726174652e796d6c3f6272616e63683d646576656c6f70)](https://github.com/decodelabs/archetype/actions/workflows/integrate.yml)[![PHPStan](https://camo.githubusercontent.com/e25c14ce011edabdd0fbd2e10415b41cc5d66ed11ef3e5b7edd074c5bdd35a2d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d3434434331312e7376673f6c6f6e6743616368653d74727565267374796c653d666c6174)](https://github.com/phpstan/phpstan)[![License](https://camo.githubusercontent.com/26d4367f85119a49a92717917b8dd06b545093beb844d39389f055a387e3057d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6465636f64656c6162732f6172636865747970653f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/archetype)

### Simple class name resolution for PHP

[](#simple-class-name-resolution-for-php)

Archetype provides a generic frontend to resolving implementation classes for a named interface with an extensible plugin architechture.

---

Installation
------------

[](#installation)

This package requires PHP 8.4 or higher.

Install via Composer:

```
composer require decodelabs/archetype
```

Usage
-----

[](#usage)

Use `Archetype` when designing plugin oriented libraries that need to load arbitrary extension classes based on a naming convention.

By mapping names to classes in an extensible and customisable resolver structure, `Archetype` allows fast and reliable means to create loosely coupled plugin ecosystems.

```
use DecodeLabs\Archetype;
use MyInterface;

$archetype = new Archetype();
$class = $archetype->resolve(MyInterface::class, 'MyClass');
```

It is especially useful in `Factory` patterns where you need to load arbitrary classes based on a name.

Example:

```
// Main library
namespace My\Library
{

    use DecodeLabs\Archetype;

    interface Thing {}

    class Factory {

        public function __construct(
            private Archetype $archetype
        ) {
            $this->archetype = $archetype;
        }

        public function loadThing(
            string $name
        ): Thing {
            // Resolve name to class for Thing interface
            $class = $this->archetype->resolve(Thing::class, $name);
            return new $class();
        }
    }
}

// Thing implementations
namespace My\Library\Thing
{

    use My\Library\Thing;

    class Box implements Thing {}
    class Potato implements Thing {}
    class Dog implements Thing {}
}

// Calling code
namespace My\App
{

    use My\Library\Factory;

    $factory = new Factory(new Archetype());

    $box = $factory->loadThing('Box');
    $potato = $factory->loadThing('Potato');
    $dog = $factory->loadThing('Dog');
}
```

Resolvers
---------

[](#resolvers)

Archetype uses a hierarchy of `Resolvers` to turn a name into a class. By default, the `Handler` will fall back on a generic resolver that simply locates the named class within the namespace of the associated interface.

In the above example, the implementations of the `My\Library\Thing` can be found at `My\Library\Thing\\*`.

### Custom resolvers

[](#custom-resolvers)

The `Resolver\Archetype` implementation however will also automatically look for custom `Resolver` classes in the same location as the target interface, named `\Archetype`.

The following example will replace the default functionality and cause Archetype to look in a different location for the `Thing` implementations:

```
namespace My\Library {

    use DecodeLabs\Archetype\Resolver;

    class ThingArchetype implements Resolver
    {

        public function getInterface(): string
        {
            return Thing::class;
        }

        public function getPriority(): int
        {
            return 10;
        }

        public function resolve(string $name): ?string
        {
            return 'Some\\Other\\Namespace\\'.$name;
        }
    }
}
```

### Multiple resolvers

[](#multiple-resolvers)

Multiple `Resolver` instances can be stacked against a single interface, called in series based on the priority they request, the first one to return a non-null class name wins.

Alternative `Resolvers` can be loaded with:

```
use My\Library\Resolver\Alternative as AlternativeResolver;

$archetype = new Archetype();
$archetype->register(new AlternativeResolver());
```

### Class scanning

[](#class-scanning)

Some resolvers (including the default one) can scan and list all classes resolvable under a namespace.

```
foreach($archetype->scanClasses(Thing::class) as $path => $class) {
    echo 'Found class: '.$class.' at '.$path.PHP_EOL;
}
```

### File lookup

[](#file-lookup)

`Resolvers` that also implement the `Finder` interface can define the means to lookup a file path based on the provided name, against the space defined by the target interface.

This can be useful when the *space* that is defined by the root interface may contain assets aside from PHP code.

It is down to the implementation to decide how to map names to file paths (there are no pre-built default `Finder` classes).

Example:

```
namespace My\Library {

    use DecodeLabs\Archetype\Finder;

    class ThingArchetype implements Finder
    {

        public function getInterface(): string
        {
            return Thing::class;
        }

        public function getPriority(): int
        {
            return 10;
        }

        public function resolve(
            string $name
        ): ?string {
            return 'Some\\Other\\Namespace\\'.$name;
        }

        public function findFile(
            string $name
        ): ?string {
            return './some/other/namespace/'.$name.'.jpg';
        }
    }
}

namespace My\App {

    use My\Library\Thing;

    $boxImagePath = $archetype->findFile(Thing::class, 'box');
}
```

Licensing
---------

[](#licensing)

Archetype is licensed under the MIT License. See [LICENSE](./LICENSE) for the full license text.

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance68

Regular maintenance activity

Popularity29

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~36 days

Recently: every ~29 days

Total

40

Last Release

225d ago

PHP version history (4 changes)v0.1.0PHP ^7.2|^8.0

v0.2.0PHP ^8.0

v0.2.22PHP ^8.1

v0.3.8PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/8a241d64d12b3b5ee94197862ec1ec30b82ed2efa34a0cd7f4c3565a021daddd?d=identicon)[betterthanclay](/maintainers/betterthanclay)

---

Top Contributors

[![betterthanclay](https://avatars.githubusercontent.com/u/1273586?v=4)](https://github.com/betterthanclay "betterthanclay (226 commits)")

---

Tags

class-loaderphpresolverlibraryloaderfinder

### Embed Badge

![Health badge](/badges/decodelabs-archetype/health.svg)

```
[![Health](https://phpackages.com/badges/decodelabs-archetype/health.svg)](https://phpackages.com/packages/decodelabs-archetype)
```

###  Alternatives

[yosymfony/resource-watcher

A simple resource watcher using Symfony Finder

698.2M22](/packages/yosymfony-resource-watcher)[ergebnis/classy

Provides collectors for classy constructs (classes, enums, interfaces, and traits).

382.8M20](/packages/ergebnis-classy)[arthurhoaro/favicon

PHP Library used to discover favicon from given URL

36737.4k](/packages/arthurhoaro-favicon)[edsdk/flmngr-server-php

Flmngr file manager PHP backend

20279.5k3](/packages/edsdk-flmngr-server-php)[samsonasik/array-lookup

A fast lookup library that help you verify and search array and Traversable data

2863.0k2](/packages/samsonasik-array-lookup)[mpclarkson/icon-scraper

PHP Library to get the apple-touch-icons and favicon from a website.

2129.2k](/packages/mpclarkson-icon-scraper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
