PHP code example of vox / data

1. Go to this page and download the library: Download vox/data 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/ */

    

vox / data example snippets


class DataClass {
    private string $name;
    
    public int $age;
    
    public function __construct($name, $age) {
        $this->name = $name;
        $this->age = $age;
    }
    
    public function getName() {
        return $this->name;
    }
}

$mf = (new MetadataFactoryFactory())->createAnnotationMetadataFactory();
$oe = new ObjectExtractor($mf);
$oh = new ObjectHydrator($mf);

$context = ['extractType' => true];
$data = $extractor->extract(new DataClass('John Doe', 18), $context);

$object = $oh->hydrate(DataClass::class, $data);
$oh->hydrate($object, $data);

class DataClass {
    #[Bindings(source: 'first_name', target: 'username')]
    private string $name;
    
    #[Exclude(input: false, output: true)]
    public int $age;
    
    public function __construct($name, $age) {
        $this->name = $name;
        $this->age = $age;
    }
    
    public function getName() {
        return $this->name;
    }
}