示例#1
0
 public function getType(string $name) : BaseNode
 {
     if (isset($this->types[$name])) {
         $type = new $this->types[$name]();
         $type->setTypeHandler($this);
         return $type;
     }
     if ($this->isScalarCollectionType($name)) {
         $type = new ScalarCollectionNode();
         $type->setType($this->getCollectionType($name));
         $type->setTypeHandler($this);
         return $type;
     }
     if ($this->isClassType($name)) {
         $type = new ObjectNode();
         $type->setType($name);
         $type->setTypeHandler($this);
         $type->setInstantiator($this->defaultInstantiator);
         return $type;
     }
     if ($this->isCollectionType($name)) {
         $type = new CollectionNode();
         $type->setType($this->getCollectionType($name));
         $type->setTypeHandler($this);
         $type->setInstantiator($this->defaultInstantiator);
         return $type;
     }
     throw new \InvalidArgumentException('Unknown type name: ' . $name);
 }
示例#2
0
 public function testIsGettingValue()
 {
     $expectedInput = ['timestamp' => 1389312000];
     $expectedObj = new \DateTime('@1389312000');
     $instantiator = $this->prophesize(InstantiatorInterface::class);
     $instantiator->instantiate('DateTime', $expectedInput)->willReturn($expectedObj);
     $collectionNode = new CollectionNode();
     $collectionNode->setInstantiator($instantiator->reveal());
     $typeHandler = $this->prophesize(TypeHandler::class);
     $typeHandler->getType('DateTime')->willReturn($collectionNode);
     $base = new CollectionNode();
     $base->setTypeHandler($typeHandler->reveal());
     $child = $base->add('foobar', 'DateTime');
     $child->setType('DateTime');
     $this->assertEquals([$expectedObj], $child->getValue('foobar', [$expectedInput]));
 }