pdns-console/src/Deblan/PowerDNS/Command/ZoneListCommand.php

52 lines
1.4 KiB
PHP
Raw Normal View History

2015-02-17 01:56:22 +01:00
<?php
namespace Deblan\PowerDNS\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Deblan\PowerDNS\Model\ZoneQuery;
2015-02-18 13:39:02 +01:00
class ZoneListCommand extends AbstractZoneCommand
2015-02-17 01:56:22 +01:00
{
protected function configure()
{
2015-02-18 13:54:54 +01:00
parent::configure();
2015-02-18 13:39:02 +01:00
2015-02-17 01:56:22 +01:00
$this
->setName('zone:list')
->setDescription('List DNS zones')
2015-02-23 21:36:20 +01:00
->addOption('name', null, InputOption::VALUE_REQUIRED, 'Filter by zone name')
->addOption('id', null, InputOption::VALUE_REQUIRED, 'Filter by zone ID')
->addOption('vs', null, InputOption::VALUE_REQUIRED, 'Filter zone version');
2015-02-17 01:56:22 +01:00
}
protected function execute(InputInterface $input, OutputInterface $output)
{
2015-02-18 13:39:02 +01:00
parent::execute($input, $output);
2015-02-18 13:54:54 +01:00
$query = $this->getZoneQuery();
2015-02-17 01:56:22 +01:00
2015-02-18 13:39:02 +01:00
$zones = $query->find();
2015-02-17 01:56:22 +01:00
2015-02-18 13:39:02 +01:00
foreach ($zones as $key => $zone) {
$this->getHelper('zone')->showZone($zone, $key);
2015-02-17 14:29:30 +01:00
}
}
2015-02-18 13:39:02 +01:00
protected function getZoneQuery()
2015-02-17 14:29:30 +01:00
{
2015-02-18 13:39:02 +01:00
$query = ZoneQuery::create()->orderByName();
2015-02-17 14:29:30 +01:00
2015-02-18 13:39:02 +01:00
if ($this->getInput()->getOption('name')) {
$query->filterByName(sprintf('%%%s%%', $this->getInput()->getOption('name')));
2015-02-17 14:29:30 +01:00
}
2015-02-23 21:36:20 +01:00
if ($this->getInput()->getOption('id')) {
2015-02-21 17:47:01 +01:00
$query->filterById((int) $this->getInput()->getOption('id'));
}
2015-02-17 14:29:30 +01:00
2015-02-18 13:39:02 +01:00
return $query;
2015-02-17 01:56:22 +01:00
}
}