-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathphpstanBootstrap.php
More file actions
96 lines (85 loc) · 3.53 KB
/
Copy pathphpstanBootstrap.php
File metadata and controls
96 lines (85 loc) · 3.53 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
<?php
/*
* Copyright (C) 2022 SYSTOPIA GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation in version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types = 1);
// phpcs:disable Drupal.Commenting.DocComment.ContentAfterOpen
/** @var \PHPStan\DependencyInjection\Container $container */
/** @phpstan-var array<string> $bootstrapFiles */
use Composer\Autoload\ClassLoader;
$bootstrapFiles = $container->getParameter('bootstrapFiles');
foreach ($bootstrapFiles as $bootstrapFile) {
if (str_ends_with($bootstrapFile, 'vendor/autoload.php')) {
$vendorDir = dirname($bootstrapFile);
// Installation via composer (e.g. as Drupal module)
$civiCrmVendorDir = $vendorDir . '/civicrm';
$civiCrmCoreDir = $civiCrmVendorDir . '/civicrm-core';
$civiCrmPackagesDir = $civiCrmVendorDir . '/civicrm-packages';
// Installation without composer (e.g. as WordPress plugin)
if (!is_dir($civiCrmCoreDir) || !is_dir($civiCrmPackagesDir)) {
$civiCrmCoreDir = $vendorDir . '/..';
$civiCrmPackagesDir = $civiCrmCoreDir . '/packages';
}
if (!is_dir($civiCrmCoreDir) || !is_dir($civiCrmPackagesDir)) {
continue;
}
if (file_exists($civiCrmCoreDir)) {
set_include_path(
get_include_path()
. PATH_SEPARATOR . $civiCrmCoreDir
. PATH_SEPARATOR . $civiCrmPackagesDir
);
require_once 'api/api.php';
require_once 'api/v3/utils.php';
require_once 'api/v3/Generic.php';
/** @var list<string> $api3GenericFiles */
$api3GenericFiles = glob("$civiCrmCoreDir/api/v3/Generic/*.php");
array_map(fn ($file) => require_once $file, $api3GenericFiles);
$loader = new ClassLoader();
$loader->addClassMap([
'civicrm_api3' => "$civiCrmCoreDir/api/class.api.php",
'API_Wrapper' => "$civiCrmCoreDir/api/Wrapper.php",
]);
$loader->add('CRM_', [$civiCrmCoreDir]);
$loader->add('DB_', [$civiCrmPackagesDir]);
$loader->add('HTML_', [$civiCrmPackagesDir]);
// The class \Smarty extended by \CRM_Core_SmartyCompatibility uses the
// __call() method to delegate method calls to \Smarty\Smarty, but hasn't
// defined the methods itself which results in method not found errors. By
// aliasing \Smarty\Smarty to \Smarty we avoid these errors.
$smartyAutoloadFile = $civiCrmPackagesDir . '/smarty5/vendor/autoload.php';
if (file_exists($smartyAutoloadFile)) {
require_once $smartyAutoloadFile;
class_alias(\Smarty\Smarty::class, 'Smarty');
}
$coreExtDirs = glob("$civiCrmCoreDir/ext/*");
if (FALSE !== $coreExtDirs) {
foreach ($coreExtDirs as $extensionDir) {
if (is_dir("$extensionDir/CRM")) {
$loader->add('CRM_', [$extensionDir]);
}
if (is_dir("$extensionDir/Civi")) {
$loader->addPsr4('Civi\\', [$extensionDir . '/Civi']);
}
}
}
$loader->register();
break;
}
}
}
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
}