yiisoft / yii-base-web

Home Page:https://www.yiiframework.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Accessing application config and environment values

schmunk42 opened this issue · comments

We found it pretty handy to have the ability to get the (merged) app-config and environment from a command.

    /**
     * Shows application configuration
     * Note that this action shows console configuration.
     *
     * @param null $key configuration section
     */
    public function actionConfig($key = null)
    {
        // get config from global variable (TODO)
        $data = $GLOBALS['config'];
        if ($key) {
            $keys = explode('.', $key);
            if (isset($keys[0])) {
                $data = $GLOBALS['config'][$keys[0]];
            }
            if (isset($keys[1])) {
                $data = $GLOBALS['config'][$keys[0]][$keys[1]];
            }
        }
        $this->stdout(VarDumper::dumpAsString($data));
    }

    /**
     * Shows application environment variables.
     */
    public function actionEnv()
    {
        $env = $_ENV;
        ksort($env);
        $this->stdout(VarDumper::dumpAsString($env));
    }

Unfortunately it's a bit hacky in the config part, but this might be an issue for the core.

What's the use case?

When dealing with many config files, which are dynamically merged in specific order or some values are set via ENV variables it can be really cumbersome to find out which values finally made it into the app.

Looks out of Yii scope to me.

Why should it be out of scope that the application can return it's configuration?

Currently it's like a black-box, you can get the config, when the application instance is created, but this is usually in global scope. Not even to mention event handlers and DI.

It's like running php -i or nginx -T.

I've meant out of scope of the application template. That's definitely a core thing.

Can the bot move this issue to the core?

Can the bot move this issue to the core?

It can do that now, the label is core issue

@cebe Cool, but the bot should also close it or is there a special reason to leave it open?

it had no permission to do so, fixed now.