Skip to content

Commit

Permalink
remove use method. just copy
Browse files Browse the repository at this point in the history
  • Loading branch information
santutu committed Oct 24, 2019
1 parent 5d91b0e commit 754e07a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 23 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ composer require santutu/laravel-dotenv

__Facade__
```php
\DotEnv::copy('.env.example','.env'); // Copy .env.example -> .env and load .env. if already exist, backup to .env.temp
\DotEnv::use('.env.example') // is equels \DotEnv::copy('.env.example','.env');
\DotEnv::copy('.env.example','.env'); // Copy .env.example->.env. if already exist, backup to .env.temp
\DotEnv::copy('.env.example') // is equels \DotEnv::copy('.env.example','.env');
\DotEnv::load('.env.example') // Not copy, just load '.env.example'

\DotEnv::set('APP_NAME','MY_APP_NAME');
Expand All @@ -25,9 +25,9 @@ __Facade__
__Instance__

```php
$dotEnv= (new DotEnv)->copy('.env.example','.env')) // copy .env.example -> .env. if already exist, backup to .env.temp
$dotEnv= (new DotEnv)->copy('.env.example','.env')) // copy .env.example->.env. if already exist, backup to .env.temp
$dotEnv->copy('.env.prod') // copy .env.prod -> .env. if already exist, backup to .env.temp
$dotEnv= new DotEnv('.env.dev') //load .env.dev. if not exist, create empty file.
$dotEnv->use('.env.example') // copy .env.example -> .env.dev
$dotEnv->set('APP_NAME', 'name')
$dotEnv->get('APP_NAME') //name
$dotEnv->delete('APP_NAME')
Expand All @@ -37,15 +37,14 @@ $dotEnv->delete('APP_NAME')
#### As alias
```php
$devDotEnv = new DotEnv('dev'); // is equels new DotEnv('.env.dev');
\DotEnv::copy('example','dev'); //is equels \DotEnv::copy('.env.example','.env.dev');
\DotEnv::use('dev'); //is equels \DotEnv::use('.env.dev')
\DotEnv::copy('dev'); //is equels \DotEnv::copy('.env.dev')
```


#### In Console

```php
php artisan env:use prod // if exist .env, Can be skipped.
php artisan env:copy prod // if exist .env, Can be skipped.
php artisan env:set APP_NAME MY_APP_NAME //default is .env
php artisan env:get APP_NAME //MY_APP_NAME
php artisan env:delete APP_NAME //APP_NAME=MY_APP_NAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use Illuminate\Console\Command;
use Santutu\LaravelDotEnv\DotEnv;

class UseDotEnvCommand extends Command
class CopyDotEnvCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'env:use {env}';
protected $signature = 'env:copy {env}';

/**
* The console command description.
Expand Down Expand Up @@ -49,8 +49,8 @@ public function handle()
}
}

if ($dotEnv->use($env, true)) {
$this->info("use {$env}");
if ($dotEnv->copy($env, true)) {
$this->info("copy {$env}");
}
}

Expand Down
8 changes: 0 additions & 8 deletions src/DotEnv.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@ public function delete(string $key): ?string
return null;
}

public function use(string $envFilePath): self
{
$this->assertDotEnvFilePath();
if ($this->useAutoPrefix) {
$envFilePath = $this->makePrefix($envFilePath);
}
return $this->copy($envFilePath, $this->getDotEnvFilePath());
}

public function copy(string $path = '.env.example', ?string $target = null): self
{
Expand Down
4 changes: 2 additions & 2 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Santutu\LaravelDotEnv\Commands\DeleteDotEnvCommand;
use Santutu\LaravelDotEnv\Commands\GetDotEnvCommand;
use Santutu\LaravelDotEnv\Commands\SetDotEnvCommand;
use Santutu\LaravelDotEnv\Commands\UseDotEnvCommand;
use Santutu\LaravelDotEnv\Commands\CopyDotEnvCommand;

class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
Expand All @@ -23,7 +23,7 @@ public function boot()
SetDotEnvCommand::class,
GetDotEnvCommand::class,
DeleteDotEnvCommand::class,
UseDotEnvCommand::class,
CopyDotEnvCommand::class,
]);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/DotEnvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ public function test_dot_env()

//use
$prodDotEnv->set('TEST', 'PROD');
$dotEnv->use('prod');
$dotEnv->copy('prod');
$this->assertEquals('PROD', $dotEnv->get('TEST'));
$this->assertTrue(file_exists('.env.temp'));

Artisan::call('env:set TEST null');
// Artisan::call('env:use prod');
// Artisan::call('env:copy prod');
// $this->assertEquals('PROD', $dotEnv->get('TEST'));

//space
Expand Down

0 comments on commit 754e07a

Please sign in to comment.