PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 17, 2022

[FIXED] PHP Composer, command line (CLI) to add a class path to autoload PSR-4 / PSR-0 / file in composer.json

 January 17, 2022     autoload, command, command-line-interface, composer-php     No comments   

Issue

Does Composer have any Command from CLI to add to composer.json such entry?

{
    "autoload": {
        "psr-4": {
            "Monolog\\": "src/",
            "Vendor\\Namespace\\": ""
        }
    }
}

and add this:

{
    "autoload": {
        "psr-0": {
            "Monolog\\": "src/",
            "Vendor\\Namespace\\": "src/",
            "Vendor_Namespace_": "src/"
        }
    }
}

and this

{
    "autoload": {
        "classmap": ["src/", "lib/", "Something.php"]
    }
}

and this:

{
    "autoload": {
        "files": ["src/MyLibrary/functions.php"]
    }
}

I looked here: Composer Command Line Documentation

but haven't found any dedicated command. Perhaps there is a workaround command like:

composer add-entry <key> <value>

or

composer set-key <key> <value>

but I don't know such, do you know any?


Solution

Unfortunately NO. 😢 At least in v1.8.4 and I also want this feature too.

I thought the closest command would be config.

$ composer config bin-dir bin/
$ composer config repositories.github.com '{"type": "vcs", "url": "https://github.com/[YOUR]/[REPO]", "//url": "https://github.com/[YOUR]/[REPO].git"}'

Since this will add the following in composer.json:

"config": {
    "bin-dir": "bin/"
},
"repositories": {
    "github.com": {
        "type": "vcs",
        "url": "https://github.com/[YOUR]/[REPO]",
        "//url": "https://github.com/[YOUR]/[REPO].git"
    }
}

Though, this command seems to work only for "config" and "repositories" keys.

And then I found an issue about this topic. Seems that the community won't add this feature.😭

Yup I don't think we really want to offer this from CLI it's gonna be a bunch of code for very limited use as typically this is done once on package creation.

  • From: Issue #3398
    • "[Feature] Adding processing autoloading sections to the command line interface" @ GitHub


Answered By - KEINOS
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing