Symfony 3.4 Сериализатор JMS DoctrineObjectConstructor :: __ construct () ожидает ManagerRegistry, данный экземпляр Doctrine \ Bundle \ DoctrineBundle \ Registry - PullRequest
1 голос
/ 12 июля 2020

Пожалуйста, помогите мне, я застрял здесь. Я недавно обновил версию Symfony с 2.8 до Symfony 3.4 LTS. Все работает нормально, за исключением конечной точки Rest API, где я расширяю Sonata \ UserBundle \ Controller \ Api \ UserController на моем настраиваемом контроллере. Когда я запускаю API, я получаю следующую ошибку:

Type error: Argument 1 passed to JMS\Serializer\Construction\DoctrineObjectConstructor::__construct() must be an instance of Doctrine\Persistence\ManagerRegistry, instance of Doctrine\Bundle\DoctrineBundle\Registry given, called in /var/www/html/var/cache/dev/Container9bzqz8e/appDevDebugProjectContainer.php on line 3303

Это началось после обновления.

My Controller

use FOS\RestBundle\View\View;
use Sonata\UserBundle\Controller\Api\UserController as SonataUserController;
use League\Fractal\Manager;
use League\Fractal\Resource\Item;

class CustomerUserController extends SonataUserController {
protected $formFactory;

/**
 * @var CustomerUserService
 */
private $customerUserService;

/**
 * @var Manager
 */
private $fractal;

/**
 * CustomerUserController constructor.
 * @param UserManagerInterface $userManager
 * @param FormFactory $formFactory
 * @param CustomerUserService $customerUserService
 * @param LoggerInterface $logger
 * @param GroupManagerInterface $groupManager
 */
public function __construct(
    UserManagerInterface $userManager,
    FormFactory $formFactory,
    CustomerUserService $customerUserService,
    LoggerInterface $logger,
    GroupManagerInterface $groupManager
) {
    parent::__construct($userManager, $groupManager, $formFactory);

    $this->formFactory = $formFactory;
    $this->customerUserService = $customerUserService;
    $this->fractal = new Manager();
    $this->logger = $logger;
    $this->fractal->setSerializer(new CleanCollectionArraySerializer());
}

/**
 * Retrieves a specific CustomerUser
 *
 * @param integer $id
 * @return array
 */
public function getUserAction($id)
{
    /** @var User $user */
    $user = parent::getUserAction($id);
    $this->ensureUserIsCustomerUser($user);

    $this->fractal->parseIncludes('customer');
    $userObject = new Item($user, new UserTransformer());
    return $this->fractal->createData($userObject)->toArray();
}}

Composer Информация

Я добавил только соответствующие пакеты

doctrine/annotations                     1.10.3          
doctrine/cache                           1.10.2          
doctrine/collections                     1.6.6           
doctrine/common                          v2.8.1          
doctrine/data-fixtures                   1.3.3           
doctrine/dbal                            v2.6.3          
doctrine/doctrine-bundle                 1.10.3          
doctrine/doctrine-cache-bundle           1.4.0           
doctrine/doctrine-fixtures-bundle        v2.4.1          
doctrine/doctrine-migrations-bundle      v1.3.2          
doctrine/inflector                       1.4.3           
doctrine/instantiator                    1.0.5           
doctrine/lexer                           1.2.1           
doctrine/migrations                      v1.8.1          
doctrine/orm                             v2.5.14
friendsofsymfony/rest-bundle             2.8.1           
friendsofsymfony/user-bundle             v2.1.2
jms-serializer/serializer                1.3.0           
jms/metadata                             1.7.0           
jms/parser-lib                           1.0.0           
jms/serializer                           1.14.1          
jms/serializer-bundle                    2.4.4
sonata-project/user-bundle               4.5.1

Config.yaml

jms_serializer:
    metadata:
        directories:
            AppUserBundle:
                namespace_prefix: "App\\UserBundle"
                path: "@AppUserBundle/Resources/config/serializer"
            SonataUserBundle:
                namespace_prefix: "Sonata\\UserBundle"
                path: "@AppUserBundle/Resources/config/serializer"
            FOSUserBundle:
                namespace_prefix: "FOS\\UserBundle"
                path: "@AppUserBundle/Resources/config/serializer"


fos_rest:
    param_fetcher_listener: true
    body_listener:          true
    format_listener:        true
    view:
        view_response_listener: 'force'
        formats:
            json: true
        force_redirects:
            html: true
            json: true
    routing_loader:
        default_format: json
    body_converter:
        enabled: true
        validate: true
    disable_csrf_role: ROLE_API
    exception:
        enabled: true
        messages:
            'App\UserBundle\Controller\Api\Exception': true

Файл Serlializer Entity.User.yaml

Sonata\UserBundle\Model\User:
    exclusion_policy: ALL
    properties:
        firstname:
            expose: true
            groups: [sonata_api_read, sonata_api_write]
        lastname:
            expose: true
            groups: [sonata_api_read, sonata_api_write]

FOS\UserBundle\Model\User:
    exclusion_policy: ALL
    properties:
        id:
            expose: true
            groups: [sonata_api_read, sonata_api_write]
        username:
            expose: true
            skip_when_empty: true
            groups: [sonata_api_read, sonata_api_write]
        email:
            expose: true
            skip_when_empty: true
            groups: [sonata_api_read, sonata_api_write]
        enabled:
            expose: true
            groups: [sonata_api_read, sonata_api_write]
        locked:
            expose: true
            groups: [sonata_api_read, sonata_api_write]
        expired:
            expose: true
            groups: [sonata_api_read, sonata_api_write]
        credentialsExpired:
            expose: true
            skip_when_empty: true
            groups: [sonata_api_read, sonata_api_write]

Любая помощь очень ценится.

1 Ответ

1 голос
/ 14 июля 2020

Мне удалось решить проблему, явно добавив

"jms / serializer-bundle": "^ 1.0 | ^ 2.4"

в мой composer . json файл.

Надеюсь, это кому-то поможет

...