public function showCallLocation() { $namespace = Debug::libraryNamespace(); $base = __DIR__; $stack = debug_backtrace(0); $FNS = self::GLOBAL_LOG_FNS; // Discard frames of all functions that belong to this library. while (!empty($stack) && (isset($stack[0]['file']) && stripos($stack[0]['file'], $base) === 0 || isset($stack[0]['class']) && stripos($stack[0]['class'], $namespace) === 0 || isset($stack[0]['function']) && !isset($FNS[$stack[0]['function']]))) { array_shift($stack); } $trace = $stack ? $stack[0] : []; $path = isset($trace['file']) ? $trace['file'] : ''; $line = isset($trace['line']) ? $trace['line'] : ''; $shortPath = ErrorConsole::shortFileName($path); $shortPath = str_segmentsLast($shortPath, '/'); $location = empty($line) ? $shortPath : ErrorConsole::errorLink($path, $line, 1, "{$shortPath}:{$line}", 'hint--rounded hint--left', 'data-hint'); if ($path != '') { $path = <<<HTML <div class="__debug-location">At {$location}</div> HTML; } $this->write($path); return $this; }
/** * Handle the case where a file has been uploaded for a field, possibly replacing another already set on the field. * * @param Model $model * @param string $fieldName * @param UploadedFileInterface $file */ private function newUpload(Model $model, $fieldName, UploadedFileInterface $file) { $filename = $file->getClientFilename(); $ext = strtolower(str_segmentsLast($filename, '.')); $name = str_segmentsStripLast($filename, '.'); $id = uniqid(); $mime = FileUtil::getUploadedFileMimeType($file); $isImage = FileUtil::isImageType($mime); $fileModel = $model->files()->create(['id' => $id, 'name' => $name, 'ext' => $ext, 'mime' => $mime, 'image' => $isImage, 'group' => str_segmentsLast($fieldName, '.')]); // Save the uploaded file. $path = "{$this->fileArchivePath}/{$fileModel->path}"; $dir = dirname($path); if (!file_exists($dir)) { mkdir($dir, 0777, true); } $file->moveTo($path); // Delete the previous file for this field, if one exists. $prevFilePath = $model->getOriginal($fieldName); if (exists($prevFilePath)) { $this->deleteFile($prevFilePath); } $model->{$fieldName} = $fileModel->path; $model->save(); }