54 const DEFAULT_LANG =
'en';
55 const DEFAULT_LIMIT = 10;
67 private static $_setups = [];
84 if (self::$_instance === null) {
85 self::$_instance = self::factory();
86 self::setGlobalConfig(self::$_instance);
89 return self::$_instance;
100 self::$_instance = $application;
111 $this->_services = $services;
131 foreach (self::getEngineLibs() as
$file) {
133 $setups[] = self::requireSetupFileOnce(
"$path/$file");
134 }
catch (\Error $e) {
135 throw new \InstallationException(
"Elgg lib file failed include: $path/$file");
151 if (isset(self::$_setups[
$file])) {
152 return self::$_setups[
$file];
155 $return = Includer::requireFileOnce($file);
156 self::$_setups[
$file] = $return;
173 $app = self::getInstance();
185 return function_exists(
'elgg');
226 return $this->_services->dbConfig;
239 return $this->_services->publicDb;
251 $CONFIG = $application->_services->config;
268 public static function factory(array $spec = []) {
272 'handle_exceptions' =>
true,
273 'handle_shutdown' =>
true,
275 'service_provider' => null,
276 'set_start_time' =>
true,
277 'settings_path' => null,
281 if ($spec[
'set_start_time']) {
287 if (!isset($GLOBALS[
'START_MICROTIME'])) {
288 $GLOBALS[
'START_MICROTIME'] = microtime(
true);
292 if ($spec[
'handle_exceptions']) {
299 if (!$spec[
'service_provider']) {
300 if (!$spec[
'config']) {
301 $spec[
'config'] = Config::factory($spec[
'settings_path']);
306 if ($spec[
'request']) {
308 $spec[
'service_provider']->setValue(
'request', $spec[
'request']);
314 $app =
new self($spec[
'service_provider']);
316 if ($spec[
'handle_shutdown']) {
338 if ($request->isRewriteCheck()) {
339 $response =
new OkResponse(HttpRequest::REWRITE_TEST_OUTPUT);
340 return self::respond($response);
343 if (self::$_instance) {
344 $app = self::$_instance;
345 $app->_services->setValue(
'request', $request);
348 $app = self::factory([
349 'request' => $request,
352 self::setGlobalConfig($app);
353 self::setInstance($app);
355 return self::install();
374 if (self::$_instance) {
375 self::$_instance->_services->responseFactory->respond($builder);
377 return self::$_instance->_services->responseFactory->getSentResponse();
392 $response =
new Response($ex->getMessage(), 500);
395 $response->headers->set(
'Pragma',
'public');
396 $response->headers->set(
'Cache-Control',
'no-cache, must-revalidate');
397 $response->headers->set(
'Expires',
'Fri, 05 Feb 1982 00:00:00 -0500');
399 self::getResponseTransport()->send($response);
415 return self::route(self::getRequest());
429 $config = $this->_services->config;
430 $request = $this->_services->request;
439 $www_root = rtrim(
$request->getSchemeAndHttpHost() .
$request->getBaseUrl(),
'/') .
'/';
441 $config->wwwroot_cli_server = $www_root;
444 if (0 === strpos(
$request->getElggPath(),
'/cache/')) {
445 $config->_disable_session_save =
true;
446 $response = $this->_services->cacheHandler->handleRequest(
$request, $this)->prepare(
$request);
447 self::getResponseTransport()->send($response);
452 if (0 === strpos(
$request->getElggPath(),
'/serve-file/')) {
453 $response = $this->_services->serveFileHandler->getResponse(
$request);
454 self::getResponseTransport()->send($response);
462 $request = $this->_services->request;
464 if (!$this->_services->router->route(
$request)) {
472 }
else if (
$request->getFirstUrlSegment() ==
'action') {
484 if ($ex->getMessage()) {
485 $this->_services->systemMessages->addErrorMessage($ex->getMessage());
492 self::respond($response);
495 return $this->_services->responseFactory->getSentResponse();
505 return Local::elggRoot();
514 return Local::projectRoot();
524 ini_set(
'display_errors', 1);
533 return self::respond($response);
562 $request = self::$_instance->_services->request;
563 $signer = self::$_instance->_services->urlSigner;
570 if (isset(
$mac) && !$signer->isValid(
$url)) {
574 unset(
$query[UrlSigner::KEY_MAC]);
580 $url = self::$_instance->_services->urlSigner->sign(
$url);
588 return self::respond($response);
599 $constants = self::elggDir()->getPath(
'engine/lib/constants.php');
600 self::requireSetupFileOnce($constants);
602 $conf = self::elggDir()->getPath(
'engine/conf/migrations.php');
610 $app = new \Phinx\Console\PhinxApplication();
611 $wrapper = new \Phinx\Wrapper\TextWrapper($app, [
612 'configuration' => $conf,
614 $log = $wrapper->getMigrate();
616 if (!empty($_SERVER[
'argv']) && in_array(
'--verbose', $_SERVER[
'argv'])) {
630 $db_config = DbConfig::fromElggConfig(
$config);
632 if ($db_config->isDatabaseSplit()) {
633 $conn = $db_config->getConnectionConfig(DbConfig::WRITE);
635 $conn = $db_config->getConnectionConfig();
640 "migrations" =>
Paths::elgg() .
'engine/schema/migrations/',
643 "default_migration_table" =>
"{$conn['prefix']}migrations",
644 "default_database" =>
"prod",
646 "adapter" =>
"mysql",
647 "host" => $conn[
'host'],
648 "name" => $conn[
'database'],
649 "user" => $conn[
'user'],
650 "pass" => $conn[
'password'],
651 "charset" => $conn[
'encoding'],
652 "table_prefix" => $conn[
'prefix'],
666 $request = $this->_services->request;
667 $new = $this->_services->router->allowRewrite(
$request);
672 $this->_services->setValue(
'request', $new);
680 switch (php_sapi_name()) {
695 if (self::$_instance) {
696 return self::$_instance->_services->request;
699 return HttpRequest::createFromGlobals();
709 $argv =
$request->server->get(
'argv') ? : [];
710 return new ArgvInput($argv);
713 return new ArrayInput([]);
722 return new ConsoleOutput();
724 return new NullOutput();
733 $std_out = self::getStdOut();
734 if (is_callable([$std_out,
'getErrorOutput'])) {
735 return $std_out->getErrorOutput();
747 return new \Elgg\Http\OutputBufferTransport();
750 return new \Elgg\Http\HttpProtocolTransport();
760 private static function getEngineLibs() {
773 'deprecated-2.3.php',
774 'deprecated-3.0.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.
if(!$entity->delete()) $forward_url
if(!array_key_exists($filename, $text_files)) $file
getStatusCode()
Returns status code.
isRedirection()
Check if response is redirection.
static projectDir()
Returns a directory that points to the project root, where composer is installed. ...
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.
Thrown when page is not accessible.
$request
Page handler for autocomplete endpoint.
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.
trait Loggable
Enables adding a logger.
static getStdOut()
Load console output interface.
getDbConfig()
Get the DB credentials.
static getStdErr()
Load console error output interface.
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
getDb()
Get a Database wrapper for performing queries without booting Elgg.
$config
Advanced site settings, debugging section.
static start()
Start and boot the core.
bootCore()
Bootstrap the Elgg engine, loads plugins, and calls initial system events.
static getResponseTransport()
Build a transport for sending responses.
Thrown when one of the gatekeepers prevents access.
static getMigrationSettings()
Returns configuration array for database migrations.
static upgrade()
Elgg upgrade script.
static isCli()
Is application running in CLI.
__construct(ServiceProvider $services)
Constructor.
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 global
Pointer to the global context.
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.
getRedirectUrl()
Get preferred redirect URL.
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
static elggDir()
Returns a directory that points to the root of Elgg, but not necessarily the install root...
getHeaders()
Returns additional response headers.
static setGlobalConfig(Application $application)
Make the global $CONFIG a reference to this application's config service.
static requireSetupFileOnce($file)
Require a library/plugin file once and capture returned anonymous functions.
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.
static getInstance()
Get the global Application instance.