改名
This commit is contained in:
@@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Snowflake\Abstracts;
|
||||||
|
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class Input
|
||||||
|
{
|
||||||
|
|
||||||
|
private $_argv = [];
|
||||||
|
|
||||||
|
|
||||||
|
private $_command = '';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Input constructor.
|
||||||
|
* @param $argv
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function __construct($argv)
|
||||||
|
{
|
||||||
|
$this->_argv = $this->resolve($argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $key
|
||||||
|
* @param null $default
|
||||||
|
* @return mixed|null
|
||||||
|
*/
|
||||||
|
public function get($key, $default = null)
|
||||||
|
{
|
||||||
|
return $this->_argv[$key] ?? $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $key
|
||||||
|
* @param $value
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function set($key, $value)
|
||||||
|
{
|
||||||
|
$this->_argv[$key] = $value;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return false|string
|
||||||
|
*/
|
||||||
|
public function toJson()
|
||||||
|
{
|
||||||
|
return json_encode($this->_argv, JSON_UNESCAPED_UNICODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $parameters
|
||||||
|
* @return array
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function resolve($parameters)
|
||||||
|
{
|
||||||
|
$arrays = [];
|
||||||
|
$parameters = array_slice($parameters, 1);
|
||||||
|
$this->_command = array_shift($parameters);
|
||||||
|
foreach ($parameters as $parameter) {
|
||||||
|
$explode = explode('=', $parameter);
|
||||||
|
if (count($explode) < 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$arrays[array_shift($explode)] = current($explode);
|
||||||
|
}
|
||||||
|
return $arrays;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getCommand()
|
||||||
|
{
|
||||||
|
return $this->_command;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+12
-1
@@ -16,6 +16,7 @@ use HttpServer\Server;
|
|||||||
use HttpServer\ServerProviders;
|
use HttpServer\ServerProviders;
|
||||||
use Snowflake\Abstracts\BaseApplication;
|
use Snowflake\Abstracts\BaseApplication;
|
||||||
use Snowflake\Abstracts\Config;
|
use Snowflake\Abstracts\Config;
|
||||||
|
use Snowflake\Abstracts\Input;
|
||||||
use Snowflake\Exception\NotFindClassException;
|
use Snowflake\Exception\NotFindClassException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,10 +68,20 @@ class Application extends BaseApplication
|
|||||||
* @param $argv
|
* @param $argv
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function start($argv)
|
public function start(Input $argv)
|
||||||
{
|
{
|
||||||
$manager = Snowflake::app()->server;
|
$manager = Snowflake::app()->server;
|
||||||
|
switch ($argv->get('action')) {
|
||||||
|
case 'stop':
|
||||||
|
$manager->shutdown();
|
||||||
|
break;
|
||||||
|
case 'restart':
|
||||||
|
$manager->shutdown();
|
||||||
$manager->start();
|
$manager->start();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$manager->start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user