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');
202 return $this->boot_status[
$type] ??
false;
216 $this->boot_status[
$type] = $status;
229 return $this->internal_services->publicDb;
241 $CONFIG = $application->internal_services->config;
257 public static function factory(array $spec = []) {
261 'handle_exceptions' =>
true,
262 'handle_shutdown' =>
true,
264 'internal_services' => null,
265 'set_start_time' =>
true,
266 'settings_path' => null,
270 if ($spec[
'set_start_time']) {
276 if (!isset($GLOBALS[
'START_MICROTIME'])) {
277 $GLOBALS[
'START_MICROTIME'] =
microtime(
true);
281 if ($spec[
'handle_exceptions']) {
288 if (!$spec[
'internal_services']) {
289 if (!$spec[
'config']) {
290 $spec[
'config'] = Config::factory($spec[
'settings_path']);
292 $spec[
'internal_services'] = InternalContainer::factory([
'config' => $spec[
'config']]);
295 if ($spec[
'request']) {
297 $spec[
'request']->initializeTrustedProxyConfiguration($spec[
'internal_services']->config);
298 $spec[
'request']->correctBaseURL($spec[
'internal_services']->config);
299 $spec[
'internal_services']->set(
'request', $spec[
'request']);
305 $app =
new self($spec[
'internal_services']);
307 if ($spec[
'handle_shutdown']) {
324 if ($request->isRewriteCheck()) {
325 $response =
new OkResponse(HttpRequest::REWRITE_TEST_OUTPUT);
326 return self::respond($response);
329 if (self::$_instance) {
330 $app = self::$_instance;
331 $app->internal_services->set(
'request', $request);
334 $app = self::factory([
335 'request' => $request,
338 self::setGlobalConfig($app);
339 self::setInstance($app);
341 return self::install();
359 if (self::$_instance) {
360 self::$_instance->internal_services->responseFactory->respond($builder);
362 return self::$_instance->internal_services->responseFactory->getSentResponse();
377 $response =
new Response($ex->getMessage(), 500);
380 $response->headers->set(
'Pragma',
'public');
381 $response->headers->set(
'Cache-Control',
'no-store, must-revalidate');
382 $response->headers->set(
'Expires',
'Fri, 05 Feb 1982 00:00:00 -0500');
384 self::getResponseTransport()->send($response);
395 return self::route(self::getRequest());
405 $config = $this->internal_services->config;
406 $request = $this->internal_services->request;
417 $config->wwwroot_cli_server = $www_root;
421 $config->_disable_session_save =
true;
422 $response = $this->internal_services->cacheHandler->handleRequest(
$request, $this)->prepare(
$request);
423 self::getResponseTransport()->send($response);
428 if (
$request->getElggPath() ===
'/refresh_token') {
429 $config->_disable_session_save =
true;
430 $token = new \Elgg\Controllers\RefreshCsrfToken();
432 self::getResponseTransport()->send($response);
438 $config->_disable_session_save =
true;
439 $response = $this->internal_services->serveFileHandler->getResponse(
$request);
440 self::getResponseTransport()->send($response);
445 if ($this->isCli()) {
446 $config->_disable_session_save =
true;
452 $request = $this->internal_services->request;
454 if (!$this->internal_services->router->route(
$request)) {
462 }
else if (
$request->getFirstUrlSegment() ==
'action') {
474 if ($ex->getMessage()) {
475 $this->internal_services->system_messages->addErrorMessage($ex->getMessage());
484 self::respond($response);
487 return $this->internal_services->responseFactory->getSentResponse();
497 return Local::elggRoot();
506 return Local::projectRoot();
515 ini_set(
'display_errors', 1);
524 return self::respond($response);
547 $request = self::$_instance->internal_services->request;
548 $signer = self::$_instance->internal_services->urlSigner;
555 if (isset(
$mac) && !$signer->isValid(
$url)) {
559 unset(
$query[UrlSigner::KEY_MAC]);
565 $url = self::$_instance->internal_services->urlSigner->sign(
$url);
573 return self::respond($response);
584 $constants = self::elggDir()->getPath(
'engine/lib/constants.php');
585 Includer::requireFileOnce($constants);
587 $conf = self::elggDir()->getPath(
'engine/conf/migrations.php');
595 $app = new \Phinx\Console\PhinxApplication();
596 $wrapper = new \Phinx\Wrapper\TextWrapper($app, [
597 'configuration' => $conf,
599 $log = $wrapper->getMigrate();
601 if (!empty($_SERVER[
'argv']) && in_array(
'--verbose', $_SERVER[
'argv'])) {
615 $db_config = DbConfig::fromElggConfig(
$config);
617 if ($db_config->isDatabaseSplit()) {
618 $conn = $db_config->getConnectionConfig(DbConfig::WRITE);
620 $conn = $db_config->getConnectionConfig();
625 "migrations" =>
Paths::elgg() .
'engine/schema/migrations/',
628 "default_migration_table" =>
"{$conn['prefix']}migrations",
629 "default_database" =>
"prod",
631 "adapter" =>
"mysql",
632 "host" => $conn[
'host'],
633 "port" => $conn[
'port'],
634 "name" => $conn[
'database'],
635 "user" => $conn[
'user'],
636 "pass" => $conn[
'password'],
637 "charset" => $conn[
'encoding'],
638 "table_prefix" => $conn[
'prefix'],
652 $request = $this->internal_services->request;
653 $new = $this->internal_services->router->allowRewrite(
$request);
658 $this->internal_services->set(
'request', $new);
666 switch (php_sapi_name()) {
681 if (self::$_instance) {
682 return self::$_instance->internal_services->request;
685 return HttpRequest::createFromGlobals();
695 $argv =
$request->server->get(
'argv') ? : [];
696 return new ArgvInput($argv);
699 return new ArrayInput([]);
708 return new ConsoleOutput();
710 return new NullOutput();
719 $std_out = self::getStdOut();
720 if (is_callable([$std_out,
'getErrorOutput'])) {
721 return $std_out->getErrorOutput();
733 return new \Elgg\Http\OutputBufferTransport();
736 return new \Elgg\Http\HttpProtocolTransport();
746 private static function getEngineLibs() {
758 'deprecated-4.0.php',
759 'deprecated-4.1.php',
760 'deprecated-4.2.php',
761 'deprecated-4.3.php',
764 'external_files.php',
static index()
Elgg's front controller.
static factory(array $spec=[])
Create a new application.
elgg_http_add_url_query_elements($url, array $elements)
Sets elements in a URL's query string.
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.
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.
const ELGG_HTTP_PERMANENTLY_REDIRECT
static isCoreLoaded()
Are Elgg's global functions loaded?
elgg_normalize_site_url($unsafe_url)
From untrusted input, get a site URL safe for forwarding.
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
static getStdOut()
Load console output interface.
static getStdErr()
Load console error output interface.
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
getDb()
Get a Database wrapper for performing queries without booting Elgg.
$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.
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.
if(!$entity->delete()) $forward_url
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
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...
setException(\Exception $e)
Set an exception for this response.the exception for this responseself
setBootStatus(string $type, bool $status)
Sets the boot status.
getHeaders()
Returns additional response headers.
elgg global
Pointer to the global context.
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.
elgg_get_login_url(array $query=[], $fragment= '')
Returns site's login URL Triggers a 'login_url', 'site' plugin hook that can be used by plugins to al...
static migrate()
Runs database migrations.
getForwardURL()
Returns redirect URL.
getRedirectUrl()
Get preferred redirect URL.
static getInstance()
Get the global Application instance.