soberwp / controller

Composer package to enable a controller when using Blade with Sage 9
MIT License
368 stars 43 forks source link

Suddenly stopped working #132

Closed humet closed 4 years ago

humet commented 5 years ago

Hi,

I have been using Roots Sage theme for the past few years with no issues.

Recently however the soberwp controller has stopped working and it has stopped passing classes and functions down to the blade templates. With a fresh Roots Sage install it will just return an error that it can't find the class App. If I 'use' the class manually directly in the template it will work fine.

I am using version 2.1.0 with PHP 7.2.21.

darrenjacoby commented 5 years ago

Hey @humet , no changes have been made to Controller. I'll need to investigate if there has been changes to Sage 9.x.

humet commented 5 years ago

There are a few people having a similar issue here: https://discourse.roots.io/t/another-class-app-not-found/16291

behzod commented 4 years ago

Hey @humet,

If you are using VirtualBox, check if the guest additions on your VM match the installed version of VirtualBox. In my case, that was the root cause and upgrading VirtualBox resolved this issue.

When the guest additions do not match, it can prevent things such as shared folders from working properly. As a result, the function \Sober\Controller\Loader::setListOfFiles was not able to read the files under the Controllers folder:

    /**
     * Set File List
     *
     * Recursively get file list and place into array
     */
    protected function setListOfFiles()
    {
        $this->listOfFiles = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->path));
    }
thomasdebruin commented 4 years ago

I'm having the same problem within my VVV 3.1.1 it seems the RecursiveDirectoryIterator is not returning a thing (tried php 7.1 7.2 and 7.3). On my colleagues machine we have VVV 2.5.1 with php 7.2.17 and there it works perfect. Both on ubuntu 18.04.2.

Only thing it returns when I print the filenames in the loop: /srv/www/projectname/public_html/wp-content/themes/mytheme/app/Controllers/. /srv/www/projectname/public_html/wp-content/themes/mytheme/app/Controllers/..

The $this->path is the same on both environments. It seems that the problem is with the RecursiveDirectoryIterator (not working with other valid paths as well). maybe in combination with some change in VVV? lso been pulling my hair out on this one.

When i change setClassesToRun to the following, it does work. Although, this is not a real (nor recursive) solution. protected function setClassesToRun() { $listOfFiles = scandir($this->path); foreach ($listOfFiles as $filename) { // Exclude non-PHP files if (!Utils::isFilePhp($filename)) { continue; } $this->classesToRun[] = $this->namespace . '\\' . pathinfo($filename, PATHINFO_FILENAME); } }

Also trying some different flags of RecursiveDirectoryIterator, no success. I plan to do some more tests with RecursiveDirectoryIterator, but I expect to stay stuck. The VVV version difference might lead to a solution.

humet commented 4 years ago

@behzod Upgrading my Virtual Box to 6.0.12 fixed the problem! Thanks so much for the reply and suggestion.

thomasdebruin commented 4 years ago

@behzod and @humet I can confirm this works, running 6.0.12 fixes the issue.

darrenjacoby commented 4 years ago

Thanks for the feedback and information @humet and @thomasdebruin