Skip to content

Commit 39d1476

Browse files
feat: use line endings of the file instead of the system
1 parent c245156 commit 39d1476

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Intermax\Veil\Concerns;
6+
7+
trait LineEndingDetection
8+
{
9+
protected function detectLineEnding(string $contents): string
10+
{
11+
return str_contains($contents, "\r\n") ? "\r\n" : "\n";
12+
}
13+
}

src/Console/EnvironmentDecryptCommand.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
use Illuminate\Support\Env;
1212
use Illuminate\Support\Str;
1313
use Illuminate\Support\Stringable;
14+
use Intermax\Veil\Concerns\LineEndingDetection;
1415

1516
class EnvironmentDecryptCommand extends BaseDecryptCommand
1617
{
18+
use LineEndingDetection;
19+
1720
protected $signature = 'env:decrypt
1821
{--key= : The encryption key}
1922
{--cipher= : The encryption cipher}
@@ -87,7 +90,9 @@ public function handle()
8790

8891
protected function decryptValues(string $contents, Encrypter $encrypter): string
8992
{
90-
return implode(PHP_EOL, collect(explode(PHP_EOL, $contents))->map(function (string $line) use ($encrypter) {
93+
$lineEnding = $this->detectLineEnding($contents);
94+
95+
return implode($lineEnding, collect(explode($lineEnding, $contents))->map(function (string $line) use ($encrypter) {
9196
$line = Str::of($line);
9297

9398
if (! $line->contains('=')) {

src/Console/EnvironmentEncryptCommand.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
use Illuminate\Foundation\Console\EnvironmentEncryptCommand as BaseEncryptCommand;
1010
use Illuminate\Support\Str;
1111
use Illuminate\Support\Stringable;
12+
use Intermax\Veil\Concerns\LineEndingDetection;
1213

1314
class EnvironmentEncryptCommand extends BaseEncryptCommand
1415
{
16+
use LineEndingDetection;
17+
1518
protected $signature = 'env:encrypt
1619
{--key= : The encryption key}
1720
{--cipher= : The encryption cipher}
@@ -81,7 +84,9 @@ protected function encryptValues(string $contents, Encrypter $encrypter): string
8184
/** @var array<int, string> $only */
8285
$only = $this->option('only');
8386

84-
return implode(PHP_EOL, collect(explode(PHP_EOL, $contents))->map(function (string $line) use ($encrypter, $only) {
87+
$lineEnding = $this->detectLineEnding($contents);
88+
89+
return implode($lineEnding, collect(explode($lineEnding, $contents))->map(function (string $line) use ($encrypter, $only) {
8590
$line = Str::of($line);
8691

8792
if (! $line->contains('=')) {

0 commit comments

Comments
 (0)