Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update config.php #1628

Merged
merged 6 commits into from
Oct 26, 2023
Merged

Update config.php #1628

merged 6 commits into from
Oct 26, 2023

Conversation

solomon-ochepa
Copy link
Contributor

Format the file structure to the current Laravel standard.

These changes will only apply to newly created modules.

Format the file structure to the current Laravel standard.
@dcblogdev dcblogdev closed this Oct 22, 2023
@solomon-ochepa
Copy link
Contributor Author

Please, I need an explanation as to why this PR was closed without being merged.

This particular PR is crucial, and I expected it to be treated before any other. Please quote me if I'm wrong!

@dcblogdev
Copy link
Collaborator

this is making sweeping changes that I don't want. This would require a version dump due to breaking changes.

In future, before making fundamental changes I suggest asking to see if it would be well received to save your time.

You're free to change the config to your liking in your application. I try to keep changes in the config to essential changes only to avoid breaking existing applications that may not have published the config file.

@solomon-ochepa
Copy link
Contributor Author

solomon-ochepa commented Oct 22, 2023

this is making sweeping changes that I don't want. This would require a version dump due to breaking changes.

In future, before making fundamental changes I suggest asking to see if it would be well received to save your time.

You're free to change the config to your liking in your application. I try to keep changes in the config to essential changes only to avoid breaking existing applications that may not have published the config file.

You are right, but not in all aspects.

'statuses-file' => base_path('modules.json'),

There is a breaking change at line: 274, which is true (sorry, my mistake).

However, the rest of the code is as clean as possible, and wouldn't cause any form of breaking changes from Laravel 5 up to date.

Please, do point out any of the other observations.

Thanks.

@solomon-ochepa
Copy link
Contributor Author

Please, can you reopen the PR so I can make an edit so we can continue the review?

@dcblogdev dcblogdev reopened this Oct 22, 2023
@dcblogdev
Copy link
Collaborator

You're right the generator changes don't break existing modules. I don't think its a good idea to be a mix of namespaces names ie:

a controller would have lower case app

namespace Modules\Contacts\app\Http\Controllers;

or a seeder

namespace Modules\Contacts\database\seeders;

They would be better to match the style ie

namespace Modules\Contacts\App\Http\Controllers;
namespace Modules\Contacts\Database\Seeders;

@solomon-ochepa
Copy link
Contributor Author

solomon-ochepa commented Oct 22, 2023

They would be better to match the style ie

namespace Modules\Contacts\App\Http\Controllers;
namespace Modules\Contacts\Database\Seeders;

That's not correct, following the Laravel code standard.

Note that the namespace should be assigned in accordance with the path! Note that the /app and /database/seeders directories are in lower case.

@dcblogdev
Copy link
Collaborator

I disagree, for instance, looking at seeders from Laravel their namespace is Database\Seeders not database\seeders

Reverse activator filename to `modules_statuses.json`
@solomon-ochepa
Copy link
Contributor Author

solomon-ochepa commented Oct 22, 2023

I disagree, for instance, looking at seeders from Laravel their namespace is Database\Seeders not database\seeders

That's true. It's configured via the composer autoload: psr-4 rule. Laravel modules on the other side only loaded the Modules/ path.

Can you please review the standard Laravel's composer.json?

    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/",
            "Modules\\": "Modules/"
        }
    },

Screenshot_20231022-185347.png

Notwithstanding, I think your concept may be possible if we added these same rules to each generated module's composer.json file.

Moreover, in a future release, you may consider renaming the root path from /Modules to /modules.

Thanks.

@solomon-ochepa
Copy link
Contributor Author

solomon-ochepa commented Oct 24, 2023

Hi, @dcblogdev.

I'm still waiting for you here, please.

@dcblogdev
Copy link
Collaborator

dcblogdev commented Oct 25, 2023

if you can get this to work with the namespaces Modules\Books\Http\Controllers etc we can move forward.

I've tried the config and adding

"psr-4": {
    "Modules\\Books\\": "app/",
    "Modules\\Books\\Tests\\": "tests",
    "Modules\\Books\\Database\\Factories\\": "database/factories",
    "Modules\\Books\\Database\\Seeders\\": "database/seeders"
}

but having problems getting this to work.

@solomon-ochepa
Copy link
Contributor Author

solomon-ochepa commented Oct 26, 2023

If you can get this to work with the namespaces Modules\Books\Http\Controllers etc we can move forward.

I've tried the config and adding

"psr-4": {
    "Modules\\Books\\": "app/",
    "Modules\\Books\\Tests\\": "tests",
    "Modules\\Books\\Database\\Factories\\": "database/factories",
    "Modules\\Books\\Database\\Seeders\\": "database/seeders"
}

but having problems getting this to work.

You are complicating the whole process! This PR has nothing to do with the composer.json file within each module, as illustrated in your example above.

This PR aims to give each new module the same file structure as the latest Laravel version.

From Laravel v5.* to the current v10.*, the Controller's namespace, for instance, has been app/Http/Controllers.

So, if a new module Book is to be created using the latest Laravel version, it would be Modules\Books\ app\Http\Controllers, instead of Modules\Books\ Http\Controllers as given in your example above.

Making the app in the namespace appear as App is not the aim of this PR in the first place, so where is your argument coming from?

We can work on making the app appear as App in subsequent PR, but not within the scope of this particular PR, in the sense that the /composer.json responsible for this PR effect is entirely different from the /Modules/Books/composer.json, responsible for the result you are seeking. Do you get my point now?

@solomon-ochepa
Copy link
Contributor Author

solomon-ochepa commented Oct 26, 2023

...
I've tried the config and adding

"psr-4": {
    "Modules\\Books\\": "app/",
    "Modules\\Books\\Tests\\": "tests",
    "Modules\\Books\\Database\\Factories\\": "database/factories",
    "Modules\\Books\\Database\\Seeders\\": "database/seeders"
}

but having problems getting this to work.

Please take note of the "Modules\\Books\\": "app/" it should be "Modules\\Books\\App": "app/" instead.

Try this out instead:

"psr-4": {
    "Modules\\Books\\": "",
    "Modules\\Books\\App\\": "app/",
    "Modules\\Books\\Tests\\": "tests/",
    "Modules\\Books\\Database\\Factories\\": "database/factories/",
    "Modules\\Books\\Database\\Seeders\\": "database/seeders/"
}

Copy link
Contributor Author

@solomon-ochepa solomon-ochepa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The namespace can be changed from the config file.

Notwithstanding, I'm working on how to get the value directly from the module's composer.json file.

@dcblogdev dcblogdev merged commit 2991616 into nWidart:master Oct 26, 2023
1 of 4 checks passed
@mstojanovv
Copy link

This change has resulted in a less appealing namespace structure, in fact, not really following Laravel modern architecture or standards.

The usage of lowercase directory namespace like Modules\ModuleName\app\Providers, Modules\ModuleName\database\seeders, affects the overall code.

I believe that @dcblogdev or @solomon-ochepa should have addressed the issue of these lowercase directory related namespace, including app, database, and any others located at the root of the module, before merging the change into the package.

The PR is great, but using a lowercase namespace folder is not that much.

Despite my attempts to find various solutions, I haven't found any solution to make it working.

@solomon-ochepa
Copy link
Contributor Author

This change has resulted in a less appealing namespace structure, in fact, not really following Laravel modern architecture or standards.

The usage of lowercase directory namespace like Modules\ModuleName\app\Providers, Modules\ModuleName\database\seeders, affects the overall code.

I believe that @dcblogdev or @solomon-ochepa should have addressed the issue of these lowercase directory related namespace, including app, database, and any others located at the root of the module, before merging the change into the package.

The PR is great, but using a lowercase namespace folder is not that much.

Despite my attempts to find various solutions, I haven't found any solution to make it working.

Point of correction, the structures are accurate and follows Laravel current standard.

The only point we are currently missing and seeking solution to is how to map the namespaces.

Like in Laravel, the app/, database/migrations/ & database/seeders namespaces are not based on the paths lowercase names, but rather were config via the composer.json file.

We are currently working towards that, in short we have added the necessary properties to the Module's composer.json already.

So, please, this issue has nothing to do with the lowercase directories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants