0
votes

I have a typo3 extension (created with extension manager) and it seems no matter what I try I always get the following error:

Class CM\Parser\Controller\ParserController does not exist. Reflection failed.

I used the explanations for this problem TYPO3 tutorial extension, controller does not exist and "Controller does not exist. Reflection failed." TYPO3. Neither of them seem to work. My composer.json in the root directory has the following entry:

    "autoload": {
    "psr-4": {
    "CM\\parser\\": "./packages/cm-parser/Classes"
    }
}

My typo3conf/ext folder has a symlink on packages/cm-parser. My composer.json inside the extension directory (packages/cm-parser) has the entry:

    "autoload": {
    "psr-4": {
       "CM\\parser\\": "./Classes"
    }
   }

Thanks in advance for any help.

My directory structure looks like this (starting in /opt/lampp/htdocs/my-new-project) which is a typo3 v9.5 installation

    > .
    ├── packages
    │   └── cm-parser
    │       ├── Classes
    │       ├── Configuration
    │       ├── Documentation.tmpl
    │       ├── Resources
    │       └── Tests
    ├── public
    │   ├── fileadmin
    │   │   ├── _processed_
    │   │   ├── _temp_
    │   │   └── user_upload
    │   ├── typo3
    │   │   └── sysext
    │   ├── typo3conf
    │   │   ├── ext
    │   │   └── l10n
    │   ├── typo3temp
    │   │   ├── assets
    │   │   └── var
    │   └── uploads
    │       └── tx_extensionbuilder
    ├── var
    ...

In my typo3conf/ext directory there is a symlink called parser to packages/cm-parser (I think the composer created that for me). So I hope this symlink works for Typo3. The files ext_emconf.php and ext_localconf.php are also in the right place. The folder structure above only displays my folders (tree -L 3) up to the third level.

2
the .Classes or ./packages won't work. Try to give the complete path to your classes, from the composer.json position. - Aristeidis Karavas
I deleted the starting ./ but the relative paths are alright...? - christian2222
i do not know how is your directory structure. You should take the absolute path from your composer.json to your extension classes. sth llike that: htdocs/typo3conf/ext/cm-parser/Classes . But this is my directory structure. My composer.json is located in the same folder with htdocs, so i define the path from there - Aristeidis Karavas
. ├── packages │ └── cm-parser │ ├── Classes │ ├── Configuration │ ├── Documentation.tmpl │ ├── Resources │ └── Tests ├── public │ ├── fileadmin │ │ ├── processed │ │ ├── temp │ │ └── user_upload │ ├── typo3 │ │ └── sysext │ ├── typo3conf │ │ ├── ext │ │ └── l10n │ ├── typo3temp │ │ ├── assets │ │ └── var │ └── uploads │ └── tx_extensionbuilder this is a part of my directory structure produced by tree starting in /opt/lampp/htdocs/my-new-project where my-new-project is a typo3 install - christian2222
would you mind include the structure on your question, because it does not make any sense here :P . - Aristeidis Karavas

2 Answers

1
votes

The controller class is CM\Parser\Controller\ParserController, while in your composer.json you're using CM\\parser\\ (with a lowercase p) in the PSR4 autoload. This should be CM\\Parser\\

After changing this you need to of course run composer dumpautoload to reload the autoload information.

0
votes

In your root composer.json file:

➊ You do not need the PSR-4 autoload section for "CM\\parser\\".
➋ You possibly have to add the path to packages/* as a repository.
➌ You have to include the composer namespace of your extension.

In your file system:

➍ You do not need typo3conf/ext/ as a symbolic link to packages/.

Try the following changes:

In your root composer.json file, remove the PSR-4 autoload section as outlined above. Add the packages/ directory as a path under repositories. For example:

{
  "repositories": [
    {
      "type": "composer",
      "url": "https://composer.typo3.org/"
    },
    {
      "type": "path",
      "url": "packages/*"
    }
  ],
 ...
}

Store your extension code in the following path: packages/parser/.

Assuming your extension key reads parser and your vendor name is CM, the composer namespace becomes cm/parser. Add this as a requirement to the composer config file. You can use the following command on the command line:

composer require cm/parser:dev-master

This assumes, that packages/parser/ is a valid Git repository and has the master branch (do not use a version in the extension's composer.json file).

If the local Git repository and version (in the example above: dev-master) can be found, composer will automatically install all dependencies as required and it will create a symbolic link:

typo3conf/ext/parser -> ../../../packages/parser/

Also double check if all PHP files show the correct PHP namespace: CM\Parser\... and your controller class name reads ParserController.

If you can share your TYPO3 extension code, upload it to GitHub (or any other place) and share the link here. This way people can review your code and possibly spot further errors.