-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathscoper.inc.php
228 lines (200 loc) · 10.1 KB
/
scoper.inc.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
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
217
218
219
220
221
222
223
224
225
226
227
228
<?php
declare(strict_types=1);
use Isolated\Symfony\Component\Finder\Finder;
// You can do your own things here, e.g. collecting symbols to expose dynamically
// or files to exclude.
// However beware that this file is executed by PHP-Scoper, hence if you are using
// the PHAR it will be loaded by the PHAR. So it is highly recommended to avoid
// to auto-load any code here: it can result in a conflict or even corrupt
// the PHP-Scoper analysis.
return [
// The prefix configuration. If a non null value is be used, a random prefix
// will be generated instead.
//
// For more see: https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#prefix
'prefix' => 'WPUM',
// By default when running php-scoper add-prefix, it will prefix all relevant code found in the current working
// directory. You can however define which files should be scoped by defining a collection of Finders in the
// following configuration key.
//
// This configuration entry is completely ignored when using Box.
//
// For more see: https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#finders-and-paths
'finders' => [
Finder::create()
->files()
->ignoreVCS(true)
->notName('/LICENSE|.*\\.md|.*\\.dist|Makefile|composer\\.json|composer\\.lock/')
->exclude([
'doc',
'test',
'test_old',
'tests',
'Tests',
'vendor-bin',
])
->in('vendor'),
Finder::create()->append([
'composer.json',
]),
],
// List of excluded files, i.e. files for which the content will be left untouched.
// Paths are relative to the configuration file unless if they are already absolute
//
// For more see: https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#patchers
'exclude-files' => [
'vendor/htmlburger/carbon-fields/templates/Container/comment_meta.php',
'vendor/htmlburger/carbon-fields/templates/Container/nav_menu_item.php',
'vendor/htmlburger/carbon-fields/templates/Container/network.php',
'vendor/htmlburger/carbon-fields/templates/Container/post_meta.php',
'vendor/htmlburger/carbon-fields/templates/Container/term_meta.php',
'vendor/htmlburger/carbon-fields/templates/Container/theme_options.php',
'vendor/htmlburger/carbon-fields/templates/Container/user_meta.php',
'vendor/htmlburger/carbon-fields/templates/Container/widget.php',
'vendor/htmlburger/carbon-fields/templates/Exception/incorrect-syntax.php',
],
// When scoping PHP files, there will be scenarios where some of the code being scoped indirectly references the
// original namespace. These will include, for example, strings or string manipulations. PHP-Scoper has limited
// support for prefixing such strings. To circumvent that, you can define patchers to manipulate the file to your
// heart contents.
//
// For more see: https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#patchers
'patchers' => [
function (string $filePath, string $prefix, string $contents): string {
$wordpress_functions = array(
'add_action',
'add_filter',
'apply_filters',
'do_action',
'update_site_option',
'delete_site_option',
'wp_die',
'check_ajax_referer',
'is_multisite',
'get_site_transient',
'set_site_transient',
'delete_site_transient',
'maybe_serialize',
'maybe_unserialize',
'__',
'wp_next_scheduled',
'wp_schedule_event',
'wp_unschedule_event',
'wp_clear_scheduled_hook',
'add_query_arg',
'wp_remote_post',
'esc_url_raw',
'wp_create_nonce',
'admin_url',
'check_ajax_referer',
'wp_convert_hr_to_bytes',
'trailingslashit',
'untrailingslashit',
'plugins_url',
'content_url',
'site_url',
);
$wp_files = array(
'htmlburger/carbon-fields/core/Carbon_Fields.php'
);
foreach ( $wp_files as $wp_file ) {
if ( false !== strrpos( $filePath, $wp_file ) ) {
// Don't prefix WordPress functions
foreach ( $wordpress_functions as $wordpress_function ) {
$contents = str_replace( '\\' . $prefix . '\\' . $wordpress_function, $wordpress_function, $contents );
}
return $contents;
}
}
if ( false !== strrpos( $filePath, 'htmlburger/carbon-fields/core/Loader/Loader.php' ) ) {
$contents = str_replace( "'' : '.min';", "'.min' : '.min';", $contents );
}
if ( false !== strrpos( $filePath, 'wpbp/widgets-helper/wph-widget.php' ) ) {
$contents = str_replace( $prefix . '\\\\WP_Widget', '\\WP_Widget', $contents );
$contents = str_replace( 'extends WP_Widget', 'extends \\WP_Widget', $contents );
}
if ( false !== strrpos( $filePath, 'wpbp/widgets-helper/class.wph-widget.php' ) ) {
$contents = str_replace( 'extends WP_Widget', 'extends \\WP_Widget', $contents );
}
if ( false !== strrpos( $filePath, 'htmlburger/carbon-fields/core/Field.php' ) ) {
$contents = str_replace( '\\\\Carbon_Fields\\\\Field', '\\\\' . $prefix . '\\\\Carbon_Fields\\\\Field', $contents );
}
if ( false !== strrpos( $filePath, 'htmlburger/carbon-fields/core/Container.php' ) ) {
$contents = str_replace( '\\\\Carbon_Fields\\\\Container', '\\\\' . $prefix . '\\\\Carbon_Fields\\\\Container', $contents );
}
if ( false !== strrpos( $filePath, 'htmlburger/carbon-fields/core/Helper/Helper.php' ) ) {
$contents = str_replace( 'use ' . $prefix . '\\WP_Query;', 'use \\WP_Query;', $contents );
}
if ( false !== strrpos( $filePath, 'htmlburger/carbon-fields/core/Widget/Widget.php' ) ) {
$contents = str_replace( '\\' . $prefix . '\\WP_Widget', '\\WP_Widget', $contents );
}
if ( false !== strrpos( $filePath, 'htmlburger/carbon-fields/core/Libraries/Sidebar_Manager/Sidebar_Manager.php' ) ) {
$contents = str_replace( '\\' . $prefix . '\\WP_Error', '\\WP_Error', $contents );
}
if ( false !== strrpos( $filePath, 'htmlburger/carbon-fields/core/Walker/Nav_Menu_Item_Edit_Walker.php' ) ) {
$contents = str_replace( '\\' . $prefix . '\\Walker_Nav_Menu_Edit', '\\Walker_Nav_Menu_Edit', $contents );
}
if ( false !== strrpos( $filePath, 'htmlburger/carbon-fields/core/REST_API/Router.php' ) ) {
$contents = str_replace( '\\' . $prefix . '\\WP_REST_Response', '\\WP_REST_Response', $contents );
}
if ( false !== strrpos( $filePath, 'htmlburger/carbon-fields/core/Toolset/WP_Toolset.php' ) ) {
$contents = str_replace( '\\' . $prefix . '\\WP_Term', '\\WP_Term', $contents );
}
if ( false !== strrpos( $filePath, 'wp-user-manager/wpum-blocks/blocks-loader.php' ) ) {
$contents = str_replace( 'vendor/wp-user-manager/wpum-blocks/', 'vendor-dist/wp-user-manager/wpum-blocks/', $contents );
$contents = str_replace( 'WP_Block_Type_Registry', '\\WP_Block_Type_Registry', $contents );
$contents = str_replace( 'new WPUserManagerBlocks\Loader()', 'new \\' . $prefix . '\\WPUserManagerBlocks\Loader()', $contents );
}
if ( false !== strrpos( $filePath, 'wp-user-manager/wpum-blocks/includes/classes/Loader.php' ) ) {
$contents = str_replace( $prefix . '\\\\register_block_type', '\\\\register_block_type', $contents );
$contents = str_replace( $prefix . '\\\\WPUM_Groups', '\\\\WPUM_Groups', $contents );
$contents = str_replace( $prefix . '\\\\WPUM_Frontend_Posting', '\\\\WPUM_Frontend_Posting', $contents );
$contents = str_replace( $prefix . '\\\\WPUM_Likes', '\\\\WPUM_Likes', $contents );
$contents = str_replace( $prefix . '\\\\WPUM_Social_Login', '\\\\WPUM_Social_Login', $contents );
$contents = str_replace( $prefix . '\\\\WPUM_Private_Content', '\\\\WPUM_Private_Content', $contents );
}
if ( false !== strrpos( $filePath, 'brain/cortex' ) ) {
$contents = str_replace( '\\' . $prefix . '\\WP', '\\WP', $contents );
}
if ( false !== strrpos( $filePath, 'wp-user-manager/wp-optionskit/includes/class-wpok-rest-server.php' ) ) {
$contents = str_replace( 'extends \\' . $prefix . '\\WP_Rest_Controller', 'extends \\WP_Rest_Controller', $contents );
$contents = str_replace( '\\' . $prefix . '\\WP_Error', '\\WP_Error', $contents );
$contents = str_replace( '\\' . $prefix . '\\WP_REST_Server', '\\WP_REST_Server', $contents );
$contents = str_replace( '\\' . $prefix . '\\WP_REST_Request', '\\WP_REST_Request', $contents );
$contents = str_replace( '\\' . $prefix . '\\WP_REST_Response', '\\WP_REST_Response', $contents );
}
return $contents;
},
],
// List of symbols to consider internal i.e. to leave untouched.
//
// For more information see: https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#excluded-symbols
'exclude-namespaces' => [
// 'Acme\Foo' // The Acme\Foo namespace (and sub-namespaces)
// '~^PHPUnit\\\\Framework$~', // The whole namespace PHPUnit\Framework (but not sub-namespaces)
// '~^$~', // The root namespace only
// '', // Any namespace
],
'exclude-classes' => [
// 'ReflectionClassConstant',
],
'exclude-functions' => [
// 'mb_str_split',
],
'exclude-constants' => [
// 'STDIN',
],
// For more information see: https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#exposed-symbols
'expose-global-constants' => true,
'expose-global-classes' => false,
'expose-global-functions' => false,
'expose-namespaces' => [
// 'Acme\Foo' // The Acme\Foo namespace (and sub-namespaces)
// '~^PHPUnit\\\\Framework$~', // The whole namespace PHPUnit\Framework (but not sub-namespaces)
// '~^$~', // The root namespace only
// '', // Any namespace
],
'expose-classes' => [],
'expose-functions' => [],
'expose-constants' => [],
];