Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
chore: fix file path
Browse files Browse the repository at this point in the history
  • Loading branch information
devuri committed Feb 12, 2024
1 parent d74a24e commit d441619
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/App/Http/AppFramework.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct( string $app_path, string $site_config, string $opti
*
* @var string
*/
$params_file = $this->setup->get_tenant_file_path( $options, $this->config_dir, (bool) REQUIRE_TENANT_CONFIG );
$params_file = $this->setup->get_tenant_file_path( $options, $this->app_path, (bool) REQUIRE_TENANT_CONFIG );

if ( ! empty( $params_file ) ) {
$this->config = require_once $params_file;
Expand Down
20 changes: 19 additions & 1 deletion src/App/Http/BaseKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,25 @@ public function get_app_config(): array
*/
public function overrides(): void
{
$config_override_file = $this->app_setup->get_tenant_file_path( $this->config_dir, $this->config_file );
$config_override_file = null;

// Check if multi-tenant mode is enabled and a tenant ID is set
if ( env( 'IS_MULTITENANT' ) && ! empty( $this->tenant_id ) ) {
$tenant_config_file = $this->app_path . "/{$this->config_dir}/{$this->tenant_id}/{$this->config_file}.php";

// Check if the tenant-specific config file exists
if ( file_exists( $tenant_config_file ) ) {
$config_override_file = $tenant_config_file;
}
}

// If no tenant-specific file found, use the default config file
if ( empty( $config_override_file ) ) {
$default_config_file = $this->app_path . "/{$this->config_file}.php";
if ( file_exists( $default_config_file ) ) {
$config_override_file = $default_config_file;
}
}

// If a valid config override file is found, require it
if ( ! empty( $config_override_file ) ) {
Expand Down
8 changes: 4 additions & 4 deletions src/App/Traits/TenantTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ public function get_tenant_file_path( string $file, string $dir, bool $find_or_f
return null;
}


// Construct the path for the tenant-specific file
$tenant_file_path = "{$this->path}/{$dir}/{$tenant_id}/{$file}.php";
$tenant_file_path = "{$this->path}/{$file}.php";

// Check for the tenant file's existence
if ( file_exists( $tenant_file_path ) ) {
return $tenant_file_path;
}
if ( $find_or_fail ) {
} elseif ( $find_or_fail ) {
return null;
}

// Construct the path for the fallback/default file
$fallback_file_path = "{$this->path}/{$dir}/{$file}.php";
$fallback_file_path = "{$dir}/config/{$file}.php";

// Return the fallback file path if it exists
return file_exists( $fallback_file_path ) ? $fallback_file_path : null;
Expand Down

0 comments on commit d441619

Please sign in to comment.