PHPackages                             zemd/micro - 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. [API Development](/categories/api)
4. /
5. zemd/micro

AbandonedArchivedLibrary[API Development](/categories/api)

zemd/micro
==========

Microservices router and handler component

1.0.0(9y ago)014MITPHPPHP &gt;=5.6

Since Nov 21Pushed 9y ago1 watchersCompare

[ Source](https://github.com/zemd/micro)[ Packagist](https://packagist.org/packages/zemd/micro)[ Docs](https://reactive.world)[ RSS](/packages/zemd-micro/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Micro
=====

[](#micro)

> Lightweight domain driven rest api architecture

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

[](#installation)

```
composer require zemd/micro
```

Usage
-----

[](#usage)

This is lightweight approach to manage rest api calls translate them into pretty domain objects and route to handler. Such approach lets to avoid messy boilerplate code during handling api requests.

So you have some specific code that handles "requests" and returns some data. It is independent code that can be placed in rabbitMQ consumer or elsewhere on the net. Let's call it **handler** and define that each such handler must implement simple method `handle`.

As such `handler` doesn't know about http requests it receives in it's parameter some **command** object. It nothing else than serializable object that can be transferred via any transport mechanism without data loss.

```
class FeatureHandler implements HandlerInterface {
  public function handle(CommandInterface $command, $context) {
    // do stuff
    return "response";
  }
}
```

To make it accessible to some router that will look up for handlers there need to be passed some **meta** information about your endpoint and it's destination. In systems where endpoint can be physically be placed in different servers, you can share meta information in your target services, and return collected info in instance of **HandlerMetaInterface** interface.

```
class FeatureMetaInformation implements HandlerMetaInterface {
    public function getMethods() {
      return ['GET'];
    }

    // Unique string that match handler name, it should be possible to be constructed from request string
    public function getEndpoint() {
      return '/users/search';
    }

    public function getCommandGuesser() {
      return false; // If false returns getCommandClass() method will be used.
    }

    public function getCommandClass() {
      return 'my.command.as.service'; // or FeatureCommand::class
    }

    public function getDescription() {
      return 'Some cool feature';
    }
}
```

Do not forget to tag your meta provider in **services.yml**

```
my.feature.handler.meta.information:
  class: Namespace\To\My\FeatureMetaInformation
  tags:
    - zemd.micro.handler_meta
```

Now we have information and handler, we can continue with building **Command**. Commands are building automatically with **CommandBuilder**, so you should only define it with passing additional information using annotations and make command available to builder and handler.

`@RequestParam` - says that prop's value is defined in request under desired alias, can define custom pattern to validate, and set if this parameter is required to build command.

`@Type` - says that prop is defined as object type

You can defined your own annotations if you wish.

```
  class FeatureCommand implements CommandInterface {
    /**
     * @RequestParam("mobile", pattern="\+\d{8,13}", required=true)
     * @Type("\My\Project\ValueObjects\MobileObject")
     * @Constraints\NotNull()
     */
    protected $mobile;

    /**
     * @RequestParam("country_code", required=false)
     * @Type("\My\Project\ValueObjects\CountryInfoObject")
     */
    protected $countryInfo;

    /**
     * @RequestParam("lang", required=false)
     */
    protected $lang;

    // ... getters/setters/serialize/unserialize
  }
```

As you can see this class is plain domain without any complexity.

So now we have **handler**, **meta** and **command** and we already can launch our command pipe. We can define one controller action that will be responsible for handling all api calls.

```
class TestController {
  public function handleAction($param1, $param2, $param3, Request $request) {
    $checkpoint = "$param1/$param2/$param3";

    $handlerMetaManager = new HandlerMetaManager();
    $handlerMeta = $handlerMetaManager->getMeta($checkpoint);

    $commandBuilder = new CommandBuilder();
    // in case command guesser returns service id, container must be passed to builder
    $commandBuilder->setContainer($container);

    $command = $commandBuilder->setRequest($request)
                  ->setMeta($handlerMeta)
                  ->build();

    $handlerDispatcher = new CommandDispatcher($config);
    $result = $handlerDispatcher->dispatch($command);

    // now we have $result with response
    // we can serialize it in json/xml/...

    return $result;
  }
}
```

Advanced usage
--------------

[](#advanced-usage)

For now we built simple handler that is placed on the same machine. But what if we want to make it distributed and asynchronous. You can achieve this by implementing `CommandDispatcherInterface`. By default `CommandDispatcher` supports rabbitmq via **old\_sound\_rabbit\_mq** package. This requires to implement you `Consumer`, inside of it you should transfer command to handler and return response using rabbitmq xml/rpc mechanism. In such architecture you can implement simple map/reduce handler or run several heavy computations asynchronously inside handler and then return result back.

License
-------

[](#license)

Micro is released under the MIT license.

Donate
------

[](#donate)

[![](https://camo.githubusercontent.com/f9e075baad95563481d35174d43ef50757281abb6bc795d0f473fad452afa030/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617472656f6e2d646f6e6174652d79656c6c6f772e737667)](https://www.patreon.com/red_rabbit)[![](https://camo.githubusercontent.com/d79e412f78041f87e203449041ad81848a8405cf0f3c622c51e3bad0c2a4b599/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f666c617474722d646f6e6174652d79656c6c6f772e737667)](https://flattr.com/profile/red_rabbit)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

3462d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d46cc103bcb14e2302c7c06da8a4099048bd275d956b403c14ded18a99ddb62d?d=identicon)[zemd](/maintainers/zemd)

---

Top Contributors

[![zemd](https://avatars.githubusercontent.com/u/433708?v=4)](https://github.com/zemd "zemd (3 commits)")

---

Tags

microservicesmicroservices-architecturephpsymfony

### Embed Badge

![Health badge](/badges/zemd-micro/health.svg)

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

###  Alternatives

[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)[hubspot/api-client

Hubspot API client

23414.2M16](/packages/hubspot-api-client)

PHPackages © 2026

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