PHPackages                             selami/entity - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. selami/entity

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

selami/entity
=============

A library to assert variable types and values for a model defined using JSON Schema standard (draft-07 and draft-06).

1.4.2(7y ago)38MITPHPPHP ^7.2

Since Nov 6Pushed 7y ago2 watchersCompare

[ Source](https://github.com/selamiphp/entity)[ Packagist](https://packagist.org/packages/selami/entity)[ RSS](/packages/selami-entity/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (10)Dependencies (6)Versions (12)Used By (0)

Selami Entity
=============

[](#selami-entity)

Framework agnostic entity/value object library to assert variable types and values for a model defined using JSON Schema standard (draft-07 and draft-06) written in PHP 7.2

[![Build Status](https://camo.githubusercontent.com/dc1387e55e3ad9050c4f36a5a390674b70a1d90ec7066dea820c7afbb655e9fc/68747470733a2f2f6170692e7472617669732d63692e6f72672f73656c616d697068702f656e746974792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/selamiphp/entity) [![Coverage Status](https://camo.githubusercontent.com/df95f60601f5d523979cef7458a42d2e89d8e34a493f52e241a0d1cdd03092fa/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f73656c616d697068702f656e746974792f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/selamiphp/entity?branch=master) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/7f1218b1670e866f99453f6d593bbff7f8dea310de29110da800d38ba1501bca/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73656c616d697068702f656e746974792f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/selamiphp/entity/) [![Codacy Badge](https://camo.githubusercontent.com/946ad5fcbfb82aaa60d6078a107fa0c5ab06a21cee41c949d358d93a8683eef8/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f6435363435363564626337353433373661396430323237333165633161663735)](https://www.codacy.com/app/mehmet/entity?utm_source=github.com&utm_medium=referral&utm_content=selamiphp/entity&utm_campaign=Badge_Grade) [![Latest Stable Version](https://camo.githubusercontent.com/54c3552a691ce0d3b0e56f852d2077ee46b0161ccea6e99b2ecd2368c6acd417/68747470733a2f2f706f7365722e707567782e6f72672f73656c616d692f656e746974792f762f737461626c65)](https://packagist.org/packages/selami/entity) [![Total Downloads](https://camo.githubusercontent.com/841795c5b5632d35540ff76105b35951756cff293533ac7c271c63e0a9e320fb/68747470733a2f2f706f7365722e707567782e6f72672f73656c616d692f656e746974792f646f776e6c6f616473)](https://packagist.org/packages/selami/entity) [![Latest Unstable Version](https://camo.githubusercontent.com/5ab09f7b635093d81e898dfeb312397f7ee4e397da022a9ffa09934e270ca617/68747470733a2f2f706f7365722e707567782e6f72672f73656c616d692f656e746974792f762f756e737461626c65)](https://packagist.org/packages/selami/entity) [![License](https://camo.githubusercontent.com/1edfe1d5a0923aa1c6255dac2cf1b98b2cdfe050a5fd039bc6a75947d170b50d/68747470733a2f2f706f7365722e707567782e6f72672f73656c616d692f656e746974792f6c6963656e7365)](https://packagist.org/packages/selami/entity)

Motivation
----------

[](#motivation)

This library is a kind of helper library to generate your own Entity or Value Object models using JSON Schema. It is not expected to use classes in this library directly (See Examples for intended usage section below). To understand differences between Entities and Value Objects read Philip Brown's post on [culttt.com](https://www.culttt.com/2014/04/30/difference-entities-value-objects/)

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

[](#installation)

```
composer require selami/entity
```

### Value Objects ([See the explanation](https://martinfowler.com/bliki/ValueObject.html))

[](#value-objects-see-the-explanation)

- Objects created using ValueObject are [Immutable](https://en.wikipedia.org/wiki/Immutable_object). This means only data injecting point is its constructor.
- It validates data on object creation
- If validation fails it throws InvalidArgumentException.
- Always use ValueObjectBuilder to create a ValueObject instance.

##### Convention when using ValueObjectBuilder

[](#convention-when-using-valueobjectbuilder)

- Uppercase first character of property name.
- Then add "with" prefix to property name.

i.e. Say our property name is creditCardNumber, then setter method name for this property is withCreditCardNumber.

#### Usage

[](#usage)

Say you have a JSON Schema file at ./models/credit-card.json. See [the Credit Card Value Object Schema](https://github.com/selamiphp/entity/blob/master/tests/resources/test-schema-credit-card-value-object.json).

```
