-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Support new Avalex API 3.0 with multilanguage texts
- Loading branch information
1 parent
15935e9
commit 4d30177
Showing
9 changed files
with
342 additions
and
85 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
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,114 @@ | ||
<?php | ||
/* | ||
* This file is part of the avalex project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
/** | ||
* Service to execute remote requests using curl | ||
* | ||
* Request page: | ||
* $this->request('https://domain.tld/api-request'); | ||
* Get http status code: | ||
* $this->getCurlInfo()['http_code']; | ||
* Get response content: | ||
* $this->getCurlOutput(); | ||
*/ | ||
class tx_avalex_CurlService | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $curlInfo = array(); | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $curlOutput = ''; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $curlError = ''; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $curlErrno = 0; | ||
|
||
/** | ||
* @param $url | ||
* @return bool true on success otherwise false | ||
*/ | ||
public function request($url) | ||
{ | ||
$curlResource = curl_init(); | ||
|
||
curl_setopt_array($curlResource, array( | ||
CURLOPT_URL => (string)$url, | ||
CURLOPT_RETURNTRANSFER => true, | ||
)); | ||
|
||
$this->curlOutput = (string)curl_exec($curlResource); | ||
$this->curlInfo = curl_getinfo($curlResource); | ||
$this->curlError = curl_error($curlResource); | ||
$this->curlErrno = curl_errno($curlResource); | ||
|
||
curl_close($curlResource); | ||
|
||
if ($this->curlError) { | ||
t3lib_div::sysLog( | ||
sprintf( | ||
'tx_avalex_CurlService::request with URL "%s" failed! Curl error (%d): "%s"', | ||
$url, | ||
$this->curlErrno, | ||
$this->curlError | ||
), | ||
'avalex_legacy', | ||
t3lib_div::SYSLOG_SEVERITY_ERROR | ||
); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getCurlInfo() | ||
{ | ||
return $this->curlInfo; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCurlOutput() | ||
{ | ||
return $this->curlOutput; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCurlError() | ||
{ | ||
return $this->curlError; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getCurlErrno() | ||
{ | ||
return $this->curlErrno; | ||
} | ||
} |
Oops, something went wrong.