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
7f9a8386
Commit
7f9a8386
authored
6 years ago
by
jurgenhaas
Browse files
Options
Downloads
Patches
Plain Diff
composer/plugin/docker4drupal#33
Better handling of git ignore and code style
parent
e805a3e4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
BaseHandler.php
+5
-24
5 additions, 24 deletions
BaseHandler.php
Utils.php
+46
-15
46 additions, 15 deletions
Utils.php
with
51 additions
and
39 deletions
BaseHandler.php
+
5
−
24
View file @
7f9a8386
...
...
@@ -47,11 +47,6 @@ abstract class BaseHandler implements BaseHandlerInterface {
*/
protected
$drupalCorePackage
;
/**
* @var string[]
*/
protected
$ignoredGitPatterns
;
/**
* Handler constructor.
*
...
...
@@ -101,7 +96,7 @@ abstract class BaseHandler implements BaseHandlerInterface {
/**
* {@inheritdoc}
*/
public
function
isDevMode
()
{
public
function
isDevMode
()
:
bool
{
if
(
$this
->
event
!==
NULL
)
{
return
$this
->
event
->
isDevMode
();
}
...
...
@@ -114,7 +109,7 @@ abstract class BaseHandler implements BaseHandlerInterface {
/**
* {@inheritdoc}
*/
public
function
isLocalDevMode
()
{
public
function
isLocalDevMode
()
:
bool
{
$local_dev_mode
=
getenv
(
'LAKEDROPS_DEV_ENV'
);
return
!
empty
(
$local_dev_mode
);
}
...
...
@@ -122,7 +117,7 @@ abstract class BaseHandler implements BaseHandlerInterface {
/**
* {@inheritdoc}
*/
public
function
isCiContext
()
{
public
function
isCiContext
()
:
bool
{
$ci_project_dir
=
getenv
(
'CI_PROJECT_DIR'
);
return
!
empty
(
$ci_project_dir
);
}
...
...
@@ -131,28 +126,14 @@ abstract class BaseHandler implements BaseHandlerInterface {
* {@inheritdoc}
*/
public
function
git
(
$command
)
{
passthru
(
escapeshellcmd
(
'git -c "user.email=composer@lakedrops.com" '
.
$command
)
)
;
Utils
::
git
(
$command
);
}
/**
* {@inheritdoc}
*/
public
function
gitIgnore
(
$pattern
)
{
if
(
$this
->
ignoredGitPatterns
===
NULL
)
{
if
(
file_exists
(
'.gitignore'
))
{
$this
->
ignoredGitPatterns
=
explode
(
PHP_EOL
,
file_get_contents
(
'.gitignore'
));
}
else
{
$this
->
ignoredGitPatterns
=
[];
}
}
if
(
\in_array
(
$pattern
,
$this
->
ignoredGitPatterns
,
TRUE
))
{
return
;
}
$this
->
ignoredGitPatterns
[]
=
$pattern
;
$this
->
git
(
'ignore '
.
$pattern
);
Utils
::
gitIgnore
(
$pattern
);
}
}
This diff is collapsed.
Click to expand it.
Utils.php
+
46
−
15
View file @
7f9a8386
<?php
<?php
/** @noinspection UnusedConstructorDependenciesInspection */
namespace
LakeDrops\Component\Composer
;
...
...
@@ -15,28 +15,33 @@ final class Utils {
*
* @var \Composer\Composer
*/
pr
otec
te
d
$composer
;
pr
iva
te
$composer
;
/**
* Content of the composer.json file.
*
* @var array
*/
pr
otec
te
d
$content
;
pr
iva
te
$content
;
/**
* The path of the directory of the composer.json file.
*
* @var string
*/
pr
otec
te
d
$sourcePath
;
pr
iva
te
$sourcePath
;
/**
* The full filename of the composer.json file.
*
* @var string
*/
protected
$composerJsonPath
;
private
$composerJsonPath
;
/**
* @var string[]
*/
private
static
$ignoredGitPatterns
;
/**
* Utils constructor.
...
...
@@ -48,9 +53,7 @@ final class Utils {
*/
public
function
__construct
(
Composer
$composer
,
$sourcePath
=
NULL
)
{
$this
->
composer
=
$composer
;
$this
->
sourcePath
=
isset
(
$sourcePath
)
?
$sourcePath
:
getcwd
()
.
$composer
->
getPackage
()
->
getTargetDir
();
$this
->
sourcePath
=
$sourcePath
??
getcwd
()
.
$composer
->
getPackage
()
->
getTargetDir
();
$this
->
composerJsonPath
=
$this
->
sourcePath
.
'/composer.json'
;
$this
->
read
();
}
...
...
@@ -60,7 +63,7 @@ final class Utils {
*
* @return $this
*/
public
function
read
()
{
public
function
read
()
:
self
{
$this
->
content
=
[];
if
(
file_exists
(
$this
->
composerJsonPath
))
{
$jsonFile
=
new
JsonFile
(
$this
->
composerJsonPath
);
...
...
@@ -74,7 +77,7 @@ final class Utils {
*
* @return $this
*/
public
function
write
()
{
public
function
write
()
:
self
{
$jsonFile
=
new
JsonFile
(
$this
->
composerJsonPath
);
if
(
file_exists
(
$this
->
composerJsonPath
))
{
$content
=
$jsonFile
->
read
();
...
...
@@ -102,7 +105,7 @@ final class Utils {
* The settings of the key.
*/
public
function
getSection
(
$key
)
{
return
isset
(
$this
->
content
[
$key
]
)
?
$this
->
content
[
$key
]
:
[];
return
$this
->
content
[
$key
]
?
?
[];
}
/**
...
...
@@ -118,7 +121,7 @@ final class Utils {
*/
public
function
getSubSection
(
$key1
,
$key2
)
{
$section
=
$this
->
getSection
(
$key1
);
return
isset
(
$section
[
$key2
]
)
?
$section
[
$key2
]
:
[];
return
$section
[
$key2
]
?
?
[];
}
/**
...
...
@@ -136,7 +139,7 @@ final class Utils {
*/
public
function
getSubSubSection
(
$key1
,
$key2
,
$key3
)
{
$subSection
=
$this
->
getSubSection
(
$key1
,
$key2
);
return
isset
(
$subSection
[
$key3
]
)
?
$subSection
[
$key3
]
:
[];
return
$subSection
[
$key3
]
?
?
[];
}
/**
...
...
@@ -149,7 +152,7 @@ final class Utils {
*
* @return $this
*/
public
function
setSection
(
$key
,
$value
)
{
public
function
setSection
(
$key
,
$value
)
:
self
{
$this
->
content
[
$key
]
=
$value
;
return
$this
;
}
...
...
@@ -166,9 +169,37 @@ final class Utils {
*
* @return $this
*/
public
function
setSubSection
(
$key1
,
$key2
,
$value
)
{
public
function
setSubSection
(
$key1
,
$key2
,
$value
)
:
self
{
$this
->
content
[
$key1
][
$key2
]
=
$value
;
return
$this
;
}
/**
* @param string $command
*/
public
static
function
git
(
$command
)
{
passthru
(
escapeshellcmd
(
'git -c "user.email=composer@lakedrops.com" '
.
$command
));
}
/**
* @param string $pattern
*/
public
static
function
gitIgnore
(
$pattern
)
{
if
(
self
::
$ignoredGitPatterns
===
NULL
)
{
if
(
file_exists
(
'.gitignore'
))
{
self
::
$ignoredGitPatterns
=
explode
(
PHP_EOL
,
file_get_contents
(
'.gitignore'
));
}
else
{
self
::
$ignoredGitPatterns
=
[];
}
}
if
(
\in_array
(
$pattern
,
self
::
$ignoredGitPatterns
,
TRUE
))
{
return
;
}
self
::
$ignoredGitPatterns
[]
=
$pattern
;
self
::
git
(
'ignore '
.
$pattern
);
}
}
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