Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeberleiExtensions doesn't register properly in laravel 5.7 #43

Open
hshahdoost opened this issue Dec 16, 2018 · 3 comments
Open

BeberleiExtensions doesn't register properly in laravel 5.7 #43

hshahdoost opened this issue Dec 16, 2018 · 3 comments

Comments

@hshahdoost
Copy link

I'm using the following packages and have just upgraded into Laravel 5.7 (from 5.4)

        "laravel-doctrine/orm": "1.4.*",
        "laravel-doctrine/extensions": "1.0.*",
        "beberlei/DoctrineExtensions": "1.1.5",
        "gedmo/doctrine-extensions": "^2.4",

I don't know why this is happening, but after upgrading into Laravel 5.7, I can no longer use BeberleiExtensions methods such as Month. I have removed the updated package service providers from my app config and kept beberlei and gedmo there. So far everything. Here is how I have registered the service providers


        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        // App\Providers\BroadcastServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,

        LaravelDoctrine\Extensions\BeberleiExtensionsServiceProvider::class,
        LaravelDoctrine\Extensions\GedmoExtensionsServiceProvider::class,

The Gedmo library is working fine, but Berberlei doesn't get registered properly, Both of them are added to Providers in bootstrap and are registered after LaravelDoctrine. But there is a difference in the way Beberlei is registered which makes this happen.
Beberlei is using the following code to register it's datetime functions in BeberleiExtensionsServiceProvider

        $manager->extendAll(function (Configuration $configuration) {
            $configuration->setCustomDatetimeFunctions($this->datetime);
            $configuration->setCustomNumericFunctions($this->numeric);
            $configuration->setCustomStringFunctions($this->string);
        });

While Gedmo is using a more sophisticated way of registering it's annotations (You can see it here)

The callback of $manager->extendAll is never called for some reason, while the callback of Gedmo is called properly.

@hshahdoost
Copy link
Author

The problem was solved by creating a new ServiceProvider for Beberlei but registering it's methods the way Gedmo was doing it

class BeberleiExtensionsServiceProvider extends BaseServiceProvider
{
    public function boot(DoctrineManager $manager){

    }

    /**
     * Register the service provider.
     * @return void
     */
    public function register()
    {
        $this->app['events']->listen('doctrine.extensions.booting', function () {
            /**
             * @var Registry $registry
             */
            $registry = $this->app->make('registry');

            foreach ($registry->getManagers() as $manager) {
                $configuration = $manager->getConfiguration();
                $configuration->setCustomDatetimeFunctions($this->datetime);
                $configuration->setCustomNumericFunctions($this->numeric);
                $configuration->setCustomStringFunctions($this->string);
            }
        });
    }
}

@whizsid
Copy link

whizsid commented Jan 24, 2022

Can reproduce this issue in laravel 8.1 too. @hshahdoost 's fix is still working.

@dpslwk
Copy link
Member

dpslwk commented Jan 24, 2022

This is working fine for me. We would need a more detailed error and example code of what is not working to help more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants