PHPackages                             liamhackett/valueobjectcompiler - 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. liamhackett/valueobjectcompiler

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

liamhackett/valueobjectcompiler
===============================

Compile strict type, read only value objects from JSON

0.0.2(2y ago)0192BSD-3-ClausePHPPHP ^8.2||^8.3

Since Dec 9Pushed 2y ago1 watchersCompare

[ Source](https://github.com/liamh101/value-object-compiler)[ Packagist](https://packagist.org/packages/liamhackett/valueobjectcompiler)[ RSS](/packages/liamhackett-valueobjectcompiler/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (7)Versions (8)Used By (0)

Value Object Compiler
=====================

[](#value-object-compiler)

[![Source Code](https://camo.githubusercontent.com/8df53863c7fb5384ec19679bfdd93203014bf1015bf7507ec5422a3f6b023081/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d6c69616d6861636b6574742f76616c75656f626a656374636f6d70696c65722d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/liamh101/value-object-compiler)[![Latest Version](https://camo.githubusercontent.com/8b74284980d77352e2d915d6162568207d03b80999ba69a1b6f78a12b80758e5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c69616d6861636b6574742f76616c75656f626a656374636f6d70696c65722e7376673f7374796c653d666c61742d737175617265266c6162656c3d72656c65617365)](https://packagist.org/packages/liamhackett/valueobjectcompiler)[![Software License](https://camo.githubusercontent.com/fae50830a9780e7c244be088318f14fcb95ceb73e5c03f688481f2ab80d812a4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c69616d6861636b6574742f76616c75656f626a656374636f6d70696c65722e7376673f7374796c653d666c61742d737175617265)](https://github.com/liamh101/value-object-compiler/blob/master/LICENSE)[![PHP Version](https://camo.githubusercontent.com/9a93db545ee4ded2dbd9f435892776d04e219419f58498c5caee81a0c7564d5f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6c69616d6861636b6574742f76616c75656f626a656374636f6d70696c65722e7376673f7374796c653d666c61742d737175617265)](https://php.net)[![Coverage Status](https://camo.githubusercontent.com/ff023a491b3d61603d80a383d300615c7107d46faee74cc482898f94b8cf9970/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6769746875622f6c69616d683130312f76616c75652d6f626a6563742d636f6d70696c65722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/repos/github/liamh101/value-object-compiler?branch=master)[![Build](https://camo.githubusercontent.com/af0b4c722457093b841d0723c1c00d20b4e8057f5d0960460092ce461b5648ae/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c69616d683130312f76616c75652d6f626a6563742d636f6d70696c65722f616374696f6e732e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/liamh101/value-object-compiler/actions?query=event%3Apush+workflow%3ABuild+branch%3Amaster)

*This is currently in Alpha*

This package takes a source file, such as JSON and creates strict typed, PSR12, readonly Value Objects.

The aim is to slowly support more file formats with the same file output.

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

[](#installation)

`composer require --dev liamhackett/valueobjectcompiler`

How To Use
----------

[](#how-to-use)

### Single JSON file Compiler

[](#single-json-file-compiler)

`vendor/bin/ValueObjectCompiler compile:json {jsonLocation} --outputDir={dir}`

Single file compiler will take a JSON file and output its value object representation. By default, it will output in the current Directory, but you can specify your own directory using the `outputDir` flag.

#### Example

[](#example)

`example.json`

```
{
  "id": 12,
  "name": "Json Object",
  "status": "Published",
  "tags": ["tag1", "tag2", "tag3"],
  "sub_objects": [
    {
      "name": "Hello",
      "value": 13.132
    },
    {
      "name": "World",
      "value": null
    }
  ]
}
```

`Example.php`

```
