TYPO3 v9.5.11 Extbase: вставить ServiceObject, сгенерированный ContainerClass, в репозиторий - PullRequest
0 голосов
/ 09 января 2020

Я пытаюсь добавить сервисный объект в мой репозиторий. Я создал различные классы обслуживания в каталоге Classes / Services. Существует также один класс, который я создал, который называется ContainerService, который создает и создает один экземпляр ServiceObject для каждого класса обслуживания.

ContainerService Class:

namespace VendorName\MyExt\Service;

use VendorName\MyExt\Service\RestClientService;

class ContainerService {

    private $restClient;     
    private $otherService;

    /**
     * @return RestClientService
     */
    public function getRestClient() {

        $objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);

        if ($this->restClient === null) {
            $this->restClient = $objectManager->get(RestClientService::class);            
        }

        return $this->restClient;
    }
...

Как я уже сказал, я создаю свои объекты ServiceObject в Класс ContainerService. Теперь я хочу внедрить ContainerService в мой репозиторий и использовать его.

MyRepository Class:

namespace VendorName\MyExt\Domain\Repository;

use VendorName\MyExt\Service\ContainerService;

class MyRepository extends Repository
{    
    /**
     * @var ContainerService
     */
    public $containerService;

    /**
     * inject the ContainerService
     *     
     * @param ContainerService $containerService 
     * @return void
     */
    public function injectContainerService(ContainerService $containerService) {
        $this->containerService = $containerService;
    }

    // Use Objects from The ContainerService

    public function findAddress($addressId) {
        $url = 'Person/getAddressbyId/' 
        $someData = $this->containerService->getRestClient()->sendRequest($url)
    return $someData;
    }

В MyController я получаю $ someData из моей функции findAddress и выполняю с ней некоторую работу.

Но когда я вызываю свою страницу, я получаю следующее сообщение об ошибке:

(1/2) #1278450972 TYPO3\CMS\Extbase\Reflection\Exception\UnknownClassException

Class ContainerService does not exist. Reflection failed.

Уже пытался перезагрузить все кэши, и выгрузка автозагрузки также не помогла. Не устанавливал TYPO3 с composer. Я ценю любой совет или помощь! Спасибо!

1 Ответ

0 голосов
/ 09 января 2020

Фактически обнаружена проблема. В классе MyRepository возникла проблема с аннотациями и TypeHint:

namespace VendorName\MyExt\Domain\Repository;

use VendorName\MyExt\Service\ContainerService;

class MyRepository extends Repository
{    
    /**
     *** @var \VendorName\MyExt\Service\ContainerService**
     */
    public $containerService;

    /**
     * inject the ContainerService
     *     
     * @param \VendorName\MyExt\Service\ContainerService $containerService 
     * @return void
     */
    public function injectContainerService(\VendorName\MyExt\Service\ContainerService $containerService) {
        $this->containerService = $containerService;
    }

    // Use Objects from The ContainerService

    public function findAddress($addressId) {
        $url = 'Person/getAddressbyId/' 
        $someData = $this->containerService->getRestClient()->sendRequest($url)
    return $someData;
    }

Теперь это работает.

...