Best way to override single method in Illuminate\Foundation\Application through service provider

134 Views Asked by At

I just made changes to the application structure for my Laravel application. It works well when runnning tests (for the Http controllers). The problem is when i try to run artisan commands (that literally need to access "getNamespace()" method), it wont resolve the namespaces.

Here are the composer.json:

 "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/",
            "Modules\\": "modules/"
        },
        "files": [
            "app/Helpers/app.php",
            "app/Helpers/form.php",
            "app/Helpers/view.php"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },

I do aware that i can add Modules\ModuleA, Modules\ModuleB to the composer json, but that put alot of work. So i decided to override the getNamespace() method instead, but what is the best way to override single method illuminate/foundation/xxx classes through service provider?

Folder tree:

laravel-project/
├── app/
│   ├── Exception
│   ├── Providers
│   └── ...
├── modules/
│   ├── ModuleA/
│   │   ├── Services
│   │   ├── Http/
│   │   │   ├── Controllers
│   │   │   └── Requests
│   │   └── Models
│   └── ModuleB/
│       └── ...
├── tests
└── ...
0

There are 0 best solutions below