Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Dotenv
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Composer
library
Dotenv
Commits
ccd81f17
Commit
ccd81f17
authored
6 years ago
by
jurgenhaas
Browse files
Options
Downloads
Patches
Plain Diff
Always store received env variables in .env file
Optimize code
parent
00715dec
No related branches found
Branches containing commit
Tags
1.0.0
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Dotenv.php
+6
-3
6 additions, 3 deletions
Dotenv.php
with
6 additions
and
3 deletions
Dotenv.php
+
6
−
3
View file @
ccd81f17
...
...
@@ -72,11 +72,12 @@ final class Dotenv {
if
(
$this
->
io
->
isInteractive
())
{
$value
=
$this
->
io
->
ask
(
$prompt
.
': '
);
}
/** @noinspection NotOptimalIfConditionsInspection */
if
(
empty
(
$value
))
{
$value
=
$default
;
}
$this
->
put
(
$key
,
$value
);
}
$this
->
put
(
$key
,
$value
);
return
$value
;
}
...
...
@@ -91,6 +92,7 @@ final class Dotenv {
* The name of the environment variable.
* @param string $value
* The value of the environment variable.
* @param bool $overwrite
*/
public
function
put
(
$key
,
$value
,
$overwrite
=
FALSE
)
{
$envContent
=
file_exists
(
'.env'
)
?
file_get_contents
(
'.env'
)
:
''
;
...
...
@@ -101,8 +103,8 @@ final class Dotenv {
}
$data
[
$key
]
=
$value
;
$envContent
=
''
;
foreach
(
$data
as
$k
ey
=>
$v
alue
)
{
$envContent
.
=
$k
ey
.
'='
.
$v
alue
.
PHP_EOL
;
foreach
(
$data
as
$k
=>
$v
)
{
$envContent
.
=
$k
.
'='
.
$v
.
PHP_EOL
;
}
file_put_contents
(
'.env'
,
$envContent
);
$this
->
load
();
...
...
@@ -132,6 +134,7 @@ final class Dotenv {
* @param string $key
*/
private
function
findEnvironmentVariables
(
&
$item
,
&
$key
)
{
/** @noinspection NotOptimalRegularExpressionsInspection */
$pattern
=
'@\{\$env:([A-Za-z0-9_]*)\}@i'
;
preg_match_all
(
$pattern
,
$item
,
$item_matches
);
preg_match_all
(
$pattern
,
$key
,
$key_matches
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment