PHP code example of jetcod / data-transport

1. Go to this page and download the library: Download jetcod/data-transport library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jetcod / data-transport example snippets


 

namespace App\DTO;

use Jetcod\DataTransport\AbstractDTO;

class Student extends AbstractDTO
{
}

 

$data = [
    'name' => 'John Doe',
    'email' => '[email protected]',
];

$dto = new \App\DTO\Student($data);

 

$dto = new \App\DTO\Student();

$dto->name = "John Doe";
$dto->email = '[email protected]';

 

$dto = \App\DTO\Student::make($data);

$dto = new \App\DTO\Student();

var_dump($dto->name);   // Returns null

$student = new Student([
    'first_name' => 'John',
    'last_name' => 'Doe',
    'email' => '[email protected]'
]);

isset($student->email);  // Returns true
isset($student->phone);  // Returns false

$student->has('email');  // Returns true
$student->has('phone');  // Returns false