Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Symfony/Component/JsonStreamer/Read/PhpGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function generate(DataModelNodeInterface $dataModel, bool $decodeFromStre
if ($decodeFromStream) {
return $this->line('<?php', $context)
.$this->line('', $context)
.$this->line('/**', $context)
.$this->line(' * @return '.$dataModel->getType(), $context)
.$this->line(' */', $context)
.$this->line('return static function (mixed $stream, \\'.ContainerInterface::class.' $valueTransformers, \\'.LazyInstantiator::class.' $instantiator, array $options): mixed {', $context)
.$providers
.($this->canBeDecodedWithJsonDecode($dataModel, $decodeFromStream)
Expand All @@ -61,6 +64,9 @@ public function generate(DataModelNodeInterface $dataModel, bool $decodeFromStre

return $this->line('<?php', $context)
.$this->line('', $context)
.$this->line('/**', $context)
.$this->line(' * @return '.$dataModel->getType(), $context)
.$this->line(' */', $context)
.$this->line('return static function (string|\\Stringable $string, \\'.ContainerInterface::class.' $valueTransformers, \\'.Instantiator::class.' $instantiator, array $options): mixed {', $context)
.$providers
.($this->canBeDecodedWithJsonDecode($dataModel, $decodeFromStream)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return Symfony\Component\JsonStreamer\Tests\Fixtures\Enum\DummyBackedEnum
*/
return static function (string|\Stringable $string, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\Instantiator $instantiator, array $options): mixed {
$providers['Symfony\Component\JsonStreamer\Tests\Fixtures\Enum\DummyBackedEnum'] = static function ($data) {
return \Symfony\Component\JsonStreamer\Tests\Fixtures\Enum\DummyBackedEnum::from($data);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return Symfony\Component\JsonStreamer\Tests\Fixtures\Enum\DummyBackedEnum
*/
return static function (mixed $stream, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\LazyInstantiator $instantiator, array $options): mixed {
$providers['Symfony\Component\JsonStreamer\Tests\Fixtures\Enum\DummyBackedEnum'] = static function ($stream, $offset, $length) {
return \Symfony\Component\JsonStreamer\Tests\Fixtures\Enum\DummyBackedEnum::from(\Symfony\Component\JsonStreamer\Read\Decoder::decodeStream($stream, $offset, $length));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return array<string,mixed>
*/
return static function (string|\Stringable $string, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\Instantiator $instantiator, array $options): mixed {
return \Symfony\Component\JsonStreamer\Read\Decoder::decodeString((string) $string);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return array<string,mixed>
*/
return static function (mixed $stream, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\LazyInstantiator $instantiator, array $options): mixed {
$providers['array<string,mixed>'] = static function ($stream, $offset, $length) use ($options, $valueTransformers, $instantiator, &$providers) {
$data = \Symfony\Component\JsonStreamer\Read\Splitter::splitDict($stream, $offset, $length);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return iterable
*/
return static function (string|\Stringable $string, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\Instantiator $instantiator, array $options): mixed {
return \Symfony\Component\JsonStreamer\Read\Decoder::decodeString((string) $string);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return iterable
*/
return static function (mixed $stream, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\LazyInstantiator $instantiator, array $options): mixed {
$providers['iterable'] = static function ($stream, $offset, $length) use ($options, $valueTransformers, $instantiator, &$providers) {
$data = \Symfony\Component\JsonStreamer\Read\Splitter::splitDict($stream, $offset, $length);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return array<int,mixed>
*/
return static function (string|\Stringable $string, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\Instantiator $instantiator, array $options): mixed {
return \Symfony\Component\JsonStreamer\Read\Decoder::decodeString((string) $string);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return array<int,mixed>
*/
return static function (mixed $stream, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\LazyInstantiator $instantiator, array $options): mixed {
$providers['array<int,mixed>'] = static function ($stream, $offset, $length) use ($options, $valueTransformers, $instantiator, &$providers) {
$data = \Symfony\Component\JsonStreamer\Read\Splitter::splitList($stream, $offset, $length);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return mixed
*/
return static function (string|\Stringable $string, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\Instantiator $instantiator, array $options): mixed {
return \Symfony\Component\JsonStreamer\Read\Decoder::decodeString((string) $string);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return mixed
*/
return static function (mixed $stream, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\LazyInstantiator $instantiator, array $options): mixed {
return \Symfony\Component\JsonStreamer\Read\Decoder::decodeStream($stream, 0, null);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return null
*/
return static function (string|\Stringable $string, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\Instantiator $instantiator, array $options): mixed {
return \Symfony\Component\JsonStreamer\Read\Decoder::decodeString((string) $string);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return null
*/
return static function (mixed $stream, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\LazyInstantiator $instantiator, array $options): mixed {
return \Symfony\Component\JsonStreamer\Read\Decoder::decodeStream($stream, 0, null);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return Symfony\Component\JsonStreamer\Tests\Fixtures\Enum\DummyBackedEnum|null
*/
return static function (string|\Stringable $string, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\Instantiator $instantiator, array $options): mixed {
$providers['Symfony\Component\JsonStreamer\Tests\Fixtures\Enum\DummyBackedEnum'] = static function ($data) {
return \Symfony\Component\JsonStreamer\Tests\Fixtures\Enum\DummyBackedEnum::from($data);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return Symfony\Component\JsonStreamer\Tests\Fixtures\Enum\DummyBackedEnum|null
*/
return static function (mixed $stream, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\LazyInstantiator $instantiator, array $options): mixed {
$providers['Symfony\Component\JsonStreamer\Tests\Fixtures\Enum\DummyBackedEnum'] = static function ($stream, $offset, $length) {
return \Symfony\Component\JsonStreamer\Tests\Fixtures\Enum\DummyBackedEnum::from(\Symfony\Component\JsonStreamer\Read\Decoder::decodeStream($stream, $offset, $length));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy|null
*/
return static function (string|\Stringable $string, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\Instantiator $instantiator, array $options): mixed {
$providers['Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy'] = static function ($data) use ($options, $valueTransformers, $instantiator, &$providers) {
return $instantiator->instantiate(\Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy::class, \array_filter(['id' => $data['id'] ?? '_symfony_missing_value', 'name' => $data['name'] ?? '_symfony_missing_value'], static function ($v) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy|null
*/
return static function (mixed $stream, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\LazyInstantiator $instantiator, array $options): mixed {
$providers['Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy'] = static function ($stream, $offset, $length) use ($options, $valueTransformers, $instantiator, &$providers) {
$data = \Symfony\Component\JsonStreamer\Read\Splitter::splitDict($stream, $offset, $length);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return array<string,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>|null
*/
return static function (string|\Stringable $string, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\Instantiator $instantiator, array $options): mixed {
$providers['array<string,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>'] = static function ($data) use ($options, $valueTransformers, $instantiator, &$providers) {
$iterable = static function ($data) use ($options, $valueTransformers, $instantiator, &$providers) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return array<string,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>|null
*/
return static function (mixed $stream, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\LazyInstantiator $instantiator, array $options): mixed {
$providers['array<string,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>'] = static function ($stream, $offset, $length) use ($options, $valueTransformers, $instantiator, &$providers) {
$data = \Symfony\Component\JsonStreamer\Read\Splitter::splitDict($stream, $offset, $length);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return array<int,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>|null
*/
return static function (string|\Stringable $string, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\Instantiator $instantiator, array $options): mixed {
$providers['array<int,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>'] = static function ($data) use ($options, $valueTransformers, $instantiator, &$providers) {
$iterable = static function ($data) use ($options, $valueTransformers, $instantiator, &$providers) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return array<int,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>|null
*/
return static function (mixed $stream, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\LazyInstantiator $instantiator, array $options): mixed {
$providers['array<int,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>'] = static function ($stream, $offset, $length) use ($options, $valueTransformers, $instantiator, &$providers) {
$data = \Symfony\Component\JsonStreamer\Read\Splitter::splitList($stream, $offset, $length);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy
*/
return static function (string|\Stringable $string, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\Instantiator $instantiator, array $options): mixed {
$providers['Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy'] = static function ($data) use ($options, $valueTransformers, $instantiator, &$providers) {
return $instantiator->instantiate(\Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy::class, \array_filter(['id' => $data['id'] ?? '_symfony_missing_value', 'name' => $data['name'] ?? '_symfony_missing_value'], static function ($v) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy
*/
return static function (mixed $stream, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\LazyInstantiator $instantiator, array $options): mixed {
$providers['Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy'] = static function ($stream, $offset, $length) use ($options, $valueTransformers, $instantiator, &$providers) {
$data = \Symfony\Component\JsonStreamer\Read\Splitter::splitDict($stream, $offset, $length);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return array<string,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>
*/
return static function (string|\Stringable $string, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\Instantiator $instantiator, array $options): mixed {
$providers['array<string,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>'] = static function ($data) use ($options, $valueTransformers, $instantiator, &$providers) {
$iterable = static function ($data) use ($options, $valueTransformers, $instantiator, &$providers) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return array<string,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>
*/
return static function (mixed $stream, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\LazyInstantiator $instantiator, array $options): mixed {
$providers['array<string,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>'] = static function ($stream, $offset, $length) use ($options, $valueTransformers, $instantiator, &$providers) {
$data = \Symfony\Component\JsonStreamer\Read\Splitter::splitDict($stream, $offset, $length);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return Symfony\Component\JsonStreamer\Tests\Fixtures\Model\DummyWithOtherDummies
*/
return static function (string|\Stringable $string, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\Instantiator $instantiator, array $options): mixed {
$providers['Symfony\Component\JsonStreamer\Tests\Fixtures\Model\DummyWithOtherDummies'] = static function ($data) use ($options, $valueTransformers, $instantiator, &$providers) {
return $instantiator->instantiate(\Symfony\Component\JsonStreamer\Tests\Fixtures\Model\DummyWithOtherDummies::class, \array_filter(['name' => $data['name'] ?? '_symfony_missing_value', 'otherDummyOne' => \array_key_exists('otherDummyOne', $data) ? $providers['Symfony\Component\JsonStreamer\Tests\Fixtures\Model\DummyWithNameAttributes']($data['otherDummyOne']) : '_symfony_missing_value', 'otherDummyTwo' => \array_key_exists('otherDummyTwo', $data) ? $providers['Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy']($data['otherDummyTwo']) : '_symfony_missing_value'], static function ($v) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return Symfony\Component\JsonStreamer\Tests\Fixtures\Model\DummyWithOtherDummies
*/
return static function (mixed $stream, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\LazyInstantiator $instantiator, array $options): mixed {
$providers['Symfony\Component\JsonStreamer\Tests\Fixtures\Model\DummyWithOtherDummies'] = static function ($stream, $offset, $length) use ($options, $valueTransformers, $instantiator, &$providers) {
$data = \Symfony\Component\JsonStreamer\Read\Splitter::splitDict($stream, $offset, $length);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return iterable<int|string,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>
*/
return static function (string|\Stringable $string, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\Instantiator $instantiator, array $options): mixed {
$providers['iterable<int|string,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>'] = static function ($data) use ($options, $valueTransformers, $instantiator, &$providers) {
$iterable = static function ($data) use ($options, $valueTransformers, $instantiator, &$providers) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return iterable<int|string,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>
*/
return static function (mixed $stream, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\LazyInstantiator $instantiator, array $options): mixed {
$providers['iterable<int|string,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>'] = static function ($stream, $offset, $length) use ($options, $valueTransformers, $instantiator, &$providers) {
$data = \Symfony\Component\JsonStreamer\Read\Splitter::splitDict($stream, $offset, $length);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return array<int,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>
*/
return static function (string|\Stringable $string, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\Instantiator $instantiator, array $options): mixed {
$providers['array<int,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>'] = static function ($data) use ($options, $valueTransformers, $instantiator, &$providers) {
$iterable = static function ($data) use ($options, $valueTransformers, $instantiator, &$providers) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return array<int,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>
*/
return static function (mixed $stream, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\LazyInstantiator $instantiator, array $options): mixed {
$providers['array<int,Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy>'] = static function ($stream, $offset, $length) use ($options, $valueTransformers, $instantiator, &$providers) {
$data = \Symfony\Component\JsonStreamer\Read\Splitter::splitList($stream, $offset, $length);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return Symfony\Component\JsonStreamer\Tests\Fixtures\Model\DummyWithNullableProperties
*/
return static function (string|\Stringable $string, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\Instantiator $instantiator, array $options): mixed {
$providers['Symfony\Component\JsonStreamer\Tests\Fixtures\Model\DummyWithNullableProperties'] = static function ($data) use ($options, $valueTransformers, $instantiator, &$providers) {
return $instantiator->instantiate(\Symfony\Component\JsonStreamer\Tests\Fixtures\Model\DummyWithNullableProperties::class, \array_filter(['name' => $data['name'] ?? '_symfony_missing_value', 'enum' => \array_key_exists('enum', $data) ? $providers['Symfony\Component\JsonStreamer\Tests\Fixtures\Enum\DummyBackedEnum|null']($data['enum']) : '_symfony_missing_value'], static function ($v) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* @return Symfony\Component\JsonStreamer\Tests\Fixtures\Model\DummyWithNullableProperties
*/
return static function (mixed $stream, \Psr\Container\ContainerInterface $valueTransformers, \Symfony\Component\JsonStreamer\Read\LazyInstantiator $instantiator, array $options): mixed {
$providers['Symfony\Component\JsonStreamer\Tests\Fixtures\Model\DummyWithNullableProperties'] = static function ($stream, $offset, $length) use ($options, $valueTransformers, $instantiator, &$providers) {
$data = \Symfony\Component\JsonStreamer\Read\Splitter::splitDict($stream, $offset, $length);
Expand Down
Loading
Loading