Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
http_client_manager-3451503
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
http_client_manager-3451503
Commits
9a7d466b
Commit
9a7d466b
authored
7 years ago
by
Adriano Cori
Committed by
Adriano Cori
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2943264
by aronne: Fixed required properties management.
parent
86b22adc
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
http_client_manager.module
+1
-1
1 addition, 1 deletion
http_client_manager.module
src/HttpClient.php
+9
-0
9 additions, 0 deletions
src/HttpClient.php
src/HttpServiceApiHandler.php
+16
-8
16 additions, 8 deletions
src/HttpServiceApiHandler.php
with
26 additions
and
9 deletions
http_client_manager.module
+
1
−
1
View file @
9a7d466b
...
...
@@ -44,7 +44,7 @@ function http_client_manager_help($route_name, RouteMatchInterface $route_match)
'#type'
=>
'details'
,
'#title'
=>
t
(
'Help - Overriding HTTP Services API definitions'
),
'#description'
=>
t
(
'HTTP Services API definitions can be overridden in settings.php. Overridable properties are: @list'
,
[
'@list'
=>
implode
(
', '
,
HttpServiceApiHandler
::
getOverridableProperties
()),
'@list'
=>
implode
(
', '
,
array_keys
(
HttpServiceApiHandler
::
getOverridableProperties
())
)
,
]),
'code'
=>
[
'#markup'
=>
$code
,
...
...
This diff is collapsed.
Click to expand it.
src/HttpClient.php
+
9
−
0
View file @
9a7d466b
...
...
@@ -187,6 +187,15 @@ class HttpClient implements HttpClientInterface {
$this
->
client
=
$this
->
createGuzzleClient
(
$config
);
}
/**
* Create a new Guzzle Client by config.
*
* @param array $config
* An array of configurations used to create a new Guzzle Client.
*
* @return \GuzzleHttp\Command\Guzzle\GuzzleClient
* A Guzzle Client instance.
*/
private
function
createGuzzleClient
(
array
$config
)
{
$client
=
new
Client
(
$config
);
return
new
GuzzleClient
(
$client
,
$this
->
loadServiceDescription
(
$config
));
...
...
This diff is collapsed.
Click to expand it.
src/HttpServiceApiHandler.php
+
16
−
8
View file @
9a7d466b
...
...
@@ -16,6 +16,11 @@ use Drupal\Core\Controller\ControllerResolver;
*/
class
HttpServiceApiHandler
implements
HttpServiceApiHandlerInterface
{
/**
* Defines the required property value.
*/
const
REQUIRED_PROPERTY
=
TRUE
;
/**
* Drupal root.
*
...
...
@@ -29,12 +34,14 @@ class HttpServiceApiHandler implements HttpServiceApiHandlerInterface {
* @var \Drupal\Core\Extension\ModuleHandler
*/
protected
$moduleHandler
;
/**
* Drupal\Core\StringTranslation\TranslationManager definition.
*
* @var \Drupal\Core\StringTranslation\TranslationManager
*/
protected
$stringTranslation
;
/**
* Drupal\Core\Controller\ControllerResolver definition.
*
...
...
@@ -196,7 +203,7 @@ class HttpServiceApiHandler implements HttpServiceApiHandlerInterface {
}
$original
=
$serviceApi
;
$overrides
=
array_flip
(
self
::
getOverridableProperties
()
)
;
$overrides
=
self
::
getOverridableProperties
();
$settings
[
$id
]
=
array_intersect_key
(
$settings
[
$id
],
$overrides
);
$serviceApi
=
array_replace_recursive
(
$serviceApi
,
$settings
[
$id
]);
...
...
@@ -210,14 +217,15 @@ class HttpServiceApiHandler implements HttpServiceApiHandlerInterface {
* Get overridable Service API properties.
*
* @return array
* An array containing a list of overridable property names.
* An associative array where keys are overridable property names and values
* are boolean indicating if the property is required or not.
*/
public
static
function
getOverridableProperties
()
{
return
[
'title'
,
'api_path'
,
'config'
,
'commands'
,
'title'
=>
self
::
REQUIRED_PROPERTY
,
'api_path'
=>
self
::
REQUIRED_PROPERTY
,
'config'
=>
self
::
REQUIRED_PROPERTY
,
'commands'
=>
!
self
::
REQUIRED_PROPERTY
,
];
}
...
...
@@ -233,8 +241,8 @@ class HttpServiceApiHandler implements HttpServiceApiHandlerInterface {
* Whether or not the api is valid.
*/
protected
function
validateServiceApiDefinition
(
$id
,
array
$serviceApi
)
{
foreach
(
self
::
getOverridableProperties
()
as
$property
)
{
if
(
!
isset
(
$serviceApi
[
$property
]))
{
foreach
(
self
::
getOverridableProperties
()
as
$property
=>
$isRequired
)
{
if
(
$isRequired
&&
!
isset
(
$serviceApi
[
$property
]))
{
$message
=
sprintf
(
'Missing required parameter "%s" in "%s" service api definition'
,
$property
,
$id
);
throw
new
\RuntimeException
(
$message
);
}
...
...
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