Edujugon / PushNotification

PHP and Laravel Package to send push notifications to Android and IOS devices.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Don't read the `config/pushnotification.php` file directly

trevorgehman opened this issue · comments

Currently, when the config is being generated, it is doing this:

if (function_exists('config_path') && file_exists(config_path('pushnotification.php'))) {
$configuration = include(config_path('pushnotification.php'));
} else {
$configuration = include(__DIR__ . '/Config/config.php');

This is not good practice. You should be accessing the cached config values instead, something like this:

$configuration = app('config')->get('pushnotification');

Not only is the performance much better, but you can run into issues (as I did) if you are setting config options using environment variables, like this:

'apn' => [
        ...
        'dry_run' => env('APP_ENV') === 'local' ? false : true,
    ],

The reason is because those env() calls will return null after the configuration has been cached:

Caching And Env
If you are using the config:cache command during deployment, you must make sure that you are only calling the env function from within your configuration files, and not from anywhere else in your application.
If you are calling env from within your application, it is strongly recommended you add proper configuration values to your configuration files and call env from that location instead, allowing you to convert your env calls to config calls.

https://laravel.com/docs/5.2/upgrade#upgrade-5.2.0

Hi @trevorgehman ,

Thanks for noticing that. I will review so and update the package accordingly to best practice.