@@ -14,85 +14,85 @@ |
||
14 | 14 | */ |
15 | 15 | class ClientSocket extends Socket { |
16 | 16 | |
17 | - /** |
|
18 | - * Whether the socket is connected |
|
19 | - * |
|
20 | - * @var boolean |
|
21 | - */ |
|
22 | - private $conntected; |
|
17 | + /** |
|
18 | + * Whether the socket is connected |
|
19 | + * |
|
20 | + * @var boolean |
|
21 | + */ |
|
22 | + private $conntected; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Create a new client socket |
|
26 | - * |
|
27 | - * @param Endpoint $endpoint |
|
28 | - * The endpoint to use |
|
29 | - * @param resource $clientHandle |
|
30 | - * optional existing client handle |
|
31 | - */ |
|
32 | - public function __construct(Endpoint $endpoint, $clientHandle = null) { |
|
33 | - $this->endpoint = $endpoint; |
|
34 | - $this->handle = $clientHandle; |
|
35 | - $this->conntected = false; |
|
24 | + /** |
|
25 | + * Create a new client socket |
|
26 | + * |
|
27 | + * @param Endpoint $endpoint |
|
28 | + * The endpoint to use |
|
29 | + * @param resource $clientHandle |
|
30 | + * optional existing client handle |
|
31 | + */ |
|
32 | + public function __construct(Endpoint $endpoint, $clientHandle = null) { |
|
33 | + $this->endpoint = $endpoint; |
|
34 | + $this->handle = $clientHandle; |
|
35 | + $this->conntected = false; |
|
36 | 36 | |
37 | - if (! is_resource ( $clientHandle )) { |
|
38 | - parent::__construct ( $endpoint ); |
|
39 | - } |
|
40 | - } |
|
37 | + if (! is_resource ( $clientHandle )) { |
|
38 | + parent::__construct ( $endpoint ); |
|
39 | + } |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Connect to remote endpoint |
|
44 | - * |
|
45 | - * @throws SocketException |
|
46 | - */ |
|
47 | - public function connect() { |
|
48 | - if (! @socket_connect ( $this->handle, $this->endpoint->getAddress (), $this->endpoint->getPort () )) { |
|
49 | - $code = socket_last_error ( $this->handle ); |
|
50 | - throw new SocketException ( socket_strerror ( $code ), array (), $code ); |
|
51 | - } |
|
52 | - $this->conntected = true; |
|
53 | - } |
|
42 | + /** |
|
43 | + * Connect to remote endpoint |
|
44 | + * |
|
45 | + * @throws SocketException |
|
46 | + */ |
|
47 | + public function connect() { |
|
48 | + if (! @socket_connect ( $this->handle, $this->endpoint->getAddress (), $this->endpoint->getPort () )) { |
|
49 | + $code = socket_last_error ( $this->handle ); |
|
50 | + throw new SocketException ( socket_strerror ( $code ), array (), $code ); |
|
51 | + } |
|
52 | + $this->conntected = true; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Disconnects the socket |
|
57 | - * |
|
58 | - * @throws SocketException |
|
59 | - */ |
|
60 | - public function disconnect() { |
|
61 | - $this->close (); |
|
62 | - } |
|
55 | + /** |
|
56 | + * Disconnects the socket |
|
57 | + * |
|
58 | + * @throws SocketException |
|
59 | + */ |
|
60 | + public function disconnect() { |
|
61 | + $this->close (); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Whether the client is connected |
|
66 | - * |
|
67 | - * @return boolean |
|
68 | - */ |
|
69 | - public function isConnected() { |
|
70 | - return $this->conntected; |
|
71 | - } |
|
64 | + /** |
|
65 | + * Whether the client is connected |
|
66 | + * |
|
67 | + * @return boolean |
|
68 | + */ |
|
69 | + public function isConnected() { |
|
70 | + return $this->conntected; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * |
|
75 | - * @see \Generics\Socket\ClientSocket::disconnect() |
|
76 | - */ |
|
77 | - public function close() { |
|
78 | - if (! $this->conntected) { |
|
79 | - throw new SocketException ( "Socket is not connected" ); |
|
80 | - } |
|
73 | + /** |
|
74 | + * |
|
75 | + * @see \Generics\Socket\ClientSocket::disconnect() |
|
76 | + */ |
|
77 | + public function close() { |
|
78 | + if (! $this->conntected) { |
|
79 | + throw new SocketException ( "Socket is not connected" ); |
|
80 | + } |
|
81 | 81 | |
82 | - parent::close (); |
|
83 | - $this->conntected = false; |
|
84 | - } |
|
82 | + parent::close (); |
|
83 | + $this->conntected = false; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * |
|
88 | - * {@inheritdoc} |
|
89 | - * @see \Generics\Socket\Socket::isWriteable() |
|
90 | - */ |
|
91 | - public function isWriteable() { |
|
92 | - if (! $this->isConnected ()) { |
|
93 | - return false; |
|
94 | - } |
|
86 | + /** |
|
87 | + * |
|
88 | + * {@inheritdoc} |
|
89 | + * @see \Generics\Socket\Socket::isWriteable() |
|
90 | + */ |
|
91 | + public function isWriteable() { |
|
92 | + if (! $this->isConnected ()) { |
|
93 | + return false; |
|
94 | + } |
|
95 | 95 | |
96 | - return parent::isWriteable (); |
|
97 | - } |
|
96 | + return parent::isWriteable (); |
|
97 | + } |
|
98 | 98 | } |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | $this->handle = $clientHandle; |
35 | 35 | $this->conntected = false; |
36 | 36 | |
37 | - if (! is_resource ( $clientHandle )) { |
|
38 | - parent::__construct ( $endpoint ); |
|
37 | + if (!is_resource($clientHandle)) { |
|
38 | + parent::__construct($endpoint); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | * @throws SocketException |
46 | 46 | */ |
47 | 47 | public function connect() { |
48 | - if (! @socket_connect ( $this->handle, $this->endpoint->getAddress (), $this->endpoint->getPort () )) { |
|
49 | - $code = socket_last_error ( $this->handle ); |
|
50 | - throw new SocketException ( socket_strerror ( $code ), array (), $code ); |
|
48 | + if (!@socket_connect($this->handle, $this->endpoint->getAddress(), $this->endpoint->getPort())) { |
|
49 | + $code = socket_last_error($this->handle); |
|
50 | + throw new SocketException(socket_strerror($code), array(), $code); |
|
51 | 51 | } |
52 | 52 | $this->conntected = true; |
53 | 53 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @throws SocketException |
59 | 59 | */ |
60 | 60 | public function disconnect() { |
61 | - $this->close (); |
|
61 | + $this->close(); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | * @see \Generics\Socket\ClientSocket::disconnect() |
76 | 76 | */ |
77 | 77 | public function close() { |
78 | - if (! $this->conntected) { |
|
79 | - throw new SocketException ( "Socket is not connected" ); |
|
78 | + if (!$this->conntected) { |
|
79 | + throw new SocketException("Socket is not connected"); |
|
80 | 80 | } |
81 | 81 | |
82 | - parent::close (); |
|
82 | + parent::close(); |
|
83 | 83 | $this->conntected = false; |
84 | 84 | } |
85 | 85 | |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | * @see \Generics\Socket\Socket::isWriteable() |
90 | 90 | */ |
91 | 91 | public function isWriteable() { |
92 | - if (! $this->isConnected ()) { |
|
92 | + if (!$this->isConnected()) { |
|
93 | 93 | return false; |
94 | 94 | } |
95 | 95 | |
96 | - return parent::isWriteable (); |
|
96 | + return parent::isWriteable(); |
|
97 | 97 | } |
98 | 98 | } |
@@ -17,68 +17,68 @@ |
||
17 | 17 | */ |
18 | 18 | class UrlParser { |
19 | 19 | |
20 | - /** |
|
21 | - * Parse a URI into a Url |
|
22 | - * |
|
23 | - * @param string $url |
|
24 | - * @throws InvalidUrlException |
|
25 | - * @return \Generics\Socket\Url |
|
26 | - */ |
|
27 | - public static function parseUrl($url) { |
|
28 | - $parts = parse_url ( $url ); |
|
20 | + /** |
|
21 | + * Parse a URI into a Url |
|
22 | + * |
|
23 | + * @param string $url |
|
24 | + * @throws InvalidUrlException |
|
25 | + * @return \Generics\Socket\Url |
|
26 | + */ |
|
27 | + public static function parseUrl($url) { |
|
28 | + $parts = parse_url ( $url ); |
|
29 | 29 | |
30 | - if (false === $parts || false === Arrays::hasElement ( $parts, 'host' )) { |
|
31 | - throw new InvalidUrlException ( 'This URL does not contain a host part' ); |
|
32 | - } |
|
33 | - if (false === $parts || false === Arrays::hasElement ( $parts, 'scheme' )) { |
|
34 | - throw new InvalidUrlException ( 'This URL does not contain a scheme part' ); |
|
35 | - } |
|
30 | + if (false === $parts || false === Arrays::hasElement ( $parts, 'host' )) { |
|
31 | + throw new InvalidUrlException ( 'This URL does not contain a host part' ); |
|
32 | + } |
|
33 | + if (false === $parts || false === Arrays::hasElement ( $parts, 'scheme' )) { |
|
34 | + throw new InvalidUrlException ( 'This URL does not contain a scheme part' ); |
|
35 | + } |
|
36 | 36 | |
37 | - $address = $parts ['host']; |
|
38 | - $scheme = $parts ['scheme']; |
|
39 | - $port = 0; |
|
40 | - $path = "/"; |
|
37 | + $address = $parts ['host']; |
|
38 | + $scheme = $parts ['scheme']; |
|
39 | + $port = 0; |
|
40 | + $path = "/"; |
|
41 | 41 | |
42 | - if (isset ( $parts ['port'] )) { |
|
43 | - $port = intval ( $parts ['port'] ); |
|
44 | - } |
|
42 | + if (isset ( $parts ['port'] )) { |
|
43 | + $port = intval ( $parts ['port'] ); |
|
44 | + } |
|
45 | 45 | |
46 | - if ($port == 0) { |
|
47 | - $port = self::getPortByScheme ( $scheme ); |
|
48 | - } |
|
46 | + if ($port == 0) { |
|
47 | + $port = self::getPortByScheme ( $scheme ); |
|
48 | + } |
|
49 | 49 | |
50 | - if (isset ( $parts ['path'] )) { |
|
51 | - $path = $parts ['path']; |
|
52 | - } |
|
50 | + if (isset ( $parts ['path'] )) { |
|
51 | + $path = $parts ['path']; |
|
52 | + } |
|
53 | 53 | |
54 | - return new Url ( $address, $port, $path, $scheme ); |
|
55 | - } |
|
54 | + return new Url ( $address, $port, $path, $scheme ); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Get port number by scheme name. |
|
59 | - * The port will be the default which is defined by |
|
60 | - * http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers |
|
61 | - * |
|
62 | - * @param string $scheme |
|
63 | - * The scheme. |
|
64 | - * @throws InvalidUrlException |
|
65 | - * @return int |
|
66 | - */ |
|
67 | - public static function getPortByScheme($scheme) { |
|
68 | - switch ($scheme) { |
|
69 | - case 'http' : |
|
70 | - return 80; |
|
57 | + /** |
|
58 | + * Get port number by scheme name. |
|
59 | + * The port will be the default which is defined by |
|
60 | + * http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers |
|
61 | + * |
|
62 | + * @param string $scheme |
|
63 | + * The scheme. |
|
64 | + * @throws InvalidUrlException |
|
65 | + * @return int |
|
66 | + */ |
|
67 | + public static function getPortByScheme($scheme) { |
|
68 | + switch ($scheme) { |
|
69 | + case 'http' : |
|
70 | + return 80; |
|
71 | 71 | |
72 | - case 'https' : |
|
73 | - return 443; |
|
72 | + case 'https' : |
|
73 | + return 443; |
|
74 | 74 | |
75 | - case 'ftp' : |
|
76 | - return 21; |
|
75 | + case 'ftp' : |
|
76 | + return 21; |
|
77 | 77 | |
78 | - default : |
|
79 | - throw new InvalidUrlException ( "Scheme {scheme} is not handled!", array ( |
|
80 | - 'scheme' => $scheme |
|
81 | - ) ); |
|
82 | - } |
|
83 | - } |
|
78 | + default : |
|
79 | + throw new InvalidUrlException ( "Scheme {scheme} is not handled!", array ( |
|
80 | + 'scheme' => $scheme |
|
81 | + ) ); |
|
82 | + } |
|
83 | + } |
|
84 | 84 | } |
@@ -25,13 +25,13 @@ discard block |
||
25 | 25 | * @return \Generics\Socket\Url |
26 | 26 | */ |
27 | 27 | public static function parseUrl($url) { |
28 | - $parts = parse_url ( $url ); |
|
28 | + $parts = parse_url($url); |
|
29 | 29 | |
30 | - if (false === $parts || false === Arrays::hasElement ( $parts, 'host' )) { |
|
31 | - throw new InvalidUrlException ( 'This URL does not contain a host part' ); |
|
30 | + if (false === $parts || false === Arrays::hasElement($parts, 'host')) { |
|
31 | + throw new InvalidUrlException('This URL does not contain a host part'); |
|
32 | 32 | } |
33 | - if (false === $parts || false === Arrays::hasElement ( $parts, 'scheme' )) { |
|
34 | - throw new InvalidUrlException ( 'This URL does not contain a scheme part' ); |
|
33 | + if (false === $parts || false === Arrays::hasElement($parts, 'scheme')) { |
|
34 | + throw new InvalidUrlException('This URL does not contain a scheme part'); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | $address = $parts ['host']; |
@@ -39,19 +39,19 @@ discard block |
||
39 | 39 | $port = 0; |
40 | 40 | $path = "/"; |
41 | 41 | |
42 | - if (isset ( $parts ['port'] )) { |
|
43 | - $port = intval ( $parts ['port'] ); |
|
42 | + if (isset ($parts ['port'])) { |
|
43 | + $port = intval($parts ['port']); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | if ($port == 0) { |
47 | - $port = self::getPortByScheme ( $scheme ); |
|
47 | + $port = self::getPortByScheme($scheme); |
|
48 | 48 | } |
49 | 49 | |
50 | - if (isset ( $parts ['path'] )) { |
|
50 | + if (isset ($parts ['path'])) { |
|
51 | 51 | $path = $parts ['path']; |
52 | 52 | } |
53 | 53 | |
54 | - return new Url ( $address, $port, $path, $scheme ); |
|
54 | + return new Url($address, $port, $path, $scheme); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | return 21; |
77 | 77 | |
78 | 78 | default : |
79 | - throw new InvalidUrlException ( "Scheme {scheme} is not handled!", array ( |
|
79 | + throw new InvalidUrlException("Scheme {scheme} is not handled!", array( |
|
80 | 80 | 'scheme' => $scheme |
81 | - ) ); |
|
81 | + )); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | } |