Skip to content

Commit ef19547

Browse files
committed
Convert newinstance to anonymous classes
1 parent 9dab443 commit ef19547

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

src/test/php/peer/ftp/unittest/TestingServer.class.php

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
<?php namespace peer\ftp\unittest;
22

3+
use lang\Throwable;
34
use peer\ftp\server\{Authentication, FtpProtocol};
45
use peer\server\Server;
56
use util\cmd\Console;
6-
use util\log\{FileAppender, Logger};
7+
use util\log\Logging;
78

89
/**
910
* FTP Server used by IntegrationTest.
1011
*
1112
* Specifics
12-
* ~~~~~~~~~
13-
* <ul>
14-
* <li>Server listens on a free port @ 127.0.0.1</li>
15-
* <li>Authentication requires "test" / "test" as credentials</li>
16-
* <li>Storage is inside an "ftproot" subdirectory of this directory</li>
17-
* <li>Server can be shut down by issuing the "SHUTDOWN" command</li>
18-
* <li>On startup success, "+ Service (IP):(PORT)" is written to standard out</li>
19-
* <li>On shutdown, "+ Done" is written to standard out</li>
20-
* <li>On errors during any phase, "- " and the exception message are written</li>
21-
* </ul>
13+
* ---------
14+
* - Server listens on a free port @ 127.0.0.1</li>
15+
* - Authentication requires "test" / "test" as credentials</li>
16+
* - Storage is inside an "ftproot" subdirectory of this directory</li>
17+
* - Server can be shut down by issuing the "SHUTDOWN" command</li>
18+
* - On startup success, "+ Service (IP):(PORT)" is written to standard out</li>
19+
* - On shutdown, "+ Done" is written to standard out</li>
20+
* - On errors during any phase, "- " and the exception message are written</li>
2221
*
2322
* @see xp://net.xp_framework.unittest.peer.ftp.IntegrationTest
2423
*/
@@ -41,32 +40,28 @@ public static function main(array $args) {
4140
$stor->add(new TestingCollection('/outer/inner', $stor));
4241
$stor->add(new TestingElement('/outer/inner/index.html', $stor));
4342

44-
$auth= newinstance(Authentication::class, [], '{
43+
$auth= new class() implements Authentication {
4544
public function authenticate($user, $password) {
46-
return ("testtest" == $user.$password);
45+
return ('testtest' == $user.$password);
4746
}
48-
}');
47+
};
4948

50-
$protocol= newinstance(FtpProtocol::class, [$stor, $auth], '{
49+
$protocol= new class($stor, $auth) extends FtpProtocol {
5150
public function onShutdown($socket, $params) {
52-
$this->answer($socket, 200, "Shutting down");
51+
$this->answer($socket, 200, 'Shutting down');
5352
$this->server->terminate= true;
5453
}
55-
}');
54+
};
55+
isset($args[0]) && $protocol->setTrace(Logging::all()->toFile($args[0]));
5656

57-
isset($args[0]) && $protocol->setTrace(Logger::getInstance()
58-
->getCategory()
59-
->withAppender(new FileAppender($args[0]))
60-
);
61-
6257
$s= new Server('127.0.0.1', 0);
6358
try {
6459
$s->setProtocol($protocol);
6560
$s->init();
6661
Console::writeLinef('+ Service %s:%d', $s->socket->host, $s->socket->port);
6762
$s->service();
6863
Console::writeLine('+ Done');
69-
} catch (\lang\Throwable $e) {
64+
} catch (Throwable $e) {
7065
Console::writeLine('- ', $e->getMessage());
7166
}
7267
}

0 commit comments

Comments
 (0)