Download the PHP package selami/entity without Composer
On this page you can find all versions of the php package selami/entity. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download selami/entity
More information about selami/entity
Files in selami/entity
Package entity
Short Description A library to assert variable types and values for a model defined using JSON Schema standard (draft-07 and draft-06).
License MIT
Informations about the package 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
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
Installation
Value Objects (See the explanation)
- Objects created using ValueObject are Immutable. 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
- 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
Say you have a JSON Schema file at ./models/credit-card.json. See the Credit Card Value Object Schema.
Entities
- Entities require id property.
- Entities are mutable.
- Entities are not automatically validated on object creation.
- When validation failed it throws InvalidArgumentException.
- It is possible to partially validate Entities.
- It can be used to form data validation, data validation before persisting it, etc...
Usage
Say you have a JSON Schema file at ./models/profile.json. See the Profile Entity Schema.
Partial Validation
Examples for intended usage
Value Object Example
Entity Example
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Ramsey\Uuid\Uuid;
$id = Uuid::uuid4()->toString();
$entity = Profile::create($id);
$entity->name = 'Kedibey';
// Prints "Kedibey"
var_dump($entity->name);
// Throws "Selami\Entity\Exception\InvalidArgumentException"
$entity->validate();