예제 #1
0
 public function testNestedDataCanBeMappedWithDotNotationForArrays()
 {
     $this->reader->expects($this->once())->method('getProperties')->willReturn(['duration' => ['field' => 'duration.0', 'type' => 'int', 'options' => []]]);
     $this->mapper->enableDotNotation(true)->setData(['duration' => [99]]);
     /** @var Movie $movie */
     $movie = $this->mapper->instantiate(Movie::class);
     $this->assertEquals(99, $movie->getDuration());
 }
예제 #2
0
<?php

require_once __DIR__ . '/../../vendor/autoload.php';
use Drift\Mapper;
use Drift\Reader\AnnotationReader;
class Car
{
    /**
     * @Drift\String(field="0.make")
     */
    private $make;
    /**
     * @Drift\String(field="0.model")
     */
    private $model;
    public function __toString()
    {
        return 'Car(make=' . $this->make . ', model=' . $this->model . ')';
    }
}
$mapper = new Mapper(new AnnotationReader());
$mapper->enableDotNotation(true);
$mapper->setData([['make' => 'Ferrari', 'model' => '335']]);
$car = $mapper->instantiate(Car::class);
echo $car;