Debian Codegraph @

vendor/react/dns/src/Query/Query.php

raw
1 <?php
2
3 namespace React\Dns\Query;
4
5 use React\Dns\Model\Message;
6
7 /**
8 * This class represents a single question in a query/response message
9 *
10 * It uses a structure similar to `\React\Dns\Message\Record`, but does not
11 * contain fields for resulting TTL and resulting record data (IPs etc.).
12 *
13 * @link https://tools.ietf.org/html/rfc1035#section-4.1.2
14 * @see \React\Dns\Message\Record
15 */
16 final class Query
17 {
18 /**
19 * @var string query name, i.e. hostname to look up
20 */
21 public $name;
22
23 /**
24 * @var int query type (aka QTYPE), see Message::TYPE_* constants
25 */
26 public $type;
27
28 /**
29 * @var int query class (aka QCLASS), see Message::CLASS_IN constant
30 */
31 public $class;
32
33 /**
34 * @param string $name query name, i.e. hostname to look up
35 * @param int $type query type, see Message::TYPE_* constants
36 * @param int $class query class, see Message::CLASS_IN constant
37 */
38 public function __construct($name, $type, $class)
39 {
40 $this->name = $name;
41 $this->type = $type;
42 $this->class = $class;
43 }
44
45 /**
46 * Describes the hostname and query type/class for this query
47 *
48 * The output format is supposed to be human readable and is subject to change.
49 * The format is inspired by RFC 3597 when handling unkown types/classes.
50 *
51 * @return string "example.com (A)" or "example.com (CLASS0 TYPE1234)"
52 * @link https://tools.ietf.org/html/rfc3597
53 */
54 public function describe()
55 {
56 $class = $this->class !== Message::CLASS_IN ? 'CLASS' . $this->class . ' ' : '';
57
58 $type = 'TYPE' . $this->type;
59 $ref = new \ReflectionClass('React\Dns\Model\Message');
60 foreach ($ref->getConstants() as $name => $value) {
61 if ($value === $this->type && \strpos($name, 'TYPE_') === 0) {
62 $type = \substr($name, 5);
63 break;
64 }
65 }
66
67 return $this->name . ' (' . $class . $type . ')';
68 }
69 }