123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
-
- namespace App\Http\Business;
-
- use Carbon\Carbon;
- use Luticate\Utils\LuBusiness;
- use App\Http\DataAccess\DnsRecordsDataAccess;
- use App\Http\DBO\DnsRecordsDbo;
-
- class DnsRecordsBusiness extends LuBusiness {
-
- const RECORD_TYPES = array("A", "AAAA", "CNAME", "HINFO", "MX", "NAPTR", "NS", "PTR",
- "SOA", "SPF", "SRV", "SSHFP", "TXT", "RP");
-
- protected static function getDataAccess()
- {
- return new DnsRecordsDataAccess();
- }
-
- public static function checkRecord(DnsRecordsDbo $record)
- {
- DnsDomainsBusiness::getById($record->getDomainId());
- if (is_null($record->getName()) || !is_string($record->getName())) {
- self::badInput("Name must be an string");
- }
- if (is_null($record->getContent()) || !is_string($record->getContent())) {
- self::badInput("Content must be an string");
- }
- if (!in_array($record->getType(), self::RECORD_TYPES)) {
- self::badInput("Type be must be one of " . join(",", self::RECORD_TYPES));
- }
- if (!is_bool($record->getDisabled())) {
- self::badInput("Disabled must be a boolean");
- }
- if (!is_bool($record->getAuth())) {
- self::badInput("Auth must be a boolean");
- }
- if (!is_null($record->getOrdername()) && !is_string($record->getOrdername())) {
- self::badInput("Ordername must be an string or null");
- }
- if (!is_int($record->getPrio())) {
- self::badInput("Prio must be an int");
- }
- if (!is_int($record->getTtl())) {
- self::badInput("Ttl must be a int");
- }
- $record->setChangeDate(Carbon::now()->timestamp);
- }
-
- public static function getAll($domain_id, $page = 0, $perPage = PHP_INT_MAX, $query = "")
- {
- return DnsRecordsDataAccess::getAll($domain_id, $query, $page, $perPage);
- }
-
- public static function add(DnsRecordsDbo $record)
- {
- self::checkRecord($record);
- return DnsRecordsDataAccess::addId($record);
- }
- }
|