From 357e23c014fafdb388daa5ffc6de6969ffbec04f Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sun, 9 Jun 2024 18:24:40 +0800 Subject: [PATCH 1/8] no state --- src/Core/Generator/Builder/EntityMemberBuilder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Core/Generator/Builder/EntityMemberBuilder.php b/src/Core/Generator/Builder/EntityMemberBuilder.php index 1d05d567..e9ee0ab4 100644 --- a/src/Core/Generator/Builder/EntityMemberBuilder.php +++ b/src/Core/Generator/Builder/EntityMemberBuilder.php @@ -197,7 +197,8 @@ protected function getTypeAndDefaultFromDbColumn(DbColumn $dbColumn): array $default = null; $this->addUse(Chronos::class); - } elseif ($dbColumn->columnName === 'state' && $dataType === 'tinyint') { + } elseif ($dbColumn->columnName === 'state' && $dataType === 'tinyint' && enum_exists(BasicState::class)) { + // Todo: This should move to unicorn package $type = 'BasicState'; $default = Symbol::none(); $this->addUse(BasicState::class); From cb155cb537f0532184a3c3fa5885246d9abdc16d Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sun, 16 Jun 2024 18:32:14 +0800 Subject: [PATCH 2/8] install orm --- src/Core/Composer/StarterInstaller.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Core/Composer/StarterInstaller.php b/src/Core/Composer/StarterInstaller.php index 77624392..f9165fb7 100644 --- a/src/Core/Composer/StarterInstaller.php +++ b/src/Core/Composer/StarterInstaller.php @@ -87,6 +87,8 @@ public static function noIgnoreLockFile(Event $event): void */ public static function genEnv(Event $event): void { + $composer = $_SERVER['COMPOSER_BINARY'] ?? null ?: 'composer'; + include getcwd() . '/vendor/autoload.php'; $io = $event->getIO(); @@ -111,6 +113,8 @@ public static function genEnv(Event $event): void $vars['APP_SECRET'] = $secret; + $installDb = false; + if ($io->askConfirmation("\nDo you want to use database? [Y/n]: ", true)) { $supportedDrivers = [ 'pdo_mysql', @@ -140,6 +144,8 @@ public static function genEnv(Event $event): void $vars['DATABASE_NAME'] = $io->ask('Database name [acme]: ', 'acme'); $vars['DATABASE_USER'] = $io->ask('Database user [root]: ', 'root'); $vars['DATABASE_PASSWORD'] = $io->askAndHideAnswer('Database password: '); + + $installDb = true; } foreach ($vars as $key => $value) { @@ -148,8 +154,12 @@ public static function genEnv(Event $event): void file_put_contents($dest, $env); + if ($installDb) { + exec($composer . ' require windwalker/orm:^4.0'); + } + $io->write(''); - $io->write('Database config setting complete.'); + $io->write('Env setting complete.'); $io->write(''); } From 575de2b20b580d1ace75f541480d8833104add31 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sun, 16 Jun 2024 19:42:18 +0800 Subject: [PATCH 3/8] [Queue] Add end message to instant logs #1234 --- src/Core/Application/ApplicationTrait.php | 5 ++++- src/Core/Queue/Command/QueueWorkerCommand.php | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Core/Application/ApplicationTrait.php b/src/Core/Application/ApplicationTrait.php index e7f5909d..83b45ddd 100644 --- a/src/Core/Application/ApplicationTrait.php +++ b/src/Core/Application/ApplicationTrait.php @@ -237,7 +237,10 @@ private function handleListener( if ($listener instanceof Closure) { // Closure with ListenTo() attribute $event = AttributesAccessor::getFirstAttributeInstance($listener, ListenTo::class); - $event->listen($dispatcher, $listener); + $event->listen( + $dispatcher, + fn (...$args) => $container->call($listener, $args) + ); } else { // Simply listener class name. $dispatcher->subscribe($container->resolve($listener)); diff --git a/src/Core/Queue/Command/QueueWorkerCommand.php b/src/Core/Queue/Command/QueueWorkerCommand.php index 780478fb..edaecfa8 100644 --- a/src/Core/Queue/Command/QueueWorkerCommand.php +++ b/src/Core/Queue/Command/QueueWorkerCommand.php @@ -17,6 +17,8 @@ use Windwalker\Core\Queue\QueueManager; use Windwalker\Core\Service\LoggerService; use Windwalker\DI\Exception\DefinitionException; +use Windwalker\Queue\Driver\DatabaseQueueDriver; +use Windwalker\Queue\Event\AfterJobRunEvent; use Windwalker\Queue\Event\BeforeJobRunEvent; use Windwalker\Queue\Event\JobFailureEvent; use Windwalker\Queue\Event\LoopEndEvent; @@ -212,6 +214,17 @@ function (BeforeJobRunEvent $event) { ); } ) + ->on( + AfterJobRunEvent::class, + function (AfterJobRunEvent $event) { + $this->app->addMessage( + sprintf( + 'Job Message: %s END', + $event->getMessage()->getId() + ) + ); + } + ) ->on( JobFailureEvent::class, function (JobFailureEvent $event) use ($io, $connection) { From f2af5e8fb9d81d1008a1aa1b0d4806cf67feab97 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sun, 16 Jun 2024 19:44:45 +0800 Subject: [PATCH 4/8] ApiException ErrorCode support previous exception #1230 --- src/Core/Http/Exception/ApiErrorCodeTrait.php | 8 ++++---- src/Core/Http/Exception/ApiException.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Core/Http/Exception/ApiErrorCodeTrait.php b/src/Core/Http/Exception/ApiErrorCodeTrait.php index dd1af4d7..3a1ce040 100644 --- a/src/Core/Http/Exception/ApiErrorCodeTrait.php +++ b/src/Core/Http/Exception/ApiErrorCodeTrait.php @@ -11,13 +11,13 @@ */ trait ApiErrorCodeTrait { - public function exception(?string $message = null): ApiException + public function exception(?string $message = null, ?\Throwable $previous = null): ApiException { - return ApiException::fromEnum($this, $message); + return ApiException::fromEnum($this, $message, $previous); } - public function throw(?string $message = null): never + public function throw(?string $message = null, ?\Throwable $previous = null): never { - throw $this->exception($message); + throw $this->exception($message, $previous); } } diff --git a/src/Core/Http/Exception/ApiException.php b/src/Core/Http/Exception/ApiException.php index b7d298ef..847b097f 100644 --- a/src/Core/Http/Exception/ApiException.php +++ b/src/Core/Http/Exception/ApiException.php @@ -32,7 +32,7 @@ public static function from(\Throwable $e, int $statusCode = 0): static return new static($e->getMessage(), $e->getCode(), $statusCode, $e); } - public static function fromEnum(\UnitEnum $enum, ?string $message = null): static + public static function fromEnum(\UnitEnum $enum, ?string $message = null, ?\Throwable $previous = null): static { static::checkBackedEnumType($enum); @@ -40,7 +40,7 @@ public static function fromEnum(\UnitEnum $enum, ?string $message = null): stati [$code, $statusCode] = static::getStatusCodeFromEnum($enum); - return new static($message, (int) $code, $statusCode); + return new static($message, (int) $code, $statusCode, $previous); } public static function wrap(\Throwable $e): static From d01dad01cab37b866c76e086c5d0ca42280e79ec Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sun, 16 Jun 2024 19:45:45 +0800 Subject: [PATCH 5/8] CorsMiddleware error if allow origin is null #1228 --- src/Core/Middleware/CorsMiddleware.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Middleware/CorsMiddleware.php b/src/Core/Middleware/CorsMiddleware.php index ef21dc5a..3db3d170 100644 --- a/src/Core/Middleware/CorsMiddleware.php +++ b/src/Core/Middleware/CorsMiddleware.php @@ -33,7 +33,7 @@ protected function configureOptions(OptionsResolver $resolver): void ->default(true); $resolver->define('allow_origins') - ->allowedTypes('string', 'array') + ->allowedTypes('string', 'array', 'null') ->default(env('CORS_ALLOW_ORIGINS') ?: null); $resolver->define('configure') From 97382f5a8a489ab0802383087db48d833ad6acad Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Sun, 16 Jun 2024 19:51:56 +0800 Subject: [PATCH 6/8] Support send exception into log #1226 --- src/Core/Manager/Logger.php | 18 +++++++++--------- src/Core/Service/LoggerService.php | 23 ++++++++++++++--------- src/functions.php | 8 ++++---- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/Core/Manager/Logger.php b/src/Core/Manager/Logger.php index 25b77258..fa024d24 100644 --- a/src/Core/Manager/Logger.php +++ b/src/Core/Manager/Logger.php @@ -9,15 +9,15 @@ /** * The Logger class. * - * @method static void log(string|array $channel, string|int $level, string|array $message, array $context = []) - * @method static void emergency(string|array $channel, string|array $message, array $context = []) - * @method static void alert(string|array $channel, string|array $message, array $context = []) - * @method static void critical(string|array $channel, string|array $message, array $context = []) - * @method static void error(string|array $channel, string|array $message, array $context = []) - * @method static void warning(string|array $channel, string|array $message, array $context = []) - * @method static void notice(string|array $channel, string|array $message, array $context = []) - * @method static void info(string|array $channel, string|array $message, array $context = []) - * @method static void debug(string|array $channel, string|array $message, array $context = []) + * @method static void log(string|array $channel, string|int $level, mixed $message, array $context = []) + * @method static void emergency(string|array $channel, mixed $message, array $context = []) + * @method static void alert(string|array $channel, mixed $message, array $context = []) + * @method static void critical(string|array $channel, mixed $message, array $context = []) + * @method static void error(string|array $channel, mixed $message, array $context = []) + * @method static void warning(string|array $channel, mixed $message, array $context = []) + * @method static void notice(string|array $channel, mixed $message, array $context = []) + * @method static void info(string|array $channel, mixed $message, array $context = []) + * @method static void debug(string|array $channel, mixed $message, array $context = []) */ class Logger { diff --git a/src/Core/Service/LoggerService.php b/src/Core/Service/LoggerService.php index 9133e929..f3d01b76 100644 --- a/src/Core/Service/LoggerService.php +++ b/src/Core/Service/LoggerService.php @@ -35,7 +35,7 @@ public function __construct(LoggerManager $manager) * System is unusable. * * @param string|array $channel - * @param string|array $message + * @param mixed $message * @param array $context * * @return static @@ -55,7 +55,7 @@ public function emergency(string|array $channel, mixed $message, array $context * trigger the SMS alerts and wake you up. * * @param string|array $channel - * @param string|array $message + * @param mixed $message * @param array $context * * @return static @@ -74,7 +74,7 @@ public function alert(string|array $channel, mixed $message, array $context = [] * Example: Application component unavailable, unexpected exception. * * @param string|array $channel - * @param string|array $message + * @param mixed $message * @param array $context * * @return static @@ -92,7 +92,7 @@ public function critical(string|array $channel, mixed $message, array $context = * be logged and monitored. * * @param string|array $channel - * @param string|array $message + * @param mixed $message * @param array $context * * @return static @@ -112,7 +112,7 @@ public function error(string|array $channel, mixed $message, array $context = [] * that are not necessarily wrong. * * @param string|array $channel - * @param string|array $message + * @param mixed $message * @param array $context * * @return static @@ -129,7 +129,7 @@ public function warning(string|array $channel, mixed $message, array $context = * Normal but significant events. * * @param string|array $channel - * @param string|array $message + * @param mixed $message * @param array $context * * @return static @@ -148,7 +148,7 @@ public function notice(string|array $channel, mixed $message, array $context = [ * Example: User logs in, SQL logs. * * @param string|array $channel - * @param string|array $message + * @param mixed $message * @param array $context * * @return static @@ -165,7 +165,7 @@ public function info(string|array $channel, mixed $message, array $context = []) * Detailed debug information. * * @param string|array $channel - * @param string|array $message + * @param mixed $message * @param array $context * * @return static @@ -183,7 +183,7 @@ public function debug(string|array $channel, mixed $message, array $context = [] * * @param string|array $channel * @param string|int $level - * @param string|array $message + * @param mixed $message * @param array $context * * @return static @@ -207,6 +207,11 @@ public function log(string|array $channel, string|int $level, mixed $message, ar return $this; } + if ($message instanceof \Throwable) { + $context = ['exception' => $message]; + $message = $message->getMessage(); + } + $this->getLogger($channel)->log($level, $message, $context); return $this; diff --git a/src/functions.php b/src/functions.php index fe3c8182..884d7983 100644 --- a/src/functions.php +++ b/src/functions.php @@ -230,28 +230,28 @@ function collapse(...$args): CollapseWrapper } if (!function_exists('\Windwalker\log')) { - function log(string|array $channel, string|int $level, string|array $message, array $context = []): void + function log(string|array $channel, string|int $level, mixed $message, array $context = []): void { Logger::log($channel, $level, $message, $context); } } if (!function_exists('\Windwalker\log_info')) { - function log_info(string|array $channel, string|array $message, array $context = []): void + function log_info(string|array $channel, mixed $message, array $context = []): void { Logger::log($channel, LogLevel::INFO, $message, $context); } } if (!function_exists('\Windwalker\log_debug')) { - function log_debug(string|array $channel, string|array $message, array $context = []): void + function log_debug(string|array $channel, mixed $message, array $context = []): void { Logger::log($channel, LogLevel::DEBUG, $message, $context); } } if (!function_exists('\Windwalker\log_notice')) { - function log_notice(string|array $channel, string|array $message, array $context = []): void + function log_notice(string|array $channel, mixed $message, array $context = []): void { Logger::log($channel, LogLevel::NOTICE, $message, $context); } From b1df9dda073a8a182168999b66dc03f0c359a342 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Mon, 17 Jun 2024 17:45:24 +0800 Subject: [PATCH 7/8] CS --- src/Core/Router/Route.php | 2 +- src/Core/Schedule/Command/ScheduleInstallCommand.php | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/Core/Router/Route.php b/src/Core/Router/Route.php index 3c3b898e..569d27ca 100644 --- a/src/Core/Router/Route.php +++ b/src/Core/Router/Route.php @@ -278,7 +278,7 @@ public function compile(): Route ]; } } - + unset($handler); } diff --git a/src/Core/Schedule/Command/ScheduleInstallCommand.php b/src/Core/Schedule/Command/ScheduleInstallCommand.php index e9612eb0..4b2f4193 100644 --- a/src/Core/Schedule/Command/ScheduleInstallCommand.php +++ b/src/Core/Schedule/Command/ScheduleInstallCommand.php @@ -6,23 +6,12 @@ use Lorisleiva\CronTranslator\CronTranslator; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Helper\Table; -use Symfony\Component\Console\Helper\TableSeparator; -use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Windwalker\Console\CommandInterface; use Windwalker\Console\CommandWrapper; use Windwalker\Console\IOInterface; -use Windwalker\Core\Application\ApplicationInterface; -use Windwalker\Core\Console\ConsoleApplication; -use Windwalker\Core\Schedule\Schedule; use Windwalker\Core\Schedule\ScheduleService; use Windwalker\Environment\Environment; -use Windwalker\Utilities\Arr; - -use Windwalker\Utilities\Str; - -use function Windwalker\fs; /** * The ScheduleShowCommand class. From 41cb285f21ea13db49eb2a2ae0a5eab6f5b4c723 Mon Sep 17 00:00:00 2001 From: Simon Asika Date: Mon, 17 Jun 2024 19:21:34 +0800 Subject: [PATCH 8/8] Release version: 4.1.10 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 18837e70..5d30083e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.1.9 +4.1.10