Custom Plugin Configuration best practice?

So here’s the thing.

I have created and packaged my own plugin, one that interfaces with an SMS API.
In order to do that, I require an API key during setup.

The way my configuration works right now, is I have a file at my plugin’s config/bootstrap.php
where I do this.

Configure::write('SMSMessenger.api_key', 'MY_KEY');

However, this is not practical for the user to change since he has to find the file in /vendor/namespace/plugin/config/bootstrap.php

How would you go about configuration like this?

I see that other plugins require the user to manually add configuration inside app.php, for example in the ‘Datasources’ array.

Isn’t there a more streamlined way to do this?

The optimal outcome would be:

  1. I install the plugin via composer
  2. I open my app.php (or bootstrap.php or any other file in MY application)
  3. I find the required section where code is already injected for me, and I just change the MY_KEY value.

Secondary thought: Could there be an even easier way to streamline this using .env? I don’t have much experience with it and there’s nothing in the docs on the plugins section about .env integration

Thanks in advance guys!

Hint:

  • check in bootstrap if sms_messenger.php file exist in config or tmp folder (if your config folder is read only)
  • if not redirect user to form where can enter config data, and save in sms_messenger.php
  • if file exist disable access to form and load that configuration in bootstarp

If you look at CakeDC users plugin, you can have a php file in the app level config folder, call it sms.php? With that users, plugin, if it doesn’t exist in the app/config then it defaults to it’s vendors/

Also being a Cake app, I feel it is conventional to use the app.php file for settings/keys. Not sure why you feel it is not streamlined?

1 Like

Ok, so after some research and following hakim’s comment, turns out you can define your own config files and call them via your bootstrap.

At first that’s what I did, but now I decided to skip this process entirely and just include the required API key inside the .env file