This commit is contained in:
Simon Vieille 2015-02-21 09:59:38 +01:00
parent bba5899bc2
commit cc6440ef89
2 changed files with 50 additions and 0 deletions

View File

@ -7,6 +7,7 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
use Deblan\PowerDNS\Command\Helper\ZoneHelper;
use Deblan\PowerDNS\Command\Helper\DomainHelper;
use Deblan\PowerDNS\Command\Helper\ValidatorHelper;
abstract class AbstractCommand extends Command
{
@ -14,6 +15,8 @@ abstract class AbstractCommand extends Command
protected $output;
protected $dialog;
public function getHelper($helper)
{
if ($helper === 'zone') {
@ -24,6 +27,14 @@ abstract class AbstractCommand extends Command
return DomainHelper::getInstance($this->getInput(), $this->getOutput());
}
if ($helper === 'validator') {
return ValidatorHelper::getInstance($this->getInput(), $this->getOutput());
}
if ($helper === 'dialog') {
return $this->getHelperSet()->get('dialog');
}
throw new \InvalidArgumentException(sprintf('Invalid helper "%s"', $helper));
}

View File

@ -0,0 +1,39 @@
<?php
namespace Deblan\PowerDNS\Command\Helper;
use Deblan\Console\Command\Helper\AbstractHelper;
use Deblan\PowerDNS\Model\Map\ZoneRecordTableMap;
class ValidatorHelper extends AbstractHelper
{
public function isIp($value)
{
return filter_var($value, FILTER_VALIDATE_IP);
}
public function isRecordType($value)
{
return in_array($value, ZoneRecordTableMap::getValueSet(ZoneRecordTableMap::COL_TYPE));
}
public function isDomainName($value)
{
return preg_match('/^(?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.?){1,126}(?!\d+)[a-zA-Z\d]{1,63}$/', $value);
}
public function isDomainMaster($value)
{
return $value === null || $this->isDomainName($value);
}
public function isDomainType($value)
{
return in_array($value, ['NATIVE', 'MASTER', 'SLAVE', 'SUPERSLAVE']);
}
public static function getName()
{
return 'validator';
}
}