API サーバー STUB を作成中ですが、これをできるだけシンプルにしたかったので、Laravel FrameWork を使用しないことにしました。
ほとんどのアプリを実行しましたが、Client SDK がサーバー STUB に POST パラメーターを送信する時点で、$_POST の代わりに Illuminate Request ライブラリを使用したいと考えていました。
これが今の私のアプリの流れです (実際の問題は一番下に説明があります)
パブリック ディレクトリの index.php が、ベンダーの自動ロードとデータベース接続のロードを処理する bootstrap.php ファイルを呼び出しています。
<?php
require 'vendor/autoload.php';
use Dotenv\Dotenv;
use Src\System\DatabaseConnector;
$dotenv = new DotEnv(__DIR__);
$dotenv->load();
$DatabaseConnector = new DatabaseConnector();
$dbConnection = $DatabaseConnector->getConnection();
$tkObj = $DatabaseConnector->getToolKit();
その後、index.php でコントローラーを呼び出します。
$controller = new OrderValidationController($dbConnection, $tkObj, $requestMethod);
$controller->processRequest();
私のコントローラーは次のようになります。
<?php
namespace Src\Controller;
use Src\Gateway\OrderValidationGateway;
use Src\Gateway\ApiLogGateway;
class OrderValidationController {
private $db;
private $tkObj;
private $requestMethod;
private $orderValidation;
public function __construct($db, $tkObj, $requestMethod)
{
$this->db = $db;
$this->tkObj = $tkObj;
$this->requestMethod = $requestMethod;
$this->OrderValidation = new OrderValidationGateway($db, $tkObj);
}
public function processRequest()
{
switch ($this->requestMethod) {
case 'GET':
break;
case 'POST':
$response = $this->postOrderValidation();
break;
case 'PUT':
break;
case 'DELETE':
break;
default:
$response = $this->notFoundResponse();
break;
}
header($response['status_code_header']);
if ($response['body']) {
echo $response['body'];
}
}
private function unprocessableEntityResponse()
{
$response['status_code_header'] = 'HTTP/1.1 422 Unprocessable Entity';
$response['body'] = json_encode([
'error' => 'Invalid input'
]);
return $response;
$ApiLogGateway = new ApiLogGateway($this->db);
$ApiLogGateway->jsonEventLog($response['body']);
}
private function notFoundResponse()
{
// Debug Info
$response['status_code_header'] = 'HTTP/1.1 404 Not Found';
$response['body'] = null;
return $response;
}
private function postOrderValidation()
{
$result = $this->OrderValidation->OrderValidation();
$response['status_code_header'] = 'HTTP/1.1 200 OK';
$response['body'] = json_encode($result);
return $response;
}
}
?>
コントローラはゲートウェイを呼び出します
<?php
namespace Src\Gateway;
use Illuminate\Http\Request;
class OrderValidationGateway {
private $db = null;
private $tkObj = null;
public function __construct($db, $tkObj)
{
$this->db = $db;
$this->tkObj = $tkObj;
}
public function OrderValidation(){
$this->tkObj->CLCommand("ADDLIBLE LIB(G2001RY)");
die($this->req->PV_SITE);
$ins = array(
"PV_SITE"=>array("type"=>"CHAR","value"=>$request->PV_SITE, "length"=>"2", "operation"=>'in'),
"PV_DEP"=>array("type"=>"CHAR","value"=>$request->PV_DEP, "length"=>"8", "operation"=>'in'),
"PV_WAVEID"=>array("type"=>"DECIMAL","value"=>$request->PV_WAVEID, "length"=>"7,0", "operation"=>'in'),
"PV_DOCNBR"=>array("type"=>"DECIMAL","value"=>$request->PV_DOCNBR, "length"=>"7,0", "operation"=>'in'),
"PV_DOID"=>array("type"=>"DECIMAL","value"=>$request->PV_DOID, "length"=>"7,0", "operation"=>'in'),
"PV_DOCLIN"=>array("type"=>"DECIMAL","value"=>$request->PV_DOCLIN, "length"=>"4,0", "operation"=>'in'),
"PV_MVTNBR"=>array("type"=>"DECIMAL","value"=>$request->PV_MVTNBR, "length"=>"9,0", "operation"=>'in'),
"PV_WRH"=>array("type"=>"CHAR","value"=>$request->PV_WRH, "length"=>"3", "operation"=>'in'),
"PV_ADDR"=>array("type"=>"CHAR","value"=>$request->PV_ADDR, "length"=>"8", "operation"=>'in'),
"PV_EXTCOD"=>array("type"=>"CHAR","value"=>$request->PV_EXTCOD, "length"=>"8", "operation"=>'in'),
"PV_OBJNBR"=>array("type"=>"DECIMAL","value"=>$request->PV_OBJNBR, "length"=>"9,0", "operation"=>'in'),
"PV_ITM"=>array("type"=>"CHAR","value"=>$request->PV_ITM, "length"=>"20", "operation"=>'in'),
"PV_STKNAT"=>array("type"=>"CHAR","value"=>$request->PV_STKNAT, "length"=>"2", "operation"=>'in'),
"PV_LOT"=>array("type"=>"CHAR","value"=>$request->PV_LOT, "length"=>"13", "operation"=>'in'),
"PV_CNTNBR"=>array("type"=>"DECIMAL","value"=>$request->PV_CNTNBR, "length"=>"7,0", "operation"=>'in'),
"PV_CNTTYP"=>array("type"=>"CHAR","value"=>$request->PV_CNTTYP, "length"=>"1", "operation"=>'in'),
"PV_CNTCOD"=>array("type"=>"CHAR","value"=>$request->PV_CNTCOD, "length"=>"2", "operation"=>'in'),
"PV_QTYUNT"=>array("type"=>"DECIMAL","value"=>$request->PV_QTYUNT, "length"=>"7,0", "operation"=>'in'),
"PV_LPNNBR"=>array("type"=>"CHAR","value"=>$request->PV_LPNNBR, "length"=>"25", "operation"=>'in'),
"PV_MVTDAT"=>array("type"=>"CHAR","value"=>$request->PV_MVTDAT, "length"=>"10", "operation"=>'in'),
"PV_MVTTIM"=>array("type"=>"CHAR","value"=>$request->PV_MVTTIM, "length"=>"8", "operation"=>'in'),
"PV_SERIAL"=>array("type"=>"CHAR","value"=>$request->PV_SERIAL, "length"=>"20", "operation"=>'in'),
"PV_USERID"=>array("type"=>"CHAR","value"=>$request->PV_USERID, "length"=>"20", "operation"=>'in')
);
$in = $this->arrayConvert($ins, $tkobj);
$result = $tkobj->PgmCall("API_POVLD", "G2001RY", $in, NULL);
return $result;
}
public function arrayConvert($arrays, $tkobj){
foreach($arrays as $key=>$line){
$in[] = $tkobj->AddParameterChar($line["operation"], $line["length"], $key, $key, $line["value"]);
}
return $in;
}
public function req(Request $request) {
return $request;
}
}
したがって、私の問題は、 $this->req->PV_SITE を使用して POST パラメータを受信できないように見えることです
ちなみに、私はそれを実行して動作させました
$request = new Request();
$request->replace($_POST);
しかし、$request は GET、PUT、POST[...] に基づいて自動的に構築されていると思いました。それとも私は何かを逃しましたか?