-
Notifications
You must be signed in to change notification settings - Fork 4
/
namespace.php
121 lines (100 loc) · 3.63 KB
/
namespace.php
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
<?php
namespace Altis\Local_Server;
use function Altis\get_config;
/**
* Configure environment for local server.
*/
function bootstrap() {
add_filter( 'admin_menu', __NAMESPACE__ . '\\tools_submenus' );
$config = get_config()['modules']['local-server'];
if ( $config['s3'] ) {
define( 'S3_UPLOADS_BUCKET', getenv( 'S3_UPLOADS_BUCKET' ) );
define( 'S3_UPLOADS_REGION', getenv( 'S3_UPLOADS_REGION' ) );
define( 'S3_UPLOADS_KEY', getenv( 'S3_UPLOADS_KEY' ) );
define( 'S3_UPLOADS_SECRET', getenv( 'S3_UPLOADS_SECRET' ) );
define( 'S3_UPLOADS_ENDPOINT', getenv( 'S3_UPLOADS_ENDPOINT' ) );
define( 'S3_UPLOADS_BUCKET_URL', getenv( 'S3_UPLOADS_BUCKET_URL' ) );
add_filter( 's3_uploads_s3_client_params', function ( $params ) {
if ( defined( 'S3_UPLOADS_ENDPOINT' ) ) {
$params['endpoint'] = S3_UPLOADS_ENDPOINT;
$params['use_path_style_endpoint'] = true;
}
return $params;
}, 5, 1 );
}
if ( empty( $_SERVER['HTTP_HOST'] ) ) {
$_SERVER['HTTP_HOST'] = getenv( 'COMPOSE_PROJECT_NAME' ) . '.altis.dev';
}
define( 'DB_HOST', getenv( 'DB_HOST' ) );
define( 'DB_USER', getenv( 'DB_USER' ) );
define( 'DB_PASSWORD', getenv( 'DB_PASSWORD' ) );
define( 'DB_NAME', getenv( 'DB_NAME' ) );
define( 'ELASTICSEARCH_HOST', getenv( 'ELASTICSEARCH_HOST' ) );
define( 'ELASTICSEARCH_PORT', getenv( 'ELASTICSEARCH_PORT' ) );
define( 'AWS_XRAY_DAEMON_IP_ADDRESS', gethostbyname( getenv( 'AWS_XRAY_DAEMON_HOST' ) ) );
global $redis_server;
$redis_server = [
'host' => getenv( 'REDIS_HOST' ),
'port' => getenv( 'REDIS_PORT' ),
];
ini_set( 'display_errors', 'on' );
if ( $config['tachyon'] ) {
define( 'TACHYON_URL', getenv( 'TACHYON_URL' ) );
/**
* In local-server, the tachyon hostname resolves to what is deemed a local url.
* This makes requests to tachyon from WordPress disallowed. We want to
* specifically allow that host.
*/
add_filter( 'http_request_host_is_external', function ( bool $is_external, string $host ) : bool {
if ( $is_external ) {
return $is_external;
}
// @codingStandardsIgnoreLine
return parse_url( TACHYON_URL, PHP_URL_HOST ) === $host;
}, 10, 2 );
}
if ( $config['analytics'] ) {
define( 'ALTIS_ANALYTICS_PINPOINT_ID', '12345678901234567890123456' );
define( 'ALTIS_ANALYTICS_PINPOINT_REGION', 'us-east-1' );
define( 'ALTIS_ANALYTICS_COGNITO_ID', 'us-east-1:f6f6f6-fafa-f5f5-8f8f-1234567890' );
define( 'ALTIS_ANALYTICS_COGNITO_REGION', 'us-east-1' );
define( 'ALTIS_ANALYTICS_PINPOINT_ENDPOINT', getenv( 'ALTIS_ANALYTICS_PINPOINT_ENDPOINT' ) );
define( 'ALTIS_ANALYTICS_COGNITO_ENDPOINT', getenv( 'ALTIS_ANALYTICS_COGNITO_ENDPOINT' ) );
}
// Set XDebug cookie if environment variable is set.
if ( getenv( 'PHP_XDEBUG_ENABLED' ) ) {
setcookie( 'XDEBUG_SESSION', $_SERVER['HTTP_HOST'], strtotime( '+1 year' ), '/', $_SERVER['HTTP_HOST'] );
}
add_filter( 'qm/output/file_path_map', __NAMESPACE__ . '\\set_file_path_map', 1 );
}
/**
* Enables Query Monitor to map paths to their original values on the host.
*
* @param array $map Map of guest path => host path
* @return array Adjusted mapping of folders
*/
function set_file_path_map( array $map ) : array {
if ( ! getenv( 'HOST_PATH' ) ) {
return $map;
}
$map['/usr/src/app'] = rtrim( getenv( 'HOST_PATH' ), DIRECTORY_SEPARATOR );
return $map;
}
/**
* Add new submenus to Tools admin menu.
*/
function tools_submenus() {
$links = [
[
'label' => 'Kibana',
'url' => network_site_url( '/kibana' ),
],
[
'label' => 'MailHog',
'url' => network_site_url( '/mailhog' ),
],
];
foreach ( $links as $link ) {
add_management_page( $link['label'], $link['label'], 'manage_options', $link['url'] );
}
}