Download the PHP package radebatz/object-mapper without Composer

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

(JSON) object mapper

A simple library to deserialize JSON into (nested) PHP arrays / objects.

Build Status Coverage Status License: MIT

Requirements

Installation

You can use Composer or simply Download the Release

Composer

The preferred method is via composer. Follow the installation instructions if you do not already have composer installed.

Once composer is installed, execute the following command in your project root to install this library:

Usage

Simple model using getXXX()/setXXX()

Value union using interface

    $objectMapper->addValueTypeResolver(
        new class() implements ValueTypeResolverInterface {
            public function resolve($className, $json): ?string
            {
                if (is_object($json) && PopoInterface::class == $className) {
                    if (property_exists($json, 'foo')) {
                        return AnotherPopo::class;
                    }

                    return SimplePopo::class;
                }

                return null;
            }
        }
    );

Configuration

The ObjectMapper class takes an array (map) as first constructor argument which allows to customise the behaviour when mapping data. All option names (keys) are defined as class constants.

OPTION_STRICT_TYPES

Enforces strict type checking on build in data types (excluding array).

Default: true

OPTION_STRICT_COLLECTIONS

Enforces strict type checking on arrays.

Default: true

OPTION_STRICT_NULL

Enforces strict check on null value assignments.

Default: true

OPTION_IGNORE_UNKNOWN

Enable/disable reporting unmapped properties (will throw ObjectMapperException).

Default: true

OPTION_VERIFY_REQUIRED

If enabled check if all properties with a @required annotation have been mapped (will throw ObjectMapperException).

Default: false

OPTION_INSTANTIATE_REQUIRE_CTOR

If disabled, object instantiation will fall back to ReflectionClass::newInstanceWithoutConstructor() if a regular new $class() fails. Futhermore, if set it will enforce a constructor argument check in case a scalar is deserialized into an object.

Default: true

OPTION_UNKNOWN_PROPERTY_HANDLER

Optional callable to handle unknown/unmappable properties. Signature:

The return value is epected to be either a property name or null.

Default: null

OPTION_VARIADIC_SETTER

If enabled, setting list values will allow variadic parameters on models (requires 5.2 >= PropertyAccess).

The return value is expected to be either a property name or null.

Default: false

Testing

This package is inspired by the excellent jsonmapper package. In order to evaluate its features, the tests folder contains an adapter that lets you run the test suite agaist the codebase.

For this you run:

Not all tests pass as this library support also, for example, mapping scalar values. As it stands the result of running the tests is:

The tests use a custom JsonMapper class that internally uses the ObjectMapper.


All versions of object-mapper with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
ext-json Version *
psr/log Version ^1.0
radebatz/property-info-extras Version ^1.1
symfony/property-access Version ^4.0|^5.0
symfony/property-info Version >=4.4.17|>=5.1.3
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 radebatz/object-mapper contains the following files

Loading the files please wait ....