Skip to content

Support xdebug.file_link_format For Views #580

Closed
@zschuessler

Description

@zschuessler

xdebug.file_link_format allows users to set a handler for opening file paths in their IDE. It is used in the Symfony Exception package so a user may click on any file and open it for editing automatically.

Using this handler in the rendered view list would be extremely handy!

An example of how this could be implemented is below:

vendor/barryvdh/laravel-debugbar/src/DataCollector/ViewCollector.php

public function addView(View $view)
    {
        $name = $view->getName();
        $path = $view->getPath();
        $fileLinkFormat = ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');

        if (!is_object($path)) {
            if ($path) {
                $path = ltrim(str_replace(base_path(), '', realpath($path)), '/');
            }

            if (substr($path, -10) == '.blade.php') {
                $type = 'blade';
            } else {
                $type = pathinfo($path, PATHINFO_EXTENSION);
            }
        } else {
            $type = get_class($view);
            $path = '';
        }

        if (!$this->collect_data) {
            $params = array_keys($view->getData());
        } else {
            $data = [];
            foreach ($view->getData() as $key => $value) {
                $data[$key] = $this->exporter->exportValue($value);
            }
            $params = $data;
        }

        if ($fileLinkFormat) {
            $link = strtr(($fileLinkFormat), array('%f' => $view->getPath(), '%l' => 0));
            $path = sprintf('<a href="%s" title="Go to source">%s</a>', $link, $path);
        }

        $this->templates[] = [
            'name' => $path ? sprintf('%s (%s)', $name, $path) : $name,
            'param_count' => count($params),
            'params' => $params,
            'type' => $type,
        ];
    }

Note that I added the $fileLinkFormat variable, as well as the if branch to create the link if it exists in the user's config. (This is very similar to how the Symfony Exception component does it)

Note that as-is, the html is escaped so it renders the html as text, not a link. Just a proof of concept to get ideas on an implementation going.

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions