Download the PHP package ttbooking/mapper-php without Composer

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

PHP Model Mapper

Feature list:

Installation

How it works

The mapper goes trough all the property names (with @name you could change property name mappings) of your model and maps the ones with the same name from the source (json/xml/array/stdClass), if available. The mapped model can be used as is, but it is recommended you validate it after mapping. Required properties (@required) must always be set and of the appropriate type (if set with @var or @rule). Not required properties may not be set (null), but if set, must match defined types or rules (if set with @var or @rule) to pass validation. So, if you have:

You could make a model like this:

Validation would fail if:

Note that $description would get mapped because it has the @name annotation set, and there is a property in the source matching that name (custom-desc).

Annotations

Heres a list of annotations we can use in models:

annotation used above description
@var property Used to declare the type of the property (validation). This is an alias for @rule annotation. See below for a list of pre-defined types (rules) for model validation
@name property Used to change the property name, while mapping and unmapping (can be used with special characters, but be careful if youre working with XML)
@required property Used to declare that a property is required for a specific action (validation). Use without the action to make the property always required
@rule property Used to enforce specific rules and filters on the property value (validation). You can use the predefined rules or create and import your own
@xmlRoot class Used to name the xml root name of the element (only for xml mapping)
@xmlAttribute property Used to declare that a property is a xml attribute for the element. Also used for namespaces (only for xml mapping)
@xmlNodeValue property Used to declare that a property contains the text node value (only for xml mapping). Please see the models in tests/ (XmlTestModel)

@var annotation type list:

type description
any anything
string string type
integer integer type
boolean boolean type
double double type
float float type
array array type
[] array type
object stdClass for example
string[] string array type
integer[] integer array type
boolean[] boolean array type
object[] object array type
NamedModel any named class (model) (if from another namespace, make sure you include it!)
NamedModel[] any model array

Usage

Mapping

Use MappableTrait inside your model to call methods from the model itself:

Or by using the ModelMapper class, providing it with the instance of the model you want mapped and the source object:

Unmapping

Use ConvertibleTrait inside your model to call methods from the model itself:

Or by using the ModelMapper class, providing it with the mapped model (converts to stdClass):

Validation

Validation will check your mapped model's property types, custom rules, and whether the property is required or not.

Validate your mapped models with ValidatableTrait, by providing it with the desired validation action:

Or if you want to validate only the properties that are always required:

You can also use the validator itself:

Rules

Rules are used for custom validation of mapped property values.

This would check if the property value contains a valid email string.

You can pass additional parameters for rules.

If setup properly this custom rule would check if the property value is between 0 and 99.

Rule setup

Lets use the limit rule example from above, to create a new custom rule:

In the example above, we can configure a new rule, by:

For more information please take a look at the pre-defined rule classes and the IRule interface.

Loading your rules

In the example above we can use custom rules by providing them to the validator one by one (useRule) or providing a path to a directory containing rules (loadRules).

Code examples

Please see the tests and models used in it.

Stuff that got me inspired:

cweiske/jsonmapper


All versions of mapper-php with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ttbooking/common-php Version ^2.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 ttbooking/mapper-php contains the following files

Loading the files please wait ....