Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.

Commit ea27223

Browse files
committed
Remove from/import and update to PHP5.4.
1 parent bef17e1 commit ea27223

File tree

14 files changed

+126
-303
lines changed

14 files changed

+126
-303
lines changed

Bin/Client.php

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,11 @@
3434
* POSSIBILITY OF SUCH DAMAGE.
3535
*/
3636

37-
namespace {
37+
namespace Hoa\Websocket\Bin;
3838

39-
from('Hoa')
40-
41-
/**
42-
* \Hoa\Websocket\Client
43-
*/
44-
-> import('Websocket.Client')
45-
46-
/**
47-
* \Hoa\Socket\Client
48-
*/
49-
-> import('Socket.Client')
50-
51-
/**
52-
* \Hoa\Console\Readline
53-
*/
54-
-> import('Console.Readline.~');
55-
56-
}
57-
58-
namespace Hoa\Websocket\Bin {
39+
use Hoa\Console;
40+
use Hoa\Socket;
41+
use Hoa\Websocket;
5942

6043
/**
6144
* Class \Hoa\Websocket\Bin\Client.
@@ -67,18 +50,18 @@
6750
* @license New BSD License
6851
*/
6952

70-
class Client extends \Hoa\Console\Dispatcher\Kit {
53+
class Client extends Console\Dispatcher\Kit {
7154

7255
/**
7356
* Options description.
7457
*
7558
* @var \Hoa\Websocket\Bin\Client array
7659
*/
77-
protected $options = array(
78-
array('server', \Hoa\Console\GetOption::REQUIRED_ARGUMENT, 's'),
79-
array('help', \Hoa\Console\GetOption::NO_ARGUMENT, 'h'),
80-
array('help', \Hoa\Console\GetOption::NO_ARGUMENT, '?')
81-
);
60+
protected $options = [
61+
['server', Console\GetOption::REQUIRED_ARGUMENT, 's'],
62+
['help', Console\GetOption::NO_ARGUMENT, 'h'],
63+
['help', Console\GetOption::NO_ARGUMENT, '?']
64+
];
8265

8366

8467

@@ -109,9 +92,9 @@ public function main ( ) {
10992
}
11093

11194

112-
$readline = new \Hoa\Console\Readline();
113-
$client = new \Hoa\Websocket\Client(
114-
new \Hoa\Socket\Client('tcp://' . $server)
95+
$readline = new Console\Readline();
96+
$client = new Websocket\Client(
97+
new Socket\Client('tcp://' . $server)
11598
);
11699
$client->setHost('localhost');
117100
$client->connect();
@@ -142,16 +125,14 @@ public function usage ( ) {
142125

143126
echo 'Usage : websocket:client <options>', "\n",
144127
'Options :', "\n",
145-
$this->makeUsageOptionsList(array(
128+
$this->makeUsageOptionsList([
146129
's' => 'Server URI (default: 127.0.0.1:8889).',
147130
'help' => 'This help.'
148-
)), "\n";
131+
]), "\n";
149132

150133
return;
151134
}
152135
}
153136

154-
}
155-
156137
__halt_compiler();
157138
Basic WebSocket client.

Client.php

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,11 @@
3434
* POSSIBILITY OF SUCH DAMAGE.
3535
*/
3636

37-
namespace {
37+
namespace Hoa\Websocket;
3838

39-
from('Hoa')
40-
41-
/**
42-
* \Hoa\Websocket\Connection
43-
*/
44-
-> import('Websocket.Connection')
45-
46-
/**
47-
* \Hoa\Http\Response
48-
*/
49-
-> import('Http.Response.~');
50-
51-
}
52-
53-
namespace Hoa\Websocket {
39+
use Hoa\Core;
40+
use Hoa\Http;
41+
use Hoa\Socket;
5442

5543
/**
5644
* Class \Hoa\Websocket\Client.
@@ -97,14 +85,14 @@ class Client extends Connection {
9785
* @return void
9886
* @throw \Hoa\Socket\Exception
9987
*/
100-
public function __construct ( \Hoa\Socket\Client $client, $endPoint = '/',
101-
\Hoa\Http\Response $response = null ) {
88+
public function __construct ( Socket\Client $client, $endPoint = '/',
89+
Http\Response $response = null ) {
10290

10391
parent::__construct($client);
10492
$this->setEndPoint($endPoint);
10593

10694
if(null === $response)
107-
$response = new \Hoa\Http\Response(false);
95+
$response = new Http\Response(false);
10896

10997
$this->setResponse($response);
11098

@@ -164,12 +152,12 @@ public function receive ( ) {
164152
*/
165153
protected function doHandshake ( ) {
166154

167-
static $_tail = array('A', 'Q', 'g', 'w');
155+
static $_tail = ['A', 'Q', 'g', 'w'];
168156

169157
$connection = $this->getConnection();
170158
$connection->connect();
171159
$connection->setStreamBlocking(true);
172-
$key = substr(base64_encode(\Hoa\Core::uuid()), 0, 21) .
160+
$key = substr(base64_encode(Core::uuid()), 0, 21) .
173161
$_tail[mt_rand(0, 3)] . '==';
174162
$expected = base64_encode(sha1($key . Protocol\Rfc6455::GUID, true));
175163

@@ -203,18 +191,18 @@ protected function doHandshake ( ) {
203191
'response.' . "\n\n" .
204192
'Client:' . "\n" . ' %s' . "\n" .
205193
'Server:' . "\n" . ' %s',
206-
0, array(
194+
0, [
207195
str_replace("\n", "\n" . ' ', $request),
208196
str_replace("\n", "\n" . ' ', $buffer)
209-
));
197+
]);
210198

211199
$currentNode = $connection->getCurrentNode();
212200
$currentNode->setHandshake(SUCCEED);
213201
$currentNode->setProtocolImplementation(new Protocol\Rfc6455($connection));
214202

215203
$this->_on->fire(
216204
'open',
217-
new \Hoa\Core\Event\Bucket()
205+
new Core\Event\Bucket()
218206
);
219207

220208
return;
@@ -277,7 +265,7 @@ public function getEndPoint ( ) {
277265
* @param \Hoa\Http\Response $response Response.
278266
* @return \Hoa\Http\Response
279267
*/
280-
public function setResponse ( \Hoa\Http\Response $response ) {
268+
public function setResponse ( Http\Response $response ) {
281269

282270
$old = $this->_response;
283271
$this->_response = $response;
@@ -326,5 +314,3 @@ public function getHost ( ) {
326314
: null);
327315
}
328316
}
329-
330-
}

0 commit comments

Comments
 (0)