drupflare/worker - v1.0.4
    Preparing search index...

    Variable CREATE_USER_PHPConst

    CREATE_USER_PHP: "\nuse Drupal\\Core\\DrupalKernel;\nuse Drupal\\Core\\Site\\Settings;\nuse Drupal\\user\\Entity\\User;\nuse Symfony\\Component\\HttpFoundation\\Request;\n\n// __CFW_FIBER_SHIM__\n// __CFW_HOST_HELPERS__\nchdir('/drupal');\n\n$opt = json_decode(__CFW_PAYLOAD__, true);\n$out = ['ok' => false, 'name' => $opt['name']];\n\n$_SERVER['HTTP_HOST'] = 'localhost';\n$_SERVER['SERVER_NAME'] = 'localhost';\n$_SERVER['SERVER_PORT'] = '80';\n$_SERVER['REQUEST_URI'] = '/';\n$_SERVER['REQUEST_METHOD'] = 'GET';\n$_SERVER['SCRIPT_NAME'] = '/index.php';\n$_SERVER['SCRIPT_FILENAME'] = '/drupal/index.php';\n$_SERVER['PHP_SELF'] = '/index.php';\n$_SERVER['DOCUMENT_ROOT'] = '/drupal';\n$_SERVER['REMOTE_ADDR'] = '127.0.0.1';\n$_SERVER['SERVER_SOFTWARE'] = 'workerd';\n$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';\n\ntry {\n\tif (!isset($GLOBALS['__pw_autoloader']) || !is_object($GLOBALS['__pw_autoloader'])) {\n\t\t$GLOBALS['__pw_autoloader'] = require '/drupal/autoload.php';\n\t}\n\t$autoloader = $GLOBALS['__pw_autoloader'];\n\tif (!isset($GLOBALS['__pw_kernel'])) {\n\t\t$boot = Request::create('/', 'GET');\n\t\t$kernel = new DrupalKernel('prod', $autoloader);\n\t\tDrupalKernel::bootEnvironment();\n\t\t$sitePath = DrupalKernel::findSitePath($boot);\n\t\t$kernel->setSitePath($sitePath);\n\t\tSettings::initialize('/drupal', $sitePath, $autoloader);\n\t\t$kernel->boot();\n\t\t$GLOBALS['__pw_kernel'] = $kernel;\n\t\t$out['bootedKernel'] = 1;\n\t}\n\n\tif (!defined('SAVED_NEW')) {\n\t\trequire_once '/drupal/core/includes/common.inc';\n\t\t$out['loadedCommonInc'] = true;\n\t}\n\n\t// __CFW_SCHEMA_REPAIR__\n\n\t$existing = Drupal::entityTypeManager()\n\t\t->getStorage('user')\n\t\t->loadByProperties(['name' => $opt['name']]);\n\t$loaded = $existing ? reset($existing) : null;\n\t$account = $loaded instanceof User ? $loaded : User::create(['name' => $opt['name']]);\n\t$account->setEmail($opt['name'] . '@example.invalid');\n\t$account->setPassword($opt['pass']);\n\t$account->activate();\n\tforeach ($opt['roles'] as $role) {\n\t\t$account->addRole($role);\n\t}\n\t$account->save();\n\n\t$out['uid'] = (int) $account->id();\n\t$out['roles'] = array_values($account->getRoles());\n\t$out['ok'] = true;\n} catch (Throwable $e) {\n\t$out['error'] = get_class($e) . ': ' . $e->getMessage();\n\t$out['trace'] = substr($e->getTraceAsString(), 0, 600);\n}\n\necho json_encode($out);\n"