How does Laravel read the file ". env"?

Asked

Viewed 977 times

3

How Laravel does to read the file ". env"?

I’ve looked in the repositories of Illuminate (from Laravel) and I didn’t find anything that gave me a hint of how to read this file.

Is there a library that Laravel uses that does this? And if so, what is the name?

  • Look for Dotenv in the project.

1 answer

3


Has a library called vlucas/phpdotenv who has this responsibility in reading the file .env.

In the composer.json of Laravel has this package configuration.

"require": {
    "php": ">=5.6.4",
    "ext-mbstring": "*",
    "ext-openssl": "*",
    "classpreloader/classpreloader": "~3.0",
    "doctrine/inflector": "~1.0",
    "jeremeamia/superclosure": "~2.2",
    "league/flysystem": "~1.0",
    "monolog/monolog": "~1.11",
    "mtdowling/cron-expression": "~1.0",
    "nesbot/carbon": "~1.20",
    "paragonie/random_compat": "~1.4|~2.0",
    "psy/psysh": "0.7.*",
    "ramsey/uuid": "~3.0",
    "swiftmailer/swiftmailer": "~5.1",
    "symfony/console": "3.1.*",
    "symfony/debug": "3.1.*",
    "symfony/finder": "3.1.*",
    "symfony/http-foundation": "3.1.*",
    "symfony/http-kernel": "3.1.*",
    "symfony/process": "3.1.*",
    "symfony/routing": "3.1.*",
    "symfony/translation": "3.1.*",
    "symfony/var-dumper": "3.1.*",
    "vlucas/phpdotenv": "~2.2"
},

In Laravel in specific its use would be made to upload the file in classe Application in the method just below:

/**
 * Register a callback to run after loading the environment.
 *
 * @param  \Closure  $callback
 * @return void
 */
public function afterLoadingEnvironment(Closure $callback)
{
    return $this->afterBootstrapping(
        'Illuminate\Foundation\Bootstrap\DetectEnvironment', $callback
    );
}

has other related methods as well, but this being the main.

  • 1

    Cool, this answer will be quite useful for anyone who wants to use Dotenv outside an Laravel :p project

  • I’m still looking for where the reading is done on Laravel if it is already edited.

  • 2

    I found out. Class is Illuminate\Foundation\Bootstrap\DetectEnvironment.

  • 1

    Ai is the file created to make the call, but who really calls is in class Application

  • 1

    Thanks for the answer, young man.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.