]> git.mxchange.org Git - friendica.git/commitdiff
Remove deprecated App::module - replace with DI::module()->getName()
authornupplaPhil <admin@philipp.info>
Mon, 16 Dec 2019 00:35:26 +0000 (01:35 +0100)
committernupplaPhil <admin@philipp.info>
Sun, 29 Dec 2019 19:17:52 +0000 (20:17 +0100)
include/api.php
src/App.php
src/App/Authentication.php
src/Content/Nav.php
src/Core/ACL.php
tests/include/ApiTest.php
tests/src/Core/Lock/SemaphoreLockTest.php
view/theme/frio/php/default.php

index e4a47cf42a0217b5fcf3d33d20c2ef6c37e5a62f..048d07d0a2047dff8f33e783a94709bf39742369 100644 (file)
@@ -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]);
 
index 892039dc5a302bd30fa44db0cdb6c52a9856fb62..75fa4f197b0efb80aa4c24e078993bd7b20e9a52 100644 (file)
@@ -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();
index b8073698f2e2bb2d669594735039ac9845c6ded9..22d429c76b8f5a3d48859b4435bc782e97f6f2df 100644 (file)
@@ -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'));
                        }
                }
index 6fca7beb91e2bc8ba71b0e9c8c6c507bd7361da1..3594bae50ef086a07e914e325940a0d54eccf54a 100644 (file)
@@ -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')];
                }
 
index d48ef3fa5176c993840adc1332cd1e7091d88766..a4b4a99190cc47c3851ca94531268eba840004d7 100644 (file)
@@ -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;
        }
index dcd98fcce93f49f3d8b087fc9dd170c4c5bd00d0..74c220d8492f94756f3c49423fd703184a610ecc 100644 (file)
@@ -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())
                );
        }
 
index 8a4baa4fa9eef7095792ed07e2d1e6153d5044de..040cdeb5214c03598d52ce99b2d173e26902ad1f 100644 (file)
@@ -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)
index cdb0f16673cba5a089b8c2a3c585d347fd5bf31d..5579680a334eb7258da33f974a7f9ffa76d4c6b9 100644 (file)
@@ -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) {