tattersoftware / codeigniter4-themes

Lightweight theme manager for CodeIgniter 4
MIT License
15 stars 5 forks source link

FileNotFound on rc.1 #16

Closed DuelistRag3 closed 2 years ago

DuelistRag3 commented 2 years ago

I freshly installed version 2.0.0-rc.1 with all dependencys and i get File not Found error with a doubled path:

CodeIgniter\Files\Exceptions\FileNotFoundException

File not found: B:\Projects\Web\warriorsweb\public\assets/B:\Projects\Web\warriorsweb\public\assets\themes\default\style.css

DuelistRag3 commented 2 years ago

Doubled path is passed after Asset Creation grafik

MGatner commented 2 years ago

The problem isn't immediately apparent to me from what you have shared. Does public/assets/themes/default/style.css actually exist or not? Did you follow the Upgrade Guide? Can you share the calling code or a full trace?

EDIT: Ah I see in your image the problem, the full directory is replicated. I will look into this more on desktop.

MGatner commented 2 years ago

Looks like it is probably an issue with Windows using a different DIRECTORY_SEPARATOR and it not trimming the relative path:


        // Resolve the directory for the active theme
        $root      = rtrim(config('Assets')->directory, '/ ') . '/';
        $directory = $root . trim($theme->path, '/ ');

        // Locate all CSS and JSS files in the them path
        $files = (new FileCollection())
            ->addDirectory($directory)
            ->retainPattern('#(.*)\.css$|(.*)\.js$#i'); // limit to .css and .js files

        // Create an Asset from each relative path and add it to the Bundle
        foreach ($files as $file) {
            $relativePath = str_replace($root, '', $file);

I will try a fix.

DuelistRag3 commented 2 years ago

A temp fix would be to remove $config->directory in Asset.php from line 94 but thats not a solution at all ^^

public static function createFromPath(string $path): self
    {
        $config = self::config();
        $path   = ltrim($path, '/');
        $file   = new File($config->directory . $path, true);

        // Build the URI
        $uri = $config->uri . $path;

        // Append a timestamp if requested
        if ($config->useTimestamps) {
            $uri .= '?v=' . $file->getMTime();
        }

        return self::createFromUri($uri);
    }
DuelistRag3 commented 2 years ago

A temp fix would be to remove $config->directory in Asset.php from line 94 but thats not a solution at all ^^

public static function createFromPath(string $path): self
    {
        $config = self::config();
        $path   = ltrim($path, '/');
        $file   = new File($config->directory . $path, true);

        // Build the URI
        $uri = $config->uri . $path;

        // Append a timestamp if requested
        if ($config->useTimestamps) {
            $uri .= '?v=' . $file->getMTime();
        }

        return self::createFromUri($uri);
    }

Nvmd it doesnt work

MGatner commented 2 years ago

@DuelistRag3 can you try the realpath branch and see if that PR fixes it for you?

DuelistRag3 commented 2 years ago

@MGatner Doesn´t seem to work still same error

MGatner commented 2 years ago

@DuelistRag3 Pushed another way of doing it, try again?

DuelistRag3 commented 2 years ago

Nope, still full path is getting handed over

DuelistRag3 commented 2 years ago

sorry, wrong button ^^

MGatner commented 2 years ago

I have another idea. I will also see about adding a Windows Actions runner to automate this testing.

MGatner commented 2 years ago

@DuelistRag3 I couldn't get the Windows automation going, mind trying one more time? I think the issue was that the paths weren't matching due to the final directory separator, so I'm handling the comparison with the portion prior to the separator instead.

DuelistRag3 commented 2 years ago

looks good

MGatner commented 2 years ago

looks good

As in, this fixed it??

DuelistRag3 commented 2 years ago

looks good

As in, this fixed it??

Yes