| 1 |
<?php |
| 2 |
namespace Kibo\PhastPlugins\PhastPress; |
| 3 |
|
| 4 |
use Kibo\Phast\HTTP\Request; |
| 5 |
use Kibo\PhastPlugins\SDK\ServiceHost; |
| 6 |
|
| 7 |
class ServiceSDKImplementation implements ServiceHost { |
| 8 |
public function getCacheRootCandidatesProvider() { |
| 9 |
return new CacheRootCandidatesProviderImplementation(); |
| 10 |
} |
| 11 |
|
| 12 |
public function onServiceConfigurationLoad(array $config) { |
| 13 |
if (class_exists(\WpOrg\Requests\Requests::class)) { |
| 14 |
$config['httpClient'] = RequestsHTTPClient::class; |
| 15 |
} |
| 16 |
|
| 17 |
if ($map = $this->getRetrieverMap()) { |
| 18 |
$config['retrieverMap'] = $map; |
| 19 |
} |
| 20 |
|
| 21 |
return $config; |
| 22 |
} |
| 23 |
|
| 24 |
private function getRetrieverMap() { |
| 25 |
if (!defined('MULTISITE') |
| 26 |
|| !MULTISITE |
| 27 |
|| !defined('SUBDOMAIN_INSTALL') |
| 28 |
|| SUBDOMAIN_INSTALL |
| 29 |
) { |
| 30 |
return null; |
| 31 |
} |
| 32 |
|
| 33 |
$request = Request::fromGlobals(); |
| 34 |
|
| 35 |
$map = [ |
| 36 |
'/' => $request->getDocumentRoot(), |
| 37 |
]; |
| 38 |
|
| 39 |
foreach (['wp-content', 'wp-admin', 'wp-includes'] as $dir) { |
| 40 |
$map["/[_0-9a-zA-Z-]+/$dir/"] = "{$request->getDocumentRoot()}/$dir"; |
| 41 |
} |
| 42 |
|
| 43 |
return [ |
| 44 |
$request->getHost() => $map, |
| 45 |
]; |
| 46 |
} |
| 47 |
} |
| 48 |
|