FOSRestBundle - «Неопределенное смещение: 0» в строке vendor \ friendsofsymfony \ rest-bundle \ EventListener \ ViewResponseListener.php 99 - PullRequest
0 голосов
/ 23 октября 2019

У меня проблема, скорее всего, с конфигурацией FOSRestBundle. У меня есть это сообщение:

"Undefined offset: 0" in ...\vendor\friendsofsymfony\rest-bundle\EventListener\ViewResponseListener.php line 99

Это происходит, когда я возвращаю что-то, перехваченное ViewResponseListener, например, в этом фрагменте кода:

 /**
  * Show an ingredient
  * @FOSRest\Get(path="/api/ingredient/{ingredient}", requirements={ "ingredient"="\d+" }, name="show_ingredient")
  * @FOSRest\View(StatusCode = 200, populateDefaultVars=false, serializerGroups={ "Show", "creator" : { "Short" }, "types" : {"Short"} })
  *
  * @param Ingredient $ingredient
  * @return Ingredient|View|Response
  */
 public function showIngredientAction(Ingredient $ingredient) {
     return $ingredient;
 }

Это моя конфигурация FOSRest:

 fos_rest:
  routing_loader:
    default_format: json
    include_format: false
  body_listener: true
  format_listener:
    rules:
      - {  path: '^/', priorities: ['json'], fallback_format: json, prefer_extension: false }
  param_fetcher_listener: true
  access_denied_listener:
    json: true
  view:
    view_response_listener: true
    formats:
      json: true
  body_converter:
    enabled: true

РЕДАКТИРОВАТЬ

Мой композитор:

{
    "type": "project",
    "license": "proprietary",
    "require": {
        "php": "^7.1.3",
        ...
        "friendsofsymfony/oauth-server-bundle": "^1.6",
        "friendsofsymfony/rest-bundle": "^2.5",
        "symfony/flex": "^1.3.1",
        ...
    },
    ...
    "extra": {
        "symfony": {
            "allow-contrib": false,
            "require": "4.3.*"
        }
    }
}

РЕДАКТИРОВАТЬ 2

У меня есть некоторые новости. Я проверил на другом ПК, где приложение работает. Кажется, у нас есть некоторые различия в файлах вендора framework-extra-bundle.

namespace Sensio\Bundle\FrameworkExtraBundle\Configuration;
/**
* The Template class handles the Template annotation parts.
*
* @author Fabien Potencier <fabien@symfony.com>
* @Annotation
 */
class Template extends ConfigurationAnnotation
{

         ....

        ----------------- After --------------------

        /**
         * The controller (+action) this annotation is set to.
         *
         * @var array
         */
        private $owner = [];

       ----------------- Before --------------------
        /**
         * The controller (+action) this annotation is set to.
         *
         * @var array
         */
        private $owner;
...