Skip to content

Commit

Permalink
up fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kiss291323003 committed Jul 4, 2019
1 parent da9f923 commit e60a50d
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"require": {
"php": ">=7.1.0",
"ext-swoole":"^4.4.0",
"easyswoole/component": "^1.7"
"easyswoole/component": "^1.7",
"easyswoole/http": "^1.3"
},
"require-dev": {
"easyswoole/swoole-ide-helper": "^1.2"
Expand Down
16 changes: 16 additions & 0 deletions src/Http/Controller/Api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php


namespace EasySwoole\Tracker\Http\Controller;


use EasySwoole\Http\AbstractInterface\Controller;

class Api extends Controller
{

function index()
{
$this->response()->write('api');
}
}
61 changes: 61 additions & 0 deletions src/Http/ServerConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php


namespace EasySwoole\Tracker\Http;


class ServerConfig
{
protected $port = 9502;
protected $listenAddress = '0.0.0.0';
protected $controllerNamaSpace = 'EasySwoole\\Tracker\\Http\\Controller\\';

/**
* @return int
*/
public function getPort(): int
{
return $this->port;
}

/**
* @param int $port
*/
public function setPort(int $port): void
{
$this->port = $port;
}

/**
* @return string
*/
public function getListenAddress(): string
{
return $this->listenAddress;
}

/**
* @param string $listenAddress
*/
public function setListenAddress(string $listenAddress): void
{
$this->listenAddress = $listenAddress;
}

/**
* @return string
*/
public function getControllerNamaSpace(): string
{
return $this->controllerNamaSpace;
}

/**
* @param string $controllerNamaSpace
*/
public function setControllerNamaSpace(string $controllerNamaSpace): void
{
$this->controllerNamaSpace = $controllerNamaSpace;
}

}
31 changes: 31 additions & 0 deletions src/Http/ServerProcess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php


namespace EasySwoole\Tracker\Http;


use Co\Http\Server;
use EasySwoole\Component\Process\AbstractProcess;
use EasySwoole\Http\Request;
use EasySwoole\Http\Response;
use EasySwoole\Http\WebService;

class ServerProcess extends AbstractProcess
{

protected function run($arg)
{
/** @var ServerConfig $config */
$config = $this->getConfig()->getArg();
go(function ()use($config) {
$server = new Server($config->getListenAddress(), $config->getPort(), false);
$webService = new WebService($config->getControllerNamaSpace());
$server->handle('/', function ($request, $response)use($webService){
$request = new Request($request);
$response = new Response($response);
$webService->onRequest($request,$response);
});
$server->start();
});
}
}

0 comments on commit e60a50d

Please sign in to comment.