Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/windwalker-io/core into m…
Browse files Browse the repository at this point in the history
…aster
  • Loading branch information
asika32764 committed Jun 18, 2024
2 parents b6b648e + 41cb285 commit e315c67
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 45 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.9
4.1.10
5 changes: 4 additions & 1 deletion src/Core/Application/ApplicationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
12 changes: 11 additions & 1 deletion src/Core/Composer/StarterInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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',
Expand Down Expand Up @@ -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) {
Expand All @@ -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('');
}

Expand Down
3 changes: 2 additions & 1 deletion src/Core/Generator/Builder/EntityMemberBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/Core/Http/Exception/ApiErrorCodeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/Core/Http/Exception/ApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ 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);

$message = $message ?: static::getAttrFromEnum($enum, Title::class)?->string;

[$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
Expand Down
18 changes: 9 additions & 9 deletions src/Core/Manager/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Middleware/CorsMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
13 changes: 13 additions & 0 deletions src/Core/Queue/Command/QueueWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -212,6 +214,17 @@ function (BeforeJobRunEvent $event) {
);
}
)
->on(
AfterJobRunEvent::class,
function (AfterJobRunEvent $event) {
$this->app->addMessage(
sprintf(
'Job Message: <info>%s</info> END',
$event->getMessage()->getId()
)
);
}
)
->on(
JobFailureEvent::class,
function (JobFailureEvent $event) use ($io, $connection) {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Router/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public function compile(): Route
];
}
}

unset($handler);
}

Expand Down
11 changes: 0 additions & 11 deletions src/Core/Schedule/Command/ScheduleInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 14 additions & 9 deletions src/Core/Service/LoggerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit e315c67

Please sign in to comment.