79 protected $boot_status = [
80 'application_boot_completed' =>
false,
81 'full_boot_completed' =>
false,
82 'plugins_boot_completed' =>
false,
83 'service_boot_completed' =>
false,
92 if (self::$_instance === null) {
93 self::$_instance = self::factory();
94 self::setGlobalConfig(self::$_instance);
97 return self::$_instance;
108 self::$_instance = $application;
119 $this->internal_services = $internal_services;
120 $this->public_services = PublicContainer::factory();
138 foreach (self::getEngineLibs() as $file) {
140 Includer::requireFileOnce(
"$path/$file");
141 }
catch (\Error $e) {
153 $app = self::getInstance();
165 return function_exists(
'elgg');
201 return $this->boot_status[
$type] ??
false;
214 $this->boot_status[
$type] = $status;
227 return $this->internal_services->publicDb;
239 $CONFIG = $application->internal_services->config;
255 public static function factory(array $spec = []) {
259 'handle_exceptions' =>
true,
260 'handle_shutdown' =>
true,
262 'internal_services' => null,
263 'set_start_time' =>
true,
264 'settings_path' =>
'',
268 if ($spec[
'set_start_time']) {
270 if (!isset($GLOBALS[
'START_MICROTIME'])) {
271 $GLOBALS[
'START_MICROTIME'] =
microtime(
true);
275 if ($spec[
'handle_exceptions']) {
282 if (!$spec[
'internal_services']) {
283 if (!$spec[
'config']) {
284 $spec[
'config'] = Config::factory($spec[
'settings_path']);
287 $spec[
'internal_services'] = InternalContainer::factory([
'config' => $spec[
'config']]);
290 if ($spec[
'request']) {
295 $spec[
'request']->initializeTrustedProxyConfiguration($spec[
'internal_services']->config);
296 $spec[
'request']->correctBaseURL($spec[
'internal_services']->config);
297 $spec[
'internal_services']->set(
'request', $spec[
'request']);
300 $app =
new self($spec[
'internal_services']);
302 if ($spec[
'handle_shutdown']) {
319 if ($request->isRewriteCheck()) {
324 if (self::$_instance) {
325 $app = self::$_instance;
326 $app->internal_services->set(
'request', $request);
329 $app = self::factory([
330 'request' => $request,
333 self::setGlobalConfig($app);
334 self::setInstance($app);
336 return self::install();
354 if (self::$_instance) {
355 self::$_instance->internal_services->responseFactory->respond($builder);
357 return self::$_instance->internal_services->responseFactory->getSentResponse();
372 $response =
new Response($ex->getMessage(), 500);
375 $response->headers->set(
'Pragma',
'public');
376 $response->headers->set(
'Cache-Control',
'no-store, must-revalidate');
377 $response->headers->set(
'Expires',
'Fri, 05 Feb 1982 00:00:00 -0500');
379 self::getResponseTransport()->send(
$response);
390 return self::route(self::getRequest());
399 $config = $this->internal_services->config;
400 $request = $this->internal_services->request;
411 $config->wwwroot_cli_server = $www_root;
414 if (str_starts_with(
$request->getElggPath(),
'/cache/')) {
415 $config->_disable_session_save =
true;
417 self::getResponseTransport()->send(
$response);
422 if (
$request->getElggPath() ===
'/refresh_token') {
423 $config->_disable_session_save =
true;
424 $token = new \Elgg\Controllers\RefreshCsrfToken();
426 self::getResponseTransport()->send(
$response);
431 if (str_starts_with(
$request->getElggPath(),
'/serve-file/')) {
432 $config->_disable_session_save =
true;
434 self::getResponseTransport()->send(
$response);
439 if ($this->isCli()) {
440 $config->_disable_session_save =
true;
446 $request = $this->internal_services->request;
448 if (!$this->internal_services->router->route(
$request)) {
456 }
else if (
$request->getFirstUrlSegment() ==
'action') {
461 $forward_url = (string) $this->internal_services->events->triggerResults(
'forward', $ex->getCode(), [
'exception' => $ex],
$forward_url);
464 if ($ex->getMessage()) {
465 $this->internal_services->system_messages->addErrorMessage($ex->getMessage());
478 return $this->internal_services->responseFactory->getSentResponse();
488 return Local::elggRoot();
497 return Local::projectRoot();
506 ini_set(
'display_errors', 1);
509 $installer = new \ElggInstaller();
538 $request = self::$_instance->internal_services->request;
539 $signer = self::$_instance->internal_services->urlSigner;
546 if (isset(
$mac) && !$signer->isValid(
$url)) {
550 unset(
$query[UrlSigner::KEY_MAC]);
556 $url = self::$_instance->internal_services->urlSigner->sign(
$url);
575 $constants = self::elggDir()->getPath(
'engine/lib/constants.php');
576 Includer::requireFileOnce($constants);
578 $conf = self::elggDir()->getPath(
'engine/schema/migrations.php');
586 $app = new \Phinx\Console\PhinxApplication();
587 $wrapper = new \Phinx\Wrapper\TextWrapper($app, [
588 'configuration' => $conf,
590 $log = $wrapper->getMigrate();
592 if (!empty($_SERVER[
'argv']) && in_array(
'--verbose', $_SERVER[
'argv'])) {
607 $db_config = DbConfig::fromElggConfig(
$config);
609 if ($db_config->isDatabaseSplit()) {
610 $conn = $db_config->getConnectionConfig(DbConfig::WRITE);
612 $conn = $db_config->getConnectionConfig();
617 'migrations' =>
Paths::elgg() .
'engine/schema/migrations/',
620 'default_migration_table' =>
"{$conn['prefix']}migrations",
621 'default_database' =>
'prod',
623 'adapter' =>
'mysql',
624 'host' => $conn[
'host'],
625 'port' => $conn[
'port'],
626 'name' => $conn[
'database'],
627 'user' => $conn[
'user'],
628 'pass' => $conn[
'password'],
629 'charset' => $conn[
'encoding'],
630 'table_prefix' => $conn[
'prefix'],
643 $request = $this->internal_services->request;
644 $new = $this->internal_services->router->allowRewrite(
$request);
649 $this->internal_services->set(
'request', $new);
674 if (self::$_instance) {
675 return self::$_instance->internal_services->request;
678 return HttpRequest::createFromGlobals();
689 $argv =
$request->server->get(
'argv') ?: [];
690 return new ArgvInput($argv);
693 return new ArrayInput([]);
703 return new ConsoleOutput();
705 return new NullOutput();
715 $std_out = self::getStdOut();
716 if (is_callable([$std_out,
'getErrorOutput'])) {
717 return $std_out->getErrorOutput();
730 return new \Elgg\Http\OutputBufferTransport();
733 return new \Elgg\Http\HttpProtocolTransport();
743 private static function getEngineLibs() {
756 'deprecated-5.0.php',
758 'external_files.php',
static index()
Elgg's front controller.
static factory(array $spec=[])
Create a new application.
allowPathRewrite()
Allow plugins to rewrite the path.
run()
Routes the request, booting core if not yet booted.
Handler for uncaught exceptions.
HTTP response builder interface.
elgg_is_logged_in()
Returns whether or not the user is currently logged in.
const ELGG_HTTP_FORBIDDEN
static install()
Renders a web UI for installing Elgg.
A generic parent class for Configuration exceptions.
getStatusCode()
Returns status code.
Exception thrown if an argument is not of the expected type.
elgg_normalize_site_url(string $unsafe_url)
From untrusted input, get a site URL safe for forwarding.
isRedirection()
Check if response is redirection.
static projectDir()
Returns a directory that points to the project root, where composer is installed. ...
__construct(InternalContainer $internal_services)
Constructor.
getContent()
Returns response body.
static $_instance
Reference to the loaded Application.
static loadCore()
Define all Elgg global functions and constants, wire up boot events, but don't boot.
elgg_get_login_url(array $query=[], string $fragment= '')
Returns site's login URL Triggers a 'login_url', 'site' event that can be used by plugins to alter th...
const ELGG_HTTP_PERMANENTLY_REDIRECT
static isCoreLoaded()
Are Elgg's global functions loaded?
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
static getStdOut()
Load console output interface.
static getStdErr()
Load console error output interface.
getDb()
Get a Database wrapper for performing queries without booting Elgg.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
$config
Advanced site settings, debugging section.
Updates the basic settings for the primary site object.
static start()
Start and boot the core.
if(!$pagination &&$limit!==false &&!empty($items)&&count($items) >=$limit) $base_url
trait Loggable
Enables adding a logger.
Thrown when page is not accessible.
const REFERRER
Used in calls to forward() to specify the browser should be redirected to the referring page...
bootCore()
Bootstrap the Elgg engine, loads plugins, and calls initial system events.
static getResponseTransport()
Build a transport for sending responses.
static getMigrationSettings()
Returns configuration array for database migrations.
static upgrade()
Elgg upgrade script.
static isCli()
Is application running in CLI.
Thrown when there is a major problem with the installation.
static respond(ResponseBuilder $builder)
Build and send a response.
static route(HttpRequest $request)
Route a request.
Handle system and PHP errors.
static getRequest()
Build request object.
elgg_http_add_url_query_elements(string $url, array $elements)
Sets elements in a URL's query string.
if(!$entity->delete()) $forward_url
Redirect response builder.
getBootStatus(string $type)
Retrieve the boot status of the application.
static getStdIn()
Load console input interface.
Load, boot, and implement a front controller for an Elgg application.
$content
Set robots.txt action.
const ELGG_HTTP_INTERNAL_SERVER_ERROR
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
static elggDir()
Returns a directory that points to the root of Elgg, but not necessarily the install root...
setBootStatus(string $type, bool $status)
Sets the boot status.
getHeaders()
Returns additional response headers.
static setGlobalConfig(Application $application)
Make the global $CONFIG a reference to this application's config service.
Thrown when one of the gatekeepers prevents access.
Handles application boot sequence.
static setInstance(Application $application=null)
Set the global Application instance.
static migrate()
Runs database migrations.
getForwardURL()
Returns redirect URL.
getRedirectUrl()
Get preferred redirect URL.
static getInstance()
Get the global Application instance.