From ab70864c16e0e8a2657132ebd44514a79444d42b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 7 Sep 2020 15:47:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- System/Abstracts/Input.php | 91 ++++++++++++++++++++++++++++++++++++++ System/Application.php | 15 ++++++- 2 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 System/Abstracts/Input.php diff --git a/System/Abstracts/Input.php b/System/Abstracts/Input.php new file mode 100644 index 00000000..c0607d84 --- /dev/null +++ b/System/Abstracts/Input.php @@ -0,0 +1,91 @@ +_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; + } + +} diff --git a/System/Application.php b/System/Application.php index 0b57bf8b..0f1ff488 100644 --- a/System/Application.php +++ b/System/Application.php @@ -16,6 +16,7 @@ use HttpServer\Server; use HttpServer\ServerProviders; use Snowflake\Abstracts\BaseApplication; use Snowflake\Abstracts\Config; +use Snowflake\Abstracts\Input; use Snowflake\Exception\NotFindClassException; /** @@ -67,10 +68,20 @@ class Application extends BaseApplication * @param $argv * @throws */ - public function start($argv) + public function start(Input $argv) { $manager = Snowflake::app()->server; - $manager->start(); + switch ($argv->get('action')) { + case 'stop': + $manager->shutdown(); + break; + case 'restart': + $manager->shutdown(); + $manager->start(); + break; + default: + $manager->start(); + } }