Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
composer.json Utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Composer
library
composer.json Utils
Commits
3224c867
Commit
3224c867
authored
4 years ago
by
jurgenhaas
Browse files
Options
Downloads
Patches
Plain Diff
docker/l3d#58
Move project settings out of composer.json
parent
24db58f8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Config.php
+34
-16
34 additions, 16 deletions
Config.php
with
34 additions
and
16 deletions
Config.php
+
34
−
16
View file @
3224c867
...
...
@@ -19,6 +19,11 @@ final class Config {
*/
private
static
$values
;
/**
* @var array
*/
private
static
$customValues
;
/**
* @var string
*/
...
...
@@ -56,11 +61,10 @@ final class Config {
$this
->
env
=
$env
;
$this
->
twig_loader
=
new
Twig_Loader_Array
([]);
$this
->
twig
=
new
Twig_Environment
(
$this
->
twig_loader
);
$this
->
configFile
=
getcwd
()
.
'/.
project
.y
a
ml'
;
$this
->
configFile
=
getcwd
()
.
'/.
lakedrops
.yml'
;
$this
->
init
();
$componentValues
=
self
::
$values
[
$component
]
??
[];
$this
->
merge
(
$default_values
,
$componentValues
);
$this
->
merge
(
$default_values
,
[]);
}
/**
...
...
@@ -68,29 +72,40 @@ final class Config {
*/
private
function
init
():
void
{
if
(
self
::
$values
===
NULL
)
{
self
::
$values
=
[];
if
(
!
file_exists
(
$this
->
configFile
))
{
self
::
$
v
alues
=
[];
self
::
$
customV
alues
=
[];
$this
->
save
();
}
else
{
self
::
$
v
alues
=
Yaml
::
parseFile
(
$this
->
configFile
);
self
::
$
customV
alues
=
Yaml
::
parseFile
(
$this
->
configFile
);
}
}
}
/**
* @param array $
v
alues
1
* @param array $
v
alues
2
* @param array $
defaultV
alues
* @param array $
customV
alues
*/
private
function
merge
(
array
$values1
,
array
$values2
):
void
{
self
::
$values
[
$this
->
component
]
=
$this
->
env
->
replaceEnvironmentVariables
(
NestedArray
::
mergeDeep
(
$values1
,
$values2
));
private
function
merge
(
array
$defaultValues
,
array
$customValues
):
void
{
$default
=
self
::
$values
[
$this
->
component
]
??
[];
$custom
=
self
::
$customValues
[
$this
->
component
]
??
[];
if
(
!
empty
(
$defaultValues
))
{
$default
=
NestedArray
::
mergeDeep
(
$default
,
$defaultValues
);
}
if
(
!
empty
(
$customValues
))
{
$default
=
NestedArray
::
mergeDeep
(
$default
,
$customValues
);
$custom
=
NestedArray
::
mergeDeep
(
$custom
,
$customValues
);
}
self
::
$values
[
$this
->
component
]
=
$this
->
env
->
replaceEnvironmentVariables
(
$default
);
self
::
$customValues
[
$this
->
component
]
=
$custom
;
}
/**
* Save the current settings.
*/
private
function
save
():
void
{
file_put_contents
(
$this
->
configFile
,
Yaml
::
dump
(
self
::
$
v
alues
,
9
,
2
));
file_put_contents
(
$this
->
configFile
,
Yaml
::
dump
(
self
::
$
customV
alues
,
9
,
2
));
}
/**
...
...
@@ -111,20 +126,23 @@ final class Config {
}
/**
* @param
$path
* @param
string|array $keys
*
* @return mixed|null
*/
public
function
readValue
(
$path
)
{
$parts
=
explode
(
'/'
,
$path
);
return
$this
->
readValueFromArray
(
self
::
$values
[
$this
->
component
],
$parts
);
public
function
readValue
(
$keys
)
{
if
(
is_string
(
$keys
))
{
$keys
=
[
$keys
];
}
return
$this
->
readValueFromArray
(
self
::
$values
[
$this
->
component
],
$keys
);
}
/**
* @param string $key
* @param array $values
*/
public
function
setValue
(
array
$values
):
void
{
$this
->
merge
(
self
::
$values
[
$this
->
component
],
[
$this
->
component
=>
$values
]);
public
function
setValue
(
string
$key
,
array
$values
):
void
{
$this
->
merge
(
[],
[
$this
->
component
=>
[
$key
=>
$values
]
]
);
$this
->
save
();
}
...
...
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