PHPackages                             chippyash/assembly-builder - 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. chippyash/assembly-builder

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

chippyash/assembly-builder
==========================

Lightweight functional assembly builder pattern with Scala like For Comprehension

3.0.0(4y ago)020.7k↓16.7%25BSD-3-ClausePHPPHP &gt;=8.0

Since Jun 28Pushed 4y ago1 watchersCompare

[ Source](https://github.com/chippyash/Assembly-Builder)[ Packagist](https://packagist.org/packages/chippyash/assembly-builder)[ Docs](http://zf4.biz/packages?utm_source=packagist&utm_medium=web&utm_campaign=blinks&utm_content=assembler)[ RSS](/packages/chippyash-assembly-builder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (15)Used By (5)

chippyash/Assembly-Builder
==========================

[](#chippyashassembly-builder)

Quality Assurance
-----------------

[](#quality-assurance)

[![PHP 5.6](https://camo.githubusercontent.com/88093c79af42bd3c07f4d6aa378289e1f5450411c56753b0323bd7d8b9b1f9ee/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d352e362d626c75652e737667)](https://camo.githubusercontent.com/88093c79af42bd3c07f4d6aa378289e1f5450411c56753b0323bd7d8b9b1f9ee/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d352e362d626c75652e737667)[![PHP 7](https://camo.githubusercontent.com/d23ce60b89c28c023d0ca69981ec9afbb17eb08a9cd1b609fd84c15d0732b7ce/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372d626c75652e737667)](https://camo.githubusercontent.com/d23ce60b89c28c023d0ca69981ec9afbb17eb08a9cd1b609fd84c15d0732b7ce/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372d626c75652e737667)[![Build Status](https://camo.githubusercontent.com/e97c9dd82dfa7595b27721aef3db459228bd00321310a1e32d759f39a5c8fc3c/68747470733a2f2f7472617669732d63692e6f72672f6368697070796173682f417373656d626c792d4275696c6465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/chippyash/Assembly-Builder)[![Code Climate](https://camo.githubusercontent.com/778056e5ef13a638eba2bea97ecd3ec48673d0b3c8896bcddbc6096ce3705c85/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6368697070796173682f417373656d626c792d4275696c6465722f6261646765732f6770612e737667)](https://codeclimate.com/github/chippyash/Assembly-Builder)[![Test Coverage](https://camo.githubusercontent.com/1681b372673b6bbbdd9a6be5a6167d0c2b0906321088d140d74c74dd26ddfe99/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6368697070796173682f417373656d626c792d4275696c6465722f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/chippyash/Assembly-Builder/coverage)

The above badges represent the current development branch. As a rule, I don't push to GitHub unless tests, coverage and usability are acceptable. This may not be true for short periods of time; on holiday, need code for some other downstream project etc. If you need stable code, use a tagged version. Read 'Further Documentation' and 'Installation'.

Developer support for PHP5.4 &amp; 5.5 was withdrawn at version 2.0.0 of this library. If you need support for PHP 5.4 or 5.5, please use a version`>=1,=2,bar(function($foo){return "$foo bar";})
    ->foo(function(){return 'foo foo';})
    ->assemble();
```

At this point, the entries become immutable and cannot be overwritten. You can continue to add additional entries, perhaps referencing earlier ones and then call -&gt;assemble() again to fix the entries.

To retrieve one of more values from the Assembler you use the `release()` method. release() takes one or more strings, the names of the items that you want to release. To release a single item:

```
$myFoo = Assembler::create()
    ->foo(function(){return 'foo})
    ->bar(function($foo){return "$foo bar";})
    ->foo(function(){return 'foo foo';})
    ->assemble()
    ->release('foo');
```

Releasing multiple items will return an array of values, so perhaps the easiest way to access them is to use the venerable PHP `list()` (or \[\]) method, e.g.

```
list($myFoo, $myBar) = Assembler::create()
    ->foo(function(){return 'foo})
    ->bar(function($foo){return "$foo bar";})
    ->foo(function(){return 'foo foo';})
    ->assemble()
    ->release('foo', 'bar');
```

You can merge one Assembler into another using the `merge()` method:

```
$worker1 = Assembler::create()
    ->foo(function(){return 'foo});

$worker2 = Assembler::create()
    ->bar(function($foo){return "$foo bar";})

$myFoo = $worker1->merge($worker2->assemble())
    ->assemble()
    ->release('foo');
```

You can send in parameters during the creation (create() or get()) of an Assembler. This is most useful to prevent you having to use the `use clause` during function definition. Parameters sent in during the create process are immutable, i.e. you cannot override them with a later declaration.

```
$a = 'foo';
$b = 'bar'

$value = Assembler::create(['a'=>$a, 'b'=>$b])
    ->foo(function($a, $b) { return "$a$b";})
    ->assemble()
    ->release('foo');
// $value == 'foobar'

//This will have no effect on 'a'
$value = Assembler::create(['a'=>$a, 'b'=>$b])
    ->a(function() {return 1;})
    ->foo(function($a, $b) { return "$a$b";})
    ->assemble()
    ->release('foo');

//without parameter injection
$value = Assembler::create()
    ->foo(function() use ($a, $b) { return "$a$b";})
    ->assemble()
    ->release('foo');

```

You can utilise the ParameterGrabable trait to facilitate parameter injection into the create() constructor.

```
use Assembler\Traits\ParameterGrabable;
use Assembler\Assembler;

class myClass {
     use ParameterGrabable;

     static function foo($param1, $param2 = null) {
         $a = Assembler::create(self::grabFunctionParameters(__CLASS__, __FUNCTION__, func_get_args());
     }

     function bar($param1, $param2 = null) {
         $a = Assembler::create($this->grabMethodParameters(__CLASS__, __METHOD__, func_get_args());
     }
}
```

### FFor

[](#ffor)

The FFor class is a simple extension of Assembler, but with restrictions:

- you cannot create a singleton FFor via get(). Use create(). FFor is intended as a language construct
- you cannot merge() a FFor.
- there is an additional method; fyield(). fyield() is a pseudonym for -&gt;assemble()-&gt;release() and takes the same parameters as release()

See the examples/CarAssemblyLine.php script for a usage example.

Further documentation
---------------------

[](#further-documentation)

Please note that what you are seeing of this documentation displayed on Github is always the latest dev-master. The features it describes may not be in a released version yet. Please check the documentation of the version you Compose in, or download.

[![Uml diag](https://github.com/chippyash/Assembly-Builder/raw/master/docs/uml.png)](https://github.com/chippyash/Assembly-Builder/blob/master/docs/uml.png)

See the tests and [Test Contract](https://github.com/chippyash/Assembly-Builder/blob/master/docs/Test-Contract.md)for further information.

Check out [ZF4 Packages](http://zf4.biz/packages?utm_source=github&utm_medium=web&utm_campaign=blinks&utm_content=assembler) for more packages

Running the examples
--------------------

[](#running-the-examples)

Although the library itself does not have any other dependencies other than PHP, the examples do. These are included in the `composer requires-dev` statement so as long as you have included the dev requirements (default for Composer,) you should be good to go.

Changing the library
--------------------

[](#changing-the-library)

1. fork it
2. write the test
3. amend it
4. do a pull request

Found a bug you can't figure out?

1. fork it
2. write the test
3. do a pull request

NB. Make sure you rebase to HEAD before your pull request

Or - raise an issue ticket.

Where?
------

[](#where)

The library is hosted at [Github](https://github.com/chippyash/Assembly-Builder). It is available at [Packagist.org](https://packagist.org/packages/chippyash/assembly-builder)

### Installation

[](#installation)

Install [Composer](https://getcomposer.org/)

#### For production

[](#for-production)

```
    "chippyash/assembly-builder": ">=3"
```

Or to use the latest, possibly unstable version:

```
    "chippyash/assembly-builder": "dev-master"
```

#### For development

[](#for-development)

Clone this repo, and then run Composer in local repo root to pull in dependencies

```
    git clone git@github.com:chippyash/Assembly-Builder.git Assembler
    cd Assembler
    composer install
```

To run the tests:

```
    cd Assembler
    vendor/bin/phpunit -c test/phpunit.xml test/
```

License
-------

[](#license)

This software library is released under the [BSD 3 Clause license](https://opensource.org/licenses/BSD-3-Clause)

This software library is Copyright (c) 2015, Ashley Kitson, UK

History
-------

[](#history)

V1.0.0 Initial Release

V1.1.0 Add ability to send in parameters on Assembler and Ffor creation

V1.1.1 Fix parameter order passing bug

V1.1.2 Add ParameterGrabable trait

V1.2.0 Update to use Chippyash\\Type V3

V1.2.1 Add link to packages

V1.2.2 Verify PHP 7 compatibility

V1.2.3 Update dependency on Monad

V1.2.4 Update build scripts

V1.2.5 update composer - forced by packagist composer.json format change

V2.0.0 BC Break. Support withdrawn for old php versions

V2.1.0 Change of license from GPL V3 to BSD 3 Clause

V3.0.0 BC Break. Support for PHP &lt;V8 withdrawn

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 97.6% 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 ~166 days

Recently: every ~308 days

Total

14

Last Release

1821d ago

Major Versions

1.2.5 → 2.0.02018-04-03

2.1.0 → 3.0.02021-05-24

PHP version history (3 changes)1.0.0PHP &gt;=5.4

2.0.0PHP &gt;=5.6

3.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/198575568597b367c8b285de16d278018c8cf292c6c75c535270135c1eea0561?d=identicon)[chippyash](/maintainers/chippyash)

---

Top Contributors

[![chippyash](https://avatars.githubusercontent.com/u/983560?v=4)](https://github.com/chippyash "chippyash (40 commits)")[![akzincsystems](https://avatars.githubusercontent.com/u/73334506?v=4)](https://github.com/akzincsystems "akzincsystems (1 commits)")

---

Tags

functionalbuilder-patternforcomprehension

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/chippyash-assembly-builder/health.svg)

```
[![Health](https://phpackages.com/badges/chippyash-assembly-builder/health.svg)](https://phpackages.com/packages/chippyash-assembly-builder)
```

###  Alternatives

[lstrojny/functional-php

Functional primitives for PHP

2.0k7.3M48](/packages/lstrojny-functional-php)[nikic/iter

Iteration primitives using generators

1.1k5.9M38](/packages/nikic-iter)[lambdish/phunctional

λ PHP functional library

3612.0M23](/packages/lambdish-phunctional)[ihor/nspl

Non-standard PHP library (NSPL) - functional primitives toolbox and more

381368.5k](/packages/ihor-nspl)[qaribou/immutable.php

Immutable, highly-performant collections, well-suited for functional programming and memory-intensive applications.

344146.0k](/packages/qaribou-immutablephp)[crell/fp

Functional utilities for PHP 8 and later

91429.8k11](/packages/crell-fp)

PHPackages © 2026

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