aboutsummaryrefslogtreecommitdiff
path: root/app/class/Flywheel/Formatter/JSON.php
blob: 8ed8a6601ca735660168f2beec4776928405da16 (plain)
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
<?php

namespace Wcms\Flywheel\Formatter;

use JsonException;

class JSON implements \JamesMoss\Flywheel\Formatter\FormatInterface
{
    public function getFileExtension()
    {
        return 'json';
    }

    /**
     * @throws JsonException if json_encode fails in PHP7.3
     * @phpstan-ignore-next-line
     */
    public function encode(array $data)
    {
        $options = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE : null;
        return json_encode($data, $options);
    }
    public function decode($data)
    {
        return json_decode($data, true);
    }
}