]> git.mxchange.org Git - friendica.git/commitdiff
Refactor dynamic App::getProfiler() to static DI::profiler()
authornupplaPhil <admin@philipp.info>
Sun, 15 Dec 2019 22:50:35 +0000 (23:50 +0100)
committernupplaPhil <admin@philipp.info>
Sun, 29 Dec 2019 19:17:42 +0000 (20:17 +0100)
12 files changed:
include/api.php
src/App.php
src/Content/Text/BBCode.php
src/Content/Text/Markdown.php
src/Core/Addon.php
src/Core/Renderer.php
src/Core/Theme.php
src/Core/Worker.php
src/DI.php
src/Object/Image.php
src/Util/Images.php
src/Util/Network.php

index 12f5dcb8ab841b5e327d0e77e6e55d7779a98330..d2b41f988d031a968d81815ef64c05dfefe8af1e 100644 (file)
@@ -328,7 +328,7 @@ function api_call(App $a)
 
                                Logger::info(API_LOG_PREFIX . 'username {username}', ['module' => 'api', 'action' => 'call', 'username' => $a->user['username'], 'duration' => round($duration, 2)]);
 
-                               $a->getProfiler()->saveLog(DI::logger(), API_LOG_PREFIX . 'performance');
+                               DI::profiler()->saveLog(DI::logger(), API_LOG_PREFIX . 'performance');
 
                                if (false === $return) {
                                        /*
index ac0f45f9b583307269b85f813ae5a94f1d0f28b5..6c88c6c94758ba2380cad4486208e5a3cd21f021 100644 (file)
@@ -155,16 +155,6 @@ class App
                return $this->config->getCache()->get('system', 'basepath');
        }
 
-       /**
-        * The profiler of this app
-        *
-        * @return Profiler
-        */
-       public function getProfiler()
-       {
-               return $this->profiler;
-       }
-
        /**
         * Returns the Mode of the Application
         *
index 2619dc92cc17dc9568c7841756a7dc9c9e9f3ffa..f7ca6efd9783946cfe282afaa59bad7a632770d0 100644 (file)
@@ -1104,7 +1104,7 @@ class BBCode
                        @curl_exec($ch);
                        $curl_info = @curl_getinfo($ch);
 
-                       $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack());
+                       DI::profiler()->saveTimestamp($stamp1, "network", System::callstack());
 
                        if (substr($curl_info['content_type'], 0, 6) == 'image/') {
                                $text = "[url=" . $match[1] . ']' . $match[1] . "[/url]";
@@ -1178,7 +1178,7 @@ class BBCode
                @curl_exec($ch);
                $curl_info = @curl_getinfo($ch);
 
-               $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, "network", System::callstack());
 
                // if its a link to a picture then embed this picture
                if (substr($curl_info['content_type'], 0, 6) == 'image/') {
@@ -2061,7 +2061,7 @@ class BBCode
                // Now convert HTML to Markdown
                $text = HTML::toMarkdown($text);
 
-               $a->getProfiler()->saveTimestamp($stamp1, "parser", System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, "parser", System::callstack());
 
                // Libertree has a problem with escaped hashtags.
                $text = str_replace(['\#'], ['#'], $text);
index 004f01beede43cbb9ba619db780a533a012959da..8d363675fc47ef9ae54bcaf254a5d86777c6a8f3 100644 (file)
@@ -43,7 +43,7 @@ class Markdown
 
                $html = $MarkdownParser->transform($text);
 
-               DI::app()->getProfiler()->saveTimestamp($stamp1, "parser", System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, "parser", System::callstack());
 
                return $html;
        }
index 59e1ec7b96d2b2f9ad4819604848376c37abdc09..252acd31f0e270d1c0da4b0ef5f2c76e4eb1b6c3 100644 (file)
@@ -286,7 +286,7 @@ class Addon
 
                $stamp1 = microtime(true);
                $f = file_get_contents("addon/$addon/$addon.php");
-               $a->getProfiler()->saveTimestamp($stamp1, "file", System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, "file", System::callstack());
 
                $r = preg_match("|/\*.*\*/|msU", $f, $m);
 
index c687a67283e1aba41a67672d7bbda284c2c38e58..8366d0db8081120bfa4906f24e54a03024a4a162 100644 (file)
@@ -75,7 +75,7 @@ class Renderer
                        exit();
                }
 
-               $a->getProfiler()->saveTimestamp($stamp1, "rendering", System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, "rendering", System::callstack());
 
                return $output;
        }
@@ -102,7 +102,7 @@ class Renderer
                        exit();
                }
 
-               $a->getProfiler()->saveTimestamp($stamp1, "file", System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, "file", System::callstack());
 
                return $template;
        }
index dea3e20e647b2ed0740a6535d135c2b80863b2b3..a4dfe2f9fad1b6a8660e9f7b2190ed15f2a69ed0 100644 (file)
@@ -73,10 +73,9 @@ class Theme
                        return $info;
                }
 
-               $a = \get_app();
                $stamp1 = microtime(true);
                $theme_file = file_get_contents("view/theme/$theme/theme.php");
-               $a->getProfiler()->saveTimestamp($stamp1, "file", System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, "file", System::callstack());
 
                $result = preg_match("|/\*.*\*/|msU", $theme_file, $matches);
 
index d4a90dd1969edc86011965847170da34c6e29b9a..fc30ce12d5777648fa27c6c4625f23dfbbd308d4 100644 (file)
@@ -386,7 +386,7 @@ class Worker
 
                // We use the callstack here to analyze the performance of executed worker entries.
                // For this reason the variables have to be initialized.
-               $a->getProfiler()->reset();
+               DI::profiler()->reset();
 
                $a->queue = $queue;
 
@@ -443,7 +443,7 @@ class Worker
 
                Logger::info('Process done.', ['priority' => $queue["priority"], 'id' => $queue["id"], 'duration' => round($duration, 3)]);
 
-               $a->getProfiler()->saveLog(DI::logger(), "ID " . $queue["id"] . ": " . $funcname);
+               DI::profiler()->saveLog(DI::logger(), "ID " . $queue["id"] . ": " . $funcname);
 
                $cooldown = Config::get("system", "worker_cooldown", 0);
 
index 6b86bddb5672cb1bce5ba948b84736f94a581e89..89b638d226df3f99e4c4bf147c32215e1bc55165 100644 (file)
@@ -17,6 +17,7 @@ use Friendica\Content;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\FileSystem;
 use Friendica\Util\Logger\WorkerLogger;
+use Friendica\Util\Profiler;
 use Psr\Log\LoggerInterface;
 
 /**
@@ -39,6 +40,7 @@ use Psr\Log\LoggerInterface;
  * @method static LoggerInterface logger()
  * @method static LoggerInterface devLogger()
  * @method static LoggerInterface workerLogger()
+ * @method static Profiler profiler()
  * @method static ISession session()
  * @method static App\Authentication auth()
  * @method static App\Arguments args()
@@ -79,6 +81,7 @@ class DI
                'session'      => ISession::class,
                'dba'          => Database::class,
                'fs'           => FileSystem::class,
+               'profiler'     => Profiler::class,
        ];
 
        /** @var Dice */
index 972b48359f6d51b918b46605ed1f236c58a92b76..e25afd5e900aa3eb6bc47ed758f30f9ef19029ef 100644 (file)
@@ -8,6 +8,7 @@ namespace Friendica\Object;
 use Exception;
 use Friendica\Core\Config;
 use Friendica\Core\System;
+use Friendica\DI;
 use Friendica\Util\Images;
 use Imagick;
 use ImagickPixel;
@@ -607,11 +608,9 @@ class Image
 
                $string = $this->asString();
 
-               $a = \get_app();
-
                $stamp1 = microtime(true);
                file_put_contents($path, $string);
-               $a->getProfiler()->saveTimestamp($stamp1, "file", System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, "file", System::callstack());
        }
 
        /**
index 7f31dd43838593e916391ef463e0c8289145a1e9..e19304bba1e5d42e8f7a426a2467b3fc387dfa8c 100644 (file)
@@ -165,7 +165,7 @@ class Images
 
                                $stamp1 = microtime(true);
                                file_put_contents($tempfile, $img_str);
-                               DI::app()->getProfiler()->saveTimestamp($stamp1, "file", System::callstack());
+                               DI::profiler()->saveTimestamp($stamp1, "file", System::callstack());
 
                                $data = getimagesize($tempfile);
                                unlink($tempfile);
index f222dc22df0b735af42158d5f4e0350dcfe95da1..b19c8af50499c93a3942b345551913822ae89633 100644 (file)
@@ -10,6 +10,7 @@ use Friendica\Core\Config;
 use Friendica\Core\Hook;
 use Friendica\Core\Logger;
 use Friendica\Core\System;
+use Friendica\DI;
 use Friendica\Network\CurlResult;
 
 class Network
@@ -233,7 +234,7 @@ class Network
 
                @curl_close($ch);
 
-               $a->getProfiler()->saveTimestamp($stamp1, 'network', System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, 'network', System::callstack());
 
                return $curlResponse;
        }
@@ -325,7 +326,7 @@ class Network
 
                curl_close($ch);
 
-               $a->getProfiler()->saveTimestamp($stamp1, 'network', System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, 'network', System::callstack());
 
                // Very old versions of Lighttpd don't like the "Expect" header, so we remove it when needed
                if ($curlResponse->getReturnCode() == 417) {
@@ -654,7 +655,7 @@ class Network
                $http_code = $curl_info['http_code'];
                curl_close($ch);
 
-               $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, "network", System::callstack());
 
                if ($http_code == 0) {
                        return $url;
@@ -696,7 +697,7 @@ class Network
                $body = curl_exec($ch);
                curl_close($ch);
 
-               $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, "network", System::callstack());
 
                if (trim($body) == "") {
                        return $url;