Hoa central
Public Member Functions | Protected Attributes | List of all members
Hoa\Dns\Bin\Resolve Class Reference
Inheritance diagram for Hoa\Dns\Bin\Resolve:

Public Member Functions

 main ()
 
 usage ()
 
- Public Member Functions inherited from Hoa\Console\Dispatcher\Kit
 __construct (Router $router, Dispatcher $dispatcher, View\Viewable $view=null)
 
 getOption (&$optionValue, $short=null)
 
 setOptions (Array $options)
 
 makeUsageOptionsList (Array $definitions=[])
 
 resolveOptionAmbiguity (Array $solutions)
 
 status ($text, $status)
 
 readLine ($prefix=null)
 
 readPassword ($prefix=null)
 
- Public Member Functions inherited from Hoa\Dispatcher\Kit
 __construct (Router $router, Dispatcher $dispatcher, View\Viewable $view=null)
 
 construct ()
 

Protected Attributes

 $options
 
- Protected Attributes inherited from Hoa\Console\Dispatcher\Kit
 $options = null
 
 $_options = null
 

Additional Inherited Members

- Public Attributes inherited from Hoa\Console\Dispatcher\Kit
 $parser = null
 
- Public Attributes inherited from Hoa\Dispatcher\Kit
 $router = null
 
 $dispatcher = null
 
 $view = null
 
 $data = null
 

Detailed Description

Class Hoa.

Quick DNS resolver.

Definition at line 52 of file Resolve.php.

Member Function Documentation

Hoa\Dns\Bin\Resolve::main ( )

The entry method.

Returns
int

Definition at line 72 of file Resolve.php.

73  {
74  $listen = '127.0.0.1:57005';
75 
76  while (false !== $c = $this->getOption($v)) {
77  switch ($c) {
78  case 'l':
79  $listen = $v;
80 
81  break;
82 
83  case '__ambiguous':
84  $this->resolveOptionAmbiguity($v);
85 
86  break;
87 
88  case 'h':
89  case '?':
90  default:
91  return $this->usage();
92  }
93  }
94 
95  $redirections = [];
96  $inputs = $this->parser->getInputs();
97 
98  if (empty($inputs)) {
99  $this->usage();
100 
101  return;
102  }
103 
104  for ($i = 0, $max = count($inputs); $i < $max; $i += 3) {
105  $from = str_replace('#', '\#', $inputs[$i]);
106 
107  if (false === @preg_match('#^' . $from . '$#', '', $_)) {
108  echo 'Expression ', $from, ' does not compile correctly.', "\n";
109 
110  return 1;
111  }
112 
113  if ('to' !== $inputs[$i + 1]) {
114  continue;
115  }
116 
117  $to = $inputs[$i + 2];
118  $redirections[$from] = $to;
119  }
120 
121  $dns = new Dns\Resolver(new Socket\Server('udp://' . $listen));
122  $dns->on('query', function (Core\Event\Bucket $bucket) use (&$redirections) {
123 
124  $data = $bucket->getData();
125  echo
126  'Resolving domain ', $data['domain'],
127  ' of type ', $data['type'], ' to ';
128 
129  foreach ($redirections as $from => $to) {
130  if (0 !== preg_match('#^' . $from . '$#', $data['domain'], $_)) {
131  echo $to, ".\n";
132 
133  return $to;
134  }
135  }
136 
137  echo '127.0.0.1 (default).', "\n";
138 
139  return '127.0.0.1';
140  });
141 
142  echo 'Server is up, on udp://' . $listen . '!', "\n\n";
143  $dns->run();
144 
145  return;
146  }
getOption(&$optionValue, $short=null)
Definition: Kit.php:104
resolveOptionAmbiguity(Array $solutions)
Definition: Kit.php:190

Here is the call graph for this function:

Hoa\Dns\Bin\Resolve::usage ( )

The command usage.

Returns
int

Definition at line 153 of file Resolve.php.

154  {
155  echo
156  'Usage : dns:resolve <options> [<regex> to <ip>]+', "\n",
157  'Options :', "\n",
158  $this->makeUsageOptionsList([
159  'l' => 'Socket URI to listen (default: 127.0.0.1:57005).',
160  'help' => 'This help.'
161  ]), "\n",
162  'Example: `… dns:resolve \'foo.*\' to 1.2.3.4 \\', "\n",
163  ' \'bar.*\' to 5.6.7.8`.', "\n";
164 
165  return;
166  }
makeUsageOptionsList(Array $definitions=[])
Definition: Kit.php:149

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

Hoa\Dns\Bin\Resolve::$options
protected
Initial value:

Definition at line 59 of file Resolve.php.


The documentation for this class was generated from the following file: