forked from phpcr/phpcr-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYamlEncoder.php
More file actions
58 lines (50 loc) · 1.17 KB
/
YamlEncoder.php
File metadata and controls
58 lines (50 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/*
* This file is part of the PHPCR Shell package
*
* (c) Daniel Leech <daniel@dantleech.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PHPCR\Shell\Serializer;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
use Symfony\Component\Yaml\Yaml;
/**
* Encodes YAML data.
*
* @author Daniel Leech <daniel@dantleech.com>
*/
class YamlEncoder implements EncoderInterface, DecoderInterface
{
/**
* Encodes PHP data to a YAML string.
*
* {@inheritdoc}
*/
public function encode($data, $format, array $context = []): string
{
return Yaml::dump($data);
}
public function decode($data, $format, array $context = []): mixed
{
$arr = Yaml::parse($data);
return $arr;
}
/**
* {@inheritdoc}
*/
public function supportsEncoding($format): bool
{
return 'yaml' === $format;
}
/**
* {@inheritdoc}
*/
public function supportsDecoding($format): bool
{
return 'yaml' === $format;
}
}