Exemple #1
0
 public function getScripts($outputType, $title, $statusCode)
 {
     $scriptTime = round((microtime(true) - LARAVEL_START) * 1000, 2);
     $scriptRAM = formatMemSize(memory_get_usage());
     $statusStyle = 'font-size:11px;border-radius:3px;padding:1px 4px;color:white; background-color: #27AE60';
     if ($statusCode >= 400 && $statusCode < 500) {
         $statusStyle = 'font-size:11px;border-radius:3px;padding:1px 4px;color:white; background-color: #F39C12';
     } elseif ($statusCode >= 500) {
         $statusStyle = 'font-size:11px;border-radius:3px;padding:1px 4px;color:white; background-color: #E74C3C';
     }
     $script = "console.groupCollapsed('%cLaravel Inspector%c {$title} (TIME:{$scriptTime}ms, RAM:{$scriptRAM}) %c {$statusCode} ',\n\t\t\t'line-height:1.8em;padding:2px 8px;font-size:12px; border-radius:3px; color:white;background:#F46661',\n\t\t\t'background-color:white', '{$statusStyle}');";
     foreach ($this->collectors as $collector) {
         if ($collector[$outputType] && $collector['obj']->count() > 0) {
             $script .= $collector['obj']->getScript();
         }
     }
     $script .= 'console.groupEnd();';
     return $script;
 }
 public function get()
 {
     $this->responseData = [];
     $resp = app('Inspector')->getResponse();
     if (isset($resp)) {
         $this->responseData['status'] = $resp->status();
         $this->responseData['headers'] = $resp->headers->all();
         $this->responseData['class'] = get_class($resp);
         $this->responseData['size'] = formatMemSize(strlen($resp->getContent()));
         if (get_class($resp) == "Illuminate\\Http\\Response") {
             if (is_object($resp->getOriginalContent()) && get_class($resp->getOriginalContent()) == 'Illuminate\\View\\View') {
                 $this->responseData['view'] = $resp->getOriginalContent()->getName();
                 $this->responseData['dataPassedToView'] = $resp->getOriginalContent()->getData();
             }
         } elseif (get_class($resp) == "Illuminate\\Http\\JsonResponse") {
             // Response is json then put the response content as part of the collector data
             $this->responseData['payload'] = json_decode($resp->getContent());
         }
     }
     return $this->responseData;
 }
Exemple #3
0
 /**
  * Show inspector full screen page and die
  * @return [type] [description]
  */
 public function dd($status = 206, $analizeResponse = false)
 {
     // Try to take these values as soon as posible
     $time = microtime(true);
     $memoryUsage = formatMemSize(memory_get_usage());
     // CLI response
     if (\App::runningInConsole()) {
         $result = $this->collectorMan->getRaw();
         dump($result);
         return;
     }
     // Json respnse
     if (request()->wantsJson()) {
         $title = $status == 206 ? 'DD' : "UNCAUGHT EXCEPTION";
         header("status: {$status}", true);
         header("Content-Type: application/json", true);
         $collectorData = request()->headers->has('laravel-inspector') ? $this->collectorMan->getScripts('inspector', $title, $status) : $this->collectorMan->getPreJson('inspector');
         if ($analizeResponse) {
             // Respond the payload also
             $collectorData = array_merge(json_decode($this->response->getContent(), true), ['LARAVEL_INSPECTOR' => $collectorData]);
         } else {
             $collectorData = ['LARAVEL_INSPECTOR' => $collectorData];
         }
         echo json_encode($collectorData);
         die;
     } else {
         // Fullscreen dd
         // Get collectors bag ready for fullscreen view
         $collectorData = $this->collectorMan->getFs();
         try {
             $view = (string) view('inspector::fullscreen', ['analizeView' => $analizeResponse, 'collectors' => $collectorData, 'memoryUsage' => $memoryUsage, 'time' => round(($time - LARAVEL_START) * 1000, 2)]);
             echo $view;
             die;
         } catch (\Exception $e) {
             dump($e);
             die;
         }
     }
 }