2017 © Pedro Peláez
 

library data-mapper

Thruster DataMapper Component

image

thruster/data-mapper

Thruster DataMapper Component

  • Thursday, April 21, 2016
  • by gcds
  • Repository
  • 2 Watchers
  • 2 Stars
  • 5,472 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 13 Versions
  • 0 % Grown

The README.md

DataMapper Component

[Latest Version] (https://github.com/ThrusterIO/data-mapper/releases) [Software License] (LICENSE) [Build Status] (https://travis-ci.org/ThrusterIO/data-mapper) [Code Coverage] (https://scrutinizer-ci.com/g/ThrusterIO/data-mapper) [Quality Score] (https://scrutinizer-ci.com/g/ThrusterIO/data-mapper) [Total Downloads] (https://packagist.org/packages/thruster/data-mapper), (*1)

[Email] (mailto:team@thruster.io), (*2)

The Thruster DataMapper Component. Provides fast and efficient way to map data from one format to another., (*3)

Install

Via Composer, (*4)

``` bash $ composer require thruster/data-mapper, (*5)


### For PHP < 7.0 For older PHP version than PHP7 there is branch **php5** ``` bash $ composer require thruster/data-mapper ">=1.0,<2.0"

Usage

Simple Data Mapping

class SimpleMapper extends BaseDataMapper {
    /**
     * @param Request $input
     */
    public function map($input)
    {
        return [
            'id' => $input->getId(),
            'name' => $input->getName()
        ];
    }
}

$dataMappers = new DataMappers();
$dataMappers->addMapper(new SimpleMapper());
$dataMappers->getMapper(SimpleMapper::class)->map($input);

Nested Data Mapping

class ItemMapper extends BaseDataMapper {
    /**
     * @param Request $input
     */
    public function map($input)
    {
        return [
            'id' => $input->getId(),
            'name' => $input->getName()
        ];
    }
}

class MainMapper extends BaseDataMapper {
    /**
     * @param Request $input
     */
    public function map($input)
    {
        return [
            'id' => $input->getId(),
            'name' => $input->getName(),
            'items' => $this->getMapper(ItemMapper::class)->mapCollection($input->getItems())
        ];
    }
}

$dataMappers = new DataMappers();
$dataMappers->addMapper(new MainMapper());
$dataMappers->addMapper(new ItemMapper());
$dataMappers->getMapper(MainMapper::class)->map($input);

Validateable Data Mapping

class UserRegistrationMapper extends BaseDataMapper implements ValidateableDataMapperInterface {
    /**
     * @param Request $input
     */
    public function map($input)
    {
        $user = new User();

        $user->setUsername($input->get('username'));
        $user->setPassword($input->get('password'));
    }

    public function supports($input) : bool
    {
        return ($input instanceof Request);
    }

    public function getValidationGroups($input) : array
    {
        return ['full'];
    }
}

$dataMappers = new DataMappers();
$dataMappers->setValidator(Validation::createValidator());

$dataMappers->addMapper(new UserRegistrationMapper());
$dataMappers->getMapper(UserRegistrationMapper::class)->map($input);

Standalone Data Mapping

$simpleMapper = new DataMapper(
    new class extends BaseDataMapper {
        /**
         * @param Request $input
         */
        public function map($input)
        {
            return [
                'id' => $input->getId(),
                'name' => $input->getName()
            ];
        }

        public function supports($input) : bool
        {
            return true;
        }
    }
);

$simpleMapper->map($input);

Testing

bash $ composer test, (*6)

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*7)

License

Please see License File for more information., (*8)

The Versions

21/04 2016

dev-php5

dev-php5 https://thruster.io

Thruster DataMapper Component

  Sources   Download

MIT

The Requires

 

The Development Requires

mapper datamapper data-mapper thruster

21/04 2016

1.5.0

1.5.0.0 https://thruster.io

Thruster DataMapper Component

  Sources   Download

MIT

The Requires

 

The Development Requires

mapper datamapper data-mapper thruster

21/04 2016

dev-master

9999999-dev https://thruster.io

Thruster DataMapper Component

  Sources   Download

MIT

The Requires

 

The Development Requires

mapper datamapper data-mapper thruster

21/04 2016

2.4.0

2.4.0.0 https://thruster.io

Thruster DataMapper Component

  Sources   Download

MIT

The Requires

 

The Development Requires

mapper datamapper data-mapper thruster

29/02 2016

1.4.0

1.4.0.0 https://thruster.io

Thruster DataMapper Component

  Sources   Download

MIT

The Requires

 

The Development Requires

mapper datamapper data-mapper thruster

29/02 2016

2.3.0

2.3.0.0 https://thruster.io

Thruster DataMapper Component

  Sources   Download

MIT

The Requires

 

The Development Requires

mapper datamapper data-mapper thruster

22/02 2016

2.2.0

2.2.0.0 https://thruster.io

Thruster DataMapper Component

  Sources   Download

MIT

The Requires

 

The Development Requires

mapper datamapper data-mapper thruster

22/02 2016

1.3.0

1.3.0.0 https://thruster.io

Thruster DataMapper Component

  Sources   Download

MIT

The Requires

 

The Development Requires

mapper datamapper data-mapper thruster

14/02 2016

1.2.0

1.2.0.0 https://thruster.io

Thruster DataMapper Component

  Sources   Download

MIT

The Requires

 

The Development Requires

mapper datamapper data-mapper thruster

01/02 2016

1.1.0

1.1.0.0 https://thruster.io

Thruster DataMapper Component

  Sources   Download

MIT

The Requires

 

The Development Requires

mapper datamapper data-mapper thruster

01/02 2016

2.1.0

2.1.0.0 https://thruster.io

Thruster DataMapper Component

  Sources   Download

MIT

The Requires

 

The Development Requires

mapper datamapper data-mapper thruster

29/01 2016

1.0.0

1.0.0.0 https://thruster.io

Thruster DataMapper Component

  Sources   Download

MIT

The Requires

 

The Development Requires

mapper datamapper data-mapper thruster

05/12 2015

2.0.0

2.0.0.0 https://thruster.io

Thruster DataMapper Component

  Sources   Download

MIT

The Requires

 

The Development Requires

mapper datamapper data-mapper thruster