Skip to content

Commit d37a9af

Browse files
committed
Merge branch 'main' of github.com:hypervel/components
2 parents 673308c + 709eefd commit d37a9af

File tree

66 files changed

+1266
-273
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1266
-273
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"Hypervel\\Bus\\": "src/bus/src/",
3131
"Hypervel\\Cache\\": "src/cache/src/",
3232
"Hypervel\\Config\\": "src/config/src/",
33+
"Hypervel\\Console\\": "src/console/src/",
3334
"Hypervel\\Container\\": "src/container/src/",
3435
"Hypervel\\Cookie\\": "src/cookie/src/",
3536
"Hypervel\\Coroutine\\": "src/coroutine/src/",
@@ -51,7 +52,6 @@
5152
"Hypervel\\Prompts\\": "src/prompts/src/",
5253
"Hypervel\\Queue\\": "src/queue/src/",
5354
"Hypervel\\Router\\": "src/router/src/",
54-
"Hypervel\\Scheduling\\": "src/scheduling/src/",
5555
"Hypervel\\Session\\": "src/session/src/",
5656
"Hypervel\\Support\\": "src/support/src/",
5757
"Hypervel\\Telescope\\": "src/telescope/src/"
@@ -127,6 +127,7 @@
127127
"hypervel/bus": "self.version",
128128
"hypervel/cache": "self.version",
129129
"hypervel/config": "self.version",
130+
"hypervel/console": "self.version",
130131
"hypervel/container": "self.version",
131132
"hypervel/cookie": "self.version",
132133
"hypervel/core": "self.version",
@@ -149,7 +150,6 @@
149150
"hypervel/prompts": "self.version",
150151
"hypervel/queue": "self.version",
151152
"hypervel/router": "self.version",
152-
"hypervel/scheduling": "self.version",
153153
"hypervel/session": "self.version",
154154
"hypervel/support": "self.version",
155155
"hypervel/telescope": "self.version"
@@ -201,6 +201,7 @@
201201
"Hypervel\\Cache\\ConfigProvider",
202202
"Hypervel\\Cookie\\ConfigProvider",
203203
"Hypervel\\Config\\ConfigProvider",
204+
"Hypervel\\Console\\ConfigProvider",
204205
"Hypervel\\Devtool\\ConfigProvider",
205206
"Hypervel\\Dispatcher\\ConfigProvider",
206207
"Hypervel\\Encryption\\ConfigProvider",
@@ -215,7 +216,6 @@
215216
"Hypervel\\Notifications\\ConfigProvider",
216217
"Hypervel\\Queue\\ConfigProvider",
217218
"Hypervel\\Router\\ConfigProvider",
218-
"Hypervel\\Scheduling\\ConfigProvider",
219219
"Hypervel\\Session\\ConfigProvider",
220220
"Hypervel\\Telescope\\ConfigProvider"
221221
]
File renamed without changes.

src/console/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Console for Hypervel
2+
===

src/console/composer.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "hypervel/console",
3+
"type": "library",
4+
"description": "The console package for Hypervel.",
5+
"license": "MIT",
6+
"keywords": [
7+
"php",
8+
"hyperf",
9+
"console",
10+
"swoole",
11+
"hypervel"
12+
],
13+
"authors": [
14+
{
15+
"name": "Albert Chen",
16+
"email": "[email protected]"
17+
}
18+
],
19+
"support": {
20+
"issues": "https://github.com/hypervel/components/issues",
21+
"source": "https://github.com/hypervel/components"
22+
},
23+
"autoload": {
24+
"psr-4": {
25+
"Hypervel\\Console\\": "src/"
26+
}
27+
},
28+
"require": {
29+
"php": "^8.2",
30+
"hyperf/command": "~3.1.0",
31+
"hyperf/context": "~3.1.0",
32+
"hypervel/foundation": "^0.1",
33+
"dragonmantank/cron-expression": "^3.3.2",
34+
"symfony/console": "^5.4|^6.4|^7.0",
35+
"friendsofhyperf/command-signals": "~3.1.0"
36+
},
37+
"suggest": {
38+
"hypervel/prompt": "Required to run schedule:test command.",
39+
"friendsofhyperf/pretty-console": "Required to run schedule:run command. (~3.1.0)"
40+
},
41+
"config": {
42+
"sort-packages": true
43+
},
44+
"extra": {
45+
"hyperf": {
46+
"config": "Hypervel\\Console\\ConfigProvider"
47+
},
48+
"branch-alias": {
49+
"dev-main": "0.1-dev"
50+
}
51+
}
52+
}

src/foundation/src/Console/Application.php renamed to src/console/src/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
declare(strict_types=1);
44

5-
namespace Hypervel\Foundation\Console;
5+
namespace Hypervel\Console;
66

77
use Closure;
88
use Hyperf\Command\Command;
99
use Hyperf\Context\Context;
10+
use Hypervel\Console\Contracts\Application as ApplicationContract;
1011
use Hypervel\Container\Contracts\Container as ContainerContract;
11-
use Hypervel\Foundation\Console\Contracts\Application as ApplicationContract;
1212
use Hypervel\Support\ProcessUtils;
1313
use Override;
1414
use Psr\EventDispatcher\EventDispatcherInterface;

src/foundation/src/Console/ApplicationFactory.php renamed to src/console/src/ApplicationFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Hypervel\Foundation\Console;
5+
namespace Hypervel\Console;
66

77
use Hypervel\Foundation\Console\Contracts\Kernel as KernelContract;
88
use Psr\Container\ContainerInterface;

src/console/src/ClosureCommand.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Hypervel\Console;
6+
7+
use BadMethodCallException;
8+
use Closure;
9+
use Hyperf\Support\Traits\ForwardsCalls;
10+
use Hypervel\Console\Scheduling\Event;
11+
use Hypervel\Container\Contracts\Container as ContainerContract;
12+
use Hypervel\Support\Facades\Schedule;
13+
use ReflectionFunction;
14+
15+
/**
16+
* @mixin \Hypervel\Console\Scheduling\Event
17+
*/
18+
class ClosureCommand extends Command
19+
{
20+
use ForwardsCalls;
21+
22+
/**
23+
* Create a new command instance.
24+
*/
25+
public function __construct(
26+
protected ContainerContract $container,
27+
string $signature,
28+
protected Closure $callback
29+
) {
30+
$this->signature = $signature;
31+
32+
parent::__construct();
33+
}
34+
35+
/**
36+
* Execute the console command.
37+
*/
38+
public function handle(): int
39+
{
40+
$inputs = array_merge($this->input->getArguments(), $this->input->getOptions());
41+
42+
$parameters = [];
43+
44+
foreach ((new ReflectionFunction($this->callback))->getParameters() as $parameter) {
45+
if (isset($inputs[$parameter->getName()])) {
46+
$parameters[$parameter->getName()] = $inputs[$parameter->getName()];
47+
}
48+
}
49+
50+
return (int) $this->container->call(
51+
$this->callback->bindTo($this, $this),
52+
$parameters
53+
);
54+
}
55+
56+
/**
57+
* Set the description for the command.
58+
*/
59+
public function purpose(string $description): static
60+
{
61+
return $this->describe($description);
62+
}
63+
64+
/**
65+
* Set the description for the command.
66+
*/
67+
public function describe(string $description): static
68+
{
69+
$this->setDescription($description);
70+
71+
return $this;
72+
}
73+
74+
/**
75+
* Create a new scheduled event for the command.
76+
*/
77+
public function schedule(array $parameters = []): Event
78+
{
79+
return Schedule::command($this->name, $parameters);
80+
}
81+
82+
/**
83+
* Dynamically proxy calls to a new scheduled event.
84+
*
85+
* @throws BadMethodCallException
86+
*/
87+
public function __call(string $method, array $parameters)
88+
{
89+
return $this->forwardCallTo($this->schedule(), $method, $parameters);
90+
}
91+
}
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Hypervel\Foundation\Console;
5+
namespace Hypervel\Console;
66

77
use FriendsOfHyperf\CommandSignals\Traits\InteractsWithSignals;
88
use FriendsOfHyperf\PrettyConsole\Traits\Prettyable;
@@ -12,7 +12,6 @@
1212
use Hyperf\Command\Event\BeforeHandle;
1313
use Hyperf\Command\Event\FailToHandle;
1414
use Hyperf\Coroutine\Coroutine;
15-
use Hypervel\Context\ApplicationContext;
1615
use Hypervel\Support\Traits\HasLaravelStyleCommand;
1716
use Swoole\ExitException;
1817
use Symfony\Component\Console\Input\InputInterface;
@@ -30,13 +29,14 @@ abstract class Command extends HyperfCommand
3029
protected function execute(InputInterface $input, OutputInterface $output): int
3130
{
3231
$this->disableDispatcher($input);
32+
$this->replaceOutput();
3333
$method = method_exists($this, 'handle') ? 'handle' : '__invoke';
3434

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

7272
return $this->exitCode >= 0 && $this->exitCode <= 255 ? $this->exitCode : self::INVALID;
7373
}
74+
75+
protected function replaceOutput(): void
76+
{
77+
/* @phpstan-ignore-next-line */
78+
if ($this->app->bound(OutputInterface::class)) {
79+
$this->output = $this->app->get(OutputInterface::class);
80+
}
81+
}
7482
}

src/foundation/src/Console/CommandReplacer.php renamed to src/console/src/CommandReplacer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Hypervel\Foundation\Console;
5+
namespace Hypervel\Console;
66

77
use Symfony\Component\Console\Command\Command;
88

src/scheduling/src/Console/ScheduleClearCacheCommand.php renamed to src/console/src/Commands/ScheduleClearCacheCommand.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
declare(strict_types=1);
44

5-
namespace Hypervel\Scheduling\Console;
5+
namespace Hypervel\Console\Commands;
66

7-
use Hyperf\Command\Command;
8-
use Hypervel\Scheduling\Schedule;
9-
use Hypervel\Support\Traits\HasLaravelStyleCommand;
7+
use Hypervel\Console\Command;
8+
use Hypervel\Console\Scheduling\Schedule;
109

1110
class ScheduleClearCacheCommand extends Command
1211
{
13-
use HasLaravelStyleCommand;
14-
1512
/**
1613
* The console command name.
1714
*/

0 commit comments

Comments
 (0)