Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
Wpct Http Bridge
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
codeccoop
WordPress
plugins
Wpct Http Bridge
Merge requests
!3
Multi backend plugin
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Multi backend plugin
feat/multi-backend
into
main
Overview
0
Commits
7
Pipelines
0
Changes
6
Merged
Lucas García
requested to merge
feat/multi-backend
into
main
4 months ago
Overview
0
Commits
7
Pipelines
0
Changes
6
Expand
Add backend class.
Add php docstrings.
Hide multipart from public API.
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
aebfbd97
7 commits,
4 months ago
6 files
+
463
−
101
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
6
Search (e.g. *.vue) (Ctrl+P)
includes/class-http-backend.php
0 → 100644
+
105
−
0
Options
<?php
namespace
WPCT_HTTP
;
use
Exception
;
/**
* HTTP Backend
*
* @since 3.0.0
*/
class
Http_Backend
{
/**
* Handle backend data.
*
* @since 3.0.0
*/
private
$data
=
null
;
/**
* Store backend data
*
* @since 3.0.0
*/
public
function
__construct
(
$name
)
{
$this
->
data
=
$this
->
get_backend
(
$name
);
if
(
!
$this
->
data
)
{
throw
new
Exception
(
"Http backend error: Unkown backend with name
{
$name
}
"
);
}
}
/**
* Backend data getter.
*
* @since 3.0.0
*/
private
function
get_backend
(
$name
)
{
$backends
=
Settings
::
get_setting
(
'wpct-http-bridge'
,
'general'
,
'backends'
);
foreach
(
$backends
as
$backend
)
{
if
(
$backend
[
'name'
]
===
$name
)
{
return
$backend
;
}
}
return
null
;
}
/**
* Intercept class gets and lookup on backend data.
*
* @since 3.0.0
*/
public
function
__get
(
$attr
)
{
if
(
isset
(
$this
->
data
[
$attr
]))
{
return
$this
->
data
[
$attr
];
}
return
null
;
}
/**
* Get backend absolute URL.
*
* @since 3.0.0
*
* @param string $path URL relative path.
* @return string $url Absolute URL.
*/
public
function
get_endpoint_url
(
$path
)
{
$url_data
=
parse_url
(
$path
);
if
(
isset
(
$url_data
[
'scheme'
]))
{
return
$path
;
}
$base_url
=
$this
->
base_url
;
return
preg_replace
(
'/\/$/'
,
''
,
$base_url
)
.
'/'
.
preg_replace
(
'/^\//'
,
''
,
$path
);
}
/**
* Get backend default headers.
*
* @since 3.0.0
*
* @return array $headers Backend headers.
*/
public
function
get_headers
()
{
$headers
=
[];
foreach
(
$this
->
headers
as
$header
)
{
$headers
[
strtolower
(
trim
(
$header
[
'name'
]))]
=
trim
(
$header
[
'value'
]);
}
return
$headers
;
}
}
// Get new backend instance.
add_filter
(
'wpct_http_backend'
,
function
(
$null
,
$name
)
{
return
new
Http_Backend
(
$name
);
},
10
,
2
);
Loading