Skip to content

Commit a4e23fc

Browse files
author
Vítězslav Dvořák
committed
function contentTypeToResponseFormat() moved to Formats class
1 parent 9b453bd commit a4e23fc

File tree

3 files changed

+86
-34
lines changed

3 files changed

+86
-34
lines changed

src/AbraFlexi/Formats.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,48 @@ static public function contentTypeToSuffix($contentType)
189189
return isset($types[$contentType]) ? $types[$contentType]['suffix'] : null;
190190
}
191191

192+
193+
/**
194+
* Obtain json for application/json.
195+
*/
196+
public static function contentTypeToResponseFormat(string $contentType, string $url = ''): string
197+
{
198+
if (!empty($url)) {
199+
$url = parse_url($url, \PHP_URL_PATH);
200+
}
201+
202+
$contentTypeClean = strstr($contentType, ';') ? substr(
203+
$contentType,
204+
0,
205+
strpos($contentType, ';'),
206+
) : $contentType;
207+
208+
switch ($url) {
209+
case '/login-logout/login':
210+
$responseFormat = 'json';
211+
212+
break;
213+
214+
default:
215+
switch ($contentTypeClean) {
216+
case 'text/javascript':
217+
$responseFormat = 'js';
218+
219+
break;
220+
221+
default:
222+
$responseFormat = self::contentTypeToSuffix($contentTypeClean);
223+
224+
break;
225+
}
226+
227+
break;
228+
}
229+
230+
return (string)$responseFormat;
231+
}
232+
233+
192234
/**
193235
* Evidence adresar (Adresy firem) Formats.
194236
*

src/AbraFlexi/RO.php

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ public function doCurlRequest($url, $method, $format = null)
13951395
$this->curlInfo['http_method'] = $method;
13961396

13971397
if ($this->curlInfo['content_type']) {
1398-
$this->responseFormat = $this->contentTypeToResponseFormat((string) $this->curlInfo['content_type'], $url);
1398+
$this->responseFormat = Formats::contentTypeToResponseFormat((string) $this->curlInfo['content_type'], $url);
13991399
} else {
14001400
$this->responseFormat = '';
14011401
}
@@ -1431,42 +1431,12 @@ public function success()
14311431

14321432
/**
14331433
* Obtain json for application/json.
1434+
*
1435+
* @deprecated since version 1.45 - use the Formats::contentTypeToResponseFormat instead
14341436
*/
14351437
public function contentTypeToResponseFormat(string $contentType, string $url = ''): string
14361438
{
1437-
if (!empty($url)) {
1438-
$url = parse_url($url, \PHP_URL_PATH);
1439-
}
1440-
1441-
$contentTypeClean = strstr($contentType, ';') ? substr(
1442-
$contentType,
1443-
0,
1444-
strpos($contentType, ';'),
1445-
) : $contentType;
1446-
1447-
switch ($url) {
1448-
case '/login-logout/login':
1449-
$responseFormat = 'json';
1450-
1451-
break;
1452-
1453-
default:
1454-
switch ($contentTypeClean) {
1455-
case 'text/javascript':
1456-
$responseFormat = 'js';
1457-
1458-
break;
1459-
1460-
default:
1461-
$responseFormat = Formats::contentTypeToSuffix($contentTypeClean);
1462-
1463-
break;
1464-
}
1465-
1466-
break;
1467-
}
1468-
1469-
return $responseFormat;
1439+
return Formats::contentTypeToResponseFormat($contentType, $url);
14701440
}
14711441

14721442
/**

tools/update_formats_class.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,46 @@ static public function contentTypeToSuffix($contentType)
237237
return isset($types[$contentType]) ? $types[$contentType][\'suffix\'] : null;
238238
}
239239
240+
/**
241+
* Obtain json for application/json.
242+
*/
243+
public static function contentTypeToResponseFormat(string $contentType, string $url = \'\'): string
244+
{
245+
if (!empty($url)) {
246+
$url = parse_url($url, \PHP_URL_PATH);
247+
}
248+
249+
$contentTypeClean = strstr($contentType, ';') ? substr(
250+
$contentType,
251+
0,
252+
strpos($contentType, \';\'),
253+
) : $contentType;
254+
255+
switch ($url) {
256+
case \'/login-logout/logi\n\':
257+
$responseFormat = \'json\';
258+
259+
break;
260+
261+
default:
262+
switch ($contentTypeClean) {
263+
case \'text/javascript\':
264+
$responseFormat = \'js\';
265+
266+
break;
267+
268+
default:
269+
$responseFormat = self::contentTypeToSuffix($contentTypeClean);
270+
271+
break;
272+
}
273+
274+
break;
275+
}
276+
277+
return (string)$responseFormat;
278+
}
279+
240280
';
241281

242282
$syncer = new RO(null, ['throwException' => false]);

0 commit comments

Comments
 (0)