// Import SPL stuff
use \InvalidArgumentException;
+use \Socket;
use \UnexpectedValueException;
/**
/**
* Creates an instance of this Client class and prepares it for usage
*
- * @param $socketResource Resource of a socket (optional)
- * @return $clientInstance An instance of a Client class
+ * @param $socketResource An instance of a Socket class
+ * @return $clientInstance An instance of a HttpClient class
*/
- public final static function createHttpClient ($socketResouce = FALSE) {
+ public final static function createHttpClient (Socket $socketResouce = NULL) {
// Get a new instance
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HTTP-CLIENT: socketResource[%s]=%s - CALLED!', gettype($socketResource), $socketResource));
$clientInstance = new HttpClient();
use Org\Mxchange\CoreFramework\Factory\BaseFactory;
use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+// Import SPL
+use \Socket;
+
/**
* An object factory for clients
*
* registry pattern to cache those instances.
*
* @param $protocolInstance An instance of a HandleableProtocol class to create a client object for (e.g. 'http' for a HTTP/1.1 client)
- * @param $socketResource A valid socket resource (optional)
+ * @param $socketResource An instance of a Socket class (optional)
* @return $clientInstance An instance of the requested client
*/
- public static final function createClientByProtocolInstance (HandleableProtocol $protocolInstance, $socketResource = FALSE) {
+ public static final function createClientByProtocolInstance (HandleableProtocol $protocolInstance, Socket $socketResource = NULL) {
// Default is NULL (to initialize variable)
$clientInstance = NULL;
$clientInstance->setSocketResource($socketResource);
} else {
// Generate object instance
- $clientInstance = ObjectFactory::createObjectByConfiguredName($registryKey, array($socketResource));
+ $clientInstance = ObjectFactory::createObjectByConfiguredName($registryKey, [$socketResource]);
// Set it in registry for later re-use
ObjectRegistry::getRegistry('factory')->addInstance($registryKey, $clientInstance);
// Import SPL stuff
use \InvalidArgumentException;
+use \Socket;
use \SplFileInfo;
use \UnexpectedValueException;
*
* @param $host Host to connect to
* @param $port Port number to connect to
- * @param $socketResource Resource of a socket
+ * @param $socketResource An instance of a Socket class
* @return $response Response array
* @throws InvalidArgumentException If a parameter is not valid
*/
- protected function setupProxyTunnel (string $host, int $port, $socketResource) {
+ protected function setupProxyTunnel (string $host, int $port, Socket $socketResource) {
// Validate parameter
//* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CONSOLE-TOOLS: host=%s,port=%d,socketResource=%s - CALLED!', $host, $port, $socketResource));
if (empty($host)) {
} elseif ($port < 1) {
// Throw IAE
throw new InvalidArgumentException(sprintf('port=%d is not valid', $port));
- } elseif (!is_resource($socketResource)) {
- // Throw IAE
- throw new InvalidArgumentException(sprintf('socketResource[]=%s is not valid', gettype($socketResource)));
}
// Initialize array
*/
public function __construct (array $messageData, int $code) {
// Construct the message
- $message = sprintf('[%s:] Invalid socketResource[%s]=%s, errno=%s, errstr=%s',
- $messageData[0]->__toString(),
- gettype($messageData[0]->getSocketResource()),
- $messageData[0]->getSocketResource(),
- $messageData[1],
- $messageData[2]
- );
+ if (isset($messageData[1]) && isset($messageData[2])) {
+ $message = sprintf('[%s:] Invalid socketResource[]=%s, errno=%s, errstr=%s',
+ $messageData[0]->__toString(),
+ gettype($messageData[1]),
+ $messageData[1],
+ $messageData[2]
+ );
+ } else {
+ $message = sprintf('[%s:] Invalid socketResource[]=%s with unknown error.',
+ $messageData[0]->__toString(),
+ gettype($messageData[1])
+ );
+ }
// Call parent exception constructor
parent::__construct($message, $code);