1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Magium\Cli\Command; |
4
|
|
|
|
5
|
|
|
use Magium\Cli\ConfigurationPathInterface; |
6
|
|
|
use Magium\NotFoundException; |
7
|
|
|
use Magium\Util\Configuration\ConfigurationCollector\DefaultPropertyCollector; |
8
|
|
|
use Symfony\Component\Console\Command\Command; |
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Input\InputOption; |
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
13
|
|
|
use Zend\Config\Config; |
14
|
|
|
use Zend\Config\Writer\Json; |
15
|
|
|
|
16
|
|
|
class GetElementValue extends Command implements ConfigurationPathInterface |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
protected $path; |
20
|
|
|
|
21
|
|
|
public function setPath($path) |
22
|
|
|
{ |
23
|
|
|
$this->path = $path; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
protected function configure() |
27
|
|
|
{ |
28
|
|
|
$this->setName('element:get'); |
29
|
|
|
$this->setDescription('Retrieves the default values for a configurable element'); |
30
|
|
|
$this->addArgument('class', InputArgument::REQUIRED, 'Need the full name of the class, including namespace'); |
31
|
|
|
$this->addArgument('filter', InputArgument::OPTIONAL, 'A stripos()-based filter of the properties'); |
32
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
36
|
|
|
{ |
37
|
|
|
$collector = new DefaultPropertyCollector(); |
38
|
|
|
$class = $input->getArgument('class'); |
39
|
|
|
if (!class_exists($class)) { |
40
|
|
|
throw new NotFoundException('Could not find the class: ' . $class); |
41
|
|
|
} |
42
|
|
|
if (!is_subclass_of($class, 'Magium\AbstractConfigurableElement')) { |
43
|
|
|
throw new \InvalidArgumentException('Class must be a sub-class of Magium\AbstractConfigurableElement'); |
44
|
|
|
} |
45
|
|
|
$properties = $collector->extract($class); |
46
|
|
|
$print = []; |
47
|
|
|
if ($input->getArgument('filter')) { |
48
|
|
|
$filter = $input->getArgument('filter'); |
49
|
|
|
foreach ($properties as $property) { |
50
|
|
|
if (stripos($property->getName(), $filter) !== false) { |
51
|
|
|
$print[] = $property; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} else { |
55
|
|
|
$print = $properties; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
foreach ($print as $property) { |
59
|
|
|
$output->writeln(''); |
60
|
|
|
$output->writeln($property->getName()); |
61
|
|
|
$output->writeln("\tDefault Value: " . $property->getDefaultValue()); |
62
|
|
|
if ($property->getDescription()) { |
63
|
|
|
$output->writeln("\t" . $property->getDescription()); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|