Skip to content

Commit

Permalink
Update jackiedo/dotenv-editor dependency version
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Dec 12, 2023
1 parent 3b14a0b commit c0a3245
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"illuminate/cache": "^8.5",
"illuminate/container": "^8.5",
"illuminate/redis": "^8.5",
"jackiedo/dotenv-editor": "^1.2",
"jackiedo/dotenv-editor": "^2.1",
"symfony/console": "^5.1",
"symfony/yaml": ">=4.4",
"ezyang/htmlpurifier": "^4.7.0",
Expand Down
31 changes: 11 additions & 20 deletions src/Support/DotenvEditor/DotenvEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@

use InvalidArgumentException;
use Jackiedo\DotenvEditor\DotenvEditor as Editor;
use Jackiedo\DotenvEditor\DotenvFormatter;
use Jackiedo\DotenvEditor\Workers\Formatters\Formatter;
use Jackiedo\DotenvEditor\DotenvReader;
use Jackiedo\DotenvEditor\DotenvWriter;
use Jackiedo\DotenvEditor\Workers\Parsers\ParserV3;

/**
* Implementation of Jackiedo DotenvEditor for use in UserFrosting.
Expand All @@ -31,9 +32,12 @@ class DotenvEditor extends Editor
*/
public function __construct(string $backupPath = '', bool $autoBackup = true)
{
$this->formatter = new DotenvFormatter();
$this->reader = new DotenvReader($this->formatter);
$this->writer = new DotenvWriter($this->formatter);
$formatter = new Formatter();
$parser = new ParserV3();

$this->reader = new DotenvReader($parser);
$this->writer = new DotenvWriter($formatter);

$this->backupPath = $backupPath;
$this->autoBackup = $autoBackup;
}
Expand All @@ -45,31 +49,18 @@ public function __construct(string $backupPath = '', bool $autoBackup = true)
* @param bool $restoreIfNotFound Restore this file from other file if it's not found
* @param string|null $restorePath The file path you want to restore from
*
* @return DotenvEditor
* @return Editor
*/
public function load($filePath = null, $restoreIfNotFound = false, $restorePath = null)
public function load(?string $filePath = null, bool $restoreIfNotFound = false, ?string $restorePath = null)
{
//Fail if path is null to maintain compatibility with Jackiedo\DotenvEditor
if (is_null($filePath)) {
throw new InvalidArgumentException('File path cannot be null');
}

$this->resetContent();
$this->filePath = $filePath;

$this->reader->load($this->filePath);

if (file_exists($this->filePath)) {
$this->writer->setBuffer($this->getContent());

return $this;
} elseif ($restoreIfNotFound) {
$this->restore($restorePath);

return $this;
} else {
return $this;
}
return parent::load($filePath, $restoreIfNotFound, $restorePath);
}

/**
Expand Down

0 comments on commit c0a3245

Please sign in to comment.