2017 © Pedro PelĂĄez
 

library dot-notation

Dot notation support for JSON-like syntax for easily creating and mapping arrays in PHP.

image

pecee/dot-notation

Dot notation support for JSON-like syntax for easily creating and mapping arrays in PHP.

  • Sunday, December 17, 2017
  • by sessingo
  • Repository
  • 1 Watchers
  • 1 Stars
  • 18 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

pecee/dot-notation

Dot notation support for JSON-like syntax for easily creating and mapping arrays in PHP., (*1)

Installation

Run the following command in terminal to add the latest version of pecee/dot-notation library to your project., (*2)

composer require pecee/dot-notation

Examples

This example returns an array from a basic dot formatted string, similar to the JSON syntax:, (*3)

$d = new \Pecee\DotNotation(['one' => ['two' => 2]]);
$d->set('one.two', 3);
echo $d->getValues();

Output:, (*4)

array ('one' => ['two' => 3]);

Easily map one array to another

class CustomerMapper {

    protected $customer;

    public function __construct(array $values) {

        // Map fields (from -> to)

        $this->customer = $this->map($values, [
            'customerId' => 'id',
            'relationshipStatus' => 'relationship_status',
            'customerGender' => 'gender',
            'meta.name' => 'name',
        ]);
    }

    protected function map(array $input, array $mapping) {
        $output = array();

        foreach($mapping as $before => $after) {

            $map = new DotNotation($input);
            $value = $map->get($before);

            $map = new DotNotation($output);
            $map->set($after, $value);
            $output = $map->getValues();
        }

        return $output;
    }

    protected function getCustomer() {
        return $this->customer;
    }
}

// Example:

$mapper = new CustomerMapper([
    'customerId' => 123456,
    'relationshipStatus' => 'single',
    'customerGender' => 'male',
    'meta' => ['name' => 'Peter']
]);

$customer = $mapper->getCustomer();

Output:, (*5)

array(
    'id' => 123456,
    'relationship_status' => 'single',
    'gender' => 'male',
    'name' => 'Peter',
);

Credits

elfet, (*6)

The MIT License (MIT)

Copyright (c) 2016 Simon Sessingø / pecee, (*7)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:, (*8)

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software., (*9)

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE., (*10)

The Versions

17/12 2017

dev-v2-development

dev-v2-development https://github.com/skipperbent/dot-notation

Dot notation support for JSON-like syntax for easily creating and mapping arrays in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

php json array syntax mapping multidimensional array-convert move-array-key

17/12 2017

dev-v2-release

dev-v2-release https://github.com/skipperbent/dot-notation

Dot notation support for JSON-like syntax for easily creating and mapping arrays in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

php json array syntax mapping multidimensional array-convert move-array-key

17/12 2017

2.2.0

2.2.0.0 https://github.com/skipperbent/dot-notation

Dot notation support for JSON-like syntax for easily creating and mapping arrays in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

php json array syntax mapping multidimensional array-convert move-array-key

29/03 2016

dev-development

dev-development https://github.com/skipperbent/instagram-php-sdk

Dot notation support for JSON-like syntax for easily creating arrays in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php json array syntax multidimensional

15/03 2016

dev-master

9999999-dev https://github.com/skipperbent/instagram-php-sdk

Dot notation support for JSON-like syntax for easily creating arrays in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php json array syntax multidimensional

15/03 2016

2.1

2.1.0.0 https://github.com/skipperbent/instagram-php-sdk

Dot notation support for JSON-like syntax for easily creating arrays in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php json array syntax multidimensional

15/03 2016

2.0

2.0.0.0 https://github.com/skipperbent/instagram-php-sdk

Dot notation support for JSON-like syntax for easily creating arrays in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

php json array syntax multidimensional