-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da9f923
commit e60a50d
Showing
4 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} | ||
} |