Skip to content

Commit

Permalink
update some info on start panel. (#561)
Browse files Browse the repository at this point in the history
update some info on start panel.
  • Loading branch information
inhere authored Jan 17, 2020
2 parents a23799a + 7463b7e commit 4470cb9
Show file tree
Hide file tree
Showing 91 changed files with 608 additions and 325 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ indent_size = 2
[*.html]
indent_size = 2

[*.xml]
indent_size = 2

[Makefile]
indent_style = tab
67 changes: 44 additions & 23 deletions run.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
/** For Swoole coroutine tests */

use PHPUnit\TextUI\Command;
use Swoft\Stdlib\Helper\Sys;
use Swoole\Coroutine;
use Swoole\ExitException;

Coroutine::set([
'log_level' => SWOOLE_LOG_INFO,
'trace_flags' => 0
]);
use Swoole\Process;

/*
* This file is part of PHPUnit.
Expand Down Expand Up @@ -42,23 +38,14 @@
}

if (!defined('PHPUNIT_COMPOSER_INSTALL')) {
fwrite(STDERR,
'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL . ' composer install' . PHP_EOL . PHP_EOL . 'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL);
die(1);
}
$tips = <<<TXT
You need to set up the project dependencies using Composer:
composer install
You can learn all about Composer on https://getcomposer.org/
TXT;

if (array_reverse(explode('/', __DIR__))[0] ?? '' === 'tests') {
$vendor_dir = dirname(PHPUNIT_COMPOSER_INSTALL);
$bin_unit = "{$vendor_dir}/bin/phpunit";
$unit_uint = "{$vendor_dir}/phpunit/phpunit/phpunit";
if (file_exists($bin_unit)) {
@unlink($bin_unit);
@symlink(__FILE__, $bin_unit);
}
if (file_exists($unit_uint)) {
@unlink($unit_uint);
@symlink(__FILE__, $unit_uint);
}
fwrite(STDERR, $tips . PHP_EOL);
die(1);
}

if (!in_array('-c', $_SERVER['argv'], true)) {
Expand All @@ -68,17 +55,51 @@

require PHPUNIT_COMPOSER_INSTALL;

// php run.php -c src/tcp-server/phpunit.xml
// SWOFT_TEST_TCP_SERVER=1
if (1 === (int)getenv('SWOFT_TEST_SERVER')) {
// Output: "php is /usr/local/bin/php"
[$ok, $ret,] = Sys::run('type php');
if (0 !== $ok) {
exit('php not found');
}

$type = 'tcp';
$php = substr(trim($ret), 7);
$proc = new Process(function (Process $proc) use ($php, $type) {
// $proc->exec($php, [ $dir . '/test/bin/swoft', 'ws:start');
$proc->exec($php, ['test/bin/swoft', $type . ':start']);
});
$pid = $proc->start();
echo "Swoft test server started, PID $pid\n";

// wait server starting...
sleep(2);
echo file_get_contents('http://127.0.0.1:28308/hi');
}

$status = 0;

Coroutine::set([
'log_level' => SWOOLE_LOG_INFO,
'trace_flags' => 0
]);
\Swoft\Co::run(function () {
// Status
global $status;

try {
$status = Command::main(false);
} catch (ExitException $e) {
} catch (Throwable $e) {
$status = $e->getCode();
echo 'ExitException: ' . $e->getMessage(), "\n";
}
});

if (isset($pid) && $pid > 0) {
echo "Stop server on tests end. PID $pid";
$ok = Process::kill($pid, 15);
echo $ok ? " OK\n" : " FAIL\n";
}

exit($status);
2 changes: 1 addition & 1 deletion src/http-server/src/HttpErrorDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function run(Throwable $e, Response $response): Response
$handlers = Swoft::getSingleton(ErrorManager::class);

/** @var HttpErrorHandlerInterface $handler */
if ($handler = $handlers->matchHandler($e, ErrorType::HTTP)) {
if ($handler = $handlers->match($e, ErrorType::HTTP)) {
return $handler->handle($e, $response);
}

Expand Down
1 change: 0 additions & 1 deletion src/http-server/src/Middleware/ValidatorMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface

/* @var Request $request */
[$parsedBody, $query, $path] = $validator->validateRequest($parsedBody, $validates, $query, $path);

if ($notParsedBody) {
$parsedBody = $data;
}
Expand Down
18 changes: 6 additions & 12 deletions src/http-server/test/testing/Controller/ValidatorController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php declare(strict_types=1);


namespace SwoftTest\Http\Server\Testing\Controller;

use Swoft\Http\Message\Request;
Expand Down Expand Up @@ -28,7 +27,7 @@ class ValidatorController
*
* @return array
*/
public function defaultValidator(Request $request)
public function defaultValidator(Request $request): array
{
$data = $request->getParsedBody();
$data['kString'] = $request->parsedBody('string');
Expand All @@ -47,14 +46,11 @@ public function defaultValidator(Request $request)
*
* @return array
*/
public function userValidator(Request $request)
public function userValidator(Request $request): array
{
$data = $request->getParsedBody();

return $data;
return $request->getParsedBody();
}


/**
* @Validate(validator=DefaultValidator::class, type=ValidateType::GET)
* @RequestMapping(route="defaultValidatorQuery")
Expand All @@ -63,7 +59,7 @@ public function userValidator(Request $request)
*
* @return array
*/
public function defaultValidatorQuery(Request $request)
public function defaultValidatorQuery(Request $request): array
{
$data = $request->getParsedQuery();

Expand All @@ -83,11 +79,9 @@ public function defaultValidatorQuery(Request $request)
*
* @return array
*/
public function userValidatorQuery(Request $request)
public function userValidatorQuery(Request $request): array
{
$data = $request->getParsedQuery();

return $data;
return $request->getParsedQuery();
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/http-server/test/unit/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testFailUserValidator(): void
/**
* @throws SwoftException
*/
public function testUserValidator()
public function testUserValidator(): void
{
$data = [
'start' => 12,
Expand All @@ -65,7 +65,7 @@ public function testUserValidator()
/**
* @throws ValidatorException
*/
public function testUserValidator2()
public function testUserValidator2(): void
{
$data = [
'start' => 12,
Expand All @@ -85,7 +85,7 @@ public function testUserValidator2()
/**
* @throws SwoftException
*/
public function testDefaultValidatorQuery()
public function testDefaultValidatorQuery(): void
{
$data = [
'string' => 'string',
Expand All @@ -105,7 +105,7 @@ public function testDefaultValidatorQuery()
/**
* @throws SwoftException
*/
public function testFailUserValidatorQuery()
public function testFailUserValidatorQuery(): void
{
$data = [
'start' => 12,
Expand All @@ -118,7 +118,7 @@ public function testFailUserValidatorQuery()
/**
* @throws SwoftException
*/
public function testUserValidatorQuery()
public function testUserValidatorQuery(): void
{
$data = [
'start' => 12,
Expand All @@ -132,7 +132,7 @@ public function testUserValidatorQuery()
/**
* @throws SwoftException
*/
public function testNoToValidate()
public function testNoToValidate(): void
{
$content = 'swoft framework';
$ext = [
Expand Down
10 changes: 3 additions & 7 deletions src/log/src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,7 @@ public function getProfilesInfos(): string
*/
public function counting(string $name, int $hit, int $total = null): void
{
if (!$this->enable) {
return;
}

if (!$name) {
if (!$this->enable || !$name) {
return;
}

Expand Down Expand Up @@ -452,7 +448,7 @@ public function flushLog(): void
*
* @throws Exception
*/
public function appendNoticeLog($flush = false): void
public function appendNoticeLog(bool $flush = false): void
{
if (!$this->enable) {
return;
Expand All @@ -468,8 +464,8 @@ public function appendNoticeLog($flush = false): void
unset($this->profiles[$cid], $this->countings[$cid], $this->pushlogs[$cid], $this->profileStacks[$cid]);
$levelName = self::$levels[self::NOTICE];

// Json
if ($this->json) {
// Json
$message = $this->formatRecord('', [], self::NOTICE, $levelName, $ts, []);
unset($message['messages']);

Expand Down
6 changes: 2 additions & 4 deletions src/rpc-server/src/Middleware/ValidatorMiddleware.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php declare(strict_types=1);


namespace Swoft\Rpc\Server\Middleware;

use Swoft\Bean\Annotation\Mapping\Bean;
Expand Down Expand Up @@ -34,8 +33,7 @@ class ValidatorMiddleware implements MiddlewareInterface
public function process(RequestInterface $request, RequestHandlerInterface $requestHandler): ResponseInterface
{
[$status, $className] = $request->getAttribute(Request::ROUTER_ATTRIBUTE);

if ($status != Router::FOUND) {
if ($status !== Router::FOUND) {
return $requestHandler->handle($request);
}

Expand All @@ -53,4 +51,4 @@ public function process(RequestInterface $request, RequestHandlerInterface $requ
$request = $request->withParams(array_values($paramsMap));
return $requestHandler->handle($request);
}
}
}
24 changes: 17 additions & 7 deletions src/server/src/Command/BaseServerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

/**
* Class BaseServerCommand
*
* @since 2.0
*/
abstract class BaseServerCommand
Expand Down Expand Up @@ -50,9 +51,10 @@ protected function showServerInfoPanel(Server $server): void

// Port listeners
$panel = $this->appendPortsToPanel($server, $panel);
$title = sprintf('SERVER INFORMATION(v%s)', Swoft::VERSION);

// Show server info
Show::panel($panel, 'Server Information', [
Show::panel($panel, $title, [
'titleStyle' => 'cyan',
]);

Expand Down Expand Up @@ -104,12 +106,19 @@ protected function buildMainServerInfo(Server $server): array
$mainHost = $server->getHost();
$mainPort = $server->getPort();

return [
$info = [
'listen' => $mainHost . ':' . $mainPort,
'type' => $server->getTypeName(),
'mode' => $server->getModeName(),
'worker' => $workerNum,
// 'type' => $server->getTypeName(),
'Mode' => $server->getModeName(),
'Worker' => $workerNum,
];

$taskNum = $settings['task_worker_num'] ?? 0;
if ($taskNum > 0) {
$info['Task worker'] = $taskNum;
}

return $info;
}

/**
Expand All @@ -128,10 +137,11 @@ protected function appendPortsToPanel(Server $server, array $panel): array
continue;
}

$upperName = strtoupper($name);
$upperName = strtoupper($name);
$panel[$upperName] = [
'listen' => $listener->getHost() . ':' . $listener->getPort(),
'type' => $listener->getTypeName()
// 'type' => $listener->getTypeName(),
'(attached)'
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/validator/src/Annotation/Mapping/ValidateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ValidateType
/**
* Get query params
*/
public const GET = 'get';
public const GET = 'get';

/**
* Post form and body
Expand Down
2 changes: 1 addition & 1 deletion src/validator/src/Annotation/Parser/AfterDateParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class AfterDateParser extends Parser
{
/**
* @param int $type
* @param int $type
* @param object $annotationObject
*
* @return array
Expand Down
2 changes: 1 addition & 1 deletion src/validator/src/Annotation/Parser/AlphaDashParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class AlphaDashParser extends Parser
{
/**
* @param int $type
* @param int $type
* @param object $annotationObject
*
* @return array
Expand Down
2 changes: 1 addition & 1 deletion src/validator/src/Annotation/Parser/AlphaNumParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class AlphaNumParser extends Parser
{
/**
* @param int $type
* @param int $type
* @param object $annotationObject
*
* @return array
Expand Down
2 changes: 1 addition & 1 deletion src/validator/src/Annotation/Parser/AlphaParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class AlphaParser extends Parser
{
/**
* @param int $type
* @param int $type
* @param object $annotationObject
*
* @return array
Expand Down
Loading

0 comments on commit 4470cb9

Please sign in to comment.