diff --git a/src/Concerns/LineEndingDetection.php b/src/Concerns/LineEndingDetection.php new file mode 100644 index 0000000..93df731 --- /dev/null +++ b/src/Concerns/LineEndingDetection.php @@ -0,0 +1,16 @@ +map(function (string $line) use ($encrypter) { + $lineEnding = $this->detectLineEnding($contents); + + return implode($lineEnding, collect(explode($lineEnding, $contents))->map(function (string $line) use ($encrypter) { $line = Str::of($line); if (! $line->contains('=')) { diff --git a/src/Console/EnvironmentEncryptCommand.php b/src/Console/EnvironmentEncryptCommand.php index b96da86..1ee4cbb 100644 --- a/src/Console/EnvironmentEncryptCommand.php +++ b/src/Console/EnvironmentEncryptCommand.php @@ -9,9 +9,12 @@ use Illuminate\Foundation\Console\EnvironmentEncryptCommand as BaseEncryptCommand; use Illuminate\Support\Str; use Illuminate\Support\Stringable; +use Intermax\Veil\Concerns\LineEndingDetection; class EnvironmentEncryptCommand extends BaseEncryptCommand { + use LineEndingDetection; + protected $signature = 'env:encrypt {--key= : The encryption key} {--cipher= : The encryption cipher} @@ -81,7 +84,9 @@ protected function encryptValues(string $contents, Encrypter $encrypter): string /** @var array $only */ $only = $this->option('only'); - return implode(PHP_EOL, collect(explode(PHP_EOL, $contents))->map(function (string $line) use ($encrypter, $only) { + $lineEnding = $this->detectLineEnding($contents); + + return implode($lineEnding, collect(explode($lineEnding, $contents))->map(function (string $line) use ($encrypter, $only) { $line = Str::of($line); if (! $line->contains('=')) {