Download the PHP package om/from-array without Composer

On this page you can find all versions of the php package om/from-array. 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 from-array

![Packagist Version](https://img.shields.io/packagist/v/om/from-array?style=for-the-badge) ![Packagist License](https://img.shields.io/packagist/l/om/from-array?style=for-the-badge) ![Packagist Downloads](https://img.shields.io/packagist/dm/om/from-array?style=for-the-badge)

FromArray Data Loader Trait

Introduction

FromArray is a lightweight PHP trait that enables effortless object hydration from associative arrays. It is especially useful in scenarios where data needs to be mapped into strongly-typed objects, such as when working with APIs, form inputs, or configuration data.

With support for PHP attributes, FromArray lets you fine-tune how each property is loaded, define type expectations, and apply custom transformation logic—all while keeping your code clean and expressive.

Install

Usage

The fromArray trait enables the creation of object instances preloaded with an initial data array:

And that will be the result:

The trait works with public properties only – private and protected properties will be ignored.

The Property, Loader and Type attributes

There are few PHP Attributes to configure the fromArray behavior:

Property

The Property attribute allows you to define a specific key (from) from the data array that will be mapped to the property.

You can also customize the loader used to load the data:

Loader can also be the name of a class, an object, or any type of callable function.

For more see basic-example.php.

Loader

The Loader attribute allows you to define a specific value loader for the property. You can add global loaders to the class or to the property.

For more see loader-property.php-

Type

The Type attribute allows you to define a specific type for the property. Types are usually auto detected, but you can force the type using the Type attribute.

There is one special case for the Type, you can specify Types::ArrayOfObjects type to load an array of objects with the same class. The class parameter is required in this case.

See array-of-objects.php for more information.

Metadata

There is a Metadata object, that contains all the information about the class and its properties. Metadata object is singleton, but you can load instance from any type of cache.

See metadata-cache.php for more information.

Testing

How to run the tests:


All versions of from-array 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 om/from-array contains the following files

Loading the files please wait ....