<commit_before><?php declare(strict_types=1);
/*
 * This file is part of the ************************ package.
 * _____________                           _______________
 *  ______/     \__  _____  ____  ______  / /_  _________
 *   ____/ __   / / / / _ \/ __`\/ / __ \/ __ \/ __ \___
 *    __/ / /  / /_/ /  __/ /  \  / /_/ / / / / /_/ /__
 *      \_\ \_/\____/\___/_/   / / .___/_/ /_/ .___/
 *         \_\                /_/_/         /_/
 *
 * The PHP Framework For Code Poem As Free As Wind. <Query Yet Simple>
 * (c) 2010-2018 http://queryphp.com All rights reserved.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Leevel\Protocol\Console;

use Exception;
use Leevel\{
    Console\Option,
    Console\Command,
    Console\Argument
};

/**
 * swoole 服务停止
 *
 * @author <NAME> <<EMAIL>>
 * @package $$
 * @since 2017.12.26
 * @version 1.0
 */
class Stop extends Command
{

    /**
     * 命令名字
     *
     * @var string
     */
    protected $strName = 'swoole:stop';

    /**
     * 命令行描述
     *
     * @var string
     */
    protected $strDescription = 'Stop swoole service process';

    /**
     * 响应命令
     *
     * @return void
     */
    public function handle()
    {
        $this->warn($this->getVersion());
        
        $objServer = app('swoole.' . $this->argument('type') . '.server');
        $objServer->setCommand($this);
        $objServer->options($this->parseOption());
        $objServer->stopServer();
    }

    /**
     * 分析参数
     *
     * @return array
     */
    protected function parseOption() :array {
        $arrOption = [];

        foreach(['host', 'port', 'pid_path'] as $sKey) {
            if(! is_null($this->option($sKey))) {
                $arrOption[$sKey] = $this->option($sKey);
            }
        }

        return $arrOption;
    }

    /**
     * 返回 QueryPHP Version
     *
     * @return string
     */
    protected function getVersion()
    {
        return 'The Stop of Swoole ' . ucfirst($this->argument('type')) . ' Server Version ' . app()->version() . PHP_EOL;
    }

    /**
     * 命令参数
     *
     * @return array
     */
    protected function getArguments()
    {
        return [<commit_msg>code poem<commit_after><?php declare(strict_types=1);
/*
 * This file is part of the ************************ package.
 * _____________                           _______________
 *  ______/     \__  _____  ____  ______  / /_  _________
 *   ____/ __   / / / / _ \/ __`\/ / __ \/ __ \/ __ \___
 *    __/ / /  / /_/ /  __/ /  \  / /_/ / / / / /_/ /__
 *      \_\ \_/\____/\___/_/   / / .___/_/ /_/ .___/
 *         \_\                /_/_/         /_/
 *
 * The PHP Framework For Code Poem As Free As Wind. <Query Yet Simple>
 * (c) 2010-2018 http://queryphp.com All rights reserved.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Leevel\Protocol\Console;

use Exception;
use Leevel\{
    Console\Option,
    Console\Command,
    Console\Argument
};

/**
 * swoole 服务停止
 *
 * @author <NAME> <<EMAIL>>
 * @package $$
 * @since 2017.12.26
 * @version 1.0
 */
class Stop extends Command
{

    /**
     * 命令名字
     *
     * @var string
     */
    protected $strName = 'swoole:stop';

    /**
     * 命令行描述
     *
     * @var string
     */
    protected $strDescription = 'Stop swoole service process';

    /**
     * 响应命令
     *
     * @return void
     */
    public function handle()
    {
        $this->warn($this->getVersion());
        
        $objServer = app('swoole.' . $this->argument('type') . '.server');
        $objServer->setCommand($this);
        $objServer->options($this->parseOption());
        $objServer->stopServer();
    }

    /**
     * 分析参数
     *
     * @return array
     */
    protected function parseOption():array
    {
        $arrOption = [];

        foreach(['host', 'port', 'pid_path'] as $sKey) {
            if(! is_null($this->option($sKey))) {
                $arrOption[$sKey] = $this->option($sKey);
            }
        }

        return $arrOption;
    }

    /**
     * 返回 QueryPHP Version
     *
     * @return string
     */
    protected function getVersion()
    {
        return 'The Stop of Swoole ' . ucfirst($this->argument('type')) . ' Server Version ' . app()->version() . PHP_EOL;
    }

    /**
     * 命令参数
     *
     * @return array
     */
    protected function getArguments()
    {
        return [
{'fraction_non_alphanumeric': 0.166924950188178, 'fraction_numerical': 0.00841266327208324, 'mean_word_length': 1.6436512580456408, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7271763', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1473, 'n_words': 286}