diff --git a/VERSION b/VERSION index 18837e70..5d30083e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.1.9 +4.1.10 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/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(''); } 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); 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 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/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') 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) { 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. 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); }