mirror of
https://gitee.com/mix-php/mix.git
synced 2024-12-03 12:17:39 +08:00
feat:examples:add mix/cli
This commit is contained in:
parent
01668267bb
commit
1f89e35b96
@ -12,7 +12,7 @@ composer create-project --prefer-dist mix/api-skeleton api
|
||||
|
||||
## 快速开始
|
||||
|
||||
启动 [cli-server](https://www.php.net/manual/zh/features.commandline.webserver.php) 开发服务
|
||||
启动 [cli-server](https://www.php.net/manual/zh/features.commandline.webserver.php) 开发服务 (零依赖)
|
||||
|
||||
```
|
||||
composer run-script --timeout=0 cliserver:start
|
||||
@ -139,8 +139,8 @@ $vega->handle('/users/{id}', [new Users(), 'index'])->methods('GET');
|
||||
|
||||
路由里使用了 `Users` 控制器,我们需要创建他
|
||||
|
||||
- 如何配置路由:[mix-php/vega](https://github.com/mix-php/vega#readme)
|
||||
- 如何调用数据库:[mix-php/database](https://github.com/mix-php/database#readme)
|
||||
- 如何配置路由:[mix/vega](https://github.com/mix-php/vega#readme)
|
||||
- 如何调用数据库:[mix/database](https://github.com/mix-php/database#readme)
|
||||
|
||||
```php
|
||||
<?php
|
||||
@ -195,38 +195,30 @@ curl http://127.0.0.1:9501/users/1
|
||||
|
||||
容器采用了一个简单的单例模式,你可以修改为更加适合自己的方式。
|
||||
|
||||
- 数据库
|
||||
- 数据库:[mix/database](https://github.com/mix-php/database#readme)
|
||||
|
||||
```
|
||||
DB::instance()
|
||||
```
|
||||
|
||||
文档:[mix-php/database](https://github.com/mix-php/database#readme)
|
||||
|
||||
- Redis
|
||||
- Redis:[mix/redis](https://github.com/mix-php/redis#readme)
|
||||
|
||||
```
|
||||
RDS::instance()
|
||||
```
|
||||
|
||||
文档:[mix-php/redis](https://github.com/mix-php/redis#readme)
|
||||
|
||||
- 日志
|
||||
- 日志:[monolog/monolog](https://seldaek.github.io/monolog/doc/01-usage.html)
|
||||
|
||||
```
|
||||
Logger::instance()
|
||||
```
|
||||
|
||||
文档:[monolog/monolog](https://seldaek.github.io/monolog/doc/01-usage.html)
|
||||
|
||||
- 配置
|
||||
- 配置:[hassankhan/config](https://github.com/hassankhan/config#getting-values)
|
||||
|
||||
```
|
||||
Config::instance()
|
||||
```
|
||||
|
||||
文档:[hassankhan/config](https://github.com/hassankhan/config#getting-values)
|
||||
|
||||
## License
|
||||
|
||||
Apache License Version 2.0, http://www.apache.org/licenses/
|
||||
|
@ -2,14 +2,25 @@
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Dotenv\Dotenv;
|
||||
use Mix\Cli\Cli;
|
||||
|
||||
Dotenv::createUnsafeImmutable(__DIR__ . '/../', '.env')->load();
|
||||
define("APP_DEBUG", env('APP_DEBUG'));
|
||||
|
||||
App\Error::register();
|
||||
|
||||
switch ($argv[1]) {
|
||||
case 'clearcache';
|
||||
(new \App\Command\ClearCache())->exec();
|
||||
break;
|
||||
}
|
||||
Cli::setName('app')->setVersion('0.0.0-alpha');
|
||||
$cmds = [
|
||||
new Mix\Cli\Command([
|
||||
'name' => 'clearcache',
|
||||
'short' => 'Clear cache',
|
||||
'options' => [
|
||||
new Mix\Cli\Option([
|
||||
'names' => ['k', 'key'],
|
||||
'usage' => 'Key name'
|
||||
]),
|
||||
],
|
||||
'run' => new App\Command\ClearCache(),
|
||||
])
|
||||
];
|
||||
Cli::addCommand(...$cmds)->run();
|
||||
|
@ -22,6 +22,7 @@
|
||||
"require": {
|
||||
"workerman/workerman": "^4.0",
|
||||
"mix/vega": "~3.0",
|
||||
"mix/cli": "~3.0",
|
||||
"mix/database": "~3.0",
|
||||
"mix/redis": "~3.0",
|
||||
"vlucas/phpdotenv": "^5.3",
|
||||
|
@ -3,17 +3,20 @@
|
||||
namespace App\Command;
|
||||
|
||||
use App\Container\RDS;
|
||||
use Mix\Cli\Flag;
|
||||
use Mix\Cli\RunInterface;
|
||||
|
||||
/**
|
||||
* Class ClearCache
|
||||
* @package App\Command
|
||||
*/
|
||||
class ClearCache
|
||||
class ClearCache implements RunInterface
|
||||
{
|
||||
|
||||
public function exec(): void
|
||||
public function main(): void
|
||||
{
|
||||
RDS::instance()->del('foo_cache');
|
||||
$key = Flag::match('k', 'key')->string();
|
||||
RDS::instance()->del($key);
|
||||
print 'ok';
|
||||
}
|
||||
|
||||
|
@ -135,44 +135,36 @@ composer run-script swoole:start
|
||||
|
||||
## 如何使用 gRPC 客户端
|
||||
|
||||
- [mix-php/grpc#客户端调用一个 gRPC 服务](https://github.com/mix-php/grpc#%E5%AE%A2%E6%88%B7%E7%AB%AF%E8%B0%83%E7%94%A8%E4%B8%80%E4%B8%AA-grpc-%E6%9C%8D%E5%8A%A1)
|
||||
- [mix/grpc#客户端调用一个 gRPC 服务](https://github.com/mix-php/grpc#%E5%AE%A2%E6%88%B7%E7%AB%AF%E8%B0%83%E7%94%A8%E4%B8%80%E4%B8%AA-grpc-%E6%9C%8D%E5%8A%A1)
|
||||
|
||||
## 使用容器中的对象
|
||||
|
||||
容器采用了一个简单的单例模式,你可以修改为更加适合自己的方式。
|
||||
|
||||
- 数据库
|
||||
- 数据库:[mix/database](https://github.com/mix-php/database#readme)
|
||||
|
||||
```
|
||||
DB::instance()
|
||||
```
|
||||
|
||||
文档:[mix-php/database](https://github.com/mix-php/database#readme)
|
||||
|
||||
- Redis
|
||||
- Redis:[mix/redis](https://github.com/mix-php/redis#readme)
|
||||
|
||||
```
|
||||
RDS::instance()
|
||||
```
|
||||
|
||||
文档:[mix-php/redis](https://github.com/mix-php/redis#readme)
|
||||
|
||||
- 日志
|
||||
- 日志:[monolog/monolog](https://seldaek.github.io/monolog/doc/01-usage.html)
|
||||
|
||||
```
|
||||
Logger::instance()
|
||||
```
|
||||
|
||||
文档:[monolog/monolog](https://seldaek.github.io/monolog/doc/01-usage.html)
|
||||
|
||||
- 配置
|
||||
- 配置:[hassankhan/config](https://github.com/hassankhan/config#getting-values)
|
||||
|
||||
```
|
||||
Config::instance()
|
||||
```
|
||||
|
||||
文档:[hassankhan/config](https://github.com/hassankhan/config#getting-values)
|
||||
|
||||
## License
|
||||
|
||||
Apache License Version 2.0, http://www.apache.org/licenses/
|
||||
|
@ -2,14 +2,25 @@
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Dotenv\Dotenv;
|
||||
use Mix\Cli\Cli;
|
||||
|
||||
Dotenv::createUnsafeImmutable(__DIR__ . '/../', '.env')->load();
|
||||
define("APP_DEBUG", env('APP_DEBUG'));
|
||||
|
||||
App\Error::register();
|
||||
|
||||
switch ($argv[1]) {
|
||||
case 'clearcache';
|
||||
(new \App\Command\ClearCache())->exec();
|
||||
break;
|
||||
}
|
||||
Cli::setName('app')->setVersion('0.0.0-alpha');
|
||||
$cmds = [
|
||||
new Mix\Cli\Command([
|
||||
'name' => 'clearcache',
|
||||
'short' => 'Clear cache',
|
||||
'options' => [
|
||||
new Mix\Cli\Option([
|
||||
'names' => ['k', 'key'],
|
||||
'usage' => 'Key name'
|
||||
]),
|
||||
],
|
||||
'run' => new App\Command\ClearCache(),
|
||||
])
|
||||
];
|
||||
Cli::addCommand(...$cmds)->run();
|
||||
|
@ -23,6 +23,7 @@
|
||||
"workerman/workerman": "^4.0",
|
||||
"mix/vega": "~3.0",
|
||||
"mix/grpc": "~3.0",
|
||||
"mix/cli": "~3.0",
|
||||
"mix/database": "~3.0",
|
||||
"mix/redis": "~3.0",
|
||||
"vlucas/phpdotenv": "^5.3",
|
||||
|
@ -3,17 +3,20 @@
|
||||
namespace App\Command;
|
||||
|
||||
use App\Container\RDS;
|
||||
use Mix\Cli\Flag;
|
||||
use Mix\Cli\RunInterface;
|
||||
|
||||
/**
|
||||
* Class ClearCache
|
||||
* @package App\Command
|
||||
*/
|
||||
class ClearCache
|
||||
class ClearCache implements RunInterface
|
||||
{
|
||||
|
||||
public function exec(): void
|
||||
public function main(): void
|
||||
{
|
||||
RDS::instance()->del('foo_cache');
|
||||
$key = Flag::match('k', 'key')->string();
|
||||
RDS::instance()->del($key);
|
||||
print 'ok';
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ composer create-project --prefer-dist mix/web-skeleton web
|
||||
|
||||
## 快速开始
|
||||
|
||||
启动 [cli-server](https://www.php.net/manual/zh/features.commandline.webserver.php) 开发服务
|
||||
启动 [cli-server](https://www.php.net/manual/zh/features.commandline.webserver.php) 开发服务 (零依赖)
|
||||
|
||||
```
|
||||
composer run-script --timeout=0 cliserver:start
|
||||
@ -139,7 +139,7 @@ $vega->handle('/', [new Hello(), 'index'])->methods('GET');
|
||||
|
||||
路由里使用了 `Hello` 控制器,我们需要创建他
|
||||
|
||||
- 如何配置路由:[mix-php/vega](https://github.com/mix-php/vega#readme)
|
||||
- 如何配置路由:[mix/vega](https://github.com/mix-php/vega#readme)
|
||||
|
||||
```php
|
||||
<?php
|
||||
@ -196,38 +196,30 @@ curl http://127.0.0.1:9501/
|
||||
|
||||
容器采用了一个简单的单例模式,你可以修改为更加适合自己的方式。
|
||||
|
||||
- 数据库
|
||||
- 数据库:[mix/database](https://github.com/mix-php/database#readme)
|
||||
|
||||
```
|
||||
DB::instance()
|
||||
```
|
||||
|
||||
文档:[mix-php/database](https://github.com/mix-php/database#readme)
|
||||
|
||||
- Redis
|
||||
- Redis:[mix/redis](https://github.com/mix-php/redis#readme)
|
||||
|
||||
```
|
||||
RDS::instance()
|
||||
```
|
||||
|
||||
文档:[mix-php/redis](https://github.com/mix-php/redis#readme)
|
||||
|
||||
- 日志
|
||||
- 日志:[monolog/monolog](https://seldaek.github.io/monolog/doc/01-usage.html)
|
||||
|
||||
```
|
||||
Logger::instance()
|
||||
```
|
||||
|
||||
文档:[monolog/monolog](https://seldaek.github.io/monolog/doc/01-usage.html)
|
||||
|
||||
- 配置
|
||||
- 配置:[hassankhan/config](https://github.com/hassankhan/config#getting-values)
|
||||
|
||||
```
|
||||
Config::instance()
|
||||
```
|
||||
|
||||
文档:[hassankhan/config](https://github.com/hassankhan/config#getting-values)
|
||||
|
||||
## License
|
||||
|
||||
Apache License Version 2.0, http://www.apache.org/licenses/
|
||||
|
@ -2,14 +2,25 @@
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Dotenv\Dotenv;
|
||||
use Mix\Cli\Cli;
|
||||
|
||||
Dotenv::createUnsafeImmutable(__DIR__ . '/../', '.env')->load();
|
||||
define("APP_DEBUG", env('APP_DEBUG'));
|
||||
|
||||
App\Error::register();
|
||||
|
||||
switch ($argv[1]) {
|
||||
case 'clearcache';
|
||||
(new \App\Command\ClearCache())->exec();
|
||||
break;
|
||||
}
|
||||
Cli::setName('app')->setVersion('0.0.0-alpha');
|
||||
$cmds = [
|
||||
new Mix\Cli\Command([
|
||||
'name' => 'clearcache',
|
||||
'short' => 'Clear cache',
|
||||
'options' => [
|
||||
new Mix\Cli\Option([
|
||||
'names' => ['k', 'key'],
|
||||
'usage' => 'Key name'
|
||||
]),
|
||||
],
|
||||
'run' => new App\Command\ClearCache(),
|
||||
])
|
||||
];
|
||||
Cli::addCommand(...$cmds)->run();
|
||||
|
@ -22,6 +22,7 @@
|
||||
"require": {
|
||||
"workerman/workerman": "^4.0",
|
||||
"mix/vega": "~3.0",
|
||||
"mix/cli": "~3.0",
|
||||
"mix/database": "~3.0",
|
||||
"mix/redis": "~3.0",
|
||||
"vlucas/phpdotenv": "^5.3",
|
||||
|
@ -3,17 +3,20 @@
|
||||
namespace App\Command;
|
||||
|
||||
use App\Container\RDS;
|
||||
use Mix\Cli\Flag;
|
||||
use Mix\Cli\RunInterface;
|
||||
|
||||
/**
|
||||
* Class ClearCache
|
||||
* @package App\Command
|
||||
*/
|
||||
class ClearCache
|
||||
class ClearCache implements RunInterface
|
||||
{
|
||||
|
||||
public function exec(): void
|
||||
public function main(): void
|
||||
{
|
||||
RDS::instance()->del('foo_cache');
|
||||
$key = Flag::match('k', 'key')->string();
|
||||
RDS::instance()->del($key);
|
||||
print 'ok';
|
||||
}
|
||||
|
||||
|
@ -81,8 +81,8 @@ $vega->handle('/websocket', [new WebSocket(), 'index'])->methods('GET');
|
||||
|
||||
路由里使用了 `WebSocket` 控制器,我们需要创建他
|
||||
|
||||
- 如何配置路由:[mix-php/vega](https://github.com/mix-php/vega#readme)
|
||||
- 如何使用 WebSocket 升级器:[mix-php/websocket](https://github.com/mix-php/websocket#readme)
|
||||
- 如何配置路由:[mix/vega](https://github.com/mix-php/vega#readme)
|
||||
- 如何使用 WebSocket 升级器:[mix/websocket](https://github.com/mix-php/websocket#readme)
|
||||
|
||||
```php
|
||||
<?php
|
||||
@ -214,38 +214,30 @@ composer run-script swoole:start
|
||||
|
||||
容器采用了一个简单的单例模式,你可以修改为更加适合自己的方式。
|
||||
|
||||
- 数据库
|
||||
- 数据库:[mix/database](https://github.com/mix-php/database#readme)
|
||||
|
||||
```
|
||||
DB::instance()
|
||||
```
|
||||
|
||||
文档:[mix-php/database](https://github.com/mix-php/database#readme)
|
||||
|
||||
- Redis
|
||||
- Redis:[mix/redis](https://github.com/mix-php/redis#readme)
|
||||
|
||||
```
|
||||
RDS::instance()
|
||||
```
|
||||
|
||||
文档:[mix-php/redis](https://github.com/mix-php/redis#readme)
|
||||
|
||||
- 日志
|
||||
- 日志:[monolog/monolog](https://seldaek.github.io/monolog/doc/01-usage.html)
|
||||
|
||||
```
|
||||
Logger::instance()
|
||||
```
|
||||
|
||||
文档:[monolog/monolog](https://seldaek.github.io/monolog/doc/01-usage.html)
|
||||
|
||||
- 配置
|
||||
- 配置:[hassankhan/config](https://github.com/hassankhan/config#getting-values)
|
||||
|
||||
```
|
||||
Config::instance()
|
||||
```
|
||||
|
||||
文档:[hassankhan/config](https://github.com/hassankhan/config#getting-values)
|
||||
|
||||
## License
|
||||
|
||||
Apache License Version 2.0, http://www.apache.org/licenses/
|
||||
|
@ -2,14 +2,25 @@
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Dotenv\Dotenv;
|
||||
use Mix\Cli\Cli;
|
||||
|
||||
Dotenv::createUnsafeImmutable(__DIR__ . '/../', '.env')->load();
|
||||
define("APP_DEBUG", env('APP_DEBUG'));
|
||||
|
||||
App\Error::register();
|
||||
|
||||
switch ($argv[1]) {
|
||||
case 'clearcache';
|
||||
(new \App\Command\ClearCache())->exec();
|
||||
break;
|
||||
}
|
||||
Cli::setName('app')->setVersion('0.0.0-alpha');
|
||||
$cmds = [
|
||||
new Mix\Cli\Command([
|
||||
'name' => 'clearcache',
|
||||
'short' => 'Clear cache',
|
||||
'options' => [
|
||||
new Mix\Cli\Option([
|
||||
'names' => ['k', 'key'],
|
||||
'usage' => 'Key name'
|
||||
]),
|
||||
],
|
||||
'run' => new App\Command\ClearCache(),
|
||||
])
|
||||
];
|
||||
Cli::addCommand(...$cmds)->run();
|
||||
|
@ -19,6 +19,7 @@
|
||||
"require": {
|
||||
"mix/vega": "~3.0",
|
||||
"mix/websocket": "~3.0",
|
||||
"mix/cli": "~3.0",
|
||||
"mix/database": "~3.0",
|
||||
"mix/redis": "~3.0",
|
||||
"vlucas/phpdotenv": "^5.3",
|
||||
|
@ -3,17 +3,20 @@
|
||||
namespace App\Command;
|
||||
|
||||
use App\Container\RDS;
|
||||
use Mix\Cli\Flag;
|
||||
use Mix\Cli\RunInterface;
|
||||
|
||||
/**
|
||||
* Class ClearCache
|
||||
* @package App\Command
|
||||
*/
|
||||
class ClearCache
|
||||
class ClearCache implements RunInterface
|
||||
{
|
||||
|
||||
public function exec(): void
|
||||
public function main(): void
|
||||
{
|
||||
RDS::instance()->del('foo_cache');
|
||||
$key = Flag::match('k', 'key')->string();
|
||||
RDS::instance()->del($key);
|
||||
print 'ok';
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user