-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDiff.php
54 lines (45 loc) · 1.46 KB
/
Diff.php
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
<?php
namespace Swaggest\JsonCli;
use Yaoi\Command;
class Diff extends BaseDiff
{
public $prettyShort;
public $merge;
/**
* @param Command\Definition $definition
* @param \stdClass|static $options
*/
public static function setUpDefinition(Command\Definition $definition, $options)
{
parent::setUpDefinition($definition, $options);
$definition->description = 'Make patch from two json documents, output to STDOUT';
$options->prettyShort = Command\Option::create()
->setDescription('Pretty short format');
$options->merge = Command\Option::create()
->setDescription('Use merge patch (RFC 7386)');
}
public function performAction()
{
$this->prePerform();
if (null === $this->diff) {
return;
}
if ($this->merge) {
$this->out = $this->diff->getMergePatch();
} else {
$this->out = $this->diff->getPatch();
$outJson = $this->out->jsonSerialize();
if ($this->prettyShort && !empty($outJson)) {
$out = '[';
foreach ($outJson as $item) {
$out .= "\n " . json_encode($item, JSON_UNESCAPED_SLASHES) . ',';
}
$out = substr($out, 0, -1);
$out .= "\n]";
$this->response->addContent($out);
return;
}
}
$this->postPerform();
}
}