id = $id; $this->source = $source; $this->target = $target; $this->match_type = $match_type; $this->status = $status; $this->query_mode = $query_mode; $this->case_sensitive = $case_sensitive; $this->enabled = $enabled; $this->hits = $hits; $this->last_hit = $last_hit; $this->position = $position; } /** * @param array $row Database row or CSV record. */ public static function from_array( array $row ): self { return new self( (string) ( $row['source'] ?? '' ), (string) ( $row['target'] ?? '' ), (string) ( $row['match_type'] ?? self::EXACT ), (int) ( $row['status'] ?? 301 ), (string) ( $row['query_mode'] ?? self::QUERY_IGNORE ), ! empty( $row['case_sensitive'] ), ! array_key_exists( 'enabled', $row ) || ! empty( $row['enabled'] ), (int) ( $row['id'] ?? 0 ), (int) ( $row['hits'] ?? 0 ), isset( $row['last_hit'] ) && '' !== $row['last_hit'] ? (string) $row['last_hit'] : null, (int) ( $row['position'] ?? 0 ) ); } /** * @return array */ public function to_array(): array { return array( 'id' => $this->id, 'source' => $this->source, 'target' => $this->target, 'match_type' => $this->match_type, 'status' => $this->status, 'query_mode' => $this->query_mode, 'case_sensitive' => $this->case_sensitive ? 1 : 0, 'enabled' => $this->enabled ? 1 : 0, 'hits' => $this->hits, 'last_hit' => $this->last_hit, 'position' => $this->position, ); } public function is_gone(): bool { return 410 === $this->status; } }