Skip to content

Commit

Permalink
Alternate path when using composer global
Browse files Browse the repository at this point in the history
  • Loading branch information
kilrizzy committed Jul 19, 2017
1 parent 87df388 commit b0b57e9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
8 changes: 4 additions & 4 deletions app/Commands/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$this->init($input, $output);
$this->outputLogo();
if(Config::hasEnvFile()){
$this->outputInterface->writeln('<error>.env file already exists!</error>');
if($this->config->hasDotEnvFile()){
$this->outputInterface->writeln('<error>'.$this->config->dotEnvFilePath().' file already exists!</error>');
die();
}
$this->outputInterface->writeln('<info>This process attempt to create a new .env file in your homeboy directory.</info>');
Expand Down Expand Up @@ -107,13 +107,13 @@ private function interrogate(){
}

private function runTasks(){
$envPath = basePath('.env');
$envPath = $this->config->dotEnvFilePath();
$envContents = $this->generateEnvContents();
$this->outputInterface->writeln('Writing content to '.$envPath.':');
$this->outputInterface->writeln($envContents);
$fileManager = new EnvFileManager($envPath);
$fileManager->newFileContents($envContents);
$this->outputInterface->writeln('<info>Complete! Review your generated .env file at '.$envPath.'</info>');
$this->outputInterface->writeln('<info>Complete! Review your generated file at '.$envPath.'</info>');
}

private function generateEnvContents(){
Expand Down
35 changes: 33 additions & 2 deletions app/Configuration/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Config{
private $homesteadBoxPath;
private $homesteadAccessDirectoryCommand;
private $accessLocalSitesDirectoryCommand;
private $composerGlobal;
private $dotEnvDirectory;
private $dotEnvFileName;

public function updateFromEnvironment(){
$this->folder = getenv('LOCAL_SITES_PATH');
Expand All @@ -32,8 +35,12 @@ public function updateFromEnvironment(){
$this->accessLocalSitesDirectoryCommand = getenv('ACCESS_LOCAL_SITES_DIRECTORY_COMMAND');
}

public static function hasEnvFile(){
return file_exists(basePath('.env'));
public function dotEnvFilePath(){
return $this->getDotEnvDirectory().'/'.$this->getDotEnvFileName();
}

public function hasDotEnvFile(){
return file_exists($this->dotEnvFilePath());
}

public function getFolder(){
Expand Down Expand Up @@ -92,4 +99,28 @@ public function getAccessLocalSitesDirectoryCommand(){
return $this->accessLocalSitesDirectoryCommand;
}

public function setComposerGlobal($composerGlobal){
return $this->composerGlobal = $composerGlobal;
}

public function getComposerGlobal(){
return $this->composerGlobal;
}

public function setDotEnvDirectory($dotEnvDirectory){
$this->dotEnvDirectory = $dotEnvDirectory;
}

public function getDotEnvDirectory(){
return $this->dotEnvDirectory;
}

public function setDotEnvFileName($dotEnvFileName){
$this->dotEnvFileName = $dotEnvFileName;
}

public function getDotEnvFileName(){
return $this->dotEnvFileName;
}

}
21 changes: 14 additions & 7 deletions homeboy
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
#!/usr/bin/env php
<?php

$composerGlobal = false;
$dotEnvDirectory = __DIR__;
$dotEnvFileName = '.env';
if(file_exists(__DIR__.'/vendor/autoload.php')){
require __DIR__.'/vendor/autoload.php';
}else{
//If global package, pull composers global autoloader
$composerGlobal = true;
$dotEnvDirectory = __DIR__.'/../../../';
$dotEnvFileName = '.homeboy';
require __DIR__.'/../../autoload.php';
}

require 'globals.php';

use Symfony\Component\Console\Application;

if(\App\Configuration\Config::hasEnvFile()){
$dotenv = new Dotenv\Dotenv(__DIR__, '.env');
$config = new App\Configuration\Config();
$config->setComposerGlobal($composerGlobal);
$config->setDotEnvDirectory($dotEnvDirectory);
$config->setDotEnvFileName($dotEnvFileName);

if($config->hasDotEnvFile()){
$dotenv = new Dotenv\Dotenv($dotEnvDirectory, $dotEnvFileName);
$dotenv->load();
$config->updateFromEnvironment();
}

$config = new App\Configuration\Config();
$config->updateFromEnvironment();

$application = new Application();

$setupCommand = new \App\Commands\Setup(null, $config);
Expand Down

0 comments on commit b0b57e9

Please sign in to comment.