gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.31k stars 280 forks source link

Issue with extensions loading via Composer #862

Closed benmajor closed 3 years ago

benmajor commented 3 years ago

There seems to be an issue with loading extensions via Composer. Please see https://github.com/benmajor/RedSeed/issues/1.

In the above repo, extensions have been loaded via the R::ext() method, but when Composer is used, it's necessary to run class_exists() in order to have RedBean register that the class itself exists. For example, the following will throw an exception in RedBean:


require 'vendor/autoload.php';

use RedBeanPHP\R;

R::setup(
    'mysql:dbname=redseed;host=localhost',
    'root',
    'root'
);

R::seed('user', 10, [
    'forename' => 'word(3,10)',
    'surname' => 'word(5,15)',
    'email' => 'email()'
]);

Such as:

Plugin 'seed' does not exist, add this plugin using: R::ext('seed')

But running the following works as expected:

require 'vendor/autoload.php';

use RedBeanPHP\R;

class_exists('BenMajor\\RedSeed\\RedSeed');

R::setup(
    'mysql:dbname=redseed;host=localhost',
    'root',
    'root'
);

R::seed('user', 10, [
    'forename' => 'word(3,10)',
    'surname' => 'word(5,15)',
    'email' => 'email()'
]);

Are there any known bugs for R::ext()? It seems strange that even calling class_exists() seems to fix whatever issue there is?

gabordemooij commented 3 years ago

Might be related to this old issue: https://github.com/gabordemooij/redbean/issues/294 ?

gabordemooij commented 3 years ago

and https://github.com/gabordemooij/redbean/issues/221