使用Guzzle和FOSRestBundle时出现填充Symfony3请求ParameterBag的问题

时间:2016-09-01 13:37:16

标签: php symfony guzzle fosrestbundle

我们目前正在使用以下内容..

  • PHP 7.0
  • Symfony 3.1.3
  • Guzzle 6.2.1

在Symfony命令中,我们正在构建一个JSON请求,该请求将被发送回API端点(在同一个应用程序中),代码看起来像这样......

TestCommand.php

        $client = new Client(['verify' => false, 'query' => ["api_key" => $this->api_key]]);
        $uri = $this->router->generate('order_create', [], UrlGeneratorInterface::ABSOLUTE_URL);


        $request = new Request('POST', $uri, ['headers'=>['content-type' => 'application/json']],
            json_encode([
                'userId'=>$basket->getUserId(),
                'store'=>$basket->getStore(),
                'locale'=>$basket->getLocale(),
                'billingAddress'=>$basket->getBillingAddress()->getId(),
                'shippingAddress'=>$basket->getShippingAddress()->getId(),
                'currency'=>$basket->getCurrency(),
                'coupon'=>$basket->getCoupon(),
                'utmSource'=>$basket->getUtmSource(),
                'utmMedium'=>$basket->getUtmMedium(),
                'utmTerm'=>$basket->getUtmTerm(),
                'utmContent'=>$basket->getUtmContent(),
                'utmCampaign'=>$basket->getUtmCampaign()
            ]));

        $response = $client->send($request);

接收此请求的方法如下所示......

TestController.php

  class TestController extends FOSRestController{
    /**
 * Creates a new order and returns its meta information.
 * @param Request $request
 * @ApiDoc(
 *   resource = true,
 *   section = "Order Operations",
 *   statusCodes = {
 *     200 = "Returned when successful",
 *     500 = "Returned when we are unable to create a Order"
 *   },
 *  parameters={
 *      {
 *          "name"="store",
 *          "dataType"="string",
 *          "required"=true,
 *          "requirement"="DE | CH | EU | AT",
 *          "description"="What is the store the Order is coming from."
 *      },
 *      {
 *          "name"="locale",
 *          "dataType"="string",
 *          "required"=true,
 *          "requirement"="DE | EN",
 *          "description"="What is the Orders locale."
 *      },
 *      {
 *          "name"="billingAddress",
 *          "dataType"="integer",
 *          "format"="12 | 334",
 *          "required"=false,
 *          "description"="the id of an AppBundle\Address entity to use as the billing address."
 *      },
 *      {
 *          "name"="shippingAddress",
 *          "dataType"="integer",
 *          "format"="12458 | 65845",
 *          "required"=false,
 *          "description"="the id of an AppBundle\Address entity to use as the shipping address."
 *      },
 *      {
 *          "name"="coupon",
 *          "dataType"="string",
 *          "format"="eg: 50OFF, VATERTAG20",
 *          "required"=false,
 *          "description"="the coupon that has been redeemed with this Order."
 *      },
 *      {
 *          "name"="utmSource",
 *          "dataType"="string",
 *          "format"="eg: SEO, NEWSLETTER, DISPLAY",
 *          "required"=false,
 *          "description"="the UTM source of this Order."
 *      },
 *      {
 *          "name"="utmMedium",
 *          "dataType"="string",
 *          "format"="eg: Plista, Reichweite",
 *          "required"=false,
 *          "description"="the UTM medium of this Order."
 *      },
 *      {
 *          "name"="utmTerm",
 *          "dataType"="string",
 *          "required"=false,
 *          "format"="RasierKlingen, Razorblades.",
 *          "description"="the utm term of this Order to identify keywords used in your ad."
 *      },
 *      {
 *          "name"="utmContent",
 *          "dataType"="string",
 *          "format"="eg: crm_alpha_upsell_a, crm_alpha_upsell_b",
 *          "required"=false,
 *          "description"="the utm content, helpful for A/B Testing."
 *      },
 *      {
 *          "name"="utmCampaign",
 *          "dataType"="string",
 *          "format"="DISCRITDE, COPERFNETDE",
 *          "required"=false,
 *          "description"="the utm campaign - OLD ICODE."
 *      },
 *      {
 *          "name"="currency",
 *          "dataType"="string",
 *          "format"="EUR | CHF | GBP | USD",
 *          "required"=false,
 *          "description"="The currency of this Order - should one not be set EUR will be selected."
 *      },
 *      {
 *          "name"="userId",
 *          "dataType"="integer",
 *          "format"="1233 | 5512",
 *          "required"=false,
 *          "description"="If this Order belongs to an existing user then this should be their user_id."
 *      },
 *      {
 *          "name"="paymentToken",
 *          "dataType"="integer",
 *          "format"="123 | 22344",
 *          "required"=false,
 *          "description"="the payment token that is to be used in recurrence of this order."
 *      }
 *  }
 * )
 *
 * @Annotations\Post("/",name="order_create",defaults={"_format" = "json"})
 * @return Order
 * @throws \Exception;
 */
public function  postOrderAction(Request $request)
{
        $params = $request->request->all();
        *some other code...*
}

}

我们遇到的问题是在我们的开发环境(OS X)$ request-> request-> all();使用请求参数填充但是当我们部署到我们的登台服务器时,参数没有被填充,并且ParameterBag完全为空。

任何人都可以指出问题是什么吗?

注意:我们已经检查过PHP和供应商版本是否匹配,我们在设置中可以看到的唯一区别是,在我们的本地开发环境中,我们使用Apache,但在我们的staging环境中,我们使用NGINX。

感谢您的帮助!

0 个答案:

没有答案