Welcome Guest, Not a member yet? Register   Sign In
Make debugging pretty paths configurable
#1

I altered some fragments of code:

System/Debug/Toolbar/Collectors/BaseCollector.php :

Code:
    // Ugly, I know.
    public function cleanPath(string $file): string
    {
        if (strpos($file, APPPATH) === 0)
        {
            $file = 'APPPATH/' . substr($file, strlen(APPPATH));
        }
        elseif (strpos($file, SYSTEMPATH) === 0)
        {
            $file = 'SYSTEMPATH/' . substr($file, strlen(SYSTEMPATH));
        }
        elseif (strpos($file, FCPATH) === 0)
        {
            $file = 'FCPATH/' . substr($file, strlen(FCPATH));
        }
        // Additional paths of mine.
        elseif (strpos($file, COMMONPATH) === 0)
        {
            $file = 'COMMONPATH/' . substr($file, strlen(COMMONPATH));
        }
        elseif (defined('VENDORPATH') && strpos($file, VENDORPATH) === 0)
        {
            $file = 'VENDORPATH/' . substr($file, strlen(VENDORPATH));
        }
        elseif (strpos($file, BOOTSTRAPPATH) === 0)
        {
            $file = 'BOOTSTRAPPATH/' . substr($file, strlen(BOOTSTRAPPATH));
        }

        return $file;
    }

... and within System/View/View.php :

Code:
        if ($this->debug && (! isset($options['debug']) || $options['debug'] === true))
        {
            $toolbarCollectors = config(\Config\Toolbar::class)->collectors;

            if (in_array(\CodeIgniter\Debug\Toolbar\Collectors\Views::class, $toolbarCollectors))
            {
                $pretty_paths = ['APPPATH', 'COMMONPATH', 'SYSTEMPATH', 'ROOTPATH'];

                if (defined('VENDORPATH'))
                {
                    $pretty_paths[] = 'VENDORPATH';
                }

                // Clean up our path names to make them a little cleaner
                foreach ($pretty_paths as $path)
                {
                    if (strpos($this->renderVars['file'], constant($path)) === 0)
                    {
                        $this->renderVars['file'] = str_replace(constant($path), $path . '/', $this->renderVars['file']);
                        break;
                    }
                }
                ...

                ...

Could you make these pretty paths for the debugging toolbar configurable, so the system files not to be altered due to this reason.
Reply
#2

You could send over a PR to the GitHub repo. That also ensures your code is tested and reviewed before entering the framework.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB