Problem intro:
I’m implementing a custom caching solution that utilizes a file store but still allows tagging.
For this, I’ve installed some packages which are irrelevant to the question. The problem occurs with my facade implementation.
I’ve created a ServiceProvider (which is registered in Laravel 11’s providers.php
) for this implementation, where I bind a class from the composer package to taggable-cache
. Here, I’ve also used the AliasLoaded to register the TCache
alias for my Facade class.
namespace AppProviders;
use AlternativeLaravelCacheStoreAlternativeFileCacheStoreWithLocks;
use IlluminateFoundationAliasLoader;
use IlluminateSupportServiceProvider;
class TaggableCacheServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
//
$this->app->bind('taggable-cache', function() {
/** @var AlternativeFileCacheStoreWithLocks $store */
$store = app('cache')->store('file');
return $store;
});
}
/**
* Bootstrap services.
*/
public function boot(): void
{
$aliasLoader = AliasLoader::getInstance();
$aliasLoader->alias('TCache', AppFacadesTaggableCacheFacade::class);
}
}
Of course, this comes with the aforementioned Facade, which is quite simple
namespace AppFacades;
use IlluminateSupportFacadesFacade;
class TaggableCacheFacade extends Facade
{
protected static function getFacadeAccessor(): string
{
return 'taggable-cache';
}
}
Unsure if related to the issue
I ran into an issue where PhpStorm was unable to ‘recognize’ the TCache
class. To fix this I installed the package barryvdh/laravel-ide-helper. This allowed me to generate an _ide_helper.php
file and fixes the issue of PhpStorm not recognizing the class.
Actual errors
After setting this up and confirming it works as intended I tried running composer install
to test if the commands I added in the "post-update-cmd"
hook worked, except I now keep running into the following error:
// The command:
composer i
// Output:
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Package sinergi/browser-detector is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
> IlluminateFoundationComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Error
Class "TCache" not found
at app/Services/RouteService.php:446
442▕ * @return array
443▕ */
444▕ private function getAcceptedRouteParameters(): array
445▕ {
➜ 446▕ return TCache::tags(CacheTag::ROUTES->value)->rememberForever(
447▕ "accepted_route_parameters",
448▕ function () {
449▕ return [
450▕ 'locale' => ['locale'],
1 app/Services/RouteService.php:39
AppServicesRouteService::getAcceptedRouteParameters()
2 [internal]:0
AppServicesRouteService::__construct()
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
Before I ran composer install
everything was working as expected, but now I keep getting the Class not found
errors, both in the console and the front end of my website, keep in mind that this was working fine before I ran composer install
.
I tried running other commands, like composer dump-autoload
to see if that would help. I also removed the scripts from "post-update-cmd"
and ran composer install
again to no avail. So I am now unable to run any commands, also php artisan
commands.
Does anyone have an idea on how to fix this issue?
Project details:
Package | Version |
---|---|
PHP | 8.3.8 |
laravel/framework | 11.15.0 |
statamic/cms | 5.13.0 |
barryvdh/laravel-ide-helper | 3.0.0 |
swayok/alternative-laravel-cache | 6.1.16 |
swayok/cache-filesystem-adapter | 1.3.2 |