/** * Update salts in the environment file. * * @param bool $force Whether or not to force update any existing values * * @return Collection */ protected function update_salts($force = false) { return $this->salts->map(function ($salt) use($force) { list($key, $value) = $salt; if (!$force && $this->env->hasKey($key)) { WP_CLI::line("The '{$key}' already exists, skipping."); $salt['skipped'] = true; return $salt; } $this->env->set($key, $value, "'"); return $salt; }); }
/** * @test */ public function it_does_not_write_to_the_file_until_save_is_called() { $path = $this->copy_fixture('env-basic'); $env = new File($path); $env->load(); $this->assertNull($env->get('SOME_KEY')); $env->set('SOME_KEY', 'totally set'); $this->assertSame('totally set', $env->get('SOME_KEY')); $this->assertSame('integer', gettype($env->save())); $env->set('SOME_KEY', 'this will be wiped out once we load in a second'); // refresh the instance from the file $env->load(); $this->assertSame('totally set', $env->get('SOME_KEY')); }
/** * Iterate over each line and prompt for a new value * * @param File $env * * @return int */ protected function prompt_all(File $env) { $env->dictionary()->each(function ($value, $key) use($env) { $env->set($key, $this->prompt($key, $value)); }); $env->save(); }