mirror of
https://github.com/friendica/friendica
synced 2024-11-09 17:02:54 +00:00
Remove deprecated App::module - replace with DI::module()->getName()
This commit is contained in:
parent
33674808dc
commit
4835f1185f
8 changed files with 72 additions and 49 deletions
|
@ -283,30 +283,35 @@ function api_check_method($method)
|
|||
* @brief Main API entry point
|
||||
*
|
||||
* @param App $a App
|
||||
* @param App\Arguments $args The app arguments (optional, will retrieved by the DI-Container in case of missing)
|
||||
* @return string|array API call result
|
||||
* @throws Exception
|
||||
*/
|
||||
function api_call(App $a)
|
||||
function api_call(App $a, App\Arguments $args = null)
|
||||
{
|
||||
global $API, $called_api;
|
||||
|
||||
if ($args == null) {
|
||||
$args = DI::args();
|
||||
}
|
||||
|
||||
$type = "json";
|
||||
if (strpos(DI::args()->getQueryString(), ".xml") > 0) {
|
||||
if (strpos($args->getQueryString(), ".xml") > 0) {
|
||||
$type = "xml";
|
||||
}
|
||||
if (strpos(DI::args()->getQueryString(), ".json") > 0) {
|
||||
if (strpos($args->getQueryString(), ".json") > 0) {
|
||||
$type = "json";
|
||||
}
|
||||
if (strpos(DI::args()->getQueryString(), ".rss") > 0) {
|
||||
if (strpos($args->getQueryString(), ".rss") > 0) {
|
||||
$type = "rss";
|
||||
}
|
||||
if (strpos(DI::args()->getQueryString(), ".atom") > 0) {
|
||||
if (strpos($args->getQueryString(), ".atom") > 0) {
|
||||
$type = "atom";
|
||||
}
|
||||
|
||||
try {
|
||||
foreach ($API as $p => $info) {
|
||||
if (strpos(DI::args()->getQueryString(), $p) === 0) {
|
||||
if (strpos($args->getQueryString(), $p) === 0) {
|
||||
if (!api_check_method($info['method'])) {
|
||||
throw new MethodNotAllowedException();
|
||||
}
|
||||
|
@ -369,7 +374,7 @@ function api_call(App $a)
|
|||
throw new NotImplementedException();
|
||||
} catch (HTTPException $e) {
|
||||
header("HTTP/1.1 {$e->getCode()} {$e->httpdesc}");
|
||||
return api_error($type, $e);
|
||||
return api_error($type, $e, $args);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -378,18 +383,17 @@ function api_call(App $a)
|
|||
*
|
||||
* @param string $type Return type (xml, json, rss, as)
|
||||
* @param object $e HTTPException Error object
|
||||
* @param App\Arguments $args The App arguments
|
||||
* @return string|array error message formatted as $type
|
||||
*/
|
||||
function api_error($type, $e)
|
||||
function api_error($type, $e, App\Arguments $args)
|
||||
{
|
||||
$a = \get_app();
|
||||
|
||||
$error = ($e->getMessage() !== "" ? $e->getMessage() : $e->httpdesc);
|
||||
/// @TODO: https://dev.twitter.com/overview/api/response-codes
|
||||
|
||||
$error = ["error" => $error,
|
||||
"code" => $e->getCode() . " " . $e->httpdesc,
|
||||
"request" => DI::args()->getQueryString()];
|
||||
"request" => $args->getQueryString()];
|
||||
|
||||
$return = api_format_data('status', $type, ['status' => $error]);
|
||||
|
||||
|
|
|
@ -57,8 +57,6 @@ class App
|
|||
public $argv;
|
||||
/** @deprecated 2019.09 - use App\Arguments->getArgc() */
|
||||
public $argc;
|
||||
/** @deprecated 2019.09 - Use App\Module->getName() instead */
|
||||
public $module;
|
||||
public $timezone;
|
||||
public $interactive = true;
|
||||
public $identities;
|
||||
|
@ -156,7 +154,7 @@ class App
|
|||
* @param App\Arguments $args The Friendica Arguments of the call
|
||||
* @param Core\Process $process The process methods
|
||||
*/
|
||||
public function __construct(Database $database, Configuration $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, App\Module $module, App\Page $page, Core\Process $process)
|
||||
public function __construct(Database $database, Configuration $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, App\Page $page, Core\Process $process)
|
||||
{
|
||||
$this->database = $database;
|
||||
$this->config = $config;
|
||||
|
@ -170,7 +168,6 @@ class App
|
|||
|
||||
$this->argv = $args->getArgv();
|
||||
$this->argc = $args->getArgc();
|
||||
$this->module = $module->getName();
|
||||
$this->page = $page;
|
||||
|
||||
$this->load();
|
||||
|
|
|
@ -15,6 +15,7 @@ use Friendica\Core\Session;
|
|||
use Friendica\Core\System;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
@ -378,7 +379,7 @@ class Authentication
|
|||
if ($login_initial) {
|
||||
Hook::callAll('logged_in', $a->user);
|
||||
|
||||
if ($a->module !== 'home' && $this->session->exists('return_path')) {
|
||||
if (DI::module()->getName() !== 'home' && $this->session->exists('return_path')) {
|
||||
$this->baseUrl->redirect($this->session->get('return_path'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ class Nav
|
|||
if (Session::isAuthenticated()) {
|
||||
$nav['logout'] = ['logout', L10n::t('Logout'), '', L10n::t('End this session')];
|
||||
} else {
|
||||
$nav['login'] = ['login', L10n::t('Login'), ($a->module == 'login' ? 'selected' : ''), L10n::t('Sign in')];
|
||||
$nav['login'] = ['login', L10n::t('Login'), (DI::module()->getName() == 'login' ? 'selected' : ''), L10n::t('Sign in')];
|
||||
}
|
||||
|
||||
if (local_user()) {
|
||||
|
@ -179,7 +179,7 @@ class Nav
|
|||
$homelink = Session::get('visitor_home', '');
|
||||
}
|
||||
|
||||
if (($a->module != 'home') && (! (local_user()))) {
|
||||
if ((DI::module()->getName() != 'home') && (! (local_user()))) {
|
||||
$nav['home'] = [$homelink, L10n::t('Home'), '', L10n::t('Home Page')];
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ class ACL
|
|||
$arr = ['contact' => $contacts, 'entry' => $o];
|
||||
|
||||
// e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow'
|
||||
Hook::callAll($a->module . '_pre_' . $selname, $arr);
|
||||
Hook::callAll(DI::module()->getName() . '_pre_' . $selname, $arr);
|
||||
|
||||
if (DBA::isResult($contacts)) {
|
||||
foreach ($contacts as $contact) {
|
||||
|
@ -127,7 +127,7 @@ class ACL
|
|||
|
||||
$o .= '</select>' . PHP_EOL;
|
||||
|
||||
Hook::callAll($a->module . '_post_' . $selname, $o);
|
||||
Hook::callAll(DI::module()->getName() . '_post_' . $selname, $o);
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ class ACL
|
|||
$arr = ['contact' => $contacts, 'entry' => $o];
|
||||
|
||||
// e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow'
|
||||
Hook::callAll($a->module . '_pre_' . $selname, $arr);
|
||||
Hook::callAll(DI::module()->getName() . '_pre_' . $selname, $arr);
|
||||
|
||||
$receiverlist = [];
|
||||
|
||||
|
@ -201,7 +201,7 @@ class ACL
|
|||
$o .= implode(', ', $receiverlist);
|
||||
}
|
||||
|
||||
Hook::callAll($a->module . '_post_' . $selname, $o);
|
||||
Hook::callAll(DI::module()->getName() . '_post_' . $selname, $o);
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
|
|
@ -115,8 +115,7 @@ class ApiTest extends DatabaseTest
|
|||
// User ID that we know is not in the database
|
||||
$this->wrongUserId = 666;
|
||||
|
||||
$session = DI::session();
|
||||
$session->start();
|
||||
DI::session()->start();
|
||||
|
||||
// Most API require login so we force the session
|
||||
$_SESSION = [
|
||||
|
@ -433,12 +432,14 @@ class ApiTest extends DatabaseTest
|
|||
}
|
||||
];
|
||||
$_SERVER['REQUEST_METHOD'] = 'method';
|
||||
$_SERVER['QUERY_STRING'] = 'q=api_path';
|
||||
$_GET['callback'] = 'callback_name';
|
||||
|
||||
$this->app->query_string = 'api_path';
|
||||
$args = DI::args()->determine($_SERVER, $_GET);
|
||||
|
||||
$this->assertEquals(
|
||||
'callback_name(["some_data"])',
|
||||
api_call($this->app)
|
||||
api_call($this->app, $args)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -457,7 +458,12 @@ class ApiTest extends DatabaseTest
|
|||
return ['data' => ['some_data']];
|
||||
}
|
||||
];
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = 'method';
|
||||
$_SERVER['QUERY_STRING'] = 'q=api_path';
|
||||
|
||||
$args = DI::args()->determine($_SERVER, $_GET);
|
||||
|
||||
$this->config->set('system', 'profiler', true);
|
||||
$this->config->set('rendertime', 'callstack', true);
|
||||
$this->app->callstack = [
|
||||
|
@ -468,10 +474,9 @@ class ApiTest extends DatabaseTest
|
|||
'network' => ['some_function' => 200]
|
||||
];
|
||||
|
||||
$this->app->query_string = 'api_path';
|
||||
$this->assertEquals(
|
||||
'["some_data"]',
|
||||
api_call($this->app)
|
||||
api_call($this->app, $args)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -491,11 +496,13 @@ class ApiTest extends DatabaseTest
|
|||
}
|
||||
];
|
||||
$_SERVER['REQUEST_METHOD'] = 'method';
|
||||
$_SERVER['QUERY_STRING'] = 'q=api_path';
|
||||
|
||||
$args = DI::args()->determine($_SERVER, $_GET);
|
||||
|
||||
$this->app->query_string = 'api_path';
|
||||
$this->assertEquals(
|
||||
'{"status":{"error":"Internal Server Error","code":"500 Internal Server Error","request":"api_path"}}',
|
||||
api_call($this->app)
|
||||
api_call($this->app, $args)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -529,11 +536,13 @@ class ApiTest extends DatabaseTest
|
|||
}
|
||||
];
|
||||
$_SERVER['REQUEST_METHOD'] = 'method';
|
||||
$_SERVER['QUERY_STRING'] = 'q=api_path.json';
|
||||
|
||||
$args = DI::args()->determine($_SERVER, $_GET);
|
||||
|
||||
$this->app->query_string = 'api_path.json';
|
||||
$this->assertEquals(
|
||||
'["some_data"]',
|
||||
api_call($this->app)
|
||||
api_call($this->app, $args)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -553,11 +562,13 @@ class ApiTest extends DatabaseTest
|
|||
}
|
||||
];
|
||||
$_SERVER['REQUEST_METHOD'] = 'method';
|
||||
$_SERVER['QUERY_STRING'] = 'q=api_path.xml';
|
||||
|
||||
$args = DI::args()->determine($_SERVER, $_GET);
|
||||
|
||||
$this->app->query_string = 'api_path.xml';
|
||||
$this->assertEquals(
|
||||
'some_data',
|
||||
api_call($this->app)
|
||||
api_call($this->app, $args)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -577,12 +588,14 @@ class ApiTest extends DatabaseTest
|
|||
}
|
||||
];
|
||||
$_SERVER['REQUEST_METHOD'] = 'method';
|
||||
$_SERVER['QUERY_STRING'] = 'q=api_path.rss';
|
||||
|
||||
$args = DI::args()->determine($_SERVER, $_GET);
|
||||
|
||||
$this->app->query_string = 'api_path.rss';
|
||||
$this->assertEquals(
|
||||
'<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
|
||||
'some_data',
|
||||
api_call($this->app)
|
||||
api_call($this->app, $args)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -602,12 +615,14 @@ class ApiTest extends DatabaseTest
|
|||
}
|
||||
];
|
||||
$_SERVER['REQUEST_METHOD'] = 'method';
|
||||
$_SERVER['QUERY_STRING'] = 'q=api_path.atom';
|
||||
|
||||
$args = DI::args()->determine($_SERVER, $_GET);
|
||||
|
||||
$this->app->query_string = 'api_path.atom';
|
||||
$this->assertEquals(
|
||||
'<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
|
||||
'some_data',
|
||||
api_call($this->app)
|
||||
api_call($this->app, $args)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -622,10 +637,13 @@ class ApiTest extends DatabaseTest
|
|||
global $API;
|
||||
$API['api_path'] = ['method' => 'method'];
|
||||
|
||||
$this->app->query_string = 'api_path';
|
||||
$_SERVER['QUERY_STRING'] = 'q=api_path';
|
||||
|
||||
$args = DI::args()->determine($_SERVER, $_GET);
|
||||
|
||||
$this->assertEquals(
|
||||
'{"status":{"error":"Method Not Allowed","code":"405 Method Not Allowed","request":"api_path"}}',
|
||||
api_call($this->app)
|
||||
api_call($this->app, $args)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -642,13 +660,15 @@ class ApiTest extends DatabaseTest
|
|||
'method' => 'method',
|
||||
'auth' => true
|
||||
];
|
||||
$_SERVER['REQUEST_METHOD'] = 'method';
|
||||
$_SESSION['authenticated'] = false;
|
||||
$_SERVER['REQUEST_METHOD'] = 'method';
|
||||
$_SERVER['QUERY_STRING'] = 'q=api_path';
|
||||
|
||||
$args = DI::args()->determine($_SERVER, $_GET);
|
||||
|
||||
$this->app->query_string = 'api_path';
|
||||
$this->assertEquals(
|
||||
'{"status":{"error":"This API requires login","code":"401 Unauthorized","request":"api_path"}}',
|
||||
api_call($this->app)
|
||||
api_call($this->app, $args)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -662,7 +682,7 @@ class ApiTest extends DatabaseTest
|
|||
{
|
||||
$this->assertEquals(
|
||||
'{"status":{"error":"error_message","code":"200 OK","request":""}}',
|
||||
api_error('json', new HTTPException\OKException('error_message'))
|
||||
api_error('json', new HTTPException\OKException('error_message'), DI::args())
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -683,7 +703,7 @@ class ApiTest extends DatabaseTest
|
|||
' <code>200 OK</code>' . "\n" .
|
||||
' <request/>' . "\n" .
|
||||
'</status>' . "\n",
|
||||
api_error('xml', new HTTPException\OKException('error_message'))
|
||||
api_error('xml', new HTTPException\OKException('error_message'), DI::args())
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -704,7 +724,7 @@ class ApiTest extends DatabaseTest
|
|||
' <code>200 OK</code>' . "\n" .
|
||||
' <request/>' . "\n" .
|
||||
'</status>' . "\n",
|
||||
api_error('rss', new HTTPException\OKException('error_message'))
|
||||
api_error('rss', new HTTPException\OKException('error_message'), DI::args())
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -725,7 +745,7 @@ class ApiTest extends DatabaseTest
|
|||
' <code>200 OK</code>' . "\n" .
|
||||
' <request/>' . "\n" .
|
||||
'</status>' . "\n",
|
||||
api_error('atom', new HTTPException\OKException('error_message'))
|
||||
api_error('atom', new HTTPException\OKException('error_message'), DI::args())
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Friendica\Test\src\Core\Lock;
|
|||
use Dice\Dice;
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Config\Configuration;
|
||||
use Friendica\Core\Config\JitConfiguration;
|
||||
use Friendica\Core\Lock\SemaphoreLock;
|
||||
use Friendica\DI;
|
||||
|
||||
|
@ -18,7 +19,7 @@ class SemaphoreLockTest extends LockTest
|
|||
$app->shouldReceive('getHostname')->andReturn('friendica.local');
|
||||
$dice->shouldReceive('create')->with(App::class)->andReturn($app);
|
||||
|
||||
$configMock = \Mockery::mock(Configuration::class);
|
||||
$configMock = \Mockery::mock(JitConfiguration::class);
|
||||
$configMock
|
||||
->shouldReceive('get')
|
||||
->with('system', 'temppath', NULL, false)
|
||||
|
|
|
@ -66,7 +66,7 @@ $is_singleuser_class = $is_singleuser ? "is-singleuser" : "is-not-singleuser";
|
|||
?>
|
||||
</head>
|
||||
|
||||
<body id="top" class="mod-<?php echo $a->module . " " . $is_singleuser_class . " " . $view_mode_class;?>">
|
||||
<body id="top" class="mod-<?php echo DI::module()->getName() . " " . $is_singleuser_class . " " . $view_mode_class;?>">
|
||||
<a href="#content" class="sr-only sr-only-focusable">Skip to main content</a>
|
||||
<?php
|
||||
if (!empty($page['nav']) && !$minimal) {
|
||||
|
|
Loading…
Reference in a new issue