PHPackages                             subcosm/hive-foundation - 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. subcosm/hive-foundation

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

subcosm/hive-foundation
=======================

Hive Container Components Foundation

v1.1.0(9y ago)36MITPHPPHP &gt;=7.1

Since Apr 13Pushed 9y ago2 watchersCompare

[ Source](https://github.com/subcosm/hive-foundation)[ Packagist](https://packagist.org/packages/subcosm/hive-foundation)[ RSS](/packages/subcosm-hive-foundation/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

hive-foundation
===============

[](#hive-foundation)

Hive Foundation is Container Components Foundation the delivers feature-rich hierarchical Key-Value node-based containers with an omni-present query interface.

General Status:
[![Build Status](https://camo.githubusercontent.com/ab14ddce7ae26537a7c8b89f1255052c4f6575676c28098defe9d6b40b8b6501/68747470733a2f2f7472617669732d63692e6f72672f737562636f736d2f686976652d666f756e646174696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/subcosm/hive-foundation)[![codecov](https://camo.githubusercontent.com/9a5f5cc09ca46d3bd09801008323bbfe2cfb56b4ac2aa6aa1d1fef595f80e724/68747470733a2f2f636f6465636f762e696f2f67682f737562636f736d2f686976652d666f756e646174696f6e2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/subcosm/hive-foundation)[![SensioLabsInsight](https://camo.githubusercontent.com/f575159d2ff60cd539424cd9402b250b61be592daf69840aa08ddeca2970bd7c/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f31663961323163372d376338612d346330652d393930342d6564333230383133363766312f6d696e692e706e67)](https://insight.sensiolabs.com/projects/1f9a21c7-7c8a-4c0e-9904-ed32081367f1)[![Code Climate](https://camo.githubusercontent.com/f91e3794e91b7930add37b094b2bf2ee2597bde387d42663f7b70c735db3c610/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f6769746875622f737562636f736d2f686976652d666f756e646174696f6e2e737667)](https://codeclimate.com/github/subcosm/hive-foundation)[![Gittip](https://camo.githubusercontent.com/d53d5a8bb4923b56b1dbe791f52e66ce0e9ba91c9daedb1939429ab945fe3c98/687474703a2f2f696d672e736869656c64732e696f2f6769747469702f737562636f736d2e737667)](https://gittip.com/subcosm/)

Integrity and Usage:
[![Downloads](https://camo.githubusercontent.com/0d7b13d6ae981e0989074358d1c5f0bd7bf28f416ddb7da632d95df0026f5b59/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f646f776e6c6f6164732f737562636f736d2f686976652d666f756e646174696f6e2f746f74616c2e737667)](https://camo.githubusercontent.com/0d7b13d6ae981e0989074358d1c5f0bd7bf28f416ddb7da632d95df0026f5b59/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f646f776e6c6f6164732f737562636f736d2f686976652d666f756e646174696f6e2f746f74616c2e737667)[![Latest](https://camo.githubusercontent.com/a77c738c569c9352fcf540424f6e2f4b0b346cc64793666b2cb53af0d8b9387a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737562636f736d2f686976652d666f756e646174696f6e2e737667)](https://packagist.org/packages/subcosm/hive-foundation)

### Dependencies

[](#dependencies)

- [psr/container](https://packagist.org/packages/psr/container)
- [subcosm/observatory](https://packagist.org/packages/subcosm/observatory)
- PHP 7.1 or higher.

Optionally:

- `ext/spl` if do want to use `SplFileObject`'s for loaders.

### What is a hive node?

[](#what-is-a-hive-node)

A hive node implements one leaf of a hierarchy where you may set values to the node itself, child nodes or the root node with simple commands.

### How do i...

[](#how-do-i)

The following examples explain how hive nodes in general do work.

##### ... create a root node?

[](#-create-a-root-node)

Root nodes are the top-level node of any node hierarchy, there can be only one root node but as many child nodes as you need. Root nodes are created like this:

```
use Subcosm\Hive\Container\HiveNode;

$root = new HiveNode();
```

##### ... append child nodes?

[](#-append-child-nodes)

Hive nodes are self-extending, you may create nodes by yourself by calling `HiveNode::node($nodeName, true)`.

##### ... append values to a node?

[](#-append-values-to-a-node)

Like this:

```
use Subcosm\Hive\Container\HiveNode;

$root = new HiveNode();

$root->set('foo', 'bar');
```

##### ... append lazy loading for values?

[](#-append-lazy-loading-for-values)

Hive nodes do see closures as lazy-load values, just wrap what you want to be lazy loaded into a closure.

```
use Subcosm\Hive\Container\HiveNode;

$root = new HiveNode();

$root->set('foo', function() {
    return 'Hello World';
});
```

##### ... get a value from a node?

[](#-get-a-value-from-a-node)

Like this:

```
use Subcosm\Hive\Container\HiveNode;

$root = new HiveNode();

$root->set('foo', function() {
    return 'Hello World';
});

echo $root->get('foo'); // = Hello World
```

##### ... set or get values hierarchically?

[](#-set-or-get-values-hierarchically)

Hive nodes implement a hierarchy-safe query mechanism to get and store values into the hierarchy.

```
use Subcosm\Hive\Container\HiveNode;

$root = new HiveNode();

$root->set('router', function() use ($root) {
    return $root->get('router.factory')->factorize();
});

$root->set('router.factory', function() {
    return new RouterFactory();
});

$router = $root->get('router');
```

In the first set instruction, the key `router` of the root node will receive the closure. The second set instruction will (automatically) create the node 'router' (not value-key), and the key `factory` at the `router`-node who will receive the closure.

You can also access the root node from sub nodes:

```
use Subcosm\Hive\Container\HiveNode;

$root = new HiveNode();

$root->set('logger', function() {
    return new Monolog\Logger();
});

$routing = $root->node('router', true);

$root->set('router', function() use ($routing) {
    return $routing->get('factory')->factorize();
});

$routing->set('factory', function() use ($routing) {
    return new RouteFactory($routing->get('~logger'));
});

$router = $root->get('router');

// or

$router = $routing->get('~router');
```

### Is there any hook or event mechanism?

[](#is-there-any-hook-or-event-mechanism)

Yes and no. You can not manipulate values from outside the hive structure using events, but you can observe a hive node and issue events in your event dispatcher of your choice using the `Observatory`- Implementation of each hive node.

The available observer stages can be found at the `HiveInterface` and `DeclarationAwareInterface` represented by `*_STAGE` constants.

`Observatory`-Observers are shared across the entire hive structure and can be altered to own observer queues from each parent independently.

### Can i assign nodes manually?

[](#can-i-assign-nodes-manually)

No. Whenever you assign items to a container they will remain items as they were set (a closure is the only exception here). You have to use `HiveNode::node($name, true)` to create new child-nodes, or you just let the hive node create them for you. The inability to set nodes manually was decided because of avoiding conflicts of query divider and root definition tokens across node structures. Integrity first.

### Whats about value validation?

[](#whats-about-value-validation)

The `HiveNode` itself does not provided an interface to validate values. `DeclarativeHiveNode` provides an interface to declare a validator on a per item level or a default validator for all items and sub nodes.

The provided callback receives the value to set as the first parameter and requires to return the value to be set to the hive node, otherwise the value will default to null.

```
use Subcosm\Hive\Container\DeclarativeHiveNode;

$node = new DeclarativeHiveNode();

$node->entity('foo', function($value) {
    if ( ! is_string($value) ) {
        throw new InvalidArgumentException('Value must be string for foo');
    }

    return $value;
});

$node->set('foo', 12345); // throws the exception
$node->set('foo', '12345'); // sets the value
```

```
use Subcosm\Hive\Container\DeclarativeHiveNode;

$node = new DeclarativeHiveNode();

$node->defaultEntity(function($value) {
    return is_array($value) || is_object($value) ? json_encode($value) : (string) $value;
});

$node->set('foo', 12345); // foo => '12345'
$node->set('foo', ['foo' => 'bar']); // foo => {"foo":"bar"}
```

### Import data to nodes with loaders

[](#import-data-to-nodes-with-loaders)

```
use Subcosm\Hive\{
    Container\HiveNode,
    Loader\ArrayLoader
};

$node = new HiveNode();
$loader = new ArrayLoader();
$loader->load([
    'foo.bar' => 'baz'
]);

$loader->injectInto($node);

echo $node->get('foo.bar'); // => "baz"
```

### Package Stability and Maintainers

[](#package-stability-and-maintainers)

This package is considered stable. The maintainers of this package are:

- [Matthias Kaschubowski](https://github.com/nhlm)

### License

[](#license)

This package is licensed under the [MIT-License](LICENSE).

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

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 ~0 days

Total

4

Last Release

3364d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7180946?v=4)[Nihylum Development Workspace](/maintainers/nihylum)[@Nihylum](https://github.com/Nihylum)

---

Top Contributors

[![nhlm](https://avatars.githubusercontent.com/u/23406211?v=4)](https://github.com/nhlm "nhlm (16 commits)")

---

Tags

containerpsr-11

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/subcosm-hive-foundation/health.svg)

```
[![Health](https://phpackages.com/badges/subcosm-hive-foundation/health.svg)](https://phpackages.com/packages/subcosm-hive-foundation)
```

###  Alternatives

[symfony/dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application

4.2k447.1M9.1k](/packages/symfony-dependency-injection)[illuminate/contracts

The Illuminate Contracts package.

706127.7M12.7k](/packages/illuminate-contracts)[illuminate/container

The Illuminate Container package.

31180.7M2.3k](/packages/illuminate-container)[symfony/type-info

Extracts PHP types information.

20062.9M225](/packages/symfony-type-info)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

562565.8k42](/packages/ecotone-ecotone)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751284.3k37](/packages/civicrm-civicrm-core)

PHPackages © 2026

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