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