Download the PHP package sahanh/simpledto without Composer

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

SimpleDTO

Simple DTO object to move data. Requires PHP 5.4

Practical Usage

When returning complex data, instead of returning an array DTOs can be returned.

class UserService
{
    public function getUsers()
    {
        $rows = $this->db->users->get();
        return DTO::make($rows);
    }
}

View or Controllers can use DTO objects to access data. No need to worry about undefined index errors when using get method.

{{ $data->get('name') }}

@foreach($data->get('cars') as $car)
    <h1>{{ $car }}</h1>
@endforeach

Installing

Package can be installed via composer.

Install Composer

curl -sS https://getcomposer.org/installer | php

Next, update your project's composer.json file to include EZCash:

{
    "require": {
        "sahanh/simpledto": "~1.0"
    }
}

Making DTO Object

use SH\SimpleDTO\DTO;

$raw = [
    'id'      => 1,
    'name'    => 'John Doe',
    'email'   => 'john@doe.com',
    'address' => [
        'street' => '123 Main St.',
        'city'   => 'Wind'
    ],
    'cars'  => [
        'BMW-7',
        'Toyota Supra',
        'Nissan GT',
        'Jaguar'
    ]
];

//pass an array or stdClass objects
$dto = DTO::make($raw);

Accessing Data

//accessing properties
echo $dto->name; //John Doe
echo $dto->address->city; //Wind

//accessing as an array
echo $dto['name']; //John Doe
echo $dto["address"]["city"] //Wind

Using dot-notation

DTO's data can be accessed using get method, get method accept . for nested elements

echo $dto->get('address.city');

One advantage of get is, data can be accessed without making sure if they exist or not.

//returns NULL without errors, (no undefined index errors like in arrays)
$dto->get('address.country');

Iterating

For every nested array element data new DTO object will be created on retrival, and DTO object implements IteratorAggregate inteface.

foreach ($dto->cars as $car) {
    echo $car;
}

//since `$dto->cars` is an array, `$dto->cars` will be returning another DTO object.
$cars = $dto->cars;
echo $cars->get(0); //accessing get() of DTO object

JSON Serializing

Pass the DTO object to json_encode and get the data in json

echo json_encode($dto);

Write Protected

Data inside a DTO object cannot be modified once created making it perfect to move around.

//RuntimeException - 'Data cannot be modified'
$dto->new_value   = 'Some value';
$dto['new_value'] = 'Some value';

Credits: The library uses illuminate/helpers package


All versions of simpledto with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
illuminate/support Version ~5
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 sahanh/simpledto contains the following files

Loading the files please wait ....