Skip to content

Commit

Permalink
✨ Finished first version of build configuration need to test it now
Browse files Browse the repository at this point in the history
  • Loading branch information
tchartron committed Jan 31, 2019
1 parent bfa1087 commit e0fe0d2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 49 deletions.
1 change: 1 addition & 0 deletions config/project.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
APP_NAME=example-app
USER_FOLDER=/home/thomas
APP_FOLDER=/home/thomas/www/example-app
WEB_SERVER_APP_FOLDER=/var/www/example-app
APP_FOLDER_OWNER=thomas
APP_FOLDER_GROUP=thomas
APP_WEBSERVER=apache2
Expand Down
74 changes: 25 additions & 49 deletions src/WebAppMaker/Configuration/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,12 @@ public function buildAppConfiguration($configValues) : bool
//Create vhost file
if($this->noValueCheck($configValues['VHOST_FILENAME'])) {
$this->climateInstance->backgroundLightGreen()->bold()->black()->out('Creating vhost file : '.$configValues['VHOST_FILENAME'].' in /etc/apache2/sites-available/');
$this->execOrFail("touch /etc/apache2/sites-available/".trim($configValues['VHOST_FILENAME']));
$this->execOrFail("touch /etc/apache2/sites-available/".trim($configValues['VHOST_FILENAME']));
}
//Fill vhost
//trim trailing slash
// die(var_dump(TEST)); //Access constant
$vhostPath = realpath(__DIR__."/../../../config/vhost/apache2");
// $this->climateInstance->bold()->red()->out($vhostPath);
// die(var_dump($vhostPath));
$vhostPath = rtrim($vhostPath, "/");
// $brace = "{".implode(",", $this->allowedExtension)."}"; //{jpg,gif,png}
// die(realpath(__DIR__."../../config/vhost/apache2/"));
$files = glob($vhostPath."/*");
// $this->climateInstance->backgroundLightGreen()->bold()->black()->out("$vhostPath/*.$brace");
if(empty($files)) {
$this->climateInstance->bold()->red()->out("No config files found in ".$vhostPath);
exit();
Expand All @@ -119,47 +112,21 @@ public function buildAppConfiguration($configValues) : bool
if(file_exists($vhostFile)) {
$vhostContent = file_get_contents($vhostFile);
//Replace vars in template
//MAKE THIS A METHOD ?
preg_match_all("/{{[a-zA-Z_\s]+}}/", $vhostContent, $matches);
// die(var_dump($matches));
/*
*array(1) {
[0]=>
array(7) {
[0]=>
string(23) "{{ VHOST_SERVERADMIN }}"
[1]=>
string(25) "{{ VHOST_LOCAL_ADDRESS }}"
[2]=>
string(25) "{{ VHOST_LOCAL_ADDRESS }}"
[3]=>
string(25) "{{ VHOST_DOCUMENT_ROOT }}"
[4]=>
string(25) "{{ VHOST_DOCUMENT_ROOT }}"
[5]=>
string(21) "{{ VHOST_ERROR_LOG }}"
[6]=>
string(22) "{{ VHOST_ACCESS_LOG }}"
}
}
*/
if(is_array($matches)) {
foreach ($matches as &$value) {
//Replacing mustaches with nothing
$value = str_replace(["{{ ", " }}"], "", $value);
// $value = str_replace($value, $configValues[$value], $value);
if(is_array($matches[0])) {
//Extract keys from template vars
$keys = array_map(function($e) {
return str_replace(["{{ ", " }}"], "", $e);
}, $matches[0]);
foreach ($keys as $value) {
//Replace all {{ VAR }} with proper value
$vhostFinalContent = str_replace($matches[0], $configValues[$value], $vhostContent);
}
foreach ($matches as &$value) {
$tempValue = $value;
die(var_dump($tempValue));
$value = str_replace($tempValue, $configValues[$value], $value);
}
die(var_dump($matches));
//Fill the file
die(var_dump($vhostFinalContent));
file_put_contents("/etc/apache2/sites-available/".trim($configValues['VHOST_FILENAME'], $vhostFinalContent));
}
}
// return $response;
// die($vhostFile);
break;
case 'nginx':
break;
Expand All @@ -168,13 +135,22 @@ public function buildAppConfiguration($configValues) : bool
break;
}
}


//Edit /etc/hosts
if($this->noValueCheck($configValues['VHOST_LOCAL_ADDRESS'])) {
if(file_exists("/etc/hosts")) {
$hostContent = file_get_contents("/etc/hosts");
$newHost = "#".trim($configValues['VHOST_LOCAL_ADDRESS']);
$newHost .= "127.0.0.1 ".trim($configValues['VHOST_LOCAL_ADDRESS']);
file_put_contents("/etc/hosts", $newHost, FILE_APPEND);
}
}
//a2ensite
$this->execOrFail("a2ensite ".trim($configValues['VHOST_FILENAME']));
//symlink dev folder and apache RootDirectory folder /var/www/uwithi/public
//reload apache
$this->execOrFail("ln -s ".trim($configValues['APP_FOLDER'])." ".trim($configValues['WEB_SERVER_APP_FOLDER']));
//restart apache
$this->execOrFail("/etc/init.d/apache2 restart");

return false;
return true;
}
}

0 comments on commit e0fe0d2

Please sign in to comment.