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

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

nayjest/builder
===============

PHP package for instantiating objects using configurations

v2.1.0(10y ago)14196.0k↓25.4%[4 issues](https://github.com/Nayjest/Builder/issues)6MITPHPPHP &gt;=5.4.0

Since Feb 19Pushed 10y ago2 watchersCompare

[ Source](https://github.com/Nayjest/Builder)[ Packagist](https://packagist.org/packages/nayjest/builder)[ RSS](/packages/nayjest-builder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (4)Versions (8)Used By (6)

Builder
=======

[](#builder)

PHP package for constructing objects using configurations.

[![Codacy Badge](https://camo.githubusercontent.com/2fafef6f00f4d8352d141a876fcf95ac65fb352cd4a9d2fb8978a4c112e9603c/68747470733a2f2f7777772e636f646163792e636f6d2f70726f6a6563742f62616467652f3462616463363761663333343436656661633832353862383438313931326464)](https://www.codacy.com/public/mail_2/Builder)[![Code Climate](https://camo.githubusercontent.com/90552db019c01be3d731eea3202c7abe8928158a8509d7eab77dd10f42df512e/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f4e61796a6573742f4275696c6465722f6261646765732f6770612e737667)](https://codeclimate.com/github/Nayjest/Builder)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/f28118f58aaf0f6ab4be0222416c1e22e5c64e3816a08ce097295c3eabd9e037/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4e61796a6573742f4275696c6465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Nayjest/Builder/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/418474bf5c001b22a7f91be0ae3d2d47032586b856620780caf4180c5990961b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4e61796a6573742f4275696c6465722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Nayjest/Builder/?branch=master)[![Build Status](https://camo.githubusercontent.com/9271be8690df20abc326dc17b5a8826fe9c06ccfc90df494ff9e6dfa24b2d03a/68747470733a2f2f7472617669732d63692e6f72672f4e61796a6573742f4275696c6465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Nayjest/Builder)[![Latest Stable Version](https://camo.githubusercontent.com/c731e5d747949fb7c12ceb177dfb2fb8f3d670854929890beab6c0253b317249/68747470733a2f2f706f7365722e707567782e6f72672f6e61796a6573742f6275696c6465722f762f737461626c652e737667)](https://packagist.org/packages/nayjest/builder)[![Dependency Status](https://camo.githubusercontent.com/39606ebb99927b5de27239640dbe16c42842f5002002868e26f605fc8cb07a0c/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3534663938623930346633313038653738303030303065372f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/54f98b904f3108e7800000e7)

[![SensioLabsInsight](https://camo.githubusercontent.com/0e3079049d6b289e839c5ced6a15bc0e644e8fd4f1b1917e2c9df782afa920c0/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f34636134373463322d643733312d346364662d616339332d3931333866396638393037652f6269672e706e67)](https://insight.sensiolabs.com/projects/4ca474c2-d731-4cdf-ac93-9138f9f8907e)

1. Requirements
---------------

[](#1-requirements)

- php 5.4+

This package is not tested with [outdated versions of PHP](http://php.net/supported-versions.php).

If you need to use nayjest/builder in environments with php &lt;= 5.3, test it on your own.

2. Installation
---------------

[](#2-installation)

The recommended way of installing the component is through [Composer](https://getcomposer.org).

Run following command:

```
composer require nayjest/builder
```

3. Overview
-----------

[](#3-overview)

#### 3.1 Purpose

[](#31-purpose)

Building complex objects from configurations in architecturally beutiful way.

#### 3.2 Explanation

[](#32-explanation)

If you are confident with [builder design pattern](https://en.wikipedia.org/wiki/Builder_pattern), this package allows you to create builders for your classes in declarative style, based on build configuration.

#### 3.3 Usage

[](#33-usage)

##### 3.3.1 Class Blueprints

[](#331-class-blueprints)

When you need to construct objects of some type, first of all, you will create blueprint for that type. In terminology of this package *blueprint* specifies *how to construct object of some specified type*. It stores class name and set of build instructiuons.

```
use Nayjest\Builder\Blueprint;
$blueprint = new Blueprint(
  '\My\ExamplePackage\Person',  # Constructed class name
  []                            # Array of build instructions
);
```

##### 3.3.2 Builders

[](#332-builders)

Next, you will instantiate a builder with previously created blueprint as constructor argument. In terminology of this package, *builder* is a instance of Nayjest\\Builder\\Builder class, initialized with a blueprint of constructed class. This object has public *build($input)* method that accepts constructed class configurations, builds instance and returns it.

Builders are suitable for reusing. You can build multiple objects specified by same blueprint using same builder.

```
use Nayjest\Builder\Builder;

$builder = new Builder($blueprint);

$john = $builder->build([
  'name' => 'John',
  'age' => 27
]);

var_dump($john instanceof \My\ExamplePackage\Person); // result: true
var_dump($john->getAge());  // result: 27
```

##### 3.3.3 Scaffold and Instructions

[](#333-scaffold-and-instructions)

During taget object building, builder creates temporary object, called *scaffold*. Scaffold contains all information needed to build object (input config, class name, constructor arguments, target instance when it's ready).

This class is importand since all build instructions works with scaffold, scaffold provides interface for accessing all required data to instructions.

And finally, instructions. In terminology of this package, instruction is an instance of class that implements *Nayjest\\Builder\\Instructions\\Base\\InstructionInterface* and can modify data inside scaffold.

There is a set of predefined instructions, but you can create your own (the dirty way is usage of *Nayjest\\Builder\\Instructions\\Base\\Instruction\\CustomInstruction* initialized by user function that will perform operations you want).

Also, instantiating target object and setting public properties or properties that has *setters* with corresponding names in camel case (i.e. setSomeAttribute($val) for 'some\_attribute' input field) does not requires specific instruction in class blueprint, it's operations, performed by default.

4. Build Instructions
---------------------

[](#4-build-instructions)

#### `Nayjest\Builder\Instructions\CustomInstruction`

[](#nayjestbuilderinstructionscustominstruction)

Applies user function to scaffold.

#### `Nayjest\Builder\Instructions\SetValue`

[](#nayjestbuilderinstructionssetvalue)

Can be used to specify default values in build configuration or overwrite existing.

#### `Nayjest\Builder\Instructions\Remove`

[](#nayjestbuilderinstructionsremove)

Removes value from input configuration if exists.

#### `Nayjest\Builder\Instructions\Mapping\Build`

[](#nayjestbuilderinstructionsmappingbuild)

Replaces value by object builded using specified class blueprint.

#### `Nayjest\Builder\Instructions\Mapping\BuildChildren`

[](#nayjestbuilderinstructionsmappingbuildchildren)

Replaces array elements inside target field by objects builded using specified class blueprint.

#### `Nayjest\Builder\Instructions\Mapping\ClassName`

[](#nayjestbuilderinstructionsmappingclassname)

Uses value in specified field as target class name.

#### `Nayjest\Builder\Instructions\Mapping\ConstructorArgument`

[](#nayjestbuilderinstructionsmappingconstructorargument)

Uses value in specified field as constructor argument.

#### `Nayjest\Builder\Instructions\Mapping\CustomMapping`

[](#nayjestbuilderinstructionsmappingcustommapping)

Applies user function to specified field.

#### `Nayjest\Builder\Instructions\Mapping\Rename`

[](#nayjestbuilderinstructionsmappingrename)

Renames specified field inside input configuration.

5. Testing
----------

[](#5-testing)

Run following command:

```
phpunit
```

6. License
----------

[](#6-license)

© 2014 — 2015 Vitalii Stepanenko

Licensed under the MIT License.

Please see [License File](LICENSE) for more information.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance14

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity63

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

Recently: every ~85 days

Total

7

Last Release

3749d ago

Major Versions

0.1 → 1.02015-03-02

v1.1.3 → v2.0.02015-06-04

### Community

Maintainers

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

---

Top Contributors

[![Nayjest](https://avatars.githubusercontent.com/u/153999?v=4)](https://github.com/Nayjest "Nayjest (94 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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