Skip to content

Commit d5db4fd

Browse files
authored
IBX-10764: Removed dependencies to Upsun (#672)
1 parent 3f35699 commit d5db4fd

File tree

5 files changed

+7
-309
lines changed

5 files changed

+7
-309
lines changed

phpstan-baseline.neon

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,13 +1323,13 @@ parameters:
13231323
-
13241324
message: '#^Binary operation "\." between array\|bool\|float\|int\|string\|null and ''/config/packages/dfs'' results in an error\.$#'
13251325
identifier: binaryOp.invalid
1326-
count: 2
1326+
count: 1
13271327
path: src/bundle/Core/DependencyInjection/IbexaCoreExtension.php
13281328

13291329
-
13301330
message: '#^Binary operation "\." between array\|bool\|float\|int\|string\|null and ''/config/packages…'' results in an error\.$#'
13311331
identifier: binaryOp.invalid
1332-
count: 3
1332+
count: 1
13331333
path: src/bundle/Core/DependencyInjection/IbexaCoreExtension.php
13341334

13351335
-
@@ -1560,24 +1560,12 @@ parameters:
15601560
count: 1
15611561
path: src/bundle/Core/DependencyInjection/IbexaCoreExtension.php
15621562

1563-
-
1564-
message: '#^Parameter \#1 \$search of function str_replace expects array\<string\>\|string, string\|false\|null given\.$#'
1565-
identifier: argument.type
1566-
count: 1
1567-
path: src/bundle/Core/DependencyInjection/IbexaCoreExtension.php
1568-
15691563
-
15701564
message: '#^Parameter \#1 \.\.\.\$arrays of function array_merge expects array, array\|bool\|float\|int\|string\|null given\.$#'
15711565
identifier: argument.type
15721566
count: 1
15731567
path: src/bundle/Core/DependencyInjection/IbexaCoreExtension.php
15741568

1575-
-
1576-
message: '#^Parameter \#2 \.\.\.\$values of function sprintf expects bool\|float\|int\|string\|null, array\|bool\|float\|int\|string\|null given\.$#'
1577-
identifier: argument.type
1578-
count: 1
1579-
path: src/bundle/Core/DependencyInjection/IbexaCoreExtension.php
1580-
15811569
-
15821570
message: '#^Property Ibexa\\Bundle\\Core\\DependencyInjection\\IbexaCoreExtension\:\:\$defaultSettingsCollection type has no value type specified in iterable type array\.$#'
15831571
identifier: missingType.iterableValue
@@ -22122,12 +22110,6 @@ parameters:
2212222110
count: 1
2212322111
path: tests/bundle/Core/EventSubscriber/TrustedHeaderClientIpEventSubscriberTest.php
2212422112

22125-
-
22126-
message: '#^Method Ibexa\\Tests\\Bundle\\Core\\EventSubscriber\\TrustedHeaderClientIpEventSubscriberTest\:\:testTrustedHeaderEventSubscriberWithTrustedProxy\(\) has parameter \$server with no value type specified in iterable type array\.$#'
22127-
identifier: missingType.iterableValue
22128-
count: 1
22129-
path: tests/bundle/Core/EventSubscriber/TrustedHeaderClientIpEventSubscriberTest.php
22130-
2213122113
-
2213222114
message: '#^Parameter \#2 \$trustedHeaderSet of static method Symfony\\Component\\HttpFoundation\\Request\:\:setTrustedProxies\(\) expects int\<0, 63\>, \-1 given\.$#'
2213322115
identifier: argument.type

src/bundle/Core/DependencyInjection/IbexaCoreExtension.php

Lines changed: 0 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Ibexa\Bundle\Core\DependencyInjection\Configuration\Suggestion\Formatter\YamlSuggestionFormatter;
2020
use Ibexa\Bundle\Core\DependencyInjection\Security\PolicyProvider\PoliciesConfigBuilder;
2121
use Ibexa\Bundle\Core\DependencyInjection\Security\PolicyProvider\PolicyProviderInterface;
22-
use Ibexa\Bundle\Core\Session\Handler\NativeSessionHandler;
2322
use Ibexa\Bundle\Core\SiteAccess\SiteAccessConfigurationFilter;
2423
use Ibexa\Contracts\Core\MVC\EventSubscriber\ConfigScopeChangeSubscriber;
2524
use Ibexa\Contracts\Core\Repository\Values\Filter\CriterionQueryBuilder as FilteringCriterionQueryBuilder;
@@ -193,7 +192,6 @@ public function prepend(ContainerBuilder $container): void
193192
$this->handleDefaultSettingsLoading($container);
194193

195194
$this->configureGenericSetup($container);
196-
$this->configurePlatformShSetup($container);
197195
}
198196

199197
/**
@@ -802,188 +800,6 @@ private function configureGenericSetup(ContainerBuilder $container): void
802800
}
803801
}
804802

805-
/**
806-
* @throws \Exception
807-
*/
808-
private function configurePlatformShSetup(ContainerBuilder $container): void
809-
{
810-
$projectDir = $container->getParameter('kernel.project_dir');
811-
812-
// Will not be executed on build step
813-
$relationships = $_SERVER['PLATFORM_RELATIONSHIPS'] ?? false;
814-
if (!$relationships) {
815-
return;
816-
}
817-
$routes = $_SERVER['PLATFORM_ROUTES'];
818-
819-
$relationships = json_decode(base64_decode($relationships), true);
820-
$routes = json_decode(base64_decode($routes), true);
821-
822-
// PLATFORMSH_DFS_NFS_PATH is different compared to DFS_NFS_PATH in the sense that it is relative to ezplatform dir
823-
// DFS_NFS_PATH is an absolute path
824-
if ($dfsNfsPath = $_SERVER['PLATFORMSH_DFS_NFS_PATH'] ?? false) {
825-
$container->setParameter('dfs_nfs_path', sprintf('%s/%s', $projectDir, $dfsNfsPath));
826-
827-
// Map common parameters
828-
$container->setParameter('dfs_database_charset', $container->getParameter('database_charset'));
829-
$container->setParameter(
830-
'dfs_database_collation',
831-
$container->getParameter('database_collation')
832-
);
833-
if (\array_key_exists('dfs_database', $relationships)) {
834-
// process dedicated P.sh dedicated config
835-
foreach ($relationships['dfs_database'] as $endpoint) {
836-
if (empty($endpoint['query']['is_master'])) {
837-
continue;
838-
}
839-
$container->setParameter('dfs_database_driver', 'pdo_' . $endpoint['scheme']);
840-
$container->setParameter(
841-
'dfs_database_url',
842-
sprintf(
843-
'%s://%s:%s@%s:%d/%s',
844-
$endpoint['scheme'],
845-
$endpoint['username'],
846-
$endpoint['password'],
847-
$endpoint['host'],
848-
$endpoint['port'],
849-
$endpoint['path']
850-
)
851-
);
852-
}
853-
} else {
854-
// or set fallback from the Repository database, if not configured
855-
$container->setParameter('dfs_database_driver', $container->getParameter('database_driver'));
856-
}
857-
858-
$loader = new Loader\YamlFileLoader($container, new FileLocator($projectDir . '/config/packages/dfs'));
859-
$loader->load('dfs.yaml');
860-
}
861-
862-
// Use Redis-based caching if possible.
863-
if (isset($relationships['rediscache'])) {
864-
foreach ($relationships['rediscache'] as $endpoint) {
865-
if ($endpoint['scheme'] !== 'redis') {
866-
continue;
867-
}
868-
869-
$loader = new Loader\YamlFileLoader($container, new FileLocator($projectDir . '/config/packages/cache_pool'));
870-
$loader->load('cache.redis.yaml');
871-
872-
$container->setParameter('cache_pool', 'cache.redis');
873-
$container->setParameter('cache_dsn', sprintf('%s:%d', $endpoint['host'], $endpoint['port']) . '?retry_interval=3');
874-
}
875-
} elseif (isset($relationships['cache'])) {
876-
// Fallback to memcached if here (deprecated, we will only handle redis here in the future)
877-
foreach ($relationships['cache'] as $endpoint) {
878-
if ($endpoint['scheme'] !== 'memcached') {
879-
continue;
880-
}
881-
882-
@trigger_error('Usage of Memcached is deprecated, redis is recommended', E_USER_DEPRECATED);
883-
884-
$container->setParameter('cache_pool', 'cache.memcached');
885-
$container->setParameter('cache_dsn', sprintf('%s:%d', $endpoint['host'], $endpoint['port']));
886-
887-
$loader = new Loader\YamlFileLoader($container, new FileLocator($projectDir . '/config/packages/cache_pool'));
888-
$loader->load('cache.memcached.yaml');
889-
}
890-
}
891-
892-
// Use Redis-based sessions if possible. If a separate Redis instance
893-
// is available, use that. If not, share a Redis instance with the
894-
// Cache. (That should be safe to do except on especially high-traffic sites.)
895-
if (isset($relationships['redissession'])) {
896-
foreach ($relationships['redissession'] as $endpoint) {
897-
if ($endpoint['scheme'] !== 'redis') {
898-
continue;
899-
}
900-
901-
$container->setParameter('ibexa.session.handler_id', NativeSessionHandler::class);
902-
$container->setParameter('ibexa.session.save_path', sprintf('%s:%d', $endpoint['host'], $endpoint['port']));
903-
}
904-
} elseif (isset($relationships['rediscache'])) {
905-
foreach ($relationships['rediscache'] as $endpoint) {
906-
if ($endpoint['scheme'] !== 'redis') {
907-
continue;
908-
}
909-
910-
$container->setParameter('ibexa.session.handler_id', NativeSessionHandler::class);
911-
$container->setParameter('ibexa.session.save_path', sprintf('%s:%d', $endpoint['host'], $endpoint['port']));
912-
}
913-
}
914-
915-
if (isset($relationships['solr'])) {
916-
foreach ($relationships['solr'] as $endpoint) {
917-
if ($endpoint['scheme'] !== 'solr') {
918-
continue;
919-
}
920-
921-
$container->setParameter('search_engine', 'solr');
922-
923-
$container->setParameter('solr_dsn', sprintf('http://%s:%d/%s', $endpoint['host'], $endpoint['port'], 'solr'));
924-
// To set solr_core parameter we assume path is in form like: "solr/collection1"
925-
$container->setParameter('solr_core', substr($endpoint['path'], 5));
926-
}
927-
}
928-
929-
if (isset($relationships['elasticsearch'])) {
930-
foreach ($relationships['elasticsearch'] as $endpoint) {
931-
$dsn = sprintf('%s:%d', $endpoint['host'], $endpoint['port']);
932-
933-
if ($endpoint['username'] !== null && $endpoint['password'] !== null) {
934-
$dsn = $endpoint['username'] . ':' . $endpoint['password'] . '@' . $dsn;
935-
}
936-
937-
if ($endpoint['path'] !== null) {
938-
$dsn .= '/' . $endpoint['path'];
939-
}
940-
941-
$dsn = $endpoint['scheme'] . '://' . $dsn;
942-
943-
$container->setParameter('search_engine', 'elasticsearch');
944-
$container->setParameter('elasticsearch_dsn', $dsn);
945-
}
946-
}
947-
948-
// We will pick a varnish route by the following prioritization:
949-
// - The first route found that has upstream: varnish
950-
// - if primary route has upstream: varnish, that route will be prioritised
951-
// If no route is found with upstream: varnish, then purge_server will not be set
952-
$route = null;
953-
foreach ($routes as $host => $info) {
954-
if ($route === null && $info['type'] === 'upstream' && $info['upstream'] === 'varnish') {
955-
$route = $host;
956-
}
957-
if ($info['type'] === 'upstream' && $info['upstream'] === 'varnish' && $info['primary'] === true) {
958-
$route = $host;
959-
break;
960-
}
961-
}
962-
963-
if ($route !== null && !($_SERVER['SKIP_HTTPCACHE_PURGE'] ?? false)) {
964-
$purgeServer = rtrim($route, '/');
965-
if (($_SERVER['HTTPCACHE_USERNAME'] ?? false) && ($_SERVER['HTTPCACHE_PASSWORD'] ?? false)) {
966-
$domain = parse_url($purgeServer, PHP_URL_HOST);
967-
$credentials = urlencode($_SERVER['HTTPCACHE_USERNAME']) . ':' . urlencode($_SERVER['HTTPCACHE_PASSWORD']);
968-
$purgeServer = str_replace($domain, $credentials . '@' . $domain, $purgeServer);
969-
}
970-
971-
$container->setParameter('ibexa.http_cache.purge_type', 'varnish');
972-
$container->setParameter('purge_type', 'varnish');
973-
$container->setParameter('purge_server', $purgeServer);
974-
}
975-
// Setting default value for HTTPCACHE_VARNISH_INVALIDATE_TOKEN if it is not explicitly set
976-
if (!($_SERVER['HTTPCACHE_VARNISH_INVALIDATE_TOKEN'] ?? false)) {
977-
$container->setParameter('varnish_invalidate_token', $_SERVER['PLATFORM_PROJECT_ENTROPY']);
978-
}
979-
980-
// Adapt config based on enabled PHP extensions
981-
// Get imagine to use imagick if enabled, to avoid using php memory for image conversions
982-
if (\extension_loaded('imagick')) {
983-
$container->setParameter('liip_imagine_driver', 'imagick');
984-
}
985-
}
986-
987803
private function shouldLoadTestBehatServices(ContainerBuilder $container): bool
988804
{
989805
return $container->hasParameter('ibexa.behat.browser.enabled')

src/bundle/Core/EventSubscriber/TrustedHeaderClientIpEventSubscriber.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
final class TrustedHeaderClientIpEventSubscriber implements EventSubscriberInterface
1717
{
18-
private const PLATFORM_SH_TRUSTED_HEADER_CLIENT_IP = 'X-Client-IP';
19-
2018
private ?string $trustedHeaderName;
2119

2220
public function __construct(
@@ -40,9 +38,6 @@ public function onKernelRequest(RequestEvent $event): void
4038
$trustedHeaderSet = Request::getTrustedHeaderSet();
4139

4240
$trustedHeaderName = $this->trustedHeaderName;
43-
if (null === $trustedHeaderName && $this->isPlatformShProxy($request)) {
44-
$trustedHeaderName = self::PLATFORM_SH_TRUSTED_HEADER_CLIENT_IP;
45-
}
4641

4742
if (null === $trustedHeaderName) {
4843
return;
@@ -59,9 +54,4 @@ public function onKernelRequest(RequestEvent $event): void
5954

6055
Request::setTrustedProxies($trustedProxies, $trustedHeaderSet);
6156
}
62-
63-
private function isPlatformShProxy(Request $request): bool
64-
{
65-
return null !== $request->server->get('PLATFORM_RELATIONSHIPS');
66-
}
6757
}

tests/bundle/Core/DependencyInjection/IbexaCoreExtensionTest.php

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -911,51 +911,6 @@ public function testLoadsTestServicesWhenParameterIsSpecified(): void
911911
$this->assertContainerBuilderHasService(QueryControllerContext::class);
912912
}
913913

914-
/**
915-
* @throws \JsonException
916-
*/
917-
public function testConfigurePlatformShDFS(): void
918-
{
919-
$dsn = 'mysql://dfs:dfs@localhost:3306/dfs';
920-
$parts = parse_url($dsn);
921-
922-
$relationship = [
923-
'dfs_database' => [
924-
[
925-
'host' => $parts['host'],
926-
'scheme' => $parts['scheme'],
927-
'username' => $parts['user'],
928-
'password' => $parts['pass'],
929-
'port' => $parts['port'],
930-
'path' => ltrim($parts['path'], '/'),
931-
'query' => [
932-
'is_master' => true,
933-
],
934-
],
935-
],
936-
];
937-
938-
$_SERVER['PLATFORM_RELATIONSHIPS'] = base64_encode(json_encode($relationship, JSON_THROW_ON_ERROR));
939-
$_SERVER['PLATFORMSH_DFS_NFS_PATH'] = '/';
940-
$_SERVER['PLATFORM_ROUTES'] = base64_encode(json_encode([], JSON_THROW_ON_ERROR));
941-
$_SERVER['PLATFORM_PROJECT_ENTROPY'] = '';
942-
943-
$this->container->setParameter('database_charset', 'utf8mb4');
944-
$this->container->setParameter('database_collation', 'utf8mb4_general_ci');
945-
$this->container->setParameter('kernel.project_dir', __DIR__ . '/../Resources');
946-
$this->load();
947-
948-
$this->assertContainerBuilderHasParameter('dfs_database_url');
949-
self::assertEquals($dsn, $this->container->getParameter('dfs_database_url'));
950-
951-
unset(
952-
$_SERVER['PLATFORM_RELATIONSHIPS'],
953-
$_SERVER['PLATFORMSH_DFS_NFS_PATH'],
954-
$_SERVER['PLATFORM_ROUTES'],
955-
$_SERVER['PLATFORM_PROJECT_ENTROPY']
956-
);
957-
}
958-
959914
/**
960915
* Prepare Core Container for compilation by mocking required parameters and compile it.
961916
*/

0 commit comments

Comments
 (0)