PHPackages                             spaark/composite-utils - 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. [Framework](/categories/framework)
4. /
5. spaark/composite-utils

AbandonedLibrary[Framework](/categories/framework)

spaark/composite-utils
======================

Composite Object Model Utilities

v1.1.0(9y ago)1124[1 issues](https://github.com/spaark/composite-utils/issues)[1 PRs](https://github.com/spaark/composite-utils/pulls)MITPHPPHP &gt;=7.1

Since Feb 12Pushed 8y ago1 watchersCompare

[ Source](https://github.com/spaark/composite-utils)[ Packagist](https://packagist.org/packages/spaark/composite-utils)[ Docs](https://www.spaark.io/)[ RSS](/packages/spaark-composite-utils/feed)WikiDiscussions master Synced yesterday

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

Composite Utils
===============

[](#composite-utils)

[![Build Status](https://camo.githubusercontent.com/563bf98d1e2c9f6bd690614c678ceb1268ddb04c056e6af2f3bb6695b3d4367d/68747470733a2f2f7472617669732d63692e6f72672f73706161726b2f636f6d706f736974652d7574696c732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/spaark/composite-utils)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/ac2ba614331ca1bed9b428c7d4870ff0b6a638350bf0104eb1ea7b9db59de8f9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73706161726b2f636f6d706f736974652d7574696c732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/spaark/composite-utils/)[![Code Coverage](https://camo.githubusercontent.com/d9621aacfe8e6daf1380d1fa05502319b2d7fd7a5528860aa51ec514367e5be6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73706161726b2f636f6d706f736974652d7574696c732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/spaark/composite-utils/)

A set of utilities which make interacting with Composite Objects easier

The problem
-----------

[](#the-problem)

Composite objects are normally little more than a collection of properties with meaningful names. While this is definitely better than just using an array, this normally requires a long set of getters and setters; these often do nothing but move the value around:

```
public function setProperty($value)
{
    $this->property = $value;
}

public function getProperty()
{
    return $this->property;
}
```

Bloat, bloat, bloat!

That's nine lines of code to reimplement what is just `$object->property = $value`. At best, these lines might enforce some form of datatype value:

```
public function setProperty(RequiredPropertyType $value)
{
    $this->property = $value;
}
```

This problem also exists in constructors, how often have you seen something like this:

```
public function __construct($value1, $value2, $value3, $value4, $value5)
{
    // Set values
    $this->value1 = $value1;
    $this->value2 = $value2;
    $this->value3 = $value3;
    $this->value4 = $value4;
    $this->value5 = $value5;

    // Init Values
    $this->value6 = new Collection();
    $this->value7 = new HashMap();
}
```

The solution
------------

[](#the-solution)

This library introduces a set of tools to remove the need to composite getters, setters and bloated constructors without giving up your control over property access and data type enforcement.

```
class MyAwesomeComposite
{
    use AutoConstructTrait;
    use PropertyAccessTrait;

    /**
     * @var int
     */
    protected $property = 42;

    /**
     * @var string
     * @readable
     * @writable
     */
    protected $stringProperty = 'some value';

    /**
     * @var DataType
     * @readable
     * @construct required
     */
     protected $iNeedThis;

    /**
     * @var ArrayObject
     * @readable
     * @construct new
     */
    protected $collection;
}
```

That's it. Nothing more required! All the properties other than `$property` can be accessed when required, and `$collection` will be automatically constructed for you. Although you can't see it, this entity also has a constructor present which requires... you guessed it... The `$iNeedThis` property, and it needs to be a `DataType`. `$stringProperty` is also writable, if anything other than a string is passed to it, it will be automatically cast to one if possible:

```
$class = new MyAwesomeComposite(); // Fails, $iNeedThis is required

$iNeedThis = new OtherDataType();
$class = new MyAwesomeComposite(); // Fails, $iNeedThis should be a DataType

$iNeedThis = new DataType();
$class = new MyAwesomeComposite($iNeedThis); // All good!

var_dump($class->property); // Fails, not readable
var_dump($class->stringProperty); // string(10) "some value"

$class->stringProperty = 00000000123;
var_dump($class->stringProperty); // string(3) "123"

$class->iNeedThis = new DataType(); // Fails, not writable

var_dump($class->collection); // ArrayObject { }

var_dump($class->iNeedThis === $iNeedThis); // true
```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

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

Total

3

Last Release

3399d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2132420?v=4)[Emily L Shepherd](/maintainers/EmilyShepherd)[@EmilyShepherd](https://github.com/EmilyShepherd)

---

Top Contributors

[![EmilyShepherd](https://avatars.githubusercontent.com/u/2132420?v=4)](https://github.com/EmilyShepherd "EmilyShepherd (187 commits)")

---

Tags

composite-utilsopen-sourceopensourcephpphp-libraryphp-utilityphp7utility-libraryphpframeworklibrarySpaark

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spaark-composite-utils/health.svg)

```
[![Health](https://phpackages.com/badges/spaark-composite-utils/health.svg)](https://phpackages.com/packages/spaark-composite-utils)
```

###  Alternatives

[digitalstars/simplevk

Powerful PHP library/framework for VK API bots, supporting LongPoll &amp; Callback &amp; OAuth

924.2k3](/packages/digitalstars-simplevk)[marwanalsoltany/mighty

The last validation library you will ever need!

591.3k](/packages/marwanalsoltany-mighty)[ollyxar/websockets

PHP WebSocket server

311.9k1](/packages/ollyxar-websockets)

PHPackages © 2026

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