Welcome Guest, Not a member yet? Register   Sign In
Documentation: Creating Composer Packages
#11

(08-01-2023, 12:23 AM)iRedds Wrote: Did you know that if you register a module in composer.json in the autoload section, the short config name won't work?
Since only modules registered in the Autoload config and installed via `composer require` are allowed.

No. I have no idea why it does not work.
Reply
#12

(08-01-2023, 12:47 AM)kenjis Wrote:
(08-01-2023, 12:23 AM)iRedds Wrote: Did you know that if you register a module in composer.json in the autoload section, the short config name won't work?
Since only modules registered in the Autoload config and installed via `composer require` are allowed.

No. I have no idea why it does not work.

But it's you who added the code that takes the installed packages and the namespaces registered in the composer, and if there are no matches in the paths, then the namespace is discarded.

https://github.com/codeigniter4/CodeIgni...5a0433be18
Reply
#13

@iRedds I cannot reproduce that  the short config name won't work.
Can you show steps to reproduce?

I was able to get the MyConfig object.

PHP Code:
<?php

namespace Home\Config;

class 
MyConfig
{
    public string $setting 'foo';


PHP Code:
<?php

namespace Home\Controllers;

use 
App\Controllers\BaseController;

class 
Home extends BaseController
{
    public function index()
    {
        dd(config('MyConfig'));
    }


Code:
    "autoload": {
        "psr-4": {
            "Home\\": "modules/Home/src"
        },
        "exclude-from-classmap": [
            "**/Database/Migrations/**"
        ]
    },

Code:
$ php spark namespaces

CodeIgniter v4.3.7 Command Line Tool - Server Time: 2023-08-01 08:31:59 UTC+00:00

+-----------------------+------------------------------------------------------------+--------+
| Namespace            | Path                                                      | Found? |
+-----------------------+------------------------------------------------------------+--------+
| CodeIgniter          | VENDORPATH/codeigniter4/framework/system                  | Yes    |
| App                  | ROOTPATH/app                                              | Yes    |
| Config                | APPPATH/Config                                            | Yes    |
| Tests\Support        | ROOTPATH/tests/_support                                    | Yes    |
| Psr\Log              | VENDORPATH/psr/log/Psr/Log                                | Yes    |
| Psr\Container        | VENDORPATH/psr/container/src                              | Yes    |
| PhpParser            | VENDORPATH/nikic/php-parser/lib/PhpParser                  | Yes    |
| Laminas\Escaper      | VENDORPATH/laminas/laminas-escaper/src                    | Yes    |
| Home                  | ROOTPATH/modules/Home/src                                  | Yes    |
| Faker                | VENDORPATH/fakerphp/faker/src/Faker                        | Yes    |
| Doctrine\Instantiator | VENDORPATH/doctrine/instantiator/src/Doctrine/Instantiator | Yes    |
| DeepCopy              | VENDORPATH/myclabs/deep-copy/src/DeepCopy                  | Yes    |
+-----------------------+------------------------------------------------------------+--------+
Reply
#14

(This post was last modified: 08-01-2023, 02:10 AM by iRedds.)

@kenjis I think the package developer should think ahead about the namespace name. So to speak, a test of maturity.

@kenjis I placed the module in the vendor directory.
That is, if
"Acme\\" : "vendor/Acme/" - class autoloading works but short config name is not present and also Acme namespace is not visible via "php spark namespaces" command.
"Acme\\" : "Acme/" - everything works as expected.

Why did I specify vendor/Acme/?
If the developer can use the composer locally, but not on the server (that is, the developer stores the vendor directory in the repository and copies it to the server), then in this case he may well place his module in the vendor directory.
I believe that there should be no such restriction.

@luckmoshy Yes, I may be biased. Like most of the core team. =)
Reply
#15

(08-01-2023, 01:38 AM)iRedds Wrote: @kenjis I placed the module in the vendor directory.
That is, if
"Acme\\" : "vendor/Acme/" - class autoloading works but short config name is not present and also Acme namespace is not visible via "php spark namespaces" command.
"Acme\\" : "Acme/" - everything works as expected.

Why did I specify vendor/Acme/?
If the developer can use the composer locally, but not on the server (that is, the developer stores the vendor directory in the repository and copies it to the server), then in this case he may well place his module in the vendor directory.
I believe that there should be no such restriction.

Okay, I got what you say.

We assume all packages in vendor/ are Composer packages (installed by composer),
and auto-discovery searches files in Composer package namespaces.
So your way does not work.

I think your way is a misuse, because Composer controls under vendor/.
If you put the module in vendor/, you should install it via composer.
Reply
#16

@sammyskills

Added "Choosing License":
https://codeigniter4.github.io/CodeIgnit...ng-license
Reply
#17

(08-01-2023, 07:01 PM)kenjis Wrote: @sammyskills

Added "Choosing License":
https://codeigniter4.github.io/CodeIgnit...ng-license

Great, thanks for the good work.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB