Skip to content
Snippets Groups Projects
Commit f1dd7ccc 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:
stage: 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}'"}}'
<?php
namespace LakeDrops\Component\Dotenv;
use Symfony\Component\Dotenv\Dotenv as SymfonyDotenv;
/**
* Manages .env files.
*/
final class Dotenv {
/** @var string */
private $name;
/** @var \Composer\IO\IOInterface */
private $io;
/** @var \Symfony\Component\Dotenv\Dotenv */
private $dotenv;
/**
* Dotenv constructor.
*
* @param string $name
* @param \Composer\IO\IOInterface $io
*/
public function __construct($name, $io) {
$this->name = strtoupper($name);
$this->io = $io;
$this->dotenv = new SymfonyDotenv();
$this->load();
}
/**
* @param string $key
* @param string $prompt
*
* @return string
*/
public function receive($key, $prompt) {
$key = $this->name . '_' . strtoupper($key);
$value = getenv($key);
if (empty($value)) {
if ($this->io->isInteractive()) {
$value = $this->io->ask($prompt . ': ');
$this->putenv($key, $value);
}
}
return $value;
}
private function load() {
try {
$this->dotenv->load('.env');
}
catch (\Exception $ex) {
// Ignore
}
}
private function putenv($key, $value) {
$env = file_exists('.env') ? file_get_contents('.env') : '';
$env .= PHP_EOL . $key . '=' . $value . PHP_EOL;
file_put_contents('.env', $env);
$this->load();
}
}
# Dotenv
{
"name": "lakedrops/dotenv",
"description": "Composer Library as wrapper around symfony/dotenv",
"type": "library",
"keywords": ["Drupal", "Development", "Dotenv"],
"homepage": "https://gitlab.lakedrops.com/lakedrops/dotenv",
"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/dotenv/issues",
"source": "https://gitlab.lakedrops.com/lakedrops/dotenv/tree/master"
},
"require": {
"php": ">=5.4.5",
"symfony/dotenv": "^3.3"
},
"autoload": {
"psr-4": { "LakeDrops\\Component\\Dotenv\\": "" }
},
"require-dev": {
"composer/composer": "dev-master",
"phpunit/phpunit": "^4.4.0"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment