Helpers
This commit is contained in:
parent
bba5899bc2
commit
cc6440ef89
|
@ -7,6 +7,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Deblan\PowerDNS\Command\Helper\ZoneHelper;
|
use Deblan\PowerDNS\Command\Helper\ZoneHelper;
|
||||||
use Deblan\PowerDNS\Command\Helper\DomainHelper;
|
use Deblan\PowerDNS\Command\Helper\DomainHelper;
|
||||||
|
use Deblan\PowerDNS\Command\Helper\ValidatorHelper;
|
||||||
|
|
||||||
abstract class AbstractCommand extends Command
|
abstract class AbstractCommand extends Command
|
||||||
{
|
{
|
||||||
|
@ -14,6 +15,8 @@ abstract class AbstractCommand extends Command
|
||||||
|
|
||||||
protected $output;
|
protected $output;
|
||||||
|
|
||||||
|
protected $dialog;
|
||||||
|
|
||||||
public function getHelper($helper)
|
public function getHelper($helper)
|
||||||
{
|
{
|
||||||
if ($helper === 'zone') {
|
if ($helper === 'zone') {
|
||||||
|
@ -24,6 +27,14 @@ abstract class AbstractCommand extends Command
|
||||||
return DomainHelper::getInstance($this->getInput(), $this->getOutput());
|
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));
|
throw new \InvalidArgumentException(sprintf('Invalid helper "%s"', $helper));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
39
src/Deblan/PowerDNS/Command/Helper/ValidatorHelper.php
Normal file
39
src/Deblan/PowerDNS/Command/Helper/ValidatorHelper.php
Normal 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';
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue