Skip to content
Snippets Groups Projects
Commit f4a18c4d authored by jurgenhaas's avatar jurgenhaas
Browse files

Initial code

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #
# Drupal editor configuration normalization
# @see http://editorconfig.org/
# This is the top-most .editorconfig file; do not search in parent directories.
root = true
# All files.
[*]
end_of_line = LF
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[{composer.json,composer.lock}]
indent_size = 4
vendor
composer.lock
Deploy:
script:
- curl -XPOST -H'content-type:application/json' "https://packagist.org/api/update-package?username=${PACKAGIST_USERNAME}&apiToken=${PACKAGIST_API_TOKEN}" -d'{"repository":{"url":"'${CI_PROJECT_URL}'"}}'
# composer.json Tools
Utils.php 0 → 100644
<?php
namespace LakeDrops\Component\Composer;
use Composer\Composer;
use Composer\Json\JsonFile;
/**
* Manages composer.json files.
*/
final class Utils {
/**
* The composer object running this session.
*
* @var \Composer\Composer
*/
protected $composer;
/**
* Content of the project's composer.json file.
*
* @var array
*/
protected $content;
/**
* The path of the root project's directory.
*
* @var string
*/
protected $sourcePath;
/**
* The full filename of the composer.json file.
*
* @var string
*/
protected $composerJsonPath;
/**
* Utils constructor.
*
* @param \Composer\Composer $composer
* The composer object running this session.
*/
public function __construct(Composer $composer) {
$this->composer = $composer;
$this->sourcePath = $composer->getPackage()->getTargetDir();
$this->composerJsonPath = $this->sourcePath . '/composer.json';
$this->read();
}
/**
* Read the current content of the project's composer.json file.
*
* @return $this
*/
public function read() {
$this->content = [];
if (file_exists($this->composerJsonPath)) {
$jsonFile = new JsonFile($this->composerJsonPath);
$this->content = $jsonFile->read();
}
return $this;
}
/**
* Write the config to composer.json file.
*
* @return $this
*/
public function write() {
$jsonFile = new JsonFile($this->composerJsonPath);
if (file_exists($this->composerJsonPath)) {
$content = $jsonFile->read();
if (md5(json_encode($content)) == md5(json_encode($this->content))) {
// Nothing has changed.
return $this;
}
}
$jsonFile->write($this->content);
return $this;
}
/**
* Get settings for [$key].
*
* @param string $key
* The key for the section.
*
* @return array|string
* The settings of the key.
*/
public function getSection($key) {
return isset($this->content[$key]) ? $this->content[$key] : [];
}
/**
* Get settings for [$key1][$key2].
*
* @param string $key1
* The key for the section.
* @param string $key2
* The key for the sub-section.
*
* @return array|string
* The settings of the key.
*/
public function getSubSection($key1, $key2) {
$section = $this->getSection($key1);
return isset($section[$key2]) ? $section[$key2] : [];
}
/**
* Set settings for [$key].
*
* @param string $key
* The key for the section.
* @param array|string $value
* The value for the section.
*
* @return $this
*/
public function setSection($key, $value) {
$this->content[$key] = $value;
return $this;
}
/**
* Set settings for [$key1][$key2].
*
* @param string $key1
* The key for the section.
* @param string $key2
* The key for the sub-section.
* @param array|string $value
* The value for the sub-section.
*
* @return $this
*/
public function setSubSection($key1, $key2, $value) {
$this->content[$key1][$key2] = $value;
return $this;
}
}
{
"name": "lakedrops/composer-json-tools",
"description": "Composer Library to provide tools to work with projects own composer.json file",
"type": "library",
"keywords": ["Drupal", "Development", "Composer"],
"homepage": "https://gitlab.lakedrops.com/lakedrops/composer-json-tools",
"license": "GPL-2.0+",
"authors": [
{
"name": "Jürgen Haas",
"email": "juergen@paragon-es.de",
"homepage": "https://www.paragon-es.de",
"role": "Drupal Expert"
},
{
"name": "Richard Papp",
"email": "richard.papp@boromino.com",
"homepage": "http://www.boromino.com",
"role": "Drupal Expert"
}
],
"support": {
"issues": "https://gitlab.lakedrops.com/lakedrops/composer-json-tools/issues",
"source": "https://gitlab.lakedrops.com/lakedrops/composer-json-tools/tree/master"
},
"require": {
"php": ">=5.6"
},
"autoload": {
"psr-4": { "LakeDrops\\Component\\Composer\\": "" }
},
"require-dev": {
"composer/composer": "dev-master",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.3",
"drupal/coder": "^8.2",
"phpunit/phpunit": "^4.4.0"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment