darrenjacoby / intervention

WordPress plugin to configure wp-admin and application state using a single config file.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fatal error

tombroucke opened this issue · comments

Hi,

Automated updates on several website are failing since februari 20th because a fatal error:

[23-Feb-2022 19:21:46 UTC] PHP Fatal error:  Uncaught Error: Class 'Jacoby\Intervention\Illuminate\Support\Collection' not found in /Users/tombroucke/Local/adis/app/www/app/plugins/intervention/src/Support/Arr.php:65
Stack trace:
#0 /Users/tombroucke/Local/adis/app/www/app/plugins/intervention/src/Support/Arr.php(32): Jacoby\Intervention\Support\Arr::collect(Array)
#1 /Users/tombroucke/Local/adis/app/www/app/plugins/intervention/src/Support/Arr.php(48): Jacoby\Intervention\Support\Arr::normalize(Array)
#2 /Users/tombroucke/Local/adis/app/www/app/plugins/intervention/src/Intervention.php(33): Jacoby\Intervention\Support\Arr::normalizeTrue(Array)
#3 /Users/tombroucke/Local/adis/app/www/app/plugins/intervention/intervention.php(85): Jacoby\Intervention\Intervention->__construct(Array, true)
#4 /Users/tombroucke/Local/adis/app/www/wp/wp-settings.php(418): include_once('/Users/tombrouc...')
#5 /Users/tombroucke/Local/adis/app/www/wp-config.php(9): require_once('/Users/tombrouc...')
#6 /Users/tombroucke/Local/adis/app/www/wp/wp-load.php(55): require_once('/Us in /Users/tombroucke/Local/adis/app/www/app/plugins/intervention/src/Support/Arr.php on line 65

All websites are running Bedrock & Sage 9 & latest tagged version of intervention (7377e42)

Yeah, same here. Total crash of the site.

Shit, thanks for reporting.

It's because I'm trying to move it towards a WordPress plugin/wpackagist, so I need to compile third party code into vendor/. I imagine Composer is over-riding the prebuilt vendor file I have with the namespaced third party classes. I will try see how I can get this working in the meanwhile before the transfer to wpackagist. For now you can pull in version 2.0.0-rc.4 and it should work.

Sorry about this!

@tombroucke @BSBjorn I just ran composer require soberwp/intervention:dev-main and it seemed to keep the distributed vendor folder on my side.

On your side, could you check for me, under intervention/vendor/illuminate/collections/Collection.php is the namespace Jacoby\Intervention\Illuminate\Support?

@tombroucke @BSBjorn I just ran composer require soberwp/intervention:dev-main and it seemed to keep the distributed vendor folder on my side.

On your side, could you check for me, under intervention/vendor/illuminate/collections/Collection.php is the namespace Jacoby\Intervention\Illuminate\Support?

The vendor folder is present & namespace is correct. I will also try to debug the problem.

Screenshot 2022-02-24 at 10 28 45

Hmm, maybe something to do with the autoloader? Does it work if you just clone from GitHub?

@tombroucke @BSBjorn I just ran composer require soberwp/intervention:dev-main and it seemed to keep the distributed vendor folder on my side.

On your side, could you check for me, under intervention/vendor/illuminate/collections/Collection.php is the namespace Jacoby\Intervention\Illuminate\Support?

just dit

Same her. Namespace is correct.

image

@tombroucke @BSBjorn what if you remove this in the root file intervention.php?

/**
 * Support for Bedrock/Composer
 */
if (!class_exists('Jacoby\Intervention\Intervention')) {
    if (is_file(__DIR__ . '/vendor/autoload.php')) {
        require_once __DIR__ . '/vendor/autoload.php';
    }

    // include file_exists($composer = __DIR__ . '/vendor/autoload.php') ? $composer : __DIR__ . '/build/vendor/autoload.php';
}

If you remove if (!class_exists('Jacoby\Intervention\Intervention')) { ?

Does the code run inside if (is_file(__DIR__ . '/vendor/autoload.php')) { ?

I think it may be Bedrock specific.

Just tried cloning from github, same issue.

I tried removing the IF. Different error...

image

I assume the autoloader is looking for the Collection class in src/illuminate/support/Collection.php, which doesn't exist. The Collection class is located in vendor/illuminate/collections/Collection.php, in the Illuminate\Support namespace. You have prefixed the namespace with Jacoby\Intervention\, which makes the autoloader search for the class in src/Illuminate/Support/Collection.php.

@tombroucke Hm, any ideas on the best solution with php-scoper? Change the namespace of scoper so it's something different and doesn't conflict with PSR-4 loading? I'm a little stumped on the best solution.

"autoload": {
    "psr-4": {
      "Jacoby\\Intervention\\": "src/"
    }
  },

Is there a way for me to get this working for now?

@BSBjorn falling back to 2.0.0-rc.4 should work.

OK, sorry for my incompetence, but can you quickly explain how I do that with composer?

@BSBjorn try composer require soberwp/intervention:2.0.0-rc.4

THANKS! :D learned something usefull right away. :) Just let me know if you need to test, I'm happy to help!

@tombroucke @BSBjorn what if you remove this in the root file intervention.php?

/**
 * Support for Bedrock/Composer
 */
if (!class_exists('Jacoby\Intervention\Intervention')) {
    if (is_file(__DIR__ . '/vendor/autoload.php')) {
        require_once __DIR__ . '/vendor/autoload.php';
    }

    // include file_exists($composer = __DIR__ . '/vendor/autoload.php') ? $composer : __DIR__ . '/build/vendor/autoload.php';
}

If you remove if (!class_exists('Jacoby\Intervention\Intervention')) { ?

Does the code run inside if (is_file(__DIR__ . '/vendor/autoload.php')) { ?

I think it may be Bedrock specific.

Hi @darrenjacoby so I have the same problem with the dev-main version, and if I downgrade to 2.0.0-rc.4 all my params not working well like 'application.discussion' => false not removed from admin panel menu. So I tried to remove (!class_exists('Jacoby\Intervention\Intervention')) { and now it is working well. So yes I think it comes from a problem of autoloader and your new folder vendor/ with src/ Hope you will find the solution and if you need I try other things, doesn't hesitate !

@jeremydumaye committed that change to dev-main. Could you give me more insight into your setup? Sage 9/10? Bedrock? Standard WP installation?

Thanks!

@darrenjacoby Perfect I update dev-main version and all working good thanks ! For my setup, I use Sage 9 and Bedrock

@jeremydumaye and you installed the plugin now with composer require soberwp/intervention:dev-main correct?

Closing for now!

just did update as well to dev-main and is working as expected. Thanks