0

I am integrating a few php classes into a TYPO3 6.2 extension created with extension_builder. The extbase version is also 6.2.

I think I followed the indications on https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Autoloading/Index.html

  • Namespaced the classes (correctly?)

  • As I think I'm using namespaces, I didn't name the Classes in the form of Tx_MyExtension_Utility_FooBar

  • Injected the class with @inject annotation as suggested on https://wiki.typo3.org/Dependency_Injection

These are the concerned files:

EXT:apievents/Classes/Utility/SomeClass.php:

class SomeClass {
  // do something
}

EXT:apievents/Classes/Controller/ImportCommandController.php

<?php
namespace STUBR\Apievents\Controller;

// Copyright, Package, License ...

class ImportCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController {

    /**
    * @var \namespace STUBR\Apievents\Utility\SomeClass
    * @inject
    */
    protected $SomeClass;
    // do something
 }

Which when I run it (it's a scheduler task) gives me the nicely formatted error

Execution of task "Extbase CommandController Task (extbase)" failed with the following message: Could not analyse class:namespace STUBR\Apievents\Utility\SomeClass maybe not loaded or no autoloader?

So something must be missing for the class to be loaded. What am I missing or doing wrong?

1 Answer 1

2

Change your injection code to

/**
 * @var \STUBR\Apievents\Utility\SomeClass
 * @inject
 */
 protected $someClass;

In the @var annotation you just specify the fully qualified class name. Nothing more. Nothing less. Make sure that you have the namespace set in you utility class as well

namespace STUBR\Apievents\Utility;
Sign up to request clarification or add additional context in comments.

3 Comments

ahhh... now the namespace hijacks other Predefined PHP classes in that class, like throw new Exception('Text'); or new SoapClient(): Fatal error: Class 'STUBR\Apievents\Utility\SoapClient' not found. Do I have to inject those too?
Ah I think I've got it: have to escape the predefined classes to the global space, as such: new \SoapClient()
Yes correct, if you dont append the \ php will look for the class in the current namespace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.