Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Custom plugin classes are not loaded before config/cms.php is executed #1282

Closed
goldmont opened this issue Jan 7, 2025 · 2 comments
Closed

Comments

@goldmont
Copy link
Contributor

goldmont commented Jan 7, 2025

Winter CMS Build

1.2

PHP Version

8.1

Database engine

MySQL/MariaDB

Plugins installed

No response

Issue description

Hi,

In my Goldmont.System plugin, there's a class named Docker which I use to read Docker secrets and to set the values into the project config. Today, I needed to read AWS S3 credentials in order to setup a new resource storage in cms.php. However, for some reason, the Docker class is not loaded by the autoloader yet. Furthermore, this problem exists only in cms.php file. The Docker class is properly loaded when I use it in filesystems.php file. What's going on? Isn't the autoloader run before everything?

Plugin structure:
. <-- Goldmont.System
├── helpers <-- LOWER CASE
│   ├── Docker.php <-- NAMESPACE: Goldmont\System\Helpers

Error:
Class "Goldmont\System\Helpers\Docker" not found

Steps to replicate

Workaround

No response

@nmiyazaki-chapleau
Copy link

Since your directory is named in lowercase, your namespace should also be in lowercase. You should have some warnings from Composer's autoloader concerning PSR4 standards. I highly recommend changing the directory name to an uppercase H instead of changing the namespace though, as it's also part of PSR conventions.

@LukeTowers
Copy link
Member

@nmiyazaki-chapleau we actually do support the folders being lowercase and the class file being TitleCase, it's what all the first party modules and plugins do and it's what the scaffolding generates.

@goldmont as for your original issue this is known and intentional. The config loader loads those files when the values are asked for. Plugin classes are not autoloaded until the plugin itself is registered and determined to be enabled so that disabled plugins do not have their code autoloaded.

Since the System ServiceProvider loads the cms.loadModules config item in order to determine which modules to load and register before it kicks off the plugin initialization it's expected that any plugin provided classes would not be loaded at that point.

The solution is to make use of Config::set() to set the value from within your plugin's register() or boot() methods instead of referencing your plugin classes from your project's configuration files.

Furthermore at some point in the future we plan on refactoring how the CMS storage is configured so that it'll be done as real disks in filesystems.php instead of the current setup in the CMS config, so if you're interested in helping out with that I'd point you at #844 and wintercms/storm#141

@wintercms wintercms locked and limited conversation to collaborators Jan 7, 2025
@LukeTowers LukeTowers converted this issue into discussion #1283 Jan 7, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants