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
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"Hypervel\\Bus\\": "src/bus/src/",
"Hypervel\\Cache\\": "src/cache/src/",
"Hypervel\\Config\\": "src/config/src/",
"Hypervel\\Console\\": "src/console/src/",
"Hypervel\\Container\\": "src/container/src/",
"Hypervel\\Cookie\\": "src/cookie/src/",
"Hypervel\\Coroutine\\": "src/coroutine/src/",
Expand All @@ -51,7 +52,6 @@
"Hypervel\\Prompts\\": "src/prompts/src/",
"Hypervel\\Queue\\": "src/queue/src/",
"Hypervel\\Router\\": "src/router/src/",
"Hypervel\\Scheduling\\": "src/scheduling/src/",
"Hypervel\\Session\\": "src/session/src/",
"Hypervel\\Support\\": "src/support/src/",
"Hypervel\\Telescope\\": "src/telescope/src/"
Expand Down Expand Up @@ -127,6 +127,7 @@
"hypervel/bus": "self.version",
"hypervel/cache": "self.version",
"hypervel/config": "self.version",
"hypervel/console": "self.version",
"hypervel/container": "self.version",
"hypervel/cookie": "self.version",
"hypervel/core": "self.version",
Expand All @@ -149,7 +150,6 @@
"hypervel/prompts": "self.version",
"hypervel/queue": "self.version",
"hypervel/router": "self.version",
"hypervel/scheduling": "self.version",
"hypervel/session": "self.version",
"hypervel/support": "self.version",
"hypervel/telescope": "self.version"
Expand Down Expand Up @@ -201,6 +201,7 @@
"Hypervel\\Cache\\ConfigProvider",
"Hypervel\\Cookie\\ConfigProvider",
"Hypervel\\Config\\ConfigProvider",
"Hypervel\\Console\\ConfigProvider",
"Hypervel\\Devtool\\ConfigProvider",
"Hypervel\\Dispatcher\\ConfigProvider",
"Hypervel\\Encryption\\ConfigProvider",
Expand All @@ -215,7 +216,6 @@
"Hypervel\\Notifications\\ConfigProvider",
"Hypervel\\Queue\\ConfigProvider",
"Hypervel\\Router\\ConfigProvider",
"Hypervel\\Scheduling\\ConfigProvider",
"Hypervel\\Session\\ConfigProvider",
"Hypervel\\Telescope\\ConfigProvider"
]
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions src/console/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Console for Hypervel
===
52 changes: 52 additions & 0 deletions src/console/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "hypervel/console",
"type": "library",
"description": "The console package for Hypervel.",
"license": "MIT",
"keywords": [
"php",
"hyperf",
"console",
"swoole",
"hypervel"
],
"authors": [
{
"name": "Albert Chen",
"email": "[email protected]"
}
],
"support": {
"issues": "https://github.com/hypervel/components/issues",
"source": "https://github.com/hypervel/components"
},
"autoload": {
"psr-4": {
"Hypervel\\Console\\": "src/"
}
},
"require": {
"php": "^8.2",
"hyperf/command": "~3.1.0",
"hyperf/context": "~3.1.0",
"hypervel/foundation": "^0.1",
"dragonmantank/cron-expression": "^3.3.2",
"symfony/console": "^5.4|^6.4|^7.0",
"friendsofhyperf/command-signals": "~3.1.0"
},
"suggest": {
"hypervel/prompt": "Required to run schedule:test command.",
"friendsofhyperf/pretty-console": "Required to run schedule:run command. (~3.1.0)"
},
"config": {
"sort-packages": true
},
"extra": {
"hyperf": {
"config": "Hypervel\\Console\\ConfigProvider"
},
"branch-alias": {
"dev-main": "0.1-dev"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

declare(strict_types=1);

namespace Hypervel\Foundation\Console;
namespace Hypervel\Console;

use Closure;
use Hyperf\Command\Command;
use Hyperf\Context\Context;
use Hypervel\Console\Contracts\Application as ApplicationContract;
use Hypervel\Container\Contracts\Container as ContainerContract;
use Hypervel\Foundation\Console\Contracts\Application as ApplicationContract;
use Hypervel\Support\ProcessUtils;
use Override;
use Psr\EventDispatcher\EventDispatcherInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Hypervel\Foundation\Console;
namespace Hypervel\Console;

use Hypervel\Foundation\Console\Contracts\Kernel as KernelContract;
use Psr\Container\ContainerInterface;
Expand Down
91 changes: 91 additions & 0 deletions src/console/src/ClosureCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

declare(strict_types=1);

namespace Hypervel\Console;

use BadMethodCallException;
use Closure;
use Hyperf\Support\Traits\ForwardsCalls;
use Hypervel\Console\Scheduling\Event;
use Hypervel\Container\Contracts\Container as ContainerContract;
use Hypervel\Support\Facades\Schedule;
use ReflectionFunction;

/**
* @mixin \Hypervel\Console\Scheduling\Event
*/
class ClosureCommand extends Command
{
use ForwardsCalls;

/**
* Create a new command instance.
*/
public function __construct(
protected ContainerContract $container,
string $signature,
protected Closure $callback
) {
$this->signature = $signature;

parent::__construct();
}

/**
* Execute the console command.
*/
public function handle(): int
{
$inputs = array_merge($this->input->getArguments(), $this->input->getOptions());

$parameters = [];

foreach ((new ReflectionFunction($this->callback))->getParameters() as $parameter) {
if (isset($inputs[$parameter->getName()])) {
$parameters[$parameter->getName()] = $inputs[$parameter->getName()];
}
}

return (int) $this->container->call(
$this->callback->bindTo($this, $this),
$parameters
);
}

/**
* Set the description for the command.
*/
public function purpose(string $description): static
{
return $this->describe($description);
}

/**
* Set the description for the command.
*/
public function describe(string $description): static
{
$this->setDescription($description);

return $this;
}

/**
* Create a new scheduled event for the command.
*/
public function schedule(array $parameters = []): Event
{
return Schedule::command($this->name, $parameters);
}

/**
* Dynamically proxy calls to a new scheduled event.
*
* @throws BadMethodCallException
*/
public function __call(string $method, array $parameters)
{
return $this->forwardCallTo($this->schedule(), $method, $parameters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Hypervel\Foundation\Console;
namespace Hypervel\Console;

use FriendsOfHyperf\CommandSignals\Traits\InteractsWithSignals;
use FriendsOfHyperf\PrettyConsole\Traits\Prettyable;
Expand All @@ -12,7 +12,6 @@
use Hyperf\Command\Event\BeforeHandle;
use Hyperf\Command\Event\FailToHandle;
use Hyperf\Coroutine\Coroutine;
use Hypervel\Context\ApplicationContext;
use Hypervel\Support\Traits\HasLaravelStyleCommand;
use Swoole\ExitException;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -30,13 +29,14 @@ abstract class Command extends HyperfCommand
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->disableDispatcher($input);
$this->replaceOutput();
$method = method_exists($this, 'handle') ? 'handle' : '__invoke';

$callback = function () use ($method): int {
try {
$this->eventDispatcher?->dispatch(new BeforeHandle($this));
$statusCode = ApplicationContext::getContainer()
->call([$this, $method]);
/* @phpstan-ignore-next-line */
$statusCode = $this->app->call([$this, $method]);
if (is_int($statusCode)) {
$this->exitCode = $statusCode;
}
Expand Down Expand Up @@ -71,4 +71,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int

return $this->exitCode >= 0 && $this->exitCode <= 255 ? $this->exitCode : self::INVALID;
}

protected function replaceOutput(): void
{
/* @phpstan-ignore-next-line */
if ($this->app->bound(OutputInterface::class)) {
$this->output = $this->app->get(OutputInterface::class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Hypervel\Foundation\Console;
namespace Hypervel\Console;

use Symfony\Component\Console\Command\Command;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

declare(strict_types=1);

namespace Hypervel\Scheduling\Console;
namespace Hypervel\Console\Commands;

use Hyperf\Command\Command;
use Hypervel\Scheduling\Schedule;
use Hypervel\Support\Traits\HasLaravelStyleCommand;
use Hypervel\Console\Command;
use Hypervel\Console\Scheduling\Schedule;

class ScheduleClearCacheCommand extends Command
{
use HasLaravelStyleCommand;

/**
* The console command name.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@

declare(strict_types=1);

namespace Hypervel\Scheduling\Console;
namespace Hypervel\Console\Commands;

use Closure;
use Cron\CronExpression;
use DateTimeZone;
use Exception;
use Hyperf\Collection\Collection;
use Hyperf\Command\Command;
use Hypervel\Scheduling\CallbackEvent;
use Hypervel\Scheduling\Event;
use Hypervel\Scheduling\Schedule;
use Hypervel\Console\Command;
use Hypervel\Console\Scheduling\CallbackEvent;
use Hypervel\Console\Scheduling\Event;
use Hypervel\Console\Scheduling\Schedule;
use Hypervel\Support\Carbon;
use Hypervel\Support\Traits\HasLaravelStyleCommand;
use ReflectionClass;
use ReflectionFunction;
use Symfony\Component\Console\Terminal;

class ScheduleListCommand extends Command
{
use HasLaravelStyleCommand;

/**
* The console command signature.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@

declare(strict_types=1);

namespace Hypervel\Scheduling\Console;
namespace Hypervel\Console\Commands;

use Hyperf\Collection\Collection;
use Hyperf\Command\Command;
use Hyperf\Coroutine\Concurrent;
use Hyperf\Coroutine\Waiter;
use Hypervel\Cache\Contracts\Factory as CacheFactory;
use Hypervel\Container\Contracts\Container;
use Hypervel\Context\ApplicationContext;
use Hypervel\Console\Command;
use Hypervel\Console\Events\ScheduledTaskFailed;
use Hypervel\Console\Events\ScheduledTaskFinished;
use Hypervel\Console\Events\ScheduledTaskSkipped;
use Hypervel\Console\Events\ScheduledTaskStarting;
use Hypervel\Console\Scheduling\CallbackEvent;
use Hypervel\Console\Scheduling\Event;
use Hypervel\Console\Scheduling\Schedule;
use Hypervel\Foundation\Exceptions\Contracts\ExceptionHandler;
use Hypervel\Scheduling\CallbackEvent;
use Hypervel\Scheduling\Event;
use Hypervel\Scheduling\Events\ScheduledTaskFailed;
use Hypervel\Scheduling\Events\ScheduledTaskFinished;
use Hypervel\Scheduling\Events\ScheduledTaskSkipped;
use Hypervel\Scheduling\Events\ScheduledTaskStarting;
use Hypervel\Scheduling\Schedule;
use Hypervel\Support\Carbon;
use Hypervel\Support\Facades\Date;
use Hypervel\Support\Sleep;
Expand All @@ -27,8 +25,6 @@

class ScheduleRunCommand extends Command
{
protected Container $app;

/**
* The console command signature.
*/
Expand Down Expand Up @@ -72,8 +68,6 @@ public function __construct(
protected ExceptionHandler $handler,
) {
parent::__construct();

$this->app = ApplicationContext::getContainer();
}

/**
Expand Down
Loading