Download the PHP package maiorano84/object-hydrator without Composer

On this page you can find all versions of the php package maiorano84/object-hydrator. 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 object-hydrator

Object Hydrator

A small utility to streamline Object Hydration

Author Latest Stable Version Total Downloads License Build Status Code Coverage Scrutinizer Code Quality StyleCI

Requirements

Object Hydrator requires PHP 8.1 or greater.

Composer

This package may be installed as a Composer dependency by running the following command:

composer require maiorano84/object-hydrator

If you would like to use the latest unstable version, you can run:

composer require maiorano84/object-hydrator:dev-master

Usage

This is a small set of concepts to facilitate the orchestration of object hydration based on varying strategies.

There are 3 concepts that the default Hydration class uses in order to determine how a given input is applied to an object:

Hydration Keys and Hydration Strategies are both set up as Attributes, which may be used to decorate any given class structure marked for Hydration. In this way, you may customize how a given class is Hydrated.

Multiple Hydration Strategies may be applied to a single given class.

Why?

A common task that many REST APIs and ORMs require is the ability to fill arbitary objects with structured data in bulk. The criteria used for setting these values can vary wildly from class to class, and designating a unified interface by which class hydration may occur predictably can prove to be challenging.

The simplest and most common approach would be to have each object implement a given interface that is responsible for the hydration of that entity. The problem with this approach is that it violates the Single-Responsibility principle, and adds extra business logic that the entity itself doesn't really need to be handling.

This removes much of the boilerplate code needed for handling custom hydration rules, while also providing a simple interface by which classes may define their own rules and the order in which they're applied.

Usage

Given a User Entity:

Hydration of a User entity can be as simple as the following:

By default, classes with no strategy defined will use a combination of the Reflection\PropertiesStrategy and Reflection\MethodsStrategy in that order. The result will be all keys that match a public property name, and all keys that match a property setter will be used to hydrate the entity. Note in the above example that the public $username was hydrated with the value maiorano84, and the private $password was hydrated via the setPassword setter.

More complex structures may also be hydrated like so:

There are a number of things going on here:

Hydration can be done similarly as before:

The Hydrator

The Hydrator can be thought of as an orchestration tool. It doesn't really do any property setting or method invocations itself, but rather loops through all of the key/value pairs and determines the best Strategy to use.

Hydration Strategies

Hydration Strategies encapsulate the logic to determine how input keys and values are mapped to properties or methods. Every Hydration Strategy will expose an underlying Mapping Interface that can be used to define the relationship between a given key and its associated property/method.

Other methods are used to determine if a given key is available within a strategy, or if a value can be considered recursive.

See the Maiorano\ObjectHydrator\Strategies\HydrationStrategyInterface for more details.

Hydration Mappings

Mappings carry both a Hydration Key as well as a Reflection Object containing information about the associated property or method. A mapping serves primarily to store a given association, as well as to complete the appropriate hydration invocation.

See the Maiorano\ObjectHydrator\Mappings\HydrationMappingInterface for more details.

Hydration Keys

Hydration Keys serve as indicators for input. All input for a given hydration attempt is expected to be a structured associative array, with all keys of the array representing an expected Hydration Key.

The default Reflection Strategies will look first to any Properties/Methods with an explicit HydrationKey decorator.

If no Attributes are found, then the Reflection Strategies will try to determine one by name:

Other Notes

Possible points of improvement:


All versions of object-hydrator with dependencies

PHP Build Version
Package Version
Requires php Version >= 8.1
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 maiorano84/object-hydrator contains the following files

Loading the files please wait ....