0

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.

  • the .Classes or ./packages won't work. Try to give the complete path to your classes, from the composer.json position. – Aristeidis Karavas Jan 02 '20 at 14:20
  • I deleted the starting ./ but the relative paths are alright...? – christian2222 Jan 02 '20 at 14:39
  • 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 Jan 02 '20 at 14:41
  • . ├── 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 Jan 02 '20 at 15:02
  • would you mind include the structure on your question, because it does not make any sense here :P . – Aristeidis Karavas Jan 02 '20 at 15:03
  • sorry, done above – christian2222 Jan 02 '20 at 15:13
  • first of all you need to move your extension in the ext folder under public/typo3conf/ext . I dont know if it is intentional but your missing some key files like ext_emconf.php or ext_localconf.php as well. Then on your composer.json include on your psr (assuming that your composer is on the same folder with public and packages) "CM\\parser\\": "public//typo3conf/ext/cm-parser/Classes". After you re done, update the folder structure in your post. – Aristeidis Karavas Jan 02 '20 at 15:18
  • If I follow your instructions I get an error parser already installed – christian2222 Jan 02 '20 at 17:35

2 Answers2

2

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.

Rudy Gnodde
  • 4,286
  • 2
  • 12
  • 34
  • after correcting the small with a capital P in the extension composer.json and inserting the autoload too into the root composer.json with a capital P the extension wokrs fine. Thank you very much for all of your help – christian2222 Jan 03 '20 at 16:05
1

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.

Michael
  • 645
  • 5
  • 12
  • I've done all the steps above (I had to use :@dev at the composer require command and I had to rename my extension key from cm_parser to parser. At least my typo3 instance is working now. I pushed my source code to https://github.com/christian2222/example2 the problem is that the Controller does not exist. Reflection failed. message remains as I open my frontend of my extension. – christian2222 Jan 03 '20 at 11:16