1

I am developing an extension for TYPO3 v9.5.9, and have written all of my code, however when I try using the extension I get an error message saying

Class Secsign\Secsign\Controller\SecsignController does not exist. Reflection failed.

enter image description here

<?php
namespace Secsign\Secsign\Controller;

$apiPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('secsign') . 'Resources/Public/SecSignIDApi/phpApi/SecSignIDApi.php';
require_once($apiPath);

use AuthSession;
use SecSignIDApi;
use \TYPO3\CMS\Core\Utility\GeneralUtility;


/**
 * SecsignController
 */
class SecsignController extends ActionController
{...}

The controller does exist, but for some reason it can't be found. Where does this error occur? How do I fix it? Any hints are welcome.

The composer.json file looks like this:

{
    "name": "secsign/secsign",
    "type": "typo3-cms-extension",
    "description": "This extension allows users to authenticate using their smart phone running the SecSign App.",
    "authors": [
        {
            "name": "SecSign Technologies Inc.",
            "role": "Developer"
        }
    ],
    "require": {
        "typo3/cms-core": "^9.5"
    },
    "autoload": {
        "psr-4": {
            "Secsign\\Secsign\\": "Classes",
            "TYPO3\\CMS\\Secsign\\": "public/typo3conf/ext/secsign/Classes/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Secsign\\Secsign\\Tests\\": "Tests"
        }
    },
    "replace": {
        "secsign/secsign": "self.version",
        "typo3-ter/secsign": "self.version"
    }
}
Droemmelbert
  • 155
  • 1
  • 13
  • Did you tried flushing system cache and rebuild PHP autoload Information? – Geee Oct 21 '19 at 11:25
  • Yes I have tried that multiple times already. No luck. – Droemmelbert Oct 21 '19 at 11:48
  • Try removing backslashes from the namespace. See the @jokumer's answer [here](https://stackoverflow.com/questions/42133409/typo3-tutorial-extension-controller-does-not-exist) – Geee Oct 21 '19 at 11:53
  • 1) a `use` statement with a leading backslash is not recommended (but should work anyway) 2) how does your composer.json look like? – Wolfgang Oct 21 '19 at 12:09
  • @GhanshyamBhava would I have to do that in every single class I have? – Droemmelbert Oct 21 '19 at 12:10
  • @Wolfgang I added the composer.json to the question description! – Droemmelbert Oct 21 '19 at 12:12
  • there you have your answer. `"TYPO3\\CMS\\Secsign\\": "public/typo3conf/ext/secsign/Classes/"` makes no sense, change this to `"Secsign\\Secsign\\": "Classes/"` and it should work – Wolfgang Oct 21 '19 at 12:13
  • That is literally the line above that. I deleted the line you said was wrong, unistalled the extension flushed all caches and installed the extension again and it still gives me the exact same error message. – Droemmelbert Oct 21 '19 at 12:22
  • Try to dump the autoloader information `composer dump-autoload` or see https://docs.typo3.org/m/typo3/reference-coreapi/9.5/en-us/ApiOverview/Autoloading/Index.html for further troubleshooting – Wolfgang Oct 21 '19 at 13:57
  • Unfortunately that also does not do the trick. Do you know which method or class is throwing this error message? – Droemmelbert Oct 28 '19 at 13:40

1 Answers1

3

There are 2 Ways how you can solve this:

1. Load your Extension via the project composer.json

Create a folder for your custom Extensions, I named it here Extensions and move all your custom Extensions into this folder. Your public/typo3conf/ext/ folder should now hold only Extensions loaded by composer and can be cleared at any time since a simple composer i will bring all Extensions back.

└── projectRoot
    ├── Extensions
    │   └── secsign
    │       └── Classes
    ├── composer.json
    └── public
        └── typo3conf
            └── ext
                └── secsign(symlink_by_composer)

Add this to your project composer.json:

  "repositories": {
    "0": {
      "type": "composer",
      "url": "https://composer.typo3.org/"
    },
    "1": {
      "type": "path",
      "url": "./Extensions/*",
      "options": {
        "symlink": true
      }
    }
  },

  ...

  "require": {
    "secsign/secsign": "*",
    ...
  },

Remove the second line from the autoload in your Extensions composer.json

public/Extensions/secsign/composer.json:

  "autoload": {
    "psr-4": {
      "Secsign\\Secsign\\": "Classes/"
    }
  },

Now composer loads your project composer.json, finds your Extension, symlinks it into typo3conf/ext/ and reads your extensions composer.json and executes it.

Loading all Ext into your project: When your done with all this changes, just do a composer update. This will load all your third party extensions into projectRoot/public/typo3conf/ext/ and symlink your custom extensions from secsign -> ../../../Extensions/secsign

Adding more custom Extensions: Just add your custom extension into Extension/, make sure it has a valid composer.json and include it with

composer req secsign/one-more-ext

2. Add your Classes to your project composer.json

Leave your Extension where it is, don't care about your extensions composer.json and just add your Classes to your project composer.json:

  "autoload": {
    "psr-4": {
      "Secsign\\Secsign\\": "htdocs/typo3conf/ext/secsign/Classes/"
    }
  },

Now composer autoloads the classes from your projects composer.json, your Extensions composer.json is not even executed.

Final

  1. seems to be easier, but there are several reasons to go for 1.
nito
  • 1,157
  • 8
  • 21
  • At the moment the repositories part of my projects composer.json looks like this: ` "repositories": [ { "type": "composer", "url": "https://composer.typo3.org/" } ], ` how would I add the repositories statement you mentioned? I cannot seem to figure it out. Also once that is done how to I load the extension into TYPO3? – Droemmelbert Nov 04 '19 at 14:59
  • @droemmelbert I added the typo3.org repo to the example above. Also I added how one more step to 1. – nito Nov 09 '19 at 18:17
  • I actually did. Loading it via the composer.json did the trick. Thanks! – Droemmelbert Jan 21 '20 at 21:28