Compare commits

..

3 Commits
dev ... 21-auth

Author SHA1 Message Date
Sieciech 0465d05f10 fix lint
CureNetMulti/pipeline/pr-dev This commit looks good Details
CureNetMulti/pipeline/head This commit looks good Details
2021-08-04 09:03:42 +02:00
Sieciech 6020575c5a auth
CureNetMulti/pipeline/head Something is wrong with the build of this commit Details
CureNetMulti/pipeline/pr-dev There was a failure building this commit Details
2021-08-03 16:16:56 +02:00
Sieciech 239713c4f5 auth 2021-07-30 14:11:12 +02:00
2 changed files with 0 additions and 85 deletions

View File

@ -1,5 +0,0 @@
name=value
name2="value 2"
#name3=value3
name4 = value4
name5 = "value 5"

View File

@ -1,80 +0,0 @@
<?php
namespace Tools;
class PutEnv {
private string $file;
private string $key;
private string $value;
private array $content;
public function __construct() {
$argv = $_SERVER['argv'];
$argc = sizeof($argv);
switch($argc) {
case 4:
$this->file = $argv[1];
$this->key = $argv[2];
$this->value = $argv[3];
break;
case 3:
$this->file = $argv[1];
$this->key = $argv[2];
$this->value = fgets(STDIN);
break;
default:
echo "usage:
php8.0 putenv.php filename key value
echo value | php8.0 putenv filename key";
throw new Exception("invalid params");
}
if (!file_exists($this->file)) {
throw new Exception('File not found');
}
$changed = 0;
$lineWasEmpty = false;
$key = $this->key;
$value = $this->value;
if (strpos($value, ' ') !== false) {
$value = '"' . addslashes($value) . '"';
}
$this->content = file($this->file);
foreach ($this->content as $l => $line) {
if (strlen(trim($line)) < 1) {
if ($lineWasEmpty) {
$this->content[$l] = null;
} else {
$lineWasEmpty = true;
}
continue;
}
$lineWasEmpty = false;
if (!str_starts_with($line, $this->key)) {
continue;
}
$next = trim(substr($line, strlen($this->key)));
if (strlen($next) === 0 || $next[0] !== '=') {
continue;
}
$this->content[$l] = $key . '=' . $value;
$changed++;
}
if ($changed === 0) {
$this->content[] = $key . '=' . $value;
} else if ($changed > 1) {
echo "Key $key changed $changed times\n";
}
$content = $this->content;
$this->content = [];
foreach ($content as $line) {
if ($line !== null) {
$this->content[] = $line;
}
}
$content = implode('', $this->content);
file_put_contents($this->file, $content);
}
}
new PutEnv();