helhum / typo3-secure-web

Secure your TYPO3 installation by only exposing public files
60 stars 12 forks source link

Packages in ./packages autoloading issues #16

Closed pquerner closed 5 years ago

pquerner commented 5 years ago

Hey, I am going by the official guidelines (https://docs.typo3.org/m/typo3/guide-installation/master/en-us/MigrateToComposer/BestPractices.html) and playing with having my extensions in ./packages/*. That all works fine, but sometimes some classes cannot be found and it errors with

Fatal error: Trait 'CuD\Base\Traits\GlobalUidsTrait' not found in /var/www/html/packages/ext-cud_recipes/Classes/Controller/RecipeController.php on line 27

I tried with the full namespace, but also with namespace import

class RecipeController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{

    use \CuD\Base\Traits\GlobalUidsTrait;

CuD\\Base is in autoload_psr4.php of composer's autoloader.

'Cud\\Base\\' => array($baseDir . '/private/typo3conf/ext/cud_baseext/Classes'),

Pathing:

ls -lah
total 0
drwxr-xr-x  16 pascal.querner  staff   512B Aug 23 10:59 .
drwxr-xr-x   8 pascal.querner  staff   256B Aug 23 10:59 ..
lrwxr-xr-x   1 pascal.querner  staff    30B Aug 23 10:42 cud_baseext -> ../../../packages/ext-cud_base
lrwxr-xr-x   1 pascal.querner  staff    33B Aug 23 10:42 cud_recipes -> ../../../packages/ext-cud_recipes
➜  ext git:(develop) ✗ pwd
/Users/pq/projects/xxx/typo3-cms/private/typo3conf/ext

composer.jsonof cud_base

{
    "name": "cud/cud_baseext",
    "type": "typo3-cms-extension",
    "description": "xxx",
    "homepage": "xxx",
    "license": ["GPL-2.0-or-later"],
    "version": "1.0.0",
    "require": {
        "typo3/cms-core": "^8.7 || ^9.5",
        "typo3/cms-rte-ckeditor": "^8.7 || ^9.5",
        "bk2k/bootstrap-package": "^10.0"
    },
    "autoload": {
        "psr-4": {
            "Cud\\Base\\": "Classes"
        }
    },
    "replace": {
      "cud_baseext": "self.version",
      "typo3-ter/cud_baseext": "self.version"
    }
}

My best guess currently is, that because it got symlinked form ./packages/ to private/typo3conf/ext it cannot resolve the namespace imports?

Or does someone else have more input here?

Thanks!

helhum commented 5 years ago

My first question would be: why do you think your issues are related to this package? I don't think they are. :)

To your question: Hard to say without knowing details of your setup. From guessing it could be:

  1. A Composer bug
  2. Windows issue with symlinks
  3. File name casing issue
helhum commented 5 years ago

My suggestion would be to debug through the Composer autoloader and find out why these classes cannot be found.

pquerner commented 5 years ago

My guess its related to this package, since its the one that splits public and private. My intention here is to find out, if thats the case or not.

I am on MacOS 10.14 here, running ddev locally. I have not tested this against Windows.

When I didnt split the folders (no private, just public folder) it worked fine.

Yes, it can be a composer bug. I'll try and debug through that.

helhum commented 5 years ago

From a class loading perspective (which actually is the issue you describe) this package changes nothing. It does not „split“ things, but just adds an additional folder. So the issues you are seeing are unrelated to this package.

But let me know what you find out in any case. I’m also happy to re-open the ticket when it turns out I’m wrong.

fgerards commented 1 year ago

I have the same issue on CentOS 9 - composer/PHP follows the symlinks to the "packages" directory, which is outside the webservers DocumentRoot. This is a structural issue and to my mind it is related to secure-web extension: The PHP Files are NOT residing in the document root, in a normal installation, they are.

helhum commented 1 year ago

@fgerards PHP files do not need to reside in the document root. I have no clue about your exact setup, though. The PHP files must be accessible of course on the file system. It still is not related to this package, but likely a setup / server issue.

Note that with TYPO3 12, all PHP files are outside the document root as well (as in may other PHP applications)