Download the PHP package zero-to-prod/data-model without Composer

On this page you can find all versions of the php package zero-to-prod/data-model. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package data-model

Zerotoprod\DataModel

Repo GitHub Actions Workflow Status Packagist Downloads Packagist Version License

Simplify deserialization for your DTOs.

Use PHP Attributes to resolve and map values to properties on a class.

Transform data into hydrated objects by describing how to resolve values.

Features

Installation

You can install the package via Composer:

Examples

Additional Packages

Usage

Use the DataModel trait in a class.

Hydrating from Data

Use the from method to instantiate your class, passing an associative array or object.

Recursive Hydration

The DataModel trait recursively instantiates classes based on their type declarations. If a property’s type hint is a class, its value is passed to that class’s from() method.

In this example, the address element is automatically converted into an Address object, allowing direct access to its properties: $user->address->city.

Transformations

The DataModel trait provides a variety of ways to transform data before the value is assigned to a property.

The Describe attribute provides a declarative way describe how property values are resolved.

Describe Attribute

Resolve a value by adding the Describe attribute to a property.

The Describe attribute can accept these arguments.

Order of Precedence

There is an order of precedence when resolving a value for a property.

  1. Property-level Cast
  2. Method-level Cast
  3. Union Types
  4. Class-level Casts
  5. Types that have a concrete static method from().
  6. Native Types

Property-Level Cast

The using the Describe attribute directly on the property takes the highest precedence.

Life-Cycle Hooks

You can run methods before and after a value is resolved.

pre Hook

You can use pre to run a void method before the value is resolved.

post Hook

You can use post to run a void method after the value is resolved.

Method-level Cast

Use the Describe attribute to resolve values with class methods. Methods receive $value and $context as parameters.

Union Types

A value passed to property with a union type is directly assigned to the property. If you wish to resolve the value in a specific way, use a class method.

Class-Level Cast

You can define how to resolve different types at the class level.

Required Properties

Enforce that certain properties are required using the Describe attribute:

Default Values

You can set a default value for a property like this:

Nullable Missing Values

Set missing values to null by setting missing_as_null => true. This can be placed at the class or property level.

This prevents an Error when attempting to assess a property that has not been initialized.

Error: Typed property User::$age must not be accessed before initialization

Re-Mapping

You can map a key to a property of a different name like this:

Examples

Array of DataModels

This examples uses the DataModelHelper.

Collection of DataModels

This examples uses the DataModelHelper and Laravel Collections.

Laravel Validation

By leveraging the pre life-cycle hook, you run a validator before a value is resolved.

Testing


All versions of data-model with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package zero-to-prod/data-model contains the following files

Loading the files please wait ....