-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsettings.platformsh.php
More file actions
216 lines (193 loc) · 8.61 KB
/
Copy pathsettings.platformsh.php
File metadata and controls
216 lines (193 loc) · 8.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
/**
* @file
* Platform.sh settings.
*/
use Platformsh\ConfigReader\Config;
use Drupal\Core\Installer\InstallerKernel;
$platformsh = new Config();
if (PHP_SAPI !== 'cli') {
if (defined('MAINTENANCE_MODE') && constant('MAINTENANCE_MODE') === 'install') {
ini_set('memory_limit', '3072M');
}
else {
ini_set('memory_limit', '512M');
}
}
// Set up a config sync directory.
//
// This is defined inside the read-only "config" directory, deployed via Git.
$settings['config_sync_directory'] = '../config/sync';
// Configure the database.
if ($platformsh->hasRelationship('database')) {
$creds = $platformsh->credentials('database');
$databases['default']['default'] = [
'driver' => $creds['scheme'],
'database' => $creds['path'],
'username' => $creds['username'],
'password' => $creds['password'],
'host' => $creds['host'],
'port' => $creds['port'],
'pdo' => [PDO::MYSQL_ATTR_COMPRESS => !empty($creds['query']['compression'])],
'init_commands' => [
'isolation_level' => 'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED',
],
];
}
// Enable verbose error messages on development branches, but not on the production branch.
// You may add more debug-centric settings here if desired to have them automatically enable
// on development but not production.
if (isset($platformsh->branch)) {
// Production type environment.
if ($platformsh->onProduction() || $platformsh->onDedicated()) {
$config['system.logging']['error_level'] = 'hide';
}
// Development type environment.
else {
$config['system.logging']['error_level'] = 'verbose';
}
}
// Enable Redis caching.
if ($platformsh->hasRelationship('redis') && !InstallerKernel::installationAttempted() && extension_loaded('redis') && class_exists('Drupal\redis\ClientFactory')) {
$redis = $platformsh->credentials('redis');
// Set Redis as the default backend for any cache bin not otherwise specified.
$settings['cache']['default'] = 'cache.backend.redis';
$settings['redis.connection']['host'] = $redis['host'];
$settings['redis.connection']['port'] = $redis['port'];
// Apply changes to the container configuration to better leverage Redis.
// This includes using Redis for the lock and flood control systems, as well
// as the cache tag checksum. Alternatively, copy the contents of that file
// to your project-specific services.yml file, modify as appropriate, and
// remove this line.
$settings['container_yamls'][] = 'modules/contrib/redis/example.services.yml';
// Allow the services to work before the Redis module itself is enabled.
$settings['container_yamls'][] = 'modules/contrib/redis/redis.services.yml';
// Manually add the classloader path, this is required for the container cache bin definition below
// and allows to use it without the redis module being enabled.
$class_loader->addPsr4('Drupal\\redis\\', 'modules/contrib/redis/src');
// Use redis for container cache.
// The container cache is used to load the container definition itself, and
// thus any configuration stored in the container itself is not available
// yet. These lines force the container cache to use Redis rather than the
// default SQL cache.
$settings['bootstrap_container_definition'] = [
'parameters' => [],
'services' => [
'redis.factory' => [
'class' => 'Drupal\redis\ClientFactory',
],
'cache.backend.redis' => [
'class' => 'Drupal\redis\Cache\CacheBackendFactory',
'arguments' => ['@redis.factory', '@cache_tags_provider.container', '@serialization.phpserialize'],
],
'cache.container' => [
'class' => '\Drupal\redis\Cache\PhpRedis',
'factory' => ['@cache.backend.redis', 'get'],
'arguments' => ['container'],
],
'cache_tags_provider.container' => [
'class' => 'Drupal\redis\Cache\RedisCacheTagsChecksum',
'arguments' => ['@redis.factory'],
],
'serialization.phpserialize' => [
'class' => 'Drupal\Component\Serialization\PhpSerialize',
],
],
];
}
if ($platformsh->inRuntime()) {
// Configure private and temporary file paths.
if (!isset($settings['file_private_path'])) {
$settings['file_private_path'] = $platformsh->appDir . '/private';
}
if (!isset($settings['file_temp_path'])) {
$settings['file_temp_path'] = $platformsh->appDir . '/tmp';
}
// Configure the default PhpStorage and Twig template cache directories.
if (!isset($settings['php_storage']['default'])) {
$settings['php_storage']['default']['directory'] = $settings['file_private_path'];
}
if (!isset($settings['php_storage']['twig'])) {
$settings['php_storage']['twig']['directory'] = $settings['file_private_path'];
}
// Set the project-specific entropy value, used for generating one-time
// keys and such.
$settings['hash_salt'] = empty($settings['hash_salt']) ? $platformsh->projectEntropy : $settings['hash_salt'];
// Set the deployment identifier, which is used by some Drupal cache systems.
$settings['deployment_identifier'] = $settings['deployment_identifier'] ?? $platformsh->treeId;
}
// The 'trusted_hosts_pattern' setting allows an admin to restrict the Host header values
// that are considered trusted. If an attacker sends a request with a custom-crafted Host
// header then it can be an injection vector, depending on how the Host header is used.
// However, Platform.sh already replaces the Host header with the route that was used to reach
// Platform.sh, so it is guaranteed to be safe. The following line explicitly allows all
// Host headers, as the only possible Host header is already guaranteed safe.
$settings['trusted_host_patterns'] = ['.*'];
// Import variables prefixed with 'drupalsettings:' into $settings
// and 'drupalconfig:' into $config.
foreach ($platformsh->variables() as $name => $value) {
$parts = explode(':', $name);
list($prefix, $key) = array_pad($parts, 3, NULL);
switch ($prefix) {
// Variables that begin with `drupalsettings` or `drupal` get mapped
// to the $settings array verbatim, even if the value is an array.
// For example, a variable named drupalsettings:example-setting' with
// value 'foo' becomes $settings['example-setting'] = 'foo';
case 'drupalsettings':
case 'drupal':
$settings[$key] = $value;
break;
// Variables that begin with `drupalconfig` get mapped to the $config
// array. Deeply nested variable names, with colon delimiters,
// get mapped to deeply nested array elements. Array values
// get added to the end just like a scalar. Variables without
// both a config object name and property are skipped.
// Example: Variable `drupalconfig:conf_file:prop` with value `foo` becomes
// $config['conf_file']['prop'] = 'foo';
// Example: Variable `drupalconfig:conf_file:prop:subprop` with value `foo` becomes
// $config['conf_file']['prop']['subprop'] = 'foo';
// Example: Variable `drupalconfig:conf_file:prop:subprop` with value ['foo' => 'bar'] becomes
// $config['conf_file']['prop']['subprop']['foo'] = 'bar';
// Example: Variable `drupalconfig:prop` is ignored.
case 'drupalconfig':
if (count($parts) > 2) {
$temp = &$config[$key];
foreach (array_slice($parts, 2) as $n) {
$prev = &$temp;
$temp = &$temp[$n];
}
$prev[$n] = $value;
}
break;
}
}
// SOLR setup config https://docs.platform.sh/frameworks/drupal8/solr.html
/*
$platformsh->registerFormatter('drupal-solr', function($solr) {
// Default the solr core name to `collection1` for pre-Solr-6.x instances.
return [
'core' => substr($solr['path'], 5) ? : 'collection1',
'path' => '',
'host' => $solr['host'],
'port' => $solr['port'],
];
});
// Update these values to the relationship name (from .platform.app.yaml)
// and the machine name of the server from your Drupal configuration.
$relationship_name = 'solrsearch';
$solr_server_name = 'default_solr_server';
if ($platformsh->hasRelationship($relationship_name)) {
// Set the connector configuration to the appropriate value, as defined by the formatter above.
$config['search_api.server.' . $solr_server_name]['backend_config']['connector_config'] = $platformsh->formattedCredentials($relationship_name, 'drupal-solr');
}
*/
/*
* Comment the following NOT to have a Storybook on production environment.
* Uncomment when starting a storybook in development or staging.
* Use the 'development.local.services.yml' file for development or staging, and storybook.
*/
// if (isset($platformsh->branch)) {
// if (!$platformsh->onProduction() || !$platformsh->onDedicated()) {
$settings['container_yamls'][] = $app_root . '/' . $site_path . '/development.local.services.yml';
// }
// }