From 248e117497c6099cff3087b0f0f427b9ea584b04 Mon Sep 17 00:00:00 2001 From: Milwad <98118400+milwad-dev@users.noreply.github.com> Date: Tue, 16 Apr 2024 19:11:38 +0330 Subject: [PATCH] [11.x] Add namespace for `make:trait` and `make:interface` command (#51083) * Update InterfaceMakeCommand.php * Update TraitMakeCommand.php * Update TraitMakeCommand.php --------- Co-authored-by: Taylor Otwell --- .../Foundation/Console/InterfaceMakeCommand.php | 15 +++++++++++++++ .../Foundation/Console/TraitMakeCommand.php | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/Illuminate/Foundation/Console/InterfaceMakeCommand.php b/src/Illuminate/Foundation/Console/InterfaceMakeCommand.php index 2e864de169cd..6601be632da0 100644 --- a/src/Illuminate/Foundation/Console/InterfaceMakeCommand.php +++ b/src/Illuminate/Foundation/Console/InterfaceMakeCommand.php @@ -40,6 +40,21 @@ protected function getStub() return __DIR__.'/stubs/interface.stub'; } + /** + * Get the default namespace for the class. + * + * @param string $rootNamespace + * @return string + */ + protected function getDefaultNamespace($rootNamespace) + { + return match (true) { + is_dir(app_path('Contracts')) => $rootNamespace.'\\Contracts', + is_dir(app_path('Interfaces')) => $rootNamespace.'\\Interfaces', + default => $rootNamespace, + }; + } + /** * Get the console command arguments. * diff --git a/src/Illuminate/Foundation/Console/TraitMakeCommand.php b/src/Illuminate/Foundation/Console/TraitMakeCommand.php index 5d98d1c9ce0e..a66b1b1d657b 100644 --- a/src/Illuminate/Foundation/Console/TraitMakeCommand.php +++ b/src/Illuminate/Foundation/Console/TraitMakeCommand.php @@ -53,6 +53,21 @@ protected function resolveStubPath($stub) : __DIR__.$stub; } + /** + * Get the default namespace for the class. + * + * @param string $rootNamespace + * @return string + */ + protected function getDefaultNamespace($rootNamespace) + { + return match (true) { + is_dir(app_path('Concerns')) => $rootNamespace.'\\Concerns', + is_dir(app_path('Traits')) => $rootNamespace.'\\Traits', + default => $rootNamespace, + }; + } + /** * Get the console command arguments. *