PHPackages                             eclipxe/micro-catalog - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. eclipxe/micro-catalog

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

eclipxe/micro-catalog
=====================

Micro catalog template class, useful to create value objects based on a known small catalog

v0.1.5(3mo ago)3144.6k↑31.3%13MITPHPPHP &gt;=7.2CI passing

Since Oct 2Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/eclipxe13/micro-catalog)[ Packagist](https://packagist.org/packages/eclipxe/micro-catalog)[ Docs](https://github.com/eclipxe13/micro-catalog)[ RSS](/packages/eclipxe-micro-catalog/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (6)Dependencies (2)Versions (9)Used By (3)

`eclipxe/micro-catalog`
=======================

[](#eclipxemicro-catalog)

[![Source Code](https://camo.githubusercontent.com/0543a34d0e775c4b07651776e14f9c2373ab9fb1ab2c988c194c90b9edaa3a3b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d65636c697078652f6d6963726f2d2d636174616c6f672d626c75653f7374796c653d666c61742d737175617265)](https://github.com/eclipxe13/micro-catalog)[![Packagist PHP Version Support](https://camo.githubusercontent.com/b73bb22f6a14af209ee5b52bc30a7aabc285968800bf4cf59934582ba894dee8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f65636c697078652f6d6963726f2d636174616c6f673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/eclipxe/micro-catalog)[![Latest Version](https://camo.githubusercontent.com/65e0afbfe8b7f6535108ebd7430d37d58b7572150919648e56020660d2834a1f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f65636c6970786531332f6d6963726f2d636174616c6f673f7374796c653d666c61742d737175617265)](https://github.com/eclipxe13/micro-catalog/releases)[![Software License](https://camo.githubusercontent.com/444cba318db9ee8de9b486169b32673955c49555d4f38249da50374a27c313d0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f65636c6970786531332f6d6963726f2d636174616c6f673f7374796c653d666c61742d737175617265)](https://github.com/eclipxe13/micro-catalog/blob/main/LICENSE)[![Build Status](https://camo.githubusercontent.com/e9706e77a276d6ee99ffd4978131d27152991943f8378158389a0cb4809dad80/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f65636c6970786531332f6d6963726f2d636174616c6f672f6275696c642e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265)](https://github.com/eclipxe13/micro-catalog/actions/workflows/build.yml?query=branch:main)[![Scrutinizer](https://camo.githubusercontent.com/91f53e9b1e1f54950074285da191d88cefaa15c27d7b0fe1479e559f279c8c0e/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f65636c6970786531332f6d6963726f2d636174616c6f672f6d61696e3f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/eclipxe13/micro-catalog/)[![Coverage Status](https://camo.githubusercontent.com/3efbc5740b0efd4ba650b8cd904f6e44730d8739ac056925a56b21f4489e382c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f65636c6970786531332f6d6963726f2d636174616c6f672f6d61696e3f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/eclipxe13/micro-catalog/code-structure/main/code-coverage)[![Total Downloads](https://camo.githubusercontent.com/1776b6556f0a11254de3e9a38b6a6f74dad7d4ac9de58ffea09bbd24c3477ad3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f65636c697078652f6d6963726f2d636174616c6f673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/eclipxe/micro-catalog)

> Micro catalog PHP template class, useful to create value objects based on a known small catalog.

Several times I have the need for a catalog, by example, when receiving a result code and correlate to specific related values. This library helps me to resolve this common problem, and it may help you too.

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

[](#installation)

Use [composer](https://getcomposer.org/), install using:

```
composer require eclipxe/micro-catalog
```

Usage
-----

[](#usage)

`MicroCatalog` is a template class, so you need to extend it to use it. Strictly speaking, you only need to implement two abstract methods: `getEntriesArray(): array` and `getEntryValueOnUndefined(): mixed`.

The sugar lives on `is(): bool` and `get(): bool`, with the special case of `isUndefined(): bool`. The `is()` methods allow to distinct a type by its index. The `get()` methods allow to get a *string key* from the *value array* when it has content.

See the following examples:

- [`ResultCodes`](https://github.com/eclipxe13/micro-catalog/blob/main/tests/Fixtures/ResultCodes.php)Common usage with value as `scalar`, allows undefined properties.
- [`ComplexArray`](https://github.com/eclipxe13/micro-catalog/blob/main/tests/Fixtures/ComplexArray.php)Common usage with value as `array`, get property, allows undefined properties.
- [`ComplexObject`](https://github.com/eclipxe13/micro-catalog/blob/main/tests/Fixtures/ComplexObject.php)Common usage with value as `object`, get property, disable undefined properties.

### `MicroCatalog` example

[](#microcatalog-example)

```
