addCoreResources();
$parts = explode('?', $requestUri);
$args = explode('/', $parts[0] ?? '');
// Remove empty path segments, a//b becomes equivalent to a/b
$args = array_values(array_filter($args));
if (!$args) {
// This is a request for the site's homepage. See if we have one.
$item = CRM_Core_Invoke::getItem('/');
if (!$item) {
// We have no public homepage, so send them to login.
// This doesn't allow for /civicrm itself to be public,
// but that's got to be a pretty edge case, right?!
CRM_Utils_System::redirect('/civicrm/login');
}
}
// This IS required for compatibility. e.g. the extensions (at least) quickform uses it for the form's action attribute.
$_GET['q'] = implode('/', $args);
// Render the page
print CRM_Core_Invoke::invoke($args);
}
function findStandaloneSettings(): string {
return dirname($_SERVER['DOCUMENT_ROOT']) . '/data/civicrm.settings.php';
}
function findStandaloneCore(): ?string {
$candidates = [
implode(DIRECTORY_SEPARATOR, [$_SERVER['DOCUMENT_ROOT'], 'core']),
implode(DIRECTORY_SEPARATOR, [dirname($_SERVER['DOCUMENT_ROOT']), 'vendor', 'civicrm', 'civicrm-core']),
];
foreach ($candidates as $candidate) {
if (file_exists($candidate)) {
return $candidate;
}
}
return NULL;
}
function findStandaloneAutoload(): ?string {
$candidates = [
implode(DIRECTORY_SEPARATOR, [dirname($_SERVER['DOCUMENT_ROOT']), 'vendor', 'autoload.php']),
implode(DIRECTORY_SEPARATOR, [$_SERVER['DOCUMENT_ROOT'], 'core', 'vendor', 'autoload.php']),
];
foreach ($candidates as $candidate) {
if (file_exists($candidate)) {
return $candidate;
}
}
return NULL;
}
require_once findStandaloneAutoload();
$civiCorePath = findStandaloneCore();
$classLoader = implode(DIRECTORY_SEPARATOR, [$civiCorePath, 'CRM', 'Core', 'ClassLoader.php']);
require_once $classLoader;
CRM_Core_ClassLoader::singleton()->register();
function standaloneErrorHandler(
int $errno,
string $errstr,
?string $errfile,
?int $errline) {
static $handlingError = FALSE;
if ($handlingError) {
throw new \RuntimeException("Died: error was thrown during error handling");
}
$config = CRM_Core_Config::singleton();
if (!$config->debug) {
// For these errors to show, we must be debugging.
return;
}
$handlingError = TRUE;
$trace = '';
if ($config->backtrace) {
// Backtrace is configured for errors.
$trace = [];
foreach (array_slice(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), 1) as $item) {
$_ = '';
if (!empty($item['function'])) {
if (!empty($item['class']) && !empty($item['type'])) {
$_ = htmlspecialchars("$item[class]$item[type]$item[function]() ");
}
else {
$_ = htmlspecialchars("$item[function]() ");
}
}
$_ .= "" . htmlspecialchars($item['file']) . '
line ' . $item['line'];
$trace[] = $_;
}
$trace = '
' . implode("\n", $trace) . ''; } if (!isset(Civi::$statics[__FUNCTION__])) { Civi::$statics[__FUNCTION__] = []; } Civi::$statics[__FUNCTION__][] = '
' . htmlspecialchars($errfile) . "
line $errline"
. $trace
. '