|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Swaggest\JsonCli; |
|
4
|
|
|
|
|
5
|
|
|
use Yaoi\Command; |
|
6
|
|
|
|
|
7
|
|
|
class DiffInfo extends BaseDiff |
|
8
|
|
|
{ |
|
9
|
|
|
public $withContents; |
|
10
|
|
|
public $withPaths; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @param Command\Definition $definition |
|
14
|
|
|
* @param \stdClass|static $options |
|
15
|
|
|
*/ |
|
16
|
1 |
|
static function setUpDefinition(Command\Definition $definition, $options) |
|
17
|
|
|
{ |
|
18
|
1 |
|
parent::setUpDefinition($definition, $options); |
|
19
|
1 |
|
$options->withContents = Command\Option::create()->setDescription('Add content to output'); |
|
20
|
1 |
|
$options->withPaths = Command\Option::create()->setDescription('Add paths to output'); |
|
21
|
1 |
|
$definition->description = 'Show diff info for two JSON documents'; |
|
22
|
1 |
|
} |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
1 |
|
public function performAction() |
|
26
|
|
|
{ |
|
27
|
1 |
|
$this->prePerform(); |
|
28
|
|
|
|
|
29
|
1 |
|
$this->out = array( |
|
30
|
1 |
|
'addedCnt' => $this->diff->getAddedCnt(), |
|
31
|
1 |
|
'modifiedCnt' => $this->diff->getAddedCnt(), |
|
32
|
1 |
|
'removedCnt' => $this->diff->getRemovedCnt(), |
|
33
|
|
|
); |
|
34
|
1 |
|
if ($this->withPaths) { |
|
35
|
1 |
|
$this->out = array_merge($this->out, array( |
|
36
|
1 |
|
'addedPaths' => $this->diff->getAddedPaths(), |
|
37
|
1 |
|
'modifiedPaths' => $this->diff->getModifiedPaths(), |
|
38
|
1 |
|
'removedPaths' => $this->diff->getRemovedPaths(), |
|
39
|
|
|
)); |
|
40
|
|
|
} |
|
41
|
1 |
|
if ($this->withContents) { |
|
42
|
1 |
|
$this->out = array_merge($this->out, array( |
|
43
|
1 |
|
'added' => $this->diff->getAdded(), |
|
44
|
1 |
|
'modifiedNew' => $this->diff->getModifiedNew(), |
|
45
|
1 |
|
'modifiedOriginal' => $this->diff->getModifiedOriginal(), |
|
46
|
1 |
|
'removed' => $this->diff->getRemoved(), |
|
47
|
|
|
)); |
|
48
|
|
|
} |
|
49
|
1 |
|
$this->postPerform(); |
|
50
|
1 |
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
} |