App\Services\Config\DotenvReader::getConfig PHP Method

getConfig() public method

Get configuration from a .env file.
public getConfig ( string $name ) : string | null
$name string Configuration name
return string | null
    public function getConfig($name)
    {
        $contents = $this->fs->get($this->path);
        if (preg_match("/^{$name}=(.*)\$/m", $contents, $matches)) {
            $value = $matches[1];
            $value = $this->nullIfBlank($value);
        } else {
            $value = null;
        }
        return $value;
    }

Usage Example

Esempio n. 1
0
 public function test_Should_UpdateExistingDbSettings()
 {
     vfsStream::newFile('.env')->at($this->rootDir);
     $dotenvReader = new DotenvReader(new LaravelFilesystem($this->app['files']), vfsStream::url('rootDir/.env'));
     $dotenvWriter = new DotenvWriter(new LaravelFilesystem($this->app['files']), vfsStream::url('rootDir/.env'));
     $configDbSettingRepository = new ConfigDbSetting($dotenvReader, $dotenvWriter);
     $configDbSettingRepository->update(['driver' => 'mysql', 'host' => 'localhost', 'database' => 'database', 'username' => 'username', 'password' => 'password']);
     $this->assertEquals('mysql', $dotenvReader->getConfig('DB_DRIVER'));
     $this->assertEquals('localhost', $dotenvReader->getConfig('DB_HOST'));
     $this->assertEquals('database', $dotenvReader->getConfig('DB_DATABASE'));
     $this->assertEquals('username', $dotenvReader->getConfig('DB_USERNAME'));
     $this->assertEquals('password', $dotenvReader->getConfig('DB_PASSWORD'));
 }
All Usage Examples Of App\Services\Config\DotenvReader::getConfig