Commit 542f01dd authored by Sigrid Suski's avatar Sigrid Suski

(+) Output of error messages added

    (+) CURL initialisation error added
parent 728c86bf
......@@ -17,7 +17,7 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* @created Sat, Dec 3, 2016 15:22:50 by Radek Suski
* @modified 01 May 2020 by Sigrid Suski
* @modified 01 June 2020 by Sigrid Suski
*/
namespace Sobi\Communication;
......@@ -352,7 +352,7 @@ class CURL
$url = $url[ 0 ];
}
if ( !( $this->validateHttp( 'https://' . $url ) ) ) {
return [ 'err' => 500, 'msg' => Framework::Txt( 'INVALID_URL', 'https://' . $url ) ];
return [ 'err' => 500, 'msg' => Framework::Error( 'INVALID_URL', 'https://' . $url ) ];
}
$this->setOptions(
[
......@@ -368,10 +368,18 @@ class CURL
if ( !( $this->validCode( $this->exec() ) ) ) {
$err = $this->info();
return [ 'err' => $err[ 'http_code' ], 'msg' => Framework::Txt( 'NO_CONNECT', 'https://' . $url ) ];
return [ 'err' => $err[ 'http_code' ], 'msg' => Framework::Error( 'NO_CONNECT', 'https://' . $url ) ];
}
$res = stream_context_create( [ 'ssl' => [ 'capture_peer_cert' => true ] ] );
$client = stream_socket_client( "ssl://{$url}:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $res );
if ( !$client ) {
if ( $errno == 0 ) {
return [ 'err' => 998, 'msg' => Framework::Error( 'CURL_INITIALISATION_ERROR', 'https://' . $url ) ];
}
else {
return [ 'err' => $errno, 'msg' => $errstr ];
}
}
$cont = stream_context_get_options( $client );
if ( !$errno ) {
return openssl_x509_parse( $cont[ 'ssl' ][ 'peer_certificate' ] );
......@@ -462,7 +470,7 @@ class CURL
$err[] = $errno;
}
if ( $message ) {
$err[] = Framework::Txt( 'CURL_NOT_INSTALLED' );
$err[] = Framework::Error( 'CURL_NOT_INSTALLED' );
}
if ( $errno ) {
return implode( ': ', $err );
......
......@@ -17,7 +17,7 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* @created Thu, Dec 1, 2016 12:04:19 by Radek Suski
* @modified 30 April 2020 by Sigrid Suski
* @modified 01 June 2020 by Sigrid Suski
*/
namespace Sobi;
......@@ -35,6 +35,10 @@ abstract class Framework
{
/** @var array */
protected static $translator = [];
/**
* @var array
*/
protected static $errortranslator = [];
/** @var array */
protected static $config;
......@@ -47,6 +51,14 @@ abstract class Framework
self::$translator = $callback;
}
/**
* @param array $callback
*/
public static function SetErrorTranslator( array $callback )
{
self::$errortranslator = $callback;
}
/**
*
*/
......@@ -73,6 +85,22 @@ abstract class Framework
}
}
/**
* @return mixed
* @throws Exception
*/
public static function Error()
{
if ( is_array( self::$errortranslator ) && count( self::$errortranslator ) == 2 ) {
$args = func_get_args();
return call_user_func_array( self::$errortranslator, $args );
}
else {
throw new Exception( 'Error Translator has not been set' );
}
}
/**
* @return string | array
* @throws Exception
......
......@@ -33,6 +33,9 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
### 1.0.13 (31 Juli 2020)
(+) Output of error messages added
(+) CURL initialisation error added
### 1.0.12 (30 May 2020)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment