Lsrur\Inspector\Collectors\ExceptionCollector::getScript PHP Method

getScript() public method

public getScript ( )
    public function getScript()
    {
        if ($this->count() == 0) {
            return "";
        }
        $script = "console.group('EXCEPTIONS (" . $this->count() . ")');";
        $styleWarning = 'font-size:10px;line-height:1.8em;border-radius:3px;padding:3px 5px;color:white; background-color: #F39C12';
        $styleError = 'font-size:10px;line-height:1.8em;border-radius:3px;padding:3px 5px;color:white; background-color: #E74C3C';
        $styleClass = 'font-size:10px; line-height:1.8em;';
        $styleMessage = 'font-size:10px; color:red; line-height:1.8em;';
        $styleFile = 'font-size:10px; font-weight:normal; line-height:1.8em;';
        foreach ($this->exceptions as $e) {
            if ($e['caught']) {
                $caught = 'CAUGTH';
                $styleTag = 'font-size:10px;line-height:1.8em;border-radius:3px;padding:3px 5px;color:white; background-color: #18BC9C';
            } else {
                $caught = 'UNCAUGHT';
                $styleTag = 'font-size:10px;line-height:1.8em;border-radius:3px;padding:3px 5px;color:white; background-color: #E74C3C';
            }
            $fileName = $e['files'][0]['fileName'];
            if (count(explode('/', $fileName)) > 3) {
                $fileName = '../' . collect(explode('/', $fileName))->slice(3)->implode('/');
            }
            $title = "%c" . $e['class'] . " %c" . $this->e($e['message']) . ' %c(' . $fileName . ' #' . $e['files'][0]['line'] . ') %c' . $caught;
            //$title = $e['class'].' '.$e['files'][0]['fileName'].' #'.$e['files'][0]['line'].' (code '.$e['code'].') '.$caught;
            $script .= "console.groupCollapsed('" . $title . "','{$styleClass}','{$styleMessage}','{$styleFile}','{$styleTag}');";
            foreach ($e['files'] as $file) {
                $title = "%c" . $file['fileName'] . ' #' . $file['line'] . ' %c' . strtoupper($file['tag']);
                $styleTag = $file['tag'] == 'vendor' ? $styleTag = $styleWarning : $styleError;
                $script .= "console.groupCollapsed('{$title}','{$styleClass}', '{$styleTag}');";
                // dd(explode('\n',$file['txt']));
                $l = 0;
                foreach (explode(PHP_EOL, $file['source']) as $line) {
                    if ($l++ == 3) {
                        $script .= "console.warn('%c" . $this->e($line) . "','font-size:11px');";
                    } else {
                        $script .= "console.log('%c" . $this->e($line) . "','font-size:11px;');";
                    }
                }
                //                $script .= $this->cl('log', 'src', str_replace(' ', ' ',strip_tags($file['txt'])));
                $script .= $this->clGroupEnd();
            }
            $script .= $this->clGroupEnd();
        }
        $script .= 'console.groupEnd();';
        return $script;
    }