Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ class Application extends Container implements ApplicationContract, CachesConfig
*/
protected $namespace;

/**
* The prefixes of absolute paths for normalization.
*
* @var array
*/
protected $absolutePathPrefixes = [DIRECTORY_SEPARATOR];

/**
* Create a new Illuminate application instance.
*
Expand Down Expand Up @@ -1010,7 +1017,7 @@ protected function normalizeCachePath($key, $default)
return $this->bootstrapPath($default);
}

return Str::startsWith($env, '/')
return Str::startsWith($env, $this->absolutePathPrefixes)
? $env
: $this->basePath($env);
}
Expand Down Expand Up @@ -1270,4 +1277,15 @@ public function getNamespace()

throw new RuntimeException('Unable to detect application namespace.');
}

/**
* Add new prefix to list of absolute path prefixes.
*
* @param string $prefix
* @return void
*/
public function addAbsolutePathPrefix(string $prefix): void
{
$this->absolutePathPrefixes[] = $prefix;
}
}
25 changes: 25 additions & 0 deletions tests/Foundation/FoundationApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,31 @@ public function testEnvPathsAreUsedAndMadeAbsoluteForCachePathsWhenSpecifiedAsRe
$_SERVER['APP_EVENTS_CACHE']
);
}

public function testEnvPathsAreAbsoluteInWindows()
{
$app = new Application(__DIR__);
$app->addAbsolutePathPrefix('C:');
$_SERVER['APP_SERVICES_CACHE'] = 'C:\framework\services.php';
$_SERVER['APP_PACKAGES_CACHE'] = 'C:\framework\packages.php';
$_SERVER['APP_CONFIG_CACHE'] = 'C:\framework\config.php';
$_SERVER['APP_ROUTES_CACHE'] = 'C:\framework\routes.php';
$_SERVER['APP_EVENTS_CACHE'] = 'C:\framework\events.php';

$this->assertSame('C:\framework\services.php', $app->getCachedServicesPath());
$this->assertSame('C:\framework\packages.php', $app->getCachedPackagesPath());
$this->assertSame('C:\framework\config.php', $app->getCachedConfigPath());
$this->assertSame('C:\framework\routes.php', $app->getCachedRoutesPath());
$this->assertSame('C:\framework\events.php', $app->getCachedEventsPath());

unset(
$_SERVER['APP_SERVICES_CACHE'],
$_SERVER['APP_PACKAGES_CACHE'],
$_SERVER['APP_CONFIG_CACHE'],
$_SERVER['APP_ROUTES_CACHE'],
$_SERVER['APP_EVENTS_CACHE']
);
}
}

class ApplicationBasicServiceProviderStub extends ServiceProvider
Expand Down