CodeIgniter Forums
.env Property Arrays - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: .env Property Arrays (/showthread.php?tid=88709)



.env Property Arrays - donpwinston - 10-23-2023

It would be nice to be able to specify non associative arrays like this:
PHP Code:
contentsecuritypolicy.scriptSrc 'self'

contentsecuritypolicy.scriptSrc 'https://bankruptcynotices.uscourts.gov'

contentsecuritypolicy.scriptSrc 'https://bankruptcynoticestest.uscourts.gov'

contentsecuritypolicy.scriptSrc 'https://stage-bnc4-web7.bsg.na.baesystems.com' 
Which would correspond to:
PHP Code:
public $scriptSrc = [
        'self',
        'https://bankruptcynotices.uscourts.gov',
        'https://bankruptcynoticestest.uscourts.gov',
        'https://stage-bnc4-web7.bsg.na.baesystems.com',
    ]; 

Maybe CI does this already? I haven't actually tried it. If it does then the CI manual should mention it. Maybe contentsecuritypolicy.0 = 'self' and xxxx.1 = 'abcd',  xxxx.2 = 'xyzt' would be necessary.


RE: .env Property Arrays - kenjis - 10-23-2023

Yes, if you have the array key in the Config file, you can override it by .env.
See https://codeigniter4.github.io/CodeIgniter4/general/configuration.html#environment-variables-as-replacements-for-data

The following way is impossible.
Because we cannot set environment variable like that.

Code:
contentsecuritypolicy.scriptSrc = 'self'
contentsecuritypolicy.scriptSrc = 'https://bankruptcynotices.uscourts.gov'
contentsecuritypolicy.scriptSrc = 'https://bankruptcynoticestest.uscourts.gov'
contentsecuritypolicy.scriptSrc = 'https://stage-bnc4-web7.bsg.na.baesystems.com'

It is equal to
Code:
contentsecuritypolicy.scriptSrc = 'https://stage-bnc4-web7.bsg.na.baesystems.com'



RE: .env Property Arrays - donpwinston - 10-25-2023

How about:

contentsecuritypolicy.scriptSrc.0 = 'self'
contentsecuritypolicy.scriptSrc.1 = 'https://banruptcynotices.uscourts.gov'

or some sort of macro like syntax?


RE: .env Property Arrays - donpwinston - 10-28-2023

(10-23-2023, 05:11 PM)kenjis Wrote: Yes, if you have the array key in the Config file, you can override it by .env.
See https://codeigniter4.github.io/CodeIgniter4/general/configuration.html#environment-variables-as-replacements-for-data

The following way is impossible.
Because we cannot set environment variable like that.

Code:
contentsecuritypolicy.scriptSrc = 'self'
contentsecuritypolicy.scriptSrc = 'https://bankruptcynotices.uscourts.gov'
contentsecuritypolicy.scriptSrc = 'https://bankruptcynoticestest.uscourts.gov'
contentsecuritypolicy.scriptSrc = 'https://stage-bnc4-web7.bsg.na.baesystems.com'

It is equal to
Code:
contentsecuritypolicy.scriptSrc = 'https://stage-bnc4-web7.bsg.na.baesystems.com'
Code:
contentsecuritypolicy.scriptSrc.0 = 'self'
contentsecuritypolicy.scriptSrc.1 = 'xhfjjfjf'

should be doable.



RE: .env Property Arrays - kenjis - 10-29-2023

Yes, you can replace the existing elements in the Config class.
But you cannot add an element in the array.

So the following does not work.
Code:
contentsecuritypolicy.scriptSrc.5 = new_value