-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replaced Exceptions to dir with name Exception without s on the end
reduced complexity Stream class
- Loading branch information
1 parent
8bd7c23
commit e140bcb
Showing
16 changed files
with
324 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
/** | ||
* @author KonstantinKuklin <konstantin.kuklin@gmail.com> | ||
*/ | ||
|
||
namespace Stream; | ||
|
||
class Connection | ||
{ | ||
const PROTOCOL_TCP = 'tcp'; | ||
const PROTOCOL_UDP = 'udp'; | ||
const PROTOCOL_UNIX = 'unix'; | ||
|
||
private $path = null; | ||
private $protocol = null; | ||
private $port = 0; | ||
|
||
/** | ||
* @param string $path | ||
* @param string $protocol | ||
* @param int $port | ||
* | ||
* @throws Exception\PathValidateStreamException | ||
* @throws Exception\PortValidateStreamException | ||
* @throws Exception\ProtocolValidateStreamException | ||
*/ | ||
public function __construct($path, $protocol, $port = 0) | ||
{ | ||
// $this->validatePath($path); | ||
Validator::validateProtocol($protocol); | ||
// it is doesn't matter what is the port if protocol is UNIX | ||
if ($protocol !== self::PROTOCOL_UNIX) { | ||
Validator::validatePort($port); | ||
} | ||
Validator::validatePath($path); | ||
|
||
$this->port = $port; | ||
$this->path = $path; | ||
$this->protocol = $protocol; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getProtocol() | ||
{ | ||
return $this->protocol; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getPort() | ||
{ | ||
return $this->port; | ||
} | ||
|
||
/** | ||
* @return null|string | ||
*/ | ||
public function getPath() | ||
{ | ||
return $this->path; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getUrlConnection() | ||
{ | ||
$urlConnection = $this->getProtocol() . '://' . $this->getPath(); | ||
if ($this->getPort() > 0) { | ||
$urlConnection .= ':' . $this->getPort(); | ||
} | ||
|
||
return $urlConnection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* @author KonstantinKuklin <konstantin.kuklin@gmail.com> | ||
*/ | ||
|
||
namespace Stream; | ||
|
||
use Stream\Exception\NotStringStreamException; | ||
|
||
class DataHandler | ||
{ | ||
private $driver = null; | ||
|
||
public function __construct(StreamDriverInterface $driver = null) | ||
{ | ||
$this->driver = $driver; | ||
} | ||
|
||
/** | ||
* @param string $data | ||
* | ||
* @return mixed | ||
*/ | ||
public function prepareReceiveData($data) | ||
{ | ||
if ($this->hasDriver()) { | ||
return $this->getDriver()->prepareReceiveData($data); | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* @param mixed $data | ||
* | ||
* @throws NotStringStreamException | ||
* @return string | ||
*/ | ||
public function prepareSendData($data) | ||
{ | ||
if ($this->hasDriver()) { | ||
$data = $this->getDriver()->prepareSendData($data); | ||
} | ||
|
||
if (!is_string($data)) { | ||
throw new NotStringStreamException("prepareSendData method must return string."); | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* @return boolean | ||
*/ | ||
private function hasDriver() | ||
{ | ||
return ($this->driver !== null); | ||
} | ||
|
||
/** | ||
* @return null|StreamDriverInterface | ||
*/ | ||
private function getDriver() | ||
{ | ||
return $this->driver; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../Exceptions/ConnectionStreamException.php → ...m/Exception/ConnectionStreamException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...m/Exceptions/NotStringStreamException.php → ...am/Exception/NotStringStreamException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Stream\Exception; | ||
|
||
/** | ||
* @author KonstantinKuklin <konstantin.kuklin@gmail.com> | ||
*/ | ||
class PathValidateStreamException extends ValidateStreamException | ||
{ | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...xceptions/PortValidateStreamException.php → ...Exception/PortValidateStreamException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tions/ProtocolValidateStreamException.php → ...ption/ProtocolValidateStreamException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...Stream/Exceptions/ReadStreamException.php → src/Stream/Exception/ReadStreamException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ceptions/ReceiveMethodStreamException.php → ...xception/ReceiveMethodStreamException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Stream/Exceptions/StreamException.php → src/Stream/Exception/StreamException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...am/Exceptions/ValidateStreamException.php → ...eam/Exception/ValidateStreamException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.