Skip to content
Merged

Dev #324

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
6 changes: 3 additions & 3 deletions WebFiori/Framework/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@
*
* @since 2.1
*/
define('WF_VERSION', '3.0.0-RC.2');
define('WF_VERSION', 'v3.0.0-RC.3');
/**
* A constant that tells the type of framework version.
*
Expand All @@ -447,7 +447,7 @@
*
* @since 2.1
*/
define('WF_RELEASE_DATE', '2026-05-04');
define('WF_RELEASE_DATE', '2026-05-11');
}
/**
* Initiate main components of the application.
Expand Down Expand Up @@ -613,7 +613,7 @@
*
* @return bool
*/
private static function canAcceptArgs(ReflectionClass $refClass, array $args): bool {

Check warning on line 616 in WebFiori/Framework/App.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This method has 7 returns, which is more than the 5 allowed.

See more on https://sonarcloud.io/project/issues?id=WebFiori_framework&issues=AZ4WgxNg7V19oztj8mwd&open=AZ4WgxNg7V19oztj8mwd&pullRequest=324
if (empty($args)) {
return true;
}
Expand Down Expand Up @@ -835,7 +835,7 @@
//Its used to construct the folder at which index file will exist at
$DS = DIRECTORY_SEPARATOR;
$vendorPath = $DS.'vendor'.$DS.'webFiori'.$DS.'framework'.$DS.'WebFiori'.$DS.'Framework';
$rootPath = substr(__DIR__, 0, strlen(__DIR__) - strlen($vendorPath));

Check warning on line 838 in WebFiori/Framework/App.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Immediately return this expression instead of assigning it to the temporary variable "$rootPath".

See more on https://sonarcloud.io/project/issues?id=WebFiori_framework&issues=AZ4WgxNg7V19oztj8mwh&open=AZ4WgxNg7V19oztj8mwh&pullRequest=324

return $rootPath;
}
Expand Down Expand Up @@ -870,7 +870,7 @@
}

if (!$isLoaded) {
throw new Exception('Unable to locate the autoloader class.');

Check warning on line 873 in WebFiori/Framework/App.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define and throw a dedicated exception instead of using a generic one.

See more on https://sonarcloud.io/project/issues?id=WebFiori_framework&issues=AZ4WgxNg7V19oztj8mwe&open=AZ4WgxNg7V19oztj8mwe&pullRequest=324
}
}

Expand All @@ -878,7 +878,7 @@
* @throws FileException
*/
private function initMiddleware() {
App::autoRegister('middleware', function(AbstractMiddleware $inst)
App::autoRegister('Middleware', function(AbstractMiddleware $inst)
{
MiddlewareManager::register($inst);
});
Expand Down Expand Up @@ -957,9 +957,9 @@
*/
private function setHandlers() {
Handler::registerHandler(new CLIErrHandler());
// Handler::registerHandler(new APICallErrHandler());
// Handler::registerHandler(new HTTPErrHandler());
// Handler::unregisterHandler(Handler::getHandler('Default'));

Check warning on line 962 in WebFiori/Framework/App.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this commented out code.

See more on https://sonarcloud.io/project/issues?id=WebFiori_framework&issues=AZ4WgxNg7V19oztj8mwg&open=AZ4WgxNg7V19oztj8mwg&pullRequest=324
Handler::setConfig(HandlerConfig::createDevelopmentConfig());
}
}
5 changes: 5 additions & 0 deletions WebFiori/Framework/Cli/CLITestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use WebFiori\Cli\Command;
use WebFiori\Cli\CommandTestCase;
use WebFiori\Database\ConnectionPool;
use WebFiori\File\File;
use WebFiori\Framework\App;

Expand All @@ -25,6 +26,10 @@ protected function setUp(): void {
parent::setUp();
$this->setRunner(App::getRunner());
}
protected function tearDown(): void {
ConnectionPool::reset();
parent::tearDown();
}
/**
* Register multiple commands and simulate the process of executing the app
* as if in production environment.
Expand Down
8 changes: 6 additions & 2 deletions WebFiori/Framework/Cli/Commands/DryRunMigrationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public function exec(): int {
// Discover migrations
$migrationsPath = APP_PATH.'Database'.DS.'Migrations';
$namespace = APP_DIR.'\\Database\\Migrations';
$count = $this->runner->discoverFromPath($migrationsPath, $namespace);
$count = $this->runner->discoverFromPath($migrationsPath, $namespace, true);

// Discover seeders
$seedersPath = APP_PATH.'Database'.DS.'Seeders';
$seedersNs = APP_DIR.'\\Database\\Seeders';
$count += $this->runner->discoverFromPath($seedersPath, $seedersNs);
$count += $this->runner->discoverFromPath($seedersPath, $seedersNs, true);

if ($count === 0) {
$this->info('No migrations/seeders found.');
Expand All @@ -66,6 +66,10 @@ public function exec(): int {
$this->println('Message: ' . $e->getMessage());
$this->println('File: ' . $e->getFile() . ':' . $e->getLine());
return 1;
} finally {
if ($this->runner !== null) {
$this->runner->close();
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions WebFiori/Framework/Cli/Commands/FreshMigrationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public function exec(): int {
// Discover migrations
$migrationsPath = APP_PATH.'Database'.DS.'Migrations';
$namespace = APP_DIR.'\\Database\\Migrations';
$migrationsCount = $this->runner->discoverFromPath($migrationsPath, $namespace);
$migrationsCount = $this->runner->discoverFromPath($migrationsPath, $namespace, true);

$seedersPath = APP_PATH.'Database'.DS.'Seeders';
$seedersNamespace = APP_DIR.'\\Database\\Seeders';
$seedersCount = $this->runner->discoverFromPath($seedersPath, $seedersNamespace);
$seedersCount = $this->runner->discoverFromPath($seedersPath, $seedersNamespace, true);

$count = $migrationsCount + $seedersCount;

Expand Down Expand Up @@ -86,6 +86,10 @@ public function exec(): int {
$this->println('Message: ' . $e->getMessage());
$this->println('File: ' . $e->getFile() . ':' . $e->getLine());
return 1;
} finally {
if ($this->runner !== null) {
$this->runner->close();
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion WebFiori/Framework/Cli/Commands/MigrationsStatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function exec(): int {
// Discover migrations
$migrationsPath = APP_PATH.'Database'.DS.'Migrations';
$namespace = APP_DIR.'\\Database\\Migrations';
$count = $this->runner->discoverFromPath($migrationsPath, $namespace);
$count = $this->runner->discoverFromPath($migrationsPath, $namespace, true);

if ($count === 0) {
$this->info('No migrations found.');
Expand All @@ -61,6 +61,10 @@ public function exec(): int {
$this->println('Message: ' . $e->getMessage());
$this->println('File: ' . $e->getFile() . ':' . $e->getLine());
return 1;
} finally {
if ($this->runner !== null) {
$this->runner->close();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function exec(): int {
// Discover migrations
$migrationsPath = APP_PATH.'Database'.DS.'Migrations';
$namespace = APP_DIR.'\\Database\\Migrations';
$this->runner->discoverFromPath($migrationsPath, $namespace);
$this->runner->discoverFromPath($migrationsPath, $namespace, true);

return $this->rollback();

Expand All @@ -58,6 +58,10 @@ public function exec(): int {
$this->println('Message: ' . $e->getMessage());
$this->println('File: ' . $e->getFile() . ':' . $e->getLine());
return 1;
} finally {
if ($this->runner !== null) {
$this->runner->close();
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions WebFiori/Framework/Cli/Commands/RunMigrationsCommandNew.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
// Discover migrations
$migrationsPath = APP_PATH.'Database'.DS.'Migrations';
$namespace = APP_DIR.'\\Database\\Migrations';
$count = $this->runner->discoverFromPath($migrationsPath, $namespace);
$count = $this->runner->discoverFromPath($migrationsPath, $namespace, true);

$seedersPath = APP_PATH.'Database'.DS.'Seeders';
$seedersNamespace = APP_DIR.'\\Database\\Seeders';
$count += $this->runner->discoverFromPath($seedersPath, $seedersNamespace);
$count += $this->runner->discoverFromPath($seedersPath, $seedersNamespace, true);

if ($count === 0) {
$this->info('No migrations found.');
Expand All @@ -62,7 +62,7 @@

} catch (Throwable $e) {
$msg = $e->getMessage();
if ((str_contains($msg, ".schema_changes' doesn't exist") && $e->getCode() == 1146)) {

Check warning on line 65 in WebFiori/Framework/Cli/Commands/RunMigrationsCommandNew.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove these useless parentheses.

See more on https://sonarcloud.io/project/issues?id=WebFiori_framework&issues=AZ4WgxGf7V19oztj8mwJ&open=AZ4WgxGf7V19oztj8mwJ&pullRequest=324
$this->warning('Table "schema_changes" does not exist. No migrations executed.');
$this->info('Run "migrations:ini" to create the table.');
return 1;
Expand All @@ -71,6 +71,10 @@
$this->println('Message: ' . $e->getMessage());
$this->println('File: ' . $e->getFile() . ':' . $e->getLine());
return 1;
} finally {
if ($this->runner !== null) {
$this->runner->close();
}
}
}

Expand Down
27 changes: 25 additions & 2 deletions WebFiori/Framework/Router/RouterUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Closure;
use InvalidArgumentException;
use WebFiori\Framework\Middleware\AbstractMiddleware;
use WebFiori\Framework\Middleware\MiddlewareManager;
use WebFiori\Http\RequestUri;
use WebFiori\Http\Uri;
Expand Down Expand Up @@ -191,10 +192,32 @@ public function addMiddleware(string $name) {
if ($mw === null) {
$group = MiddlewareManager::getGroup($name);

foreach ($group as $mw) {
$this->assignedMiddlewareList[] = $mw;
if (!empty($group)) {
foreach ($group as $mw) {
$this->assignedMiddlewareList[] = $mw;
}

return;
}

// Try resolving as class name
if (class_exists($name) && is_subclass_of($name, AbstractMiddleware::class)) {
$inst = new $name();
MiddlewareManager::register($inst);
$this->assignedMiddlewareList[] = $inst;

return;
}

// If it looks like a class reference (contains backslash) but isn't valid, throw
if (str_contains($name, '\\')) {
throw new \InvalidArgumentException(
"Middleware '$name' is not registered, does not match any group, "
. "and is not a valid middleware class."
);
}

// Otherwise treat as a group/name that may be registered later (silent)
return;
}
$this->assignedMiddlewareList[] = $mw;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"webfiori/jsonx": "v4.0.*",
"webfiori/ui": "v4.0.*",
"webfiori/collections": "v2.0.*",
"webfiori/database": "v2.0.*",
"webfiori/database": "v2.1.*",
"webfiori/cli": "v2.1.*",
"webfiori/mailer": "v2.1.*",
"webfiori/err": "v2.0.*"
Expand Down
24 changes: 19 additions & 5 deletions tests/WebFiori/Framework/Tests/Cli/DryRunMigrationsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,26 @@ public function down(Database \$db): void {

private function cleanupMigrations(): void {
$dir = APP_PATH.'Database'.DS.'Migrations';
$this->cleanPhpFiles($dir);
$seedersDir = APP_PATH.'Database'.DS.'Seeders';
$this->cleanPhpFiles($seedersDir);
}

private function cleanPhpFiles(string $dir): void {
if (!is_dir($dir)) {
return;
}

$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);

if (is_dir($dir)) {
foreach (glob($dir.DS.'*.php') as $file) {
if (basename($file) !== '.gitkeep') {
unlink($file);
}
foreach ($iterator as $item) {
if ($item->isFile() && $item->getExtension() === 'php') {
unlink($item->getRealPath());
} elseif ($item->isDir() && count(scandir($item->getRealPath())) === 2) {
rmdir($item->getRealPath());
}
}
}
Expand Down
24 changes: 19 additions & 5 deletions tests/WebFiori/Framework/Tests/Cli/FreshMigrationsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,26 @@ public function down(Database \$db): void {

private function cleanupMigrations(): void {
$dir = APP_PATH.'Database'.DS.'Migrations';
$this->cleanPhpFiles($dir);
$seedersDir = APP_PATH.'Database'.DS.'Seeders';
$this->cleanPhpFiles($seedersDir);
}

private function cleanPhpFiles(string $dir): void {
if (!is_dir($dir)) {
return;
}

$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);

if (is_dir($dir)) {
foreach (glob($dir.DS.'*.php') as $file) {
if (basename($file) !== '.gitkeep') {
unlink($file);
}
foreach ($iterator as $item) {
if ($item->isFile() && $item->getExtension() === 'php') {
unlink($item->getRealPath());
} elseif ($item->isDir() && count(scandir($item->getRealPath())) === 2) {
rmdir($item->getRealPath());
}
}
}
Expand Down
22 changes: 17 additions & 5 deletions tests/WebFiori/Framework/Tests/Cli/MigrationsStatusCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,24 @@ public function down(Database \$db): void {

private function cleanupMigrations(): void {
$dir = APP_PATH.'Database'.DS.'Migrations';
$this->cleanPhpFiles($dir);
}

private function cleanPhpFiles(string $dir): void {
if (!is_dir($dir)) {
return;
}

$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);

if (is_dir($dir)) {
foreach (glob($dir.DS.'*.php') as $file) {
if (basename($file) !== '.gitkeep') {
unlink($file);
}
foreach ($iterator as $item) {
if ($item->isFile() && $item->getExtension() === 'php') {
unlink($item->getRealPath());
} elseif ($item->isDir() && count(scandir($item->getRealPath())) === 2) {
rmdir($item->getRealPath());
}
}
}
Expand Down
Loading
Loading