8000 [Serializer] YamlEncoder: throw if the Yaml component isn't installed by dunglas · Pull Request #24565 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer] YamlEncoder: throw if the Yaml component isn't installed #24565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions src/Symfony/Component/Serializer/Encoder/YamlEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Serializer\Encoder;

use Symfony\Component\Serializer\Exception\RuntimeException;
use Symfony\Component\Yaml\Dumper;
use Symfony\Component\Yaml\Parser;

Expand All @@ -29,6 +30,10 @@ class YamlEncoder implements EncoderInterface, DecoderInterface

public function __construct(Dumper $dumper = null, Parser $parser = null, array $defaultContext = array())
{
if (!class_exists(Dumper::class)) {
throw new RuntimeException('Unable to use YamlEncoder as the Symfony Yaml component is not installed.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add the package name here too as suggested in #24563.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

$this->dumper = $dumper ?: new Dumper();
$this->parser = $parser ?: new Parser();
$this->defaultContext = array_merge($this->defaultContext, $defaultContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function supportsDenormalization($data, $type, $format = null)
$supportedTypes = array(
\SplFileInfo::class => true,
\SplFileObject::class => true,
'Symfony\Component\HttpFoundation\File\File' => true,
File::class => true,
);

return isset($supportedTypes[$type]);
Expand Down
0