Download the PHP package flancer32/php_data_object without Composer

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

php_data_object

Build Status codecov.io

"Smart data structures and dumb code works a lot better than the other way around." (c) Eric S. Raymond

"Bad programmers worry about the code. Good programmers worry about data structures and their relationships." (c) Linus Torvalds

Overview

This is yet another PHP implementation of the data container (like DTO / SDO). Some kind of the wrapper around associative array. The main goal of this implementation is to be an accessor for the raw data.

Native PHP objects

Structure

We can use any property of any PHP object:

$obj1 = new class {};
$obj2 = new class {};
$obj1->name = 'first';
$obj2->code = 'OBJ2';
$obj1->sub = $obj2;
$this->assertEquals('first', $obj1->name);
$this->assertEquals('OBJ2', $obj1->sub->code);

More...

Paths

We can set/get value of the inner property in PHP style:

$obj->sub->code = $code;
$code = $obj->sub->code;

but we will have "Undefined property" error if $obj->sub property does not exist.

Type checking

We need to use accessors to control properties types.

This is Customer class with string property:

/**
 * @property string $name Customer name.
 */
class Customer
{
    public function getName() : string
    {
        return $this->name;
    }

    public function setName(string $data)
    {
        $this->name = $data;
    }
}

This is Order class with Customer property:

/**
 * @property Customer $customer
 */
class Order
{
    public function getCustomer() : Customer
    {
        return $this->customer;
    }

    public function setCustomer(Customer $data)
    {
        $this->customer = $data;
    }
}

This is code without errors (all types are expected):

$customer = new Customer();
$customer->setName('John Dow');
$order = new Order();
$order->setCustomer($customer);
$this->assertTrue(is_string($order->getCustomer()->getName()));

This code will throw a \TypeError exception:

$customer = new class {};
$customer->name = 'John Dow';
$order = new Order();
$order->setCustomer($customer);

More...

Data Objects

Structure

Paths

With paths we will have property value if chain of properties exists or null otherwise:

$code = $obj->get('sub/code');
$code = $obj->get('/sub/code');    // equals to 'sub/code'
$code = $obj->get('/subs/0/code'); // 'subs' is array
$code = $obj->get('/sub/code/does/not/exist'); // 'null' is returned, no error is occured

Also we can set data property by path:

$obj->set('order/customer/name', 'John Dow');

Type hinting

Installation

Add to composer.json:

"require": {
    "flancer32/php_data_object": "0.1.0"
}

Development

$ composer install
$ ./vendor/bin/phpunit -c ./test/unit/phpunit.dist.xml

All versions of php_data_object with dependencies

PHP Build Version
Package Version
No informations.
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 flancer32/php_data_object contains the following files

Loading the files please wait ....