Skip to content

Commit

Permalink
Merge pull request #2 from mabdullahsari/custom-app-structure-support
Browse files Browse the repository at this point in the history
Support disjointed app and model namespaces
  • Loading branch information
rubenvanassche authored Dec 2, 2020
2 parents c4e55d9 + 6fef885 commit bd8b14b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ return [

'autogenerate' => true,

/**
* Change the base directory if the models don't reside in the default App namespace.
*
* For example, the base directory would become 'src' if:
* - Application is in src/App
* - Models are in src/Domain
*/

'base_directory' => '/',

/*
* Within these paths, the package will search for models to be included
* in the generated morph map.
Expand Down
10 changes: 10 additions & 0 deletions config/morph-map-generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@

'autogenerate' => true,

/**
* Change the base directory if the models don't reside in the default App namespace.
*
* For example, the base directory would become 'src' if:
* - Application is in src/App
* - Models are in src/Domain
*/

'base_directory' => '/',

/*
* Within these paths, the package will search for models to be included
* in the generated morph map.
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/CacheMorphMapCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ class CacheMorphMapCommand extends Command
public function handle(MorphMapCacheDriver $cache): void
{
[
'base_directory' => $baseDir,
'paths' => $paths,
'base_models' => $baseModels,
'ignored_models' => $ignoredModels,
] = config('morph-map-generator');

$discoveredModels = DiscoverModels::create()
->ignoreModels($ignoredModels)
->withBasePath(base_path($baseDir))
->withPaths($paths)
->withBaseModels($baseModels)
->discover();
Expand Down
1 change: 1 addition & 0 deletions src/MorphMapGeneratorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function register(): void

if (config('morph-map-generator.autogenerate')) {
$discoveredModels = DiscoverModels::create()
->withBasePath(base_path(config('morph-map.generator.base_directory')))
->withPaths(config('morph-map-generator.paths'))
->withBaseModels(config('morph-map-generator.base_models'))
->ignoreModels(config('morph-map-generator.ignored_models'))
Expand Down

0 comments on commit bd8b14b

Please sign in to comment.