Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 124ecf0

Browse filesBrowse files
committed
bug #41795 [FrameworkBundle] Replace var_export with VarExporter to use array short syntax in secrets list files (alexandre-daubois)
This PR was merged into the 4.4 branch. Discussion ---------- [FrameworkBundle] Replace var_export with VarExporter to use array short syntax in secrets list files | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | _N/A_ | License | MIT | Doc PR | _N/A_ I've been using secrets a lot lately. Unfortunately, command exports the `{env}.list.php` with the "old" array syntax using `array()`, and writing `null` in uppercase. This results in tedious situations with PHP CS Fixer (for example) rewriting the whole file to restore the modern syntax, each time we add a secret. The Sodium vault currently uses `var_export`. I suggest using Symfony VarExporter, which does the work just fine. It adds a dependency to the FrameworkBundle, but it is a cleaner way to do it rather than using [this type of hack](https://www.php.net/manual/fr/function.var-export.php#124194) IMO. Commits ------- 7f1c762 [FrameworkBundle] Replace var_export with VarExporter to use array short syntax
2 parents 8445564 + 7f1c762 commit 124ecf0
Copy full SHA for 124ecf0

File tree

1 file changed

+3
-2
lines changed
Filter options

1 file changed

+3
-2
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Secrets/SodiumVault.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Secrets/SodiumVault.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Secrets;
1313

1414
use Symfony\Component\DependencyInjection\EnvVarLoaderInterface;
15+
use Symfony\Component\VarExporter\VarExporter;
1516

1617
/**
1718
* @author Tobias Schultze <http://tobion.de>
@@ -89,7 +90,7 @@ public function seal(string $name, string $value): void
8990
$list = $this->list();
9091
$list[$name] = null;
9192
uksort($list, 'strnatcmp');
92-
file_put_contents($this->pathPrefix.'list.php', sprintf("<?php\n\nreturn %s;\n", var_export($list, true), \LOCK_EX));
93+
file_put_contents($this->pathPrefix.'list.php', sprintf("<?php\n\nreturn %s;\n", VarExporter::export($list), \LOCK_EX));
9394

9495
$this->lastMessage = sprintf('Secret "%s" encrypted in "%s"; you can commit it.', $name, $this->getPrettyPath(\dirname($this->pathPrefix).\DIRECTORY_SEPARATOR));
9596
}
@@ -141,7 +142,7 @@ public function remove(string $name): bool
141142

142143
$list = $this->list();
143144
unset($list[$name]);
144-
file_put_contents($this->pathPrefix.'list.php', sprintf("<?php\n\nreturn %s;\n", var_export($list, true), \LOCK_EX));
145+
file_put_contents($this->pathPrefix.'list.php', sprintf("<?php\n\nreturn %s;\n", VarExporter::export($list), \LOCK_EX));
145146

146147
$this->lastMessage = sprintf('Secret "%s" removed from "%s".', $name, $this->getPrettyPath(\dirname($this->pathPrefix).\DIRECTORY_SEPARATOR));
147148

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.