コード例 #1
0
ファイル: example.php プロジェクト: kevbradwick/drift
<?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;
コード例 #2
0
ファイル: MapperTest.php プロジェクト: kevbradwick/drift
 /**
  * @expectedException \Drift\Types\TypeException
  * @expectedExceptionMessage Unknown config "foo" specified for type "int"
  */
 public function testExceptionForUnknownTypeOption()
 {
     $this->reader->expects($this->once())->method('getProperties')->willReturn(['duration' => ['field' => 'duration', 'type' => 'int', 'options' => ['foo' => 'bar']]]);
     $this->mapper->setData(['duration' => 90]);
     $this->mapper->instantiate(Movie::class);
 }