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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on Keep a Changelog.
- The `DemoWeb` and `Toolkit` module templates redirect back with `back()` instead of `redirect(get_referrer() ?? base_url())` and `redirectWith(get_referrer() ?? base_url(), $data)`, so generated code gets the same-origin check. Modules generated before keep their code (#541)
- Twig is a required dependency again: `twig/twig` `^3.27` is in `require` and no longer only suggested, which reverses the 3.0.3 change that made it optional while the framework supported PHP 8.0 (#532). Twig `^3.27` needs PHP 8.1, the minimum since 3.1.0. An application that pins an older Twig must allow `^3.27`. Removed `RendererException::twigNotInstalled()` and the check in `TwigAdapter` that threw it when Twig was missing, and the Twig tests no longer skip (#626)
- The test suite runs on PHPUnit `^10.5` (a development dependency) and `phpunit.xml` uses its schema. It now sets `error_reporting` to `-1`: it was the text `E_ALL & ~E_DEPRECATED`, which PHP reads as `0`, so every PHP warning was hidden in the tests (#622)
- `EnvCommand::exec()`, `Environment`, `Config` and `ViewCache` read the base directory once where they asked for it several times, and `LoadHelpersStage` builds the module helpers path with `modules_dir()`. No behavior change (#633)

### Fixed
- `php qt core:env` no longer prints `.env is successfully generated` and no longer tries to copy the file when `.env.example` is missing: it stops after the error message (#622)
Expand Down
2 changes: 1 addition & 1 deletion src/App/Stages/Boot/LoadHelpersStage.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private function loadAppHelpers(): void

private function loadModuleHelpers(): void
{
$this->loadHelperFiles(App::getBaseDir() . DS . 'modules' . DS . '*' . DS . 'helpers');
$this->loadHelperFiles(modules_dir() . DS . '*' . DS . 'helpers');
}

private function loadHelperFiles(string $dir): void
Expand Down
6 changes: 4 additions & 2 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ private function loadConfig(Setup $setup): array

private function resolveFilePath(Setup $setup): ?string
{
$filePath = App::getBaseDir() . DS;
$baseDir = App::getBaseDir();

$filePath = $baseDir . DS;

if ($setup->getModule()) {
$filePath = modules_dir() . DS . $setup->getModule() . DS;
Expand All @@ -162,7 +164,7 @@ private function resolveFilePath(Setup $setup): ?string
}

if ($setup->getHierarchy()) {
$filePath = App::getBaseDir() . DS . 'shared' . DS
$filePath = $baseDir . DS . 'shared' . DS
. strtolower($setup->getPathPrefix() ?? '') . DS
. $setup->getFilename() . '.php';

Expand Down
10 changes: 6 additions & 4 deletions src/Console/Commands/EnvCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,21 @@ public function exec(): void
{
$fs = FileSystemFactory::get();

if (!$fs->exists(App::getBaseDir() . DS . '.env.example')) {
$baseDir = App::getBaseDir();

if (!$fs->exists($baseDir . DS . '.env.example')) {
$this->error('.env.example file not found');
return;
}

if ($fs->exists(App::getBaseDir() . DS . '.env') && !$this->getOption('yes') && !$this->confirm('The operation will overwrite values of the existing .env and will create new one from .env.example. Continue?')) {
if ($fs->exists($baseDir . DS . '.env') && !$this->getOption('yes') && !$this->confirm('The operation will overwrite values of the existing .env and will create new one from .env.example. Continue?')) {
$this->info('Operation was canceled!');
return;
}

$fs->copy(
App::getBaseDir() . DS . '.env.example',
App::getBaseDir() . DS . '.env'
$baseDir . DS . '.env.example',
$baseDir . DS . '.env'
);

$this->info('.env is successfully generated');
Expand Down
6 changes: 4 additions & 2 deletions src/Environment/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ public function updateRow(string $key, ?string $value): void
*/
private function resolveEnvironmentFile(): array
{
$filePath = base_dir() . DS . 'shared' . DS . 'config' . DS . 'env.php';
$baseDir = App::getBaseDir();

$filePath = $baseDir . DS . 'shared' . DS . 'config' . DS . 'env.php';

if (!file_exists($filePath)) {
throw EnvException::fileNotFound($filePath);
Expand All @@ -183,7 +185,7 @@ private function resolveEnvironmentFile(): array
$appEnv = $envConfig['app_env'] ?? Env::PRODUCTION;
$envFile = $this->getEnvFileName($appEnv);

if (!file_exists(App::getBaseDir() . DS . $envFile)) {
if (!file_exists($baseDir . DS . $envFile)) {
throw EnvException::fileNotFound($envFile);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ResourceCache/ViewCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private function getCacheDir(): string
$viewCacheDir = base_dir() . DS . $configCacheDir . DS . 'views';

if ($module = request()->getCurrentModule()) {
$viewCacheDir = base_dir() . DS . $configCacheDir . DS . 'views' . DS . strtolower($module);
$viewCacheDir .= DS . strtolower($module);
}

return $viewCacheDir;
Expand Down
23 changes: 23 additions & 0 deletions tests/Unit/ResourceCache/ViewCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Quantum\ResourceCache\Exceptions\ResourceCacheException;
use Quantum\ResourceCache\ViewCache;
use Quantum\Tests\Unit\AppTestCase;
use Quantum\Router\MatchedRoute;
use Quantum\Router\Route;
use Quantum\Di\Di;

class ViewCacheDouble extends ViewCache
Expand Down Expand Up @@ -154,4 +156,25 @@ public function testEnableDisableViewCache(): void
$this->assertFalse($this->viewCache->isEnabled());
}

public function testCacheDirIsTheViewsDirWhenThereIsNoModule(): void
{
$this->assertSame(
base_dir() . DS . 'cache' . DS . 'views',
$this->invokePrivateMethod($this->viewCache, 'getCacheDir')
);
}

public function testCacheDirHasTheLowercaseModuleNameWhenThereIsAModule(): void
{
request()->setMatchedRoute(new MatchedRoute(
(new Route(['GET'], '/current-route', 'TestController', 'tests'))->module('Test'),
[]
));

$this->assertSame(
base_dir() . DS . 'cache' . DS . 'views' . DS . 'test',
$this->invokePrivateMethod($this->viewCache, 'getCacheDir')
);
}

}
Loading