Skip to content

Commit

Permalink
v3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Giacomo Terreni committed Oct 7, 2020
1 parent 8bb6299 commit b04f260
Show file tree
Hide file tree
Showing 11 changed files with 333 additions and 69 deletions.
44 changes: 43 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

## 3.4 - 2020-10-07
### Changed
- New logic for default environment files and storage folders
- Tests improved and updated
- README.md updated

## 3.3 - 2020-05-24
### Changed
- README.md updated with some minor correction and frontend image.
Expand All @@ -25,6 +31,12 @@ than the root Laravel's app folder. With new tests.
### Changed
- `composer.json` updated for Laravel 7.x

## 2.8 - 2020-10-07
### Changed
- New logic for default environment files and storage folders
- Tests improved and updated
- README.md updated

## 2.7 - 2020-05-24
### Changed
- README.md updated with some minor correction and frontend image.
Expand Down Expand Up @@ -65,6 +77,12 @@ skipped and not replicated in the new .env.<domain> file
### Changed
- `composer.json` updated for Laravel 6.x

## 1.4.8 - 2020-10-07
### Changed
- New logic for default environment files and storage folders
- Tests improved and updated
- README.md updated

## 1.4.7 - 2020-05-24
### Changed
- README.md updated with some minor correction and frontend image.
Expand Down Expand Up @@ -105,6 +123,12 @@ skipped and not replicated in the new .env.<domain> file
### Changed
- `composer.json` updated for Laravel 5.8

## 1.3.8 - 2020-10-07
### Changed
- New logic for default environment files and storage folders
- Tests improved and updated
- README.md updated

## 1.3.7 - 2020-05-24
### Changed
- README.md updated with some minor correction and frontend image.
Expand Down Expand Up @@ -147,6 +171,12 @@ skipped and not replicated in the new .env.<domain> file
- Bugfix in `Gecche\Multidomain\Queue\Listener` due to changes in handling
worker commands in the parent class.

## 1.2.8 - 2020-10-06
### Changed
- New logic for default environment files and storage folders
- Tests improved and updated
- README.md updated

## 1.2.7 - 2020-05-24
### Changed
- README.md updated with some minor correction and frontend image.
Expand Down Expand Up @@ -187,6 +217,12 @@ skipped and not replicated in the new .env.<domain> file
### Changed
- `composer.json` updated for Laravel 5.6

## 1.1.14 - 2020-10-06
### Changed
- New logic for default environment files and storage folders
- Tests improved and updated
- README.md updated

## 1.1.13 - 2020-05-24
### Changed
- README.md updated with some minor correction and frontend image.
Expand Down Expand Up @@ -259,11 +295,13 @@ Laravel release starting from 5.5 and as pointed out in the docs)
### Added
- Initial version for Laravel 5.5.

[Unreleased]: https://github.com/gecche/laravel-multidomain/compare/v3.3...HEAD
[Unreleased]: https://github.com/gecche/laravel-multidomain/compare/v3.4...HEAD
[3.4]: https://github.com/gecche/laravel-multidomain/compare/v3.3...v3.4
[3.3]: https://github.com/gecche/laravel-multidomain/compare/v3.2...v3.3
[3.2]: https://github.com/gecche/laravel-multidomain/compare/v3.1...v3.2
[3.1]: https://github.com/gecche/laravel-multidomain/compare/v3.0...v3.1
[3.0]: https://github.com/gecche/laravel-multidomain/compare/v2.4...v3.0
[2.8]: https://github.com/gecche/laravel-multidomain/compare/v2.7...v2.8
[2.7]: https://github.com/gecche/laravel-multidomain/compare/v2.6...v2.7
[2.6]: https://github.com/gecche/laravel-multidomain/compare/v2.5...v2.6
[2.5]: https://github.com/gecche/laravel-multidomain/compare/v2.4...v2.5
Expand All @@ -272,6 +310,7 @@ Laravel release starting from 5.5 and as pointed out in the docs)
[2.2]: https://github.com/gecche/laravel-multidomain/compare/v2.1...v2.2
[2.1]: https://github.com/gecche/laravel-multidomain/compare/v2.0...v2.1
[2.0]: https://github.com/gecche/laravel-multidomain/compare/v1.4.0...v2.0
[1.4.8]: https://github.com/gecche/laravel-multidomain/compare/v1.4.7...v1.4.8
[1.4.7]: https://github.com/gecche/laravel-multidomain/compare/v1.4.6...v1.4.7
[1.4.6]: https://github.com/gecche/laravel-multidomain/compare/v1.4.5...v1.4.6
[1.4.5]: https://github.com/gecche/laravel-multidomain/compare/v1.4.4...v1.4.5
Expand All @@ -280,6 +319,7 @@ Laravel release starting from 5.5 and as pointed out in the docs)
[1.4.2]: https://github.com/gecche/laravel-multidomain/compare/v1.4.1...v1.4.2
[1.4.1]: https://github.com/gecche/laravel-multidomain/compare/v1.4.0...v1.4.1
[1.4.0]: https://github.com/gecche/laravel-multidomain/compare/v1.3.0...v1.4.0
[1.3.8]: https://github.com/gecche/laravel-multidomain/compare/v1.3.7...v1.3.8
[1.3.7]: https://github.com/gecche/laravel-multidomain/compare/v1.3.6...v1.3.7
[1.3.6]: https://github.com/gecche/laravel-multidomain/compare/v1.3.5...v1.3.6
[1.3.5]: https://github.com/gecche/laravel-multidomain/compare/v1.3.4...v1.3.5
Expand All @@ -288,6 +328,7 @@ Laravel release starting from 5.5 and as pointed out in the docs)
[1.3.2]: https://github.com/gecche/laravel-multidomain/compare/v1.3.1...v1.3.2
[1.3.1]: https://github.com/gecche/laravel-multidomain/compare/v1.3.0...v1.3.1
[1.3.0]: https://github.com/gecche/laravel-multidomain/compare/v1.2.0...v1.3.0
[1.2.8]: https://github.com/gecche/laravel-multidomain/compare/v1.2.7...v1.2.8
[1.2.7]: https://github.com/gecche/laravel-multidomain/compare/v1.2.6...v1.2.7
[1.2.6]: https://github.com/gecche/laravel-multidomain/compare/v1.2.5...v1.2.6
[1.2.5]: https://github.com/gecche/laravel-multidomain/compare/v1.2.4...v1.2.5
Expand All @@ -296,6 +337,7 @@ Laravel release starting from 5.5 and as pointed out in the docs)
[1.2.2]: https://github.com/gecche/laravel-multidomain/compare/v1.2.1...v1.2.2
[1.2.1]: https://github.com/gecche/laravel-multidomain/compare/v1.2.0...v1.2.1
[1.2.0]: https://github.com/gecche/laravel-multidomain/compare/v1.1.6...v1.2.0
[1.1.14]: https://github.com/gecche/laravel-multidomain/compare/v1.1.13...v1.1.14
[1.1.13]: https://github.com/gecche/laravel-multidomain/compare/v1.1.12...v1.1.13
[1.1.12]: https://github.com/gecche/laravel-multidomain/compare/v1.1.11...v1.1.12
[1.1.11]: https://github.com/gecche/laravel-multidomain/compare/v1.1.10...v1.1.11
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,21 @@ $app = new Gecche\Multidomain\Foundation\Application(
If you do not specify the second argument, the standard folder is assumed. Please note that if you specify a folder,
also the standard `.env` file has to be placed in it

#### Default environment files and storage folders

If you try to run a web page or an shell command under a certain domain, e.g. `sub1.site1.com` and there is no specific
environment file for that domain, i.e. the file `.env.sub1.site1.com` does not exist, the package will use the first
available environment file by splitting the domain name with dots. In this example, the package searches for the
the first environment file among the followings:

```
.env.site1.com
.env.com
.env
```

The same logic applies to the storage folder as well.

#### About Laravel's Scheduler, Supervisor and some limitation

If in your setting you make use of the Laravel's Scheduler, remember that also the command `schedule:run` has to be
Expand Down
78 changes: 72 additions & 6 deletions src/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

class Application extends \Illuminate\Foundation\Application
{

/**
* The calculated domain storage path.
*
* @var string
*/
protected $domainStoragePath;

/**
* The environment file to load during bootstrapping.
*
Expand Down Expand Up @@ -128,8 +136,22 @@ public function environmentFileDomain($domain = null)
if (is_null($domain)) {
$domain = $this['domain'];
}
$file = '.env.' . $domain;
return ($domain && file_exists(env_path($file))) ? $file : '.env';

$envFile = $this->searchForEnvFileDomain(explode('.',$domain));

return $envFile;

}

protected function searchForEnvFileDomain($tokens = []) {
if (count($tokens) == 0) {
return '.env';
}

$file = '.env.' . implode('.',$tokens);
return file_exists(env_path($file))
? $file
: $this->searchForEnvFileDomain(array_splice($tokens,1));
}

/**
Expand All @@ -149,13 +171,57 @@ public function domainStoragePath($domain = null)
if (is_null($domain)) {
$domain = $this['domain'];
}
$domainPath = domain_sanitized($domain);
$domainStoragePath = rtrim($this->storagePath() . DIRECTORY_SEPARATOR . $domainPath,"\/");
if (file_exists($domainStoragePath))

$domainStoragePath = $this->searchForDomainStoragePath(parent::storagePath(),explode('.',$domain));

$this->domainStoragePath = $domainStoragePath;

return $domainStoragePath;
return $this->storagePath();

}


/*
* Returns the exact storage path based on the domain (useful for package commands, could not exists)
*
* @return string
*/
public function exactDomainStoragePath($domain = null)
{
$this->checkDomainDetection();

if (is_null($domain)) {
$domain = $this['domain'];
}

return rtrim(parent::storagePath() . DIRECTORY_SEPARATOR . domain_sanitized($domain),DIRECTORY_SEPARATOR);
}

/*
* Laravel storagePath updated with domains.
*
* @return string
*/
public function storagePath($domain = null)
{
return $this->storagePath ?: ($this->domainStoragePath ?: $this->domainStoragePath($domain)); // TODO: Change the autogenerated stub
}


protected function searchForDomainStoragePath($storagePath, $tokens = []) {
if (count($tokens) == 0) {
return $storagePath;
}

$tokensAsDomainString = implode('.',$tokens);

$domainStoragePath = rtrim($storagePath . DIRECTORY_SEPARATOR . domain_sanitized($tokensAsDomainString), "\/");
return file_exists($domainStoragePath)
? $domainStoragePath
: $this->searchForDomainStoragePath($storagePath,array_splice($tokens,1));
}


/**
* Get the path to the configuration cache file.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/Bootstrap/DetectDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function bootstrap(Application $app)
$app->detectDomain();

//Overrides the storage path if the domain stoarge path exists
$app->useStoragePath($app->domainStoragePath());
//$app->useStoragePath($app->domainStoragePath());

}

Expand Down
9 changes: 3 additions & 6 deletions src/Foundation/Console/DomainCommandTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function getDomainEnvFilePath($domain = null)
$domain = $this->domain;
}

return env_path('.env.' . $domain);
return rtrim(env_path('.env.' . $domain),'.');
}

/**
Expand All @@ -35,11 +35,8 @@ protected function getDomainEnvFilePath($domain = null)
*/
protected function getDomainStoragePath($domain = null)
{
if ($domain == null) {
$domain = $this->domain;
}

return storage_path() . DIRECTORY_SEPARATOR . domain_sanitized($domain);
$path = app()->exactDomainStoragePath($domain);
return $path;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Foundation/Console/ListDomainCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ListDomainCommand extends Command

protected $description = "Lists domains installed in the application.";

protected $domain;

/*
* Se il file di ambiente esiste già viene semplicemente sovrascirtto con i nuovi valori passati dal comando (update)
*/
Expand Down
16 changes: 12 additions & 4 deletions tests/src/ArtisanTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ class ArtisanTestCase extends TestCase

protected $laravelArtisanFile = 'artisan';

protected $site1 = 'site1.test';
protected $site2 = 'site2.test';
protected $subSite1 = 'sub1.site1.test';

protected $siteAppName1 = 'APPSite1';
protected $siteAppName2 = 'APPSite2';
protected $subSiteAppName1 = 'APPSubSite1';

/*
* Added for changes in artisan ouput in Laravel 5.7
*/
Expand Down Expand Up @@ -164,11 +172,11 @@ public function testKeyGenerateCommand() {
//the $_SERVER['SERVER_NAME'] value acts as the --domain option value.
$serverName = Arr::get($_SERVER,'SERVER_NAME');

$process = new Process(['php', $this->laravelAppPath.'/artisan', 'domain:add site1.test']);
$process = new Process(['php', $this->laravelAppPath.'/artisan', 'domain:add', 'site1.test']);
$process->run();

$domainValues = ['APP_NAME'=>'LARAVELTEST'];
$process = new Process(['php', $this->laravelAppPath.'/artisan', 'domain:update_env site1.test --domain_values='.json_encode($domainValues)]);
$process = new Process(['php', $this->laravelAppPath.'/artisan', 'domain:update_env', 'site1.test', '--domain_values='.json_encode($domainValues)]);
$process->run();

$process = new Process(['php', $this->laravelAppPath.'/artisan', 'key:generate']);
Expand Down Expand Up @@ -264,7 +272,7 @@ public function testQueueCommand() {

$process = new Process(['php', $this->laravelAppPath.'/artisan', 'queue:flush']);
$process->run();
if ($serverName == 'site1.test') {
if (in_array($serverName, ['site1.test']) || Str::endsWith($serverName,'.site1.test')) {
$this->assertStringContainsString('All failed jobs deleted successfully!',$process->getOutput());
} else {
$this->assertStringContainsString('SQLSTATE[42S02]: Base table or view not found: 1146 Table \'homestead.failed',$process->getOutput());
Expand Down Expand Up @@ -344,7 +352,7 @@ public function testQueueListenCommand() {
//Depending upon the domain option (or the SERVER_NAME value)
//we check accordingly the contents of the file
$fileContent = $this->files->get($fileToTest);
if ($serverName == 'site1.test') {
if (in_array($serverName, ['site1.test']) || Str::endsWith($serverName,'.site1.test')) {
$this->assertStringContainsString('LARAVELTEST --- site1',$fileContent);
} else {
$this->assertStringContainsString('Laravel --- default',$fileContent);
Expand Down
6 changes: 4 additions & 2 deletions tests/src/CommandsSubfolderTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ class CommandsSubfolderTestCase extends CommandsTestCase

protected $files = null;

protected $site = 'site1.test';
protected $siteDbName = 'db_site1';


protected function setPaths() {
$this->laravelAppPath = __DIR__ . '/../../vendor/orchestra/testbench-core/laravel';
$this->laravelEnvPath = $this->laravelAppPath . DIRECTORY_SEPARATOR . 'envs';
}

protected function resolveApplication()
{
Expand Down
Loading

0 comments on commit b04f260

Please sign in to comment.