2017 © Pedro Peláez
 

library values

An alter ego object. It is an object and an array at the same time

image

makasim/values

An alter ego object. It is an object and an array at the same time

  • Monday, July 30, 2018
  • by makasim
  • Repository
  • 3 Watchers
  • 18 Stars
  • 3,596 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 22 Versions
  • 19 % Grown

The README.md

Supporting Opensource

formapro\values is an MIT-licensed open source project with its ongoing development made possible entirely by the support of community and our customers. If you'd like to join them, please consider:, (*1)


Build Status, (*2)

Your "alter ego" objects

The approach tries to gather the best from array and object worlds. So, with the library you can deal with object as you are used to but internally everything is stored into array. The array is easy to fetch out or set into of the object., (*3)

Could be used:, (*4)

An object provide us with a contract which is easy to rely on. We can type hint a class, use auto complete on its methods. That's a good part, but it is not easy or cheap to populate objects with data or take their current state. We have provide various tools like serializers, transformers and so on. Things are getting even worse when we have to deal with object trees., (*5)

An array on the other hand is easy store or send. Whenever you call an api or do a query to database you end up working with an array. That's a strong side but it does not gives any contract and code could be easily broken when array structure changes., (*6)

Examples

Get repository info example

Let's use Github API and get info about Symfony repository. Here's the real response, we will use a shortened version., (*7)

<?php
namespace Acme;

use Formapro\Values\ValuesTrait;
use Formapro\Values\ObjectsTrait;
use function Formapro\Values\set_values;

class Repo
{
    use ValuesTrait;
    use ObjectsTrait;

    public function getStargazersCount()
    {
        return $this->getValue('stargazers_count');
    }

    /** @return Owner */
    public function getOwner()
    {
        return $this->getObject('owner', Owner::class);
    }
}

class Owner
{
    use ValuesTrait;

    public function getId()
    {
        return $this->getValue('id');
    }

    public function getLogin()
    {
        return $this->getValue('login');
    }
}

$data = json_decode('
{
  "id":458058,
  "name":"symfony",
  "full_name":"symfony/symfony",
  "owner":{
    "login":"symfony",
    "id":143937,
  },
  "stargazers_count":13945,
}
', true);

$repo = new Repo();
set_values($repo, $data);

$repo->getStargazersCount(); // 13945
$repo->getOwner()->getLogin(); // symfony

Create new gist

Now, let's create a new gist. According to Github API we have to send an object with files collection. Lets create Gist and GistFile object. Populate them with data and get it as array., (*8)

<?php
namespace  Acme;

use Formapro\Values\ObjectsTrait;
use Formapro\Values\ValuesTrait;

class Gist
{
    use ValuesTrait;
    use ObjectsTrait;

    public function setDescription($description)
    {
        $this->setValue('description', $description);
    }

    public function setPublic($bool)
    {
        $this->setValue('public', $bool);
    }

    public function addFile($fileName, GistFile $file)
    {
        $this->addObject('files', $file, $fileName);
    }
}

class GistFile
{
    use ValuesTrait;

    public function __construct($content)
    {
        $this->setValue('content', $content);
    }
}

$file = new GistFile('String file contents');

$gist = new Gist();
$gist->setDescription('the description for this gist');
$gist->setPublic(true);
$gist->addFile('file1.txt', $file);

get_values($gist);

/*
[
    'description' => 'the description for this gist',
    'public' => true,
    'files' => [
        'file1.txt' => [
            'content' => 'String file contents',
        ]
    ]
]
 */

// now you can send it to api. 

Developed by Forma-Pro

Forma-Pro is a full stack development company which interests also spread to open source development. Being a team of strong professionals we have an aim an ability to help community by developing cutting edge solutions in the areas of e-commerce, docker & microservice oriented architecture where we have accumulated a huge many-years experience. Our main specialization is Symfony framework based solution, but we are always looking to the technologies that allow us to do our job the best way. We are committed to creating solutions that revolutionize the way how things are developed in aspects of architecture & scalability., (*9)

If you have any questions and inquires about our open source development, this product particularly or any other matter feel free to contact at opensource@forma-pro.com, (*10)

License

It is released under the MIT License., (*11)

The Versions

30/07 2018

dev-master

9999999-dev

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Maksym Kotliar

model

09/07 2018

0.4.1

0.4.1.0

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Maksym Kotliar

model

06/07 2018

dev-fix-tz

dev-fix-tz

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Maksym Kotliar

model

10/04 2018

0.4.0

0.4.0.0

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Maksym Kotliar

model

09/04 2018

dev-eval

dev-eval

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Maksym Kotliar

model

16/02 2018

0.3.6

0.3.6.0

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Maksym Kotliar

model

16/02 2018

0.3.5

0.3.5.0

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Maksym Kotliar

model

16/02 2018

dev-pass-class-or-closure-to-hook

dev-pass-class-or-closure-to-hook

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Maksym Kotliar

model

25/01 2018

0.3.4

0.3.4.0

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Maksym Kotliar

model

24/10 2017

0.3.3

0.3.3.0

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Maksym Kotliar

model

24/10 2017

0.3.2

0.3.2.0

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Maksym Kotliar

model

23/10 2017

0.3.1

0.3.1.0

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7

 

The Development Requires

by Maksym Kotliar

model

20/10 2017

0.3.0

0.3.0.0

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7

 

The Development Requires

by Maksym Kotliar

model

30/05 2017

0.2.5

0.2.5.0

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7

 

The Development Requires

by Maksym Kotliar

model

30/05 2017

dev-fix-null-cast

dev-fix-null-cast

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7

 

The Development Requires

by Maksym Kotliar

model

20/03 2017

0.2.4

0.2.4.0

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7

 

The Development Requires

by Maksym Kotliar

model

18/03 2017

0.2.3

0.2.3.0

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7

 

The Development Requires

by Maksym Kotliar

model

17/03 2017

0.2.2

0.2.2.0

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7

 

The Development Requires

by Maksym Kotliar

model

03/03 2017

0.2.1

0.2.1.0

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7

 

The Development Requires

by Maksym Kotliar

model

02/03 2017

0.2.0

0.2.0.0

An alter ego object. It is an object and an array at the same time

  Sources   Download

MIT

The Requires

  • php ^7

 

The Development Requires

by Maksym Kotliar

model

18/03 2016

0.1.x-dev

0.1.9999999.9999999-dev

Highly opinionated way of build Models

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Kotlyar Maksim

model mongo

18/03 2016

0.1.0

0.1.0.0

Highly opinionated way of build Models

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Kotlyar Maksim

model mongo