forked from mertyildiran/laraup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.php
89 lines (71 loc) · 2.63 KB
/
config.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
<?php
$line_number_end_of_file = 231;
$line_number_end_of_aliases = 229;
$line_number_end_of_providers = 178;
$old_project_path = $argv[1];
$new_project_path = $argv[2];
$old_app_php_path = $old_project_path.'/app/config/app.php';
$new_app_php_path = $new_project_path.'/config/app.php';
$old_app_php = file_get_contents($old_app_php_path);
$old_app_php = preg_replace('/^.+\n/', '', $old_app_php);
function app() {}
include $old_project_path.'/vendor/laravel/framework/src/Illuminate/Support/helpers.php';
include $old_project_path.'/bootstrap/helpers.php';
include $old_project_path.'/app/helpers.php';
$config = eval($old_app_php);
$standard_keys = [
'name',
'debug',
'url',
'timezone',
'locale',
'fallback_locale',
'key',
'cipher',
'providers',
'manifest',
'aliases'
];
$provider_replacements = [
'BackupManager\Laravel\Laravel4ServiceProvider' => 'BackupManager\Laravel\Laravel55ServiceProvider',
'Netson\L4shell\L4shellServiceProvider' => '',
'Kmd\Logviewer\LogviewerServiceProvider' => 'Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider'
];
$alias_replacements = [
'LucaDegasperi\OAuth2Server\Facades\AuthorizerFacade' => 'LucaDegasperi\OAuth2Server\Facades\Authorizer'
];
$lines = file($new_app_php_path);
foreach ($config as $key => $value) {
if (! in_array($key, $standard_keys)) {
$write = "\t'".$key."' => ".var_export($value, true).",\n";
array_splice($lines, $line_number_end_of_file - 1, 0, $write);
$line_number_end_of_file++;
}
}
foreach ($config['aliases'] as $key => $value) {
if (substr($value, 0, strlen('Illuminate')) !== 'Illuminate') {
if (array_key_exists($value, $alias_replacements)) {
$value = $alias_replacements[$value];
}
array_splice($lines, $line_number_end_of_aliases - 1, 0, "\t\t'".$key."' => ".$value."::class,\n");
$line_number_end_of_aliases++;
}
}
// for "laravelcollective/html" package
array_splice($lines, $line_number_end_of_aliases - 1, 0, "\n\t\t'Form' => Collective\\Html\\FormFacade::class,\n");
$line_number_end_of_aliases++;
array_splice($lines, $line_number_end_of_aliases - 1, 0, "\t\t'Html' => Collective\\Html\\HtmlFacade::class,\n");
$line_number_end_of_aliases++;
foreach ($config['providers'] as $value) {
if (substr($value, 0, strlen('Illuminate')) !== 'Illuminate') {
if (array_key_exists($value, $provider_replacements)) {
$value = $provider_replacements[$value];
}
if (! empty($value)) {
array_splice($lines, $line_number_end_of_providers - 1, 0, "\t\t".$value."::class,\n");
$line_number_end_of_providers++;
}
}
}
file_put_contents($new_app_php_path, implode($lines));
?>