Download the PHP package fivepercent/object-mapper without Composer

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


Object Mapper

With this package, you can map array data to object instances.

Installation

Add FivePercent/ObjectMapper in your composer.json:

{
    "require": {
        "fivepercent/object-mapper": "~1.0"
    }
}

Now tell composer to download the library by running the command:

$ php composer.phar update fivepercent/object-mapper

Basic usage

Before use ObjectMapper you must configure instance:

  1. Create a metadata factory for loads metadata from objects
  2. Create a strategy manager
use Doctrine\Common\Annotations\AnnotationReader;
use FivePercent\Component\ObjectMapper\Strategy\StrategyManager;
use FivePercent\Component\ObjectMapper\Metadata\MetadataFactory;
use FivePercent\Component\ObjectMapper\Metadata\Loader\AnnotationLoader;
use FivePercent\Component\ObjectMapper\ObjectMapper;
use FivePercent\Component\ObjectMapper\Metadata\ObjectMetadata;

$strategyManager = StrategyManager::createDefault();

$annotationLoader = new AnnotationLoader(new AnnotationReader());
$metadataFactory = new MetadataFactory($annotationLoader);

$objectMapper = new ObjectMapper($metadataFactory, $strategyManager);

// Or create default object mapper
$objectMapper = ObjectMapper::createDefault(); // Used AnnotationLoader for load metadata

Attention: now supported only annotation metadata loader.

After configure and create instance, you can use ObjectMapper map function.

Example object for maps:

use FivePercent\Component\ObjectMapper\Annotation\Object;
use FivePercent\Component\ObjectMapper\Annotation\Property;

/**
 * @Object()
 */
class MyClass
{
    /**
     * @Property()
     */
    public $id;

    /**
     * @Property()
     */
    public $name;
}

And map array data:

$object = new MyClass();
$objectMapper->map($object, [
    'id' => 1,
    'name' => 'Foo Bar'
]);

If you want map all properties in object, you can set attribute allProperties for @Object, then this indicate for load all properties from class.

use FivePercent\Component\ObjectMapper\Annotation\Object;

/**
 * @Object(allProperties=true)
 */
class MyClass
{
    public $id;
    public $name;
}

If key of array not equals to property name of object, you can set attribute fieldName for @Property

use FivePercent\Component\ObjectMapper\Annotation\Object;
use FivePercent\Component\ObjectMapper\Annotation\Property;

/**
 * @Object()
 */
class MyClass
{
    /**
     * @Property()
     */
    public $id;

    /**
     * @Property(fieldName="first_name")
     */
    public $firstName;
}

$object = new MyClass();
$objectMapper->map($object, [
    'id' => 1,
    'first_name' => 'Foo Bar'
]);

Recursive mapping

You can recursive map data to object.

With simple object:

use FivePercent\Component\ObjectMapper\Annotation\Object;
use FivePercent\Component\ObjectMapper\Annotation\Property;

class MyClass
{
    /**
     * @DataMapping\Property(class="Tag")
     */
    protected $tag;
}

/**
 * @DataMapping\Object(allProperties=true)
 */
class Tag
{
    protected $name;
}

$object = new MyClass();
$objectMapper->map($object, [
    'tag' => [
        'name' => 'Foo Bar'
    ]
]);

With collection:

use FivePercent\Component\ObjectMapper\Annotation\Object;
use FivePercent\Component\ObjectMapper\Annotation\Property;

class MyClass
{
    /**
     * @DataMapping\Property(collection=true, class="Tag")
     */
    protected $tag;
}

/**
 * @DataMapping\Object(allProperties=true)
 */
class Tag
{
    protected $name;
}

$object = new MyClass();
$objectMapper->map($object, [
    'tag' => [
        ['name' => 'Foo Bar'],
        ['name' => 'Bar Foo']
    ]
]);

And you can set the collection class if necessary, to attribute collection ``collection="MyCollectionClass"` All keys as default will be saved.


All versions of object-mapper with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4
doctrine/annotations Version ~1.0
fivepercent/cache Version ~1.0
fivepercent/reflection Version ~1.0
fivepercent/exception Version ~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 fivepercent/object-mapper contains the following files

Loading the files please wait ....