swayok / alternative-laravel-cache

Replacements for Laravel's redis and file cache stores that properly implement tagging idea
MIT License
169 stars 26 forks source link

Support override of classes #56

Open peterlembke opened 1 month ago

peterlembke commented 1 month ago

Laravel v10.48.18 (PHP v8.1.2-1ubuntu2.18) Locking swayok/alternative-laravel-cache (6.1.17)

Enhancement request

If the users could override the classes in the package then they could temporarily fix urgent bugs without having to fork the package.

Background

I try to override one of the classes so I can modify one function. But that is not possible because the class objects are instantiated with new in the AlternativeCacheStoresServiceProvider.

Example

                    $store = new AlternativeRedisCacheStoreWithLocks(
                        $app['redis'],
                        $provider->getPrefix($cacheConfig),
                        $provider->getConnectionName($cacheConfig)
                    );

If that would be changed to

                    $store = resolve(AlternativeRedisCacheStoreWithLocks::class, [
                        'db' => $app['redis'],
                        'prefix' => $provider->getPrefix($cacheConfig),
                        'connection' => $provider->getConnectionName($cacheConfig)
                    ]);

Override class

then the class can be overridden in my own package service provider like this.

    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind(
            'AlternativeLaravelCache\Store\AlternativeRedisCacheStoreWithLocks',
            'AktivBo\Cache\Store\AlternativeRedisCacheStoreWithLocks'
        );
    }