@@ -33,6 +33,7 @@ abstract class EntityGenerator
3333 'database_seeder ' => 'database/seeders ' ,
3434 'tests ' => 'tests ' ,
3535 'routes ' => 'routes ' ,
36+ 'translations ' => 'lang/en ' ,
3637 ];
3738
3839 protected $ paths = [];
@@ -89,11 +90,13 @@ public function setRelations(RelationsDTO $relations): self
8990 public function __construct ()
9091 {
9192 $ this ->paths = config ('entity-generator.paths ' );
93+
94+ $ this ->checkConfigHasCorrectPaths ();
9295 }
9396
94- protected function getNamespace (string $ configPath , ?string $ subFolder = null ): string
97+ protected function generateNamespace (string $ path , ?string $ additionalSubFolder = null ): string
9598 {
96- $ pathParts = $ this ->getNamespacePathParts ($ configPath , $ subFolder );
99+ $ pathParts = $ this ->getNamespacePathParts ($ path , $ additionalSubFolder );
97100
98101 $ namespace = array_map (fn (string $ part ) => ucfirst ($ part ), $ pathParts );
99102
@@ -102,7 +105,7 @@ protected function getNamespace(string $configPath, ?string $subFolder = null):
102105
103106 protected function createNamespace (string $ configPath , ?string $ subFolder = null ): void
104107 {
105- $ path = $ this ->getPath ($ configPath , $ subFolder );
108+ $ path = $ this ->getPath ($ this -> paths [ $ configPath] , $ subFolder );
106109
107110 $ fullPath = base_path ($ path );
108111
@@ -111,26 +114,20 @@ protected function createNamespace(string $configPath, ?string $subFolder = null
111114 }
112115 }
113116
114- protected function getNamespacePathParts (string $ configPath , ?string $ subFolder = null ): array
117+ protected function getNamespacePathParts (string $ path , ?string $ additionalSubFolder = null ): array
115118 {
116- $ pathParts = explode ('/ ' , $ this ->getPath ($ configPath , $ subFolder ));
119+ $ pathParts = explode ('/ ' , $ this ->getPath ($ path , $ additionalSubFolder ));
117120
118121 if (Str::endsWith (Arr::last ($ pathParts ), '.php ' )) {
119122 array_pop ($ pathParts );
120123 }
121124
122- foreach ($ pathParts as $ part ) {
123- if (!$ this ->isFolderHasCorrectCase ($ part , $ configPath )) {
124- throw new IncorrectClassPathException ("Incorrect path to {$ configPath }, {$ part } folder must start with a capital letter, please specify the path according to the PSR. " );
125- }
126- }
127-
128125 return $ pathParts ;
129126 }
130127
131- protected function getPath (string $ configPath , ?string $ subFolder = null ): string
128+ protected function getPath (string $ path , ?string $ subFolder = null ): string
132129 {
133- return when ($ subFolder , fn () => Str::finish ($ this -> paths [ $ configPath ] , '/ ' ) . $ subFolder , $ this -> paths [ $ configPath ] );
130+ return when ($ subFolder , fn () => Str::finish ($ path , '/ ' ) . $ subFolder , $ path );
134131 }
135132
136133 protected function isFolderHasCorrectCase (string $ folder , string $ configPath ): bool
@@ -155,7 +152,7 @@ protected function classExists(string $path, string $name, ?string $subFolder =
155152
156153 protected function getClassPath (string $ path , string $ name , ?string $ subFolder = null ): string
157154 {
158- $ path = $ this ->getPath ($ path , $ subFolder );
155+ $ path = $ this ->getPath ($ this -> paths [ $ path] , $ subFolder );
159156
160157 return "{$ path }/ {$ name }.php " ;
161158 }
@@ -270,7 +267,7 @@ protected function getModelClass(string $model): string
270267 {
271268 $ subfolder = when ($ model === $ this ->model , $ this ->modelSubFolder );
272269
273- $ modelNamespace = $ this ->getNamespace ( 'models ' , $ subfolder );
270+ $ modelNamespace = $ this ->generateNamespace ( $ this -> paths [ 'models ' ] , $ subfolder );
274271
275272 return "{$ modelNamespace }\\{$ model }" ;
276273 }
@@ -310,6 +307,19 @@ protected function pathToNamespace(string $name): string
310307 return ucwords (Str::replace ('/ ' , '\\' , $ name ), '\\' );
311308 }
312309
310+ protected function checkConfigHasCorrectPaths (): void
311+ {
312+ foreach ($ this ->paths as $ configPath => $ path ) {
313+ $ pathParts = $ this ->getNamespacePathParts ($ path );
314+
315+ foreach ($ pathParts as $ part ) {
316+ if (!$ this ->isFolderHasCorrectCase ($ part , $ configPath )) {
317+ throw new IncorrectClassPathException ("Incorrect path to {$ configPath }, {$ part } folder must start with a capital letter, please specify the path according to the PSR. " );
318+ }
319+ }
320+ }
321+ }
322+
313323 protected function checkResourceExists (string $ path , string $ resourceName , ?string $ subFolder = null ): void
314324 {
315325 if ($ this ->classExists ($ path , $ resourceName , $ subFolder )) {
0 commit comments