aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2014-09-28 20:59:17 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2014-09-28 20:59:17 +0200
commit9842c9766166b79cf1532ec35961dc117b0494f3 (patch)
tree2eeb0380d41334444ca78f48aad430507b0a2603
parentd4b4a61958e0ca50445258136c2c634c7b8b85b5 (diff)
downloadDns-9842c9766166b79cf1532ec35961dc117b0494f3.zip
Dns-9842c9766166b79cf1532ec35961dc117b0494f3.tar.gz
Dns-9842c9766166b79cf1532ec35961dc117b0494f3.tar.bz2
Remove from/import and update to PHP5.4.
-rw-r--r--Bin/Server.php45
-rw-r--r--Exception.php8
-rw-r--r--Resolver.php34
3 files changed, 32 insertions, 55 deletions
diff --git a/Bin/Server.php b/Bin/Server.php
index e967246..e1d8d69 100644
--- a/Bin/Server.php
+++ b/Bin/Server.php
@@ -34,23 +34,12 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Dns\Bin;
-from('Hoa')
-
-/**
- * \Hoa\Socket\Server
- */
--> import('Socket.Server')
-
-/**
- * \Hoa\Dns
- */
--> import('Dns.~');
-
-}
-
-namespace Hoa\Dns\Bin {
+use Hoa\Core;
+use Hoa\Console;
+use Hoa\Dns;
+use Hoa\Socket;
/**
* Class Hoa\Dns\Bin\Server.
@@ -62,18 +51,18 @@ namespace Hoa\Dns\Bin {
* @license New BSD License
*/
-class Server extends \Hoa\Console\Dispatcher\Kit {
+class Server extends Console\Dispatcher\Kit {
/**
* Options description.
*
* @var \Hoa\Dns\Bin\Server array
*/
- protected $options = array(
- array('listen', \Hoa\Console\GetOption::REQUIRED_ARGUMENT, 'l'),
- array('help', \Hoa\Console\GetOption::NO_ARGUMENT, 'h'),
- array('help', \Hoa\Console\GetOption::NO_ARGUMENT, '?')
- );
+ protected $options = [
+ ['listen', Console\GetOption::REQUIRED_ARGUMENT, 'l'],
+ ['help', Console\GetOption::NO_ARGUMENT, 'h'],
+ ['help', Console\GetOption::NO_ARGUMENT, '?']
+ ];
@@ -104,7 +93,7 @@ class Server extends \Hoa\Console\Dispatcher\Kit {
break;
}
- $redirections = array();
+ $redirections = [];
$inputs = $this->parser->getInputs();
if(empty($inputs)) {
@@ -132,8 +121,8 @@ class Server extends \Hoa\Console\Dispatcher\Kit {
$redirections[$from] = $to;
}
- $dns = new \Hoa\Dns(new \Hoa\Socket\Server('udp://' . $listen));
- $dns->on('query', function ( \Hoa\Core\Event\Bucket $bucket )
+ $dns = new Dns\Resolver(new Socket\Server('udp://' . $listen));
+ $dns->on('query', function ( Core\Event\Bucket $bucket )
use ( &$redirections ) {
$data = $bucket->getData();
@@ -169,10 +158,10 @@ class Server extends \Hoa\Console\Dispatcher\Kit {
echo 'Usage : dns:server <options> [<regex> to <ip>]+', "\n",
'Options :', "\n",
- $this->makeUsageOptionsList(array(
+ $this->makeUsageOptionsList([
'l' => 'Socket URI to listen (default: 127.0.0.1:57005).',
'help' => 'This help.'
- )), "\n",
+ ]), "\n",
'Example: `… dns:server \'foo.*\' to 1.2.3.4 \\', "\n",
' \'bar.*\' to 5.6.7.8`.', "\n";
@@ -180,7 +169,5 @@ class Server extends \Hoa\Console\Dispatcher\Kit {
}
}
-}
-
__halt_compiler();
Quick DNS server.
diff --git a/Exception.php b/Exception.php
index 5fbbb57..3791bb5 100644
--- a/Exception.php
+++ b/Exception.php
@@ -34,7 +34,9 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace Hoa\Dns {
+namespace Hoa\Dns;
+
+use Hoa\Core;
/**
* Class \Hoa\Dns\Exception.
@@ -46,6 +48,4 @@ namespace Hoa\Dns {
* @license New BSD License
*/
-class Exception extends \Hoa\Core\Exception { }
-
-}
+class Exception extends Core\Exception { }
diff --git a/Resolver.php b/Resolver.php
index 57b33b7..9a30436 100644
--- a/Resolver.php
+++ b/Resolver.php
@@ -34,18 +34,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Dns;
-from('Hoa')
-
-/**
- * \Hoa\Dns\Exception
- */
--> import('Dns.Exception');
-
-}
-
-namespace Hoa\Dns {
+use Hoa\Core;
+use Hoa\Socket;
/**
* Class \Hoa\Dns\Resolver.
@@ -58,7 +50,7 @@ namespace Hoa\Dns {
* @license New BSD License
*/
-class Resolver implements \Hoa\Core\Event\Listenable {
+class Resolver implements Core\Event\Listenable {
/**
* Listeners.
@@ -81,7 +73,7 @@ class Resolver implements \Hoa\Core\Event\Listenable {
*
* @var \Hoa\Dns array
*/
- protected static $_types = array(
+ protected static $_types = [
'invalid' => 0, // Invalid.
'a' => 1, // Host address.
'ns' => 2, // Authorative name server.
@@ -146,21 +138,21 @@ class Resolver implements \Hoa\Core\Event\Listenable {
'zxfr' => 256, // BIND-specific, nonstandard.
'dlv' => 32769, // DNSSEC look-aside validation.
'max' => 65536
- );
+ ];
/**
* Class values for resources and queries.
*
* @var \Hoa\Dns\Resolver array
*/
- protected static $_classes = array(
+ protected static $_classes = [
'in' => 1, // Internet.
'cs' => 2, // CSNET (obsolete).
'ch' => 3, // Chaos.
'hs' => 4, // Hesiod.
'qnone' => 254, // QClass none.
'qany' => 255 // QClass any.
- );
+ ];
@@ -171,7 +163,7 @@ class Resolver implements \Hoa\Core\Event\Listenable {
* @param \Hoa\Socket\Server $server Server.
* @return void
*/
- public function __construct ( \Hoa\Socket\Server $server ) {
+ public function __construct ( Socket\Server $server ) {
if('udp' != $server->getSocket()->getTransport())
throw new Exception(
@@ -181,7 +173,7 @@ class Resolver implements \Hoa\Core\Event\Listenable {
set_time_limit(0);
$this->_server = $server;
- $this->_on = new \Hoa\Core\Event\Listener($this, array('query'));
+ $this->_on = new Core\Event\Listener($this, ['query']);
return;
}
@@ -248,11 +240,11 @@ class Resolver implements \Hoa\Core\Event\Listenable {
$qclass = (int) (string) ord($handle[$i]);
$class = array_search($qclass, static::$_classes) ?: $qclass;
- $ips = $this->_on->fire('query', new \Hoa\Core\Event\Bucket(array(
+ $ips = $this->_on->fire('query', new Core\Event\Bucket([
'domain' => $domain,
'type' => $type,
'class' => $class
- )));
+ ]));
$ip = null;
if(false === $ips[0]) {
@@ -345,5 +337,3 @@ class Resolver implements \Hoa\Core\Event\Listenable {
return;
}
}
-
-}