Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
Fix environment test in yii console
Browse files Browse the repository at this point in the history
  • Loading branch information
pana1990 committed Jul 27, 2017
1 parent e4ff4e6 commit 9302114
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 208 deletions.
69 changes: 0 additions & 69 deletions app/components/.gitkeep
Original file line number Diff line number Diff line change
@@ -1,69 +0,0 @@
#!/usr/bin/env php
<?php

$params = getParams();

function getParams()
{
$rawParams = [];
if (isset($_SERVER['argv'])) {
$rawParams = $_SERVER['argv'];
array_shift($rawParams);
}

$params = [];
foreach ($rawParams as $param) {
if (preg_match('/^--(\w+)(=(.*))?$/', $param, $matches)) {
$name = $matches[1];
$params[$name] = isset($matches[3]) ? $matches[3] : true;
} else {
$params[] = $param;
}
}

return $params;
}

function changeEnv($data = [])
{
if (count($data) > 0) {

// Read .env-file
$filePath = __DIR__ . '/../.env'
$env = file_get_contents($filePath);

// Split string on every " " and write into array
$env = preg_split('/\s+/', $env);;

// Loop through given data
foreach ((array)$data as $key => $value) {

// Loop through .env-data
foreach ($env as $env_key => $env_value) {

// Turn the value into an array and stop after the first split
// So it's not possible to split e.g. the App-Key by accident
$entry = explode("=", $env_value, 2);

// Check, if new key fits the actual .env-key
if ($entry[0] == $key) {
// If yes, overwrite it with the new one
$env[$env_key] = $key . "=" . $value;
} else {
// If not, keep the old one
$env[$env_key] = $env_value;
}
}
}

// Turn the array back to an String
$env = implode("\n", $env);

// And overwrite the .env with the new data
file_put_contents($filePath, $env);

return true;
} else {
return false;
}
}
69 changes: 0 additions & 69 deletions app/migrations/.gitkeep
Original file line number Diff line number Diff line change
@@ -1,69 +0,0 @@
#!/usr/bin/env php
<?php

$params = getParams();

function getParams()
{
$rawParams = [];
if (isset($_SERVER['argv'])) {
$rawParams = $_SERVER['argv'];
array_shift($rawParams);
}

$params = [];
foreach ($rawParams as $param) {
if (preg_match('/^--(\w+)(=(.*))?$/', $param, $matches)) {
$name = $matches[1];
$params[$name] = isset($matches[3]) ? $matches[3] : true;
} else {
$params[] = $param;
}
}

return $params;
}

function changeEnv($data = [])
{
if (count($data) > 0) {

// Read .env-file
$filePath = __DIR__ . '/../.env'
$env = file_get_contents($filePath);

// Split string on every " " and write into array
$env = preg_split('/\s+/', $env);;

// Loop through given data
foreach ((array)$data as $key => $value) {

// Loop through .env-data
foreach ($env as $env_key => $env_value) {

// Turn the value into an array and stop after the first split
// So it's not possible to split e.g. the App-Key by accident
$entry = explode("=", $env_value, 2);

// Check, if new key fits the actual .env-key
if ($entry[0] == $key) {
// If yes, overwrite it with the new one
$env[$env_key] = $key . "=" . $value;
} else {
// If not, keep the old one
$env[$env_key] = $env_value;
}
}
}

// Turn the array back to an String
$env = implode("\n", $env);

// And overwrite the .env with the new data
file_put_contents($filePath, $env);

return true;
} else {
return false;
}
}
69 changes: 0 additions & 69 deletions app/widgets/.gitkeep
Original file line number Diff line number Diff line change
@@ -1,69 +0,0 @@
#!/usr/bin/env php
<?php

$params = getParams();

function getParams()
{
$rawParams = [];
if (isset($_SERVER['argv'])) {
$rawParams = $_SERVER['argv'];
array_shift($rawParams);
}

$params = [];
foreach ($rawParams as $param) {
if (preg_match('/^--(\w+)(=(.*))?$/', $param, $matches)) {
$name = $matches[1];
$params[$name] = isset($matches[3]) ? $matches[3] : true;
} else {
$params[] = $param;
}
}

return $params;
}

function changeEnv($data = [])
{
if (count($data) > 0) {

// Read .env-file
$filePath = __DIR__ . '/../.env'
$env = file_get_contents($filePath);

// Split string on every " " and write into array
$env = preg_split('/\s+/', $env);;

// Loop through given data
foreach ((array)$data as $key => $value) {

// Loop through .env-data
foreach ($env as $env_key => $env_value) {

// Turn the value into an array and stop after the first split
// So it's not possible to split e.g. the App-Key by accident
$entry = explode("=", $env_value, 2);

// Check, if new key fits the actual .env-key
if ($entry[0] == $key) {
// If yes, overwrite it with the new one
$env[$env_key] = $key . "=" . $value;
} else {
// If not, keep the old one
$env[$env_key] = $env_value;
}
}
}

// Turn the array back to an String
$env = implode("\n", $env);

// And overwrite the .env with the new data
file_put_contents($filePath, $env);

return true;
} else {
return false;
}
}
2 changes: 1 addition & 1 deletion tests/bin/yii
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require(__DIR__ . '/../../bootstrap/autoload.php');
*
*/

require(__DIR__ . '/../../bootstrap/sidekit.php');
require(__DIR__ . '/../../bootstrap/sidekit-test.php');

/*
* --------------------------------------------------------------------------
Expand Down

0 comments on commit 9302114

Please sign in to comment.