Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
qfq
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
typo3
qfq
Commits
2cd05c2a
Commit
2cd05c2a
authored
4 years ago
by
Marc Egger
Browse files
Options
Downloads
Patches
Plain Diff
add alternative curl rest client, example works
parent
a7984d17
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!302
Develop
,
!296
Marc: Form/Report As File, Path class, Config class, Typo3 v9 compatability
Pipeline
#3794
failed
4 years ago
Stage: before
Stage: build
Stage: selenium
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
extension/Classes/Core/Report/RestClient.php
+61
-1
61 additions, 1 deletion
extension/Classes/Core/Report/RestClient.php
with
61 additions
and
1 deletion
extension/Classes/Core/Report/RestClient.php
+
61
−
1
View file @
2cd05c2a
...
...
@@ -56,6 +56,9 @@ class RestClient {
$options
[
'http'
][
'content'
]
=
$param
[
TOKEN_L_CONTENT
];
}
$recvBuffer
=
self
::
callAPIMarc
(
strtoupper
(
$param
[
TOKEN_L_METHOD
]),
$param
[
TOKEN_REST_CLIENT
],
$data
=
json_decode
(
$param
[
TOKEN_L_CONTENT
]));
/*
$context = stream_context_create($options);
try {
if (false === ($recvBuffer = file_get_contents($param[TOKEN_REST_CLIENT], false, $context))) {
...
...
@@ -75,7 +78,7 @@ class RestClient {
// Copy new values to STORE_CLIENT
$this->store::setStore($recv, STORE_CLIENT, true);
*/
return
$recvBuffer
;
}
...
...
@@ -134,4 +137,61 @@ class RestClient {
$param
[
TOKEN_L_HEADER
]
=
KeyValueStringParser
::
unparse
(
$header
,
': '
,
'\r\n'
)
.
'\r\n'
;
return
$param
;
}
private
static
function
callAPIMarc
(
$method
,
$url
,
$data
=
array
())
{
$ch
=
curl_init
();
$curlConfig
=
array
(
CURLOPT_RETURNTRANSFER
=>
true
,
// CURLINFO_HEADER_OUT => $debug
);
$curlHeader
=
array
(
'Content-Type: application/json'
);
switch
(
$method
)
{
case
"POST"
:
$curlConfig
[
CURLOPT_POST
]
=
true
;
if
(
!
empty
(
$data
))
{
$dataJson
=
json_encode
(
$data
);
$curlConfig
[
CURLOPT_POSTFIELDS
]
=
$dataJson
;
$curlHeader
[]
=
'Content-Length: '
.
strlen
(
$dataJson
);
}
break
;
case
"PUT"
:
$curlConfig
[
CURLOPT_CUSTOMREQUEST
]
=
'PUT'
;
if
(
!
empty
(
$data
))
$dataJson
=
json_encode
(
$data
);
$curlConfig
[
CURLOPT_POSTFIELDS
]
=
$dataJson
;
$curlHeader
[]
=
'Content-Length: '
.
strlen
(
$dataJson
);
break
;
case
"DELETE"
:
$curlConfig
[
CURLOPT_CUSTOMREQUEST
]
=
'DELETE'
;
if
(
!
empty
(
$data
))
$url
=
sprintf
(
"%s?%s"
,
$url
,
http_build_query
(
$data
));
break
;
default
:
if
(
!
empty
(
$data
))
$url
=
sprintf
(
"%s?%s"
,
$url
,
http_build_query
(
$data
));
}
$curlConfig
[
CURLOPT_URL
]
=
$url
;
curl_setopt_array
(
$ch
,
$curlConfig
);
curl_setopt
(
$ch
,
CURLOPT_HTTPHEADER
,
$curlHeader
);
// send request
$output
=
json_decode
(
curl_exec
(
$ch
),
true
);
if
(
$output
===
false
)
{
throw
new
Exception
(
curl_error
(
$ch
),
curl_errno
(
$ch
));
}
$httpCode
=
curl_getinfo
(
$ch
,
CURLINFO_HTTP_CODE
);
if
(
$httpCode
>=
300
)
{
throw
new
Exception
(
' Api error: '
.
$url
.
' HTTP code: '
.
$httpCode
.
' Message: '
.
(
$output
[
'error'
]
??
''
)
.
(
$output
[
'message'
]
??
''
),
E_ERROR
);
}
// finished
curl_close
(
$ch
);
return
$output
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment