safe icon indicating copy to clipboard operation
safe copied to clipboard

New, autoloader-centric file structure

Open szepeviktor opened this issue 2 years ago • 5 comments

Aka. for machines only

repo/
├─ generated/
│  ├─ src/
│  ├─ functions.php
  • all classes go (generated or copied) in src directory as per PSR-4
  • all functions go (generated or copied) into functions.php file
  • keep generated/functionsList.php
  • deprecated things get a PHPDoc tag
/**
 * @deprecated Reason, date, version ...
 */

Resulting Composer config.

    "autoload": {
        "psr-4": {
            "Safe\\": [
                "generated/src/"
            ]
        },
        "files": [
            "generated/functions.php"
        ]
    },

All other directories could be excluded from distribution.

Would you support a PR that modifies the generator?

szepeviktor avatar Apr 25 '22 18:04 szepeviktor

@Kharhamel I understand it may hurt your feelings.

szepeviktor avatar Apr 25 '22 18:04 szepeviktor

Asked how to do it: https://github.com/rectorphp/rector/issues/7131

szepeviktor avatar Apr 26 '22 02:04 szepeviktor

I am not sure I understand the link with rector but yes, that new structure looks good, i would definitly like a PR to do that, especially if it solves issues like #253.

However I am thinking really hard about generating several directories of functions, to be loaded depending of the php version of the client. Do you think we could do something like this:

repo/
├─ generated-lastest/
│  ├─ src/
│  ├─ functions.php
├─ generated-7.4/
│  ├─ src/
│  ├─ functions.php

And then the autoload config in composer would reference a single entrypoint file that would redirect us to the correct folder depending on the php version?

Kharhamel avatar Apr 26 '22 08:04 Kharhamel

to be loaded depending of the php version of the client

That is done by keeping one git branch for each PHP version. At least many other packages do it this way.

szepeviktor avatar Apr 26 '22 08:04 szepeviktor

I am not sure I understand the link with rector

That Rector issue is about automatically combining many .php files into one functions.php.

szepeviktor avatar Apr 26 '22 08:04 szepeviktor