コード例 #1
0
ファイル: Builder.php プロジェクト: bcncommerce/serializer
 /**
  * @param $type
  * @param  array      $options
  * @return Definition
  */
 protected function resolve($type, array $options)
 {
     if ($type instanceof Definition) {
         $definition = $type;
     } elseif ($type === null) {
         $definition = new Definition();
     } else {
         $definition = $this->resolver->getDefinition($type, $options);
     }
     return $definition;
 }
コード例 #2
0
 public function testGetDefinitionByInstance()
 {
     $options = array('foo' => 'bar');
     $type = $this->getTypeMock();
     $type->expects($this->once())->method('setDefaultOptions')->will($this->returnCallback(function (OptionsResolver $resolver) {
         $resolver->setDefaults(array('foo' => 'baz'));
     }));
     $type->expects($this->once())->method('build')->with($this->isInstanceOf('Bcn\\Component\\Serializer\\Definition\\Builder'), $options)->will($this->returnCallback(function (Builder $builder) {
         $builder->node('test');
     }));
     $resolver = new Resolver();
     $definition = $resolver->getDefinition($type, $options);
     $this->assertTrue($definition->hasProperty('test'));
 }
コード例 #3
0
ファイル: Serializer.php プロジェクト: bcncommerce/serializer
 /**
  * @param  mixed      $data
  * @param  string     $type
  * @param  array      $options
  * @param  mixed      $object
  * @return mixed
  * @throws \Exception
  */
 public function denormalize($data, $type, array $options = array(), &$object = null)
 {
     $definition = $this->resolver->getDefinition($type, $options);
     return $this->normalizer->denormalize($data, $definition, $object);
 }