Commit 19e4688
authored
Update ComposerManager.php (#643)
Problem Description and Solution for "Class core.composer does not exist" in October CMS v4
Problem
In October CMS version v4 (built on Laravel 12), an issue occurred when loading certain plugins that contained their own vendor folder and composer.json file. The system was throwing the following error:
```
ReflectionException: Class "core.composer" does not exist
```
This error occurred because the system was trying to access the core.composer object from the Laravel Container at a time when it wasn't yet available, particularly during the initial system initialization process.
Root Cause
The error was occurring in the instance() method within the October\Rain\Composer\ComposerManager class, which contained the following code:
```php
public static function instance(): static
{
return App::make('core.composer');
}
```
In previous versions of October CMS, the core.composer object was registered in the container synchronously with class loading. However, in v4 with Laravel 12, the service provider loading mechanism changed, causing timing conflicts.
Solution
The instance() method was modified to first check if the object exists in the container, and if not, create a new instance instead:
```php
public static function instance(): static
{
try {
return App::make('core.composer');
} catch (\Illuminate\Contracts\Container\BindingResolutionException $e) {
// If not available in the container, create a new instance
return new static();
}
}
```
Required Changes
1. Modify the file: plugins/october/rain/src/Composer/ComposerManager.php
2. Update the instance() method as shown above
3. Ensure the Illuminate\Contracts\Container\BindingResolutionException exception is imported at the top of the file
Additional Notes
· This solution maintains compatibility with previous versions of October CMS
· It doesn't affect the current functionality of the system
· It solves the problem without requiring major changes to the system architecture
· It works as a preventive solution even when the core.composer object isn't registered in the container
This solution has been tested on October CMS v4 and has proven effective in resolving the issue without causing any side effects.1 parent f340082 commit 19e4688
1 file changed
+5
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
| |||
0 commit comments