wecodemore / wpstarter

Easily bootstrap whole site Composer packages for WordPress.
https://wecodemore.github.io/wpstarter/
MIT License
246 stars 35 forks source link

WPStarter v3 .env custom constant `Type` for error_reporting. #115

Closed saas786 closed 2 years ago

saas786 commented 2 years ago

I am trying to add define( 'WP_SENTRY_ERROR_TYPES', E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_USER_DEPRECATED );

Ref: https://github.com/stayallive/wp-sentry/blob/e697fe5b28ddc014c358e9c0738d95e597e274af/readme.txt#L39

to my .env.development as (notice I have removed spaces, as it fails with spaces).

WP_SENTRY_ERROR_TYPES=E_ALL&~E_DEPRECATED&~E_NOTICE&~E_USER_DEPRECATED

But it turn it into string .env.cached.php:

define('WP_SENTRY_ERROR_TYPES', 'E_ALL&~E_DEPRECATED&~E_NOTICE&~E_USER_DEPRECATED');
putenv('WP_SENTRY_ERROR_TYPES=E_ALL&~E_DEPRECATED&~E_NOTICE&~E_USER_DEPRECATED');
$_ENV['WP_SENTRY_ERROR_TYPES'] = 'E_ALL&~E_DEPRECATED&~E_NOTICE&~E_USER_DEPRECATED';
$_SERVER['WP_SENTRY_ERROR_TYPES'] = 'E_ALL&~E_DEPRECATED&~E_NOTICE&~E_USER_DEPRECATED';

I had a look at: https://github.com/wecodemore/wpstarter/blob/42d32face1fc58a77e0513574a9ebaf6b848a807/src/Env/Filters.php#L30

But I don't see a Type which I could use for my need.

So either there is a way to add such constant? or can you please add such Type so I can add such constants.

gmazzap commented 2 years ago

Hi @saas786 I think the best way to do this wouldbe to define this in a PHP file, because expressions are not supported by cache.

As you can see documente here: https://github.com/wecodemore/wpstarter/blob/version-3/docs/03-WordPress-Integration.md#environment-specific-files you can have a PHP file loader per environment.

So, for example, if you have a WP_ENV environment variable that is set to my_env, like:

WP_ENV=my_env

then you can have a my_env.php file loaded, and in that file you could do:

define('WP_SENTRY_ERROR_TYPES', E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_USER_DEPRECATED);

Note that you can also use the WordPress' WP_ENVIRONMENT_TYPE env variable instead of WP_ENV, but that will affect the result of the wp_get_environment_type() function

saas786 commented 2 years ago

@gmazzap Awesome, I was trying to do it with single env file, so lost focus :)

It works with development.php, thanks a bunch.