first commit
This commit is contained in:
50
api/includes/app.php
Normal file
50
api/includes/app.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.API
|
||||
*
|
||||
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
// Saves the start time and memory usage.
|
||||
$startTime = microtime(1);
|
||||
$startMem = memory_get_usage();
|
||||
|
||||
if (file_exists(\dirname(__DIR__) . '/defines.php')) {
|
||||
include_once \dirname(__DIR__) . '/defines.php';
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/defines.php';
|
||||
|
||||
require_once JPATH_BASE . '/includes/framework.php';
|
||||
|
||||
// Set profiler start time and memory usage and mark afterLoad in the profiler.
|
||||
JDEBUG && \Joomla\CMS\Profiler\Profiler::getInstance('Application')->setStart($startTime, $startMem)->mark('afterLoad');
|
||||
|
||||
// Boot the DI container
|
||||
$container = \Joomla\CMS\Factory::getContainer();
|
||||
|
||||
/*
|
||||
* Alias the session service keys to the web session service as that is the primary session backend for this application
|
||||
*
|
||||
* In addition to aliasing "common" service keys, we also create aliases for the PHP classes to ensure autowiring objects
|
||||
* is supported. This includes aliases for aliased class names, and the keys for aliased class names should be considered
|
||||
* deprecated to be removed when the class name alias is removed as well.
|
||||
*/
|
||||
$container->alias('session', 'session.cli')
|
||||
->alias('JSession', 'session.cli')
|
||||
->alias(\Joomla\CMS\Session\Session::class, 'session.cli')
|
||||
->alias(\Joomla\Session\Session::class, 'session.cli')
|
||||
->alias(\Joomla\Session\SessionInterface::class, 'session.cli');
|
||||
|
||||
// Instantiate the application.
|
||||
$app = $container->get(\Joomla\CMS\Application\ApiApplication::class);
|
||||
|
||||
// Set the application as global app
|
||||
\Joomla\CMS\Factory::$application = $app;
|
||||
|
||||
// Execute the application.
|
||||
$app->execute();
|
||||
32
api/includes/defines.php
Normal file
32
api/includes/defines.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.API
|
||||
*
|
||||
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
// Define JPATH constants if not defined yet
|
||||
\defined('JPATH_BASE') || \define('JPATH_BASE', \dirname(__DIR__));
|
||||
|
||||
// Global definitions
|
||||
$parts = explode(DIRECTORY_SEPARATOR, JPATH_BASE);
|
||||
array_pop($parts);
|
||||
|
||||
// Defines
|
||||
\defined('JPATH_ROOT') || \define('JPATH_ROOT', implode(DIRECTORY_SEPARATOR, $parts));
|
||||
\defined('JPATH_SITE') || \define('JPATH_SITE', JPATH_ROOT);
|
||||
\defined('JPATH_PUBLIC') || \define('JPATH_PUBLIC', JPATH_ROOT);
|
||||
\defined('JPATH_CONFIGURATION') || \define('JPATH_CONFIGURATION', JPATH_ROOT);
|
||||
\defined('JPATH_ADMINISTRATOR') || \define('JPATH_ADMINISTRATOR', JPATH_ROOT . DIRECTORY_SEPARATOR . 'administrator');
|
||||
\defined('JPATH_LIBRARIES') || \define('JPATH_LIBRARIES', JPATH_ROOT . DIRECTORY_SEPARATOR . 'libraries');
|
||||
\defined('JPATH_PLUGINS') || \define('JPATH_PLUGINS', JPATH_ROOT . DIRECTORY_SEPARATOR . 'plugins');
|
||||
\defined('JPATH_INSTALLATION') || \define('JPATH_INSTALLATION', JPATH_ROOT . DIRECTORY_SEPARATOR . 'installation');
|
||||
\defined('JPATH_THEMES') || \define('JPATH_THEMES', JPATH_BASE . DIRECTORY_SEPARATOR . 'templates');
|
||||
\defined('JPATH_CACHE') || \define('JPATH_CACHE', JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'cache');
|
||||
\defined('JPATH_MANIFESTS') || \define('JPATH_MANIFESTS', JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'manifests');
|
||||
\defined('JPATH_API') || \define('JPATH_API', JPATH_ROOT . DIRECTORY_SEPARATOR . 'api');
|
||||
\defined('JPATH_CLI') || \define('JPATH_CLI', JPATH_ROOT . DIRECTORY_SEPARATOR . 'cli');
|
||||
115
api/includes/framework.php
Normal file
115
api/includes/framework.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.API
|
||||
*
|
||||
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Version;
|
||||
use Joomla\Utilities\IpHelper;
|
||||
|
||||
// System includes
|
||||
require_once JPATH_LIBRARIES . '/bootstrap.php';
|
||||
|
||||
// Installation check, and check on removal of the install directory.
|
||||
if (
|
||||
!file_exists(JPATH_CONFIGURATION . '/configuration.php')
|
||||
|| (filesize(JPATH_CONFIGURATION . '/configuration.php') < 10)
|
||||
|| (file_exists(JPATH_INSTALLATION . '/index.php') && (false === (new Version())->isInDevelopmentState()))
|
||||
) {
|
||||
if (file_exists(JPATH_INSTALLATION . '/index.php')) {
|
||||
header('HTTP/1.1 500 Internal Server Error');
|
||||
echo json_encode(
|
||||
['error' => 'You must install Joomla to use the API']
|
||||
);
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
header('HTTP/1.1 500 Internal Server Error');
|
||||
echo json_encode(
|
||||
['error' => 'No configuration file found and no installation code available. Exiting...']
|
||||
);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
// Pre-Load configuration. Don't remove the Output Buffering due to BOM issues, see JCode 26026
|
||||
ob_start();
|
||||
require_once JPATH_CONFIGURATION . '/configuration.php';
|
||||
ob_end_clean();
|
||||
|
||||
// System configuration.
|
||||
$config = new JConfig();
|
||||
|
||||
// Set the error_reporting
|
||||
switch ($config->error_reporting) {
|
||||
case 'default':
|
||||
case '-1':
|
||||
break;
|
||||
|
||||
case 'none':
|
||||
case '0':
|
||||
error_reporting(0);
|
||||
|
||||
break;
|
||||
|
||||
case 'simple':
|
||||
error_reporting(E_ERROR | E_WARNING | E_PARSE);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
break;
|
||||
|
||||
case 'maximum':
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
error_reporting($config->error_reporting);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
\define('JDEBUG', $config->debug);
|
||||
|
||||
// Check deprecation logging
|
||||
if (empty($config->log_deprecated)) {
|
||||
// Reset handler for E_USER_DEPRECATED
|
||||
set_error_handler(null, E_USER_DEPRECATED);
|
||||
} else {
|
||||
// Make sure handler for E_USER_DEPRECATED is registered
|
||||
set_error_handler(['Joomla\CMS\Exception\ExceptionHandler', 'handleUserDeprecatedErrors'], E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
if (JDEBUG || $config->error_reporting === 'maximum') {
|
||||
// Set new Exception handler with debug enabled
|
||||
$errorHandler->setExceptionHandler(
|
||||
[
|
||||
new \Symfony\Component\ErrorHandler\ErrorHandler(null, true),
|
||||
'renderException',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Correctly set the allowing of IP Overrides if behind a trusted proxy/load balancer.
|
||||
*
|
||||
* We need to do this as high up the stack as we can, as the default in \Joomla\Utilities\IpHelper is to
|
||||
* $allowIpOverride = true which is the wrong default for a generic site NOT behind a trusted proxy/load balancer.
|
||||
*/
|
||||
if (property_exists($config, 'behind_loadbalancer') && $config->behind_loadbalancer == 1) {
|
||||
// If Joomla is configured to be behind a trusted proxy/load balancer, allow HTTP Headers to override the REMOTE_ADDR
|
||||
IpHelper::setAllowIpOverrides(true);
|
||||
} else {
|
||||
// We disable the allowing of IP overriding using headers by default.
|
||||
IpHelper::setAllowIpOverrides(false);
|
||||
}
|
||||
|
||||
unset($config);
|
||||
Reference in New Issue
Block a user